aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-tasks')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/PnfConfigCdsControllerDE.java (renamed from bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java)17
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDE.java92
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETestIT.java142
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/PnfConfigCdsControllerDETest.java (renamed from bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java)43
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDETest.java143
5 files changed, 378 insertions, 59 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/PnfConfigCdsControllerDE.java
index 0f65b4b3d4..ffd49e6b84 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/PnfConfigCdsControllerDE.java
@@ -24,6 +24,7 @@ import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable;
import org.onap.so.bpmn.infrastructure.decisionpoint.api.controller.ControllerPreparable;
import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
+import org.onap.so.client.cds.PayloadConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -31,17 +32,23 @@ import org.springframework.stereotype.Component;
* This implementation of {@ref ControllerRunnable} is used for Self service, i.e, blueprint based Controller.
*/
@Component
-public class CdsControllerDE implements ControllerRunnable<DelegateExecution> {
+public class PnfConfigCdsControllerDE implements ControllerRunnable<DelegateExecution> {
+
+ private static final String ASSIGN_ACTION = "config-assign";
+ private static final String DEPLOY_ACTION = "config-deploy";
@Autowired(required = false)
private List<ControllerPreparable<DelegateExecution>> prepareList;
@Autowired
- private AbstractCDSProcessingBBUtils abstractCDSProcessingBBUtils;
+ private AbstractCDSProcessingBBUtils cdsDispatcher;
@Override
public Boolean understand(ControllerContext<DelegateExecution> context) {
- return context.getControllerActor().equalsIgnoreCase("cds");
+ return PayloadConstants.CDS_ACTOR.equalsIgnoreCase(context.getControllerActor())
+ && PayloadConstants.PNF_SCOPE.equalsIgnoreCase(context.getControllerScope())
+ && (ASSIGN_ACTION.equalsIgnoreCase(context.getControllerAction())
+ || DEPLOY_ACTION.equalsIgnoreCase(context.getControllerAction())); // legacy behavior
}
@Override
@@ -58,7 +65,7 @@ public class CdsControllerDE implements ControllerRunnable<DelegateExecution> {
@Override
public void run(ControllerContext<DelegateExecution> context) {
DelegateExecution execution = context.getExecution();
- abstractCDSProcessingBBUtils.constructExecutionServiceInputObject(execution);
- abstractCDSProcessingBBUtils.sendRequestToCDSClient(execution);
+ cdsDispatcher.constructExecutionServiceInputObject(execution);
+ cdsDispatcher.sendRequestToCDSClient(execution);
}
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDE.java
new file mode 100644
index 0000000000..d5423b2ff7
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDE.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
+import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
+import org.onap.so.client.cds.GeneratePayloadForCds;
+import org.onap.so.client.cds.PayloadConstants;
+import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * For pnf, DelegateExecution is being used.
+ *
+ * @param - DelegateExecution
+ */
+@Component
+public class GenericPnfCDSProcessingDE implements ControllerRunnable<DelegateExecution> {
+ private static final Logger logger = LoggerFactory.getLogger(GenericPnfCDSProcessingDE.class);
+ private static final String EXECUTION_OBJECT = "executionObject";
+ private static final String ASSIGN_ACTION = "config-assign";
+ private static final String DEPLOY_ACTION = "config-deploy";
+
+ @Autowired
+ private ExceptionBuilder exceptionBuilder;
+
+ @Autowired
+ private AbstractCDSProcessingBBUtils cdsDispather;
+
+ @Autowired
+ private GeneratePayloadForCds generatePayloadForCds;
+
+ @Override
+ public Boolean understand(ControllerContext<DelegateExecution> context) {
+ final String scope = context.getControllerScope();
+ return PayloadConstants.CDS_ACTOR.equalsIgnoreCase(context.getControllerActor())
+ && PayloadConstants.PNF_SCOPE.equalsIgnoreCase(scope)
+ && !(ASSIGN_ACTION.equalsIgnoreCase(context.getControllerAction())
+ || DEPLOY_ACTION.equalsIgnoreCase(context.getControllerAction()));
+ }
+
+ @Override
+ public Boolean ready(ControllerContext<DelegateExecution> context) {
+ return true;
+ }
+
+ @Override
+ public void prepare(ControllerContext<DelegateExecution> context) {
+ DelegateExecution delegateExecution = context.getExecution();
+ try {
+ AbstractCDSPropertiesBean abstractCDSPropertiesBean =
+ generatePayloadForCds.buildCdsPropertiesBean(delegateExecution);
+
+ delegateExecution.setVariable(EXECUTION_OBJECT, abstractCDSPropertiesBean);
+
+ } catch (Exception ex) {
+ logger.error("An exception occurred when creating payload for CDS request", ex);
+ exceptionBuilder.buildAndThrowWorkflowException(delegateExecution, 7000, ex);
+ }
+ }
+
+ @Override
+ public void run(ControllerContext<DelegateExecution> context) {
+ DelegateExecution obj = context.getExecution();
+ cdsDispather.constructExecutionServiceInputObject(obj);
+ cdsDispather.sendRequestToCDSClient(obj);
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETestIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETestIT.java
index 860780a2fc..275cd18f0b 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETestIT.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETestIT.java
@@ -19,50 +19,63 @@
package org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.AssertionsForClassTypes.fail;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MODEL_UUID;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MSO_REQUEST_ID;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_NAME;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_VERSION;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_CUSTOMIZATION_UUID;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_INSTANCE_NAME;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
import com.google.protobuf.Struct;
-import java.util.List;
import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.so.BaseIntegrationTest;
import org.onap.so.GrpcNettyServer;
-import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.client.aai.AAIVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.junit4.rules.SpringClassRule;
+import org.springframework.test.context.junit4.rules.SpringMethodRule;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.fail;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.*;
+@RunWith(Parameterized.class)
public class ControllerExecutionDETestIT extends BaseIntegrationTest {
private Logger logger = LoggerFactory.getLogger(this.getClass());
+ @ClassRule
+ public static final SpringClassRule springClassRule = new SpringClassRule();
+
+ @Rule
+ public final SpringMethodRule smr = new SpringMethodRule();
+
+ private static final String DOWNLOAD_ACTION = "downloadNeSw";
+ private static final String ACTIVATE_ACTION = "activateNeSw";
+ private static final String PRECHECK_ACTION = "precheck";
+ private static final String POSTCHECK_ACTION = "postcheck";
+ private static final String ASSIGN_ACTION = "config-assign";
+ private static final String DEPLOY_ACTION = "config-deploy";
+ private static final String CDS_ACTOR = "cds";
+
@Autowired
private ControllerExecutionDE controllerExecutionDE;
@Autowired
private GrpcNettyServer grpcNettyServer;
- private GenericVnf genericVnf;
-
private static String TEST_MODEL_UUID = "6bc0b04d-1873-4721-b53d-6615225b2a28";
private static String TEST_SERVICE_INSTANCE_ID = "test_service_id";
private static String TEST_PROCESS_KEY = "processKey1";
private static String TEST_MSO_REQUEST_ID = "ff874603-4222-11e7-9252-005056850d2e";
- private static String TEST_CDS_ACTION = "config-assign";
- private static String TEST_APPC_ACTION = "HealthCheck";
+ private static final AAIVersion VERSION = AAIVersion.LATEST;
private static String TEST_PNF_RESOURCE_INSTANCE_NAME = "PNF_demo_resource";
private static String TEST_PNF_CORRELATION_ID = "PNFDemo";
@@ -70,75 +83,112 @@ public class ControllerExecutionDETestIT extends BaseIntegrationTest {
private static String TEST_PNF_RESOURCE_BLUEPRINT_VERSION = "1.0.1";
private static String TEST_PNF_RESOURCE_CUSTOMIZATION_UUID = "9acb3a83-8a52-412c-9a45-901764938144";
private static String TEST_PNF_UUID = "5df8b6de-2083-11e7-93ae-92361f002671";
+ private static String TEST_SOFTWARE_VERSION = "demo-sw-ver2.0.0";
+
+ private String description;
+ private String action;
+ private String scope;
+
+ public ControllerExecutionDETestIT(String desc, String action, String scope) {
+ this.description = desc;
+ this.action = action;
+ this.scope = scope;
+
+ }
+
+ @Parameterized.Parameters(name = "index {0}")
+ public static Collection<String[]> data() {
+ return Arrays.asList(
+ new String[][] {{"Test JSON for action:" + ACTIVATE_ACTION + " scope:pnf", ACTIVATE_ACTION, "pnf"},
+ {"Test JSON for action:" + DOWNLOAD_ACTION + " scope:pnf", DOWNLOAD_ACTION, "pnf"},
+ {"Test JSON for action:" + ASSIGN_ACTION + " scope:pnf", ASSIGN_ACTION, "pnf"},
+ {"Test JSON for action:" + DEPLOY_ACTION + " scope:pnf", DEPLOY_ACTION, "pnf"},
+ {"Test JSON for action:" + PRECHECK_ACTION + " scope:pnf", PRECHECK_ACTION, "pnf"},
+ {"Test JSON for action:" + POSTCHECK_ACTION + " scope:pnf", POSTCHECK_ACTION, "pnf"}});
+ }
@Before
public void setUp() {
+ delegateExecution.setVariable("testProcessKey", TEST_PROCESS_KEY);
+ delegateExecution.setVariable(PNF_CORRELATION_ID, TEST_PNF_CORRELATION_ID);
delegateExecution.setVariable(MODEL_UUID, TEST_MODEL_UUID);
delegateExecution.setVariable(SERVICE_INSTANCE_ID, TEST_SERVICE_INSTANCE_ID);
delegateExecution.setVariable(MSO_REQUEST_ID, TEST_MSO_REQUEST_ID);
- delegateExecution.setVariable("testProcessKey", TEST_PROCESS_KEY);
+ delegateExecution.setVariable(PNF_UUID, TEST_PNF_UUID);
+ delegateExecution.setVariable(PRC_INSTANCE_NAME, TEST_PNF_RESOURCE_INSTANCE_NAME);
+ delegateExecution.setVariable(PRC_CUSTOMIZATION_UUID, TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
+ delegateExecution.setVariable(PRC_BLUEPRINT_NAME, TEST_PNF_RESOURCE_BLUEPRINT_NAME);
+ delegateExecution.setVariable(PRC_BLUEPRINT_VERSION, TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
+ delegateExecution.setVariable("targetSoftwareVersion", TEST_SOFTWARE_VERSION);
+
+ delegateExecution.setVariable("actor", CDS_ACTOR);
+ delegateExecution.setVariable("action", this.action);
+ delegateExecution.setVariable("scope", this.scope);
+
+
+ /**
+ * Get the PNF entry from AAI.
+ */
+ if (action.equalsIgnoreCase(DEPLOY_ACTION)) {
+ final String aaiPnfEntry = "{ \n" + " \"pnf-name\":\"PNFDemo\",\n" + " \"pnf-id\":\"testtest\",\n"
+ + " \"in-maint\":true,\n" + " \"resource-version\":\"1541720264047\",\n"
+ + " \"ipaddress-v4-oam\":\"1.1.1.1\",\n" + " \"ipaddress-v6-oam\":\"::/128\"\n" + "}";
+ wireMockServer.stubFor(
+ get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry)));
+ }
grpcNettyServer.cleanMessage();
}
@Test
- public void testExecution_cdsConfigAssign_actionExecuted() {
-
- configureCdsConfigAssign();
+ public void testExecution_cds_actions() {
controllerExecutionDE.execute(delegateExecution);
List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
assertThat(detailedMessages).hasSize(1);
try {
- checkConfigAssign(detailedMessages.get(0));
+ verifyRequestContentForAction(detailedMessages.get(0));
} catch (Exception e) {
e.printStackTrace();
- fail("ConfigAssign request exception", e);
+ fail(this.action + " request exception", e);
}
}
- private void configureCdsConfigAssign() {
- delegateExecution.setVariable("actor", "cds");
- delegateExecution.setVariable("action", TEST_CDS_ACTION);
- delegateExecution.setVariable("scope", "pnf");
+ private void verifyRequestContentForAction(ExecutionServiceInput executionServiceInput) {
- delegateExecution.setVariable(PNF_CORRELATION_ID, TEST_PNF_CORRELATION_ID);
- delegateExecution.setVariable(PNF_UUID, TEST_PNF_UUID);
- delegateExecution.setVariable(PRC_INSTANCE_NAME, TEST_PNF_RESOURCE_INSTANCE_NAME);
- delegateExecution.setVariable(PRC_CUSTOMIZATION_UUID, TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
- delegateExecution.setVariable(PRC_BLUEPRINT_NAME, TEST_PNF_RESOURCE_BLUEPRINT_NAME);
- delegateExecution.setVariable(PRC_BLUEPRINT_VERSION, TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
- }
-
- private void checkConfigAssign(ExecutionServiceInput executionServiceInput) {
-
- logger.info("Checking the configAssign request");
+ logger.info("Checking the " + this.action + " request");
ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
- /**
- * the fields of actionIdentifiers should match the one in the
- * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
- */
assertThat(actionIdentifiers.getBlueprintName()).isEqualTo(TEST_PNF_RESOURCE_BLUEPRINT_NAME);
assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo(TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
- assertThat(actionIdentifiers.getActionName()).isEqualTo(TEST_CDS_ACTION);
- assertThat(actionIdentifiers.getMode()).isEqualTo("sync");
+ assertThat(actionIdentifiers.getActionName()).isEqualTo(this.action);
CommonHeader commonHeader = executionServiceInput.getCommonHeader();
assertThat(commonHeader.getOriginatorId()).isEqualTo("SO");
assertThat(commonHeader.getRequestId()).isEqualTo(TEST_MSO_REQUEST_ID);
Struct payload = executionServiceInput.getPayload();
- Struct requeststruct = payload.getFieldsOrThrow("config-assign-request").getStructValue();
+ Struct requeststruct = payload.getFieldsOrThrow(this.action + "-request").getStructValue();
assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue())
.isEqualTo(TEST_PNF_CORRELATION_ID);
- Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-assign-properties").getStructValue();
+ Struct propertiesStruct = requeststruct.getFieldsOrThrow(this.action + "-properties").getStructValue();
assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo(TEST_PNF_CORRELATION_ID);
assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()).isEqualTo(TEST_MODEL_UUID);
assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
.isEqualTo(TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
+ if (action.equalsIgnoreCase(DEPLOY_ACTION)) {
+ assertThat(actionIdentifiers.getMode()).isEqualTo("async");
+ assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv4-address").getStringValue()).isEqualTo("1.1.1.1");
+ assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv6-address").getStringValue()).isEqualTo("::/128");
+ } else if (!action.equalsIgnoreCase(ASSIGN_ACTION)) {
+ assertThat(actionIdentifiers.getMode()).isEqualTo("sync");
+ assertThat(propertiesStruct.getFieldsOrThrow("target-software-version").getStringValue())
+ .isEqualTo(TEST_SOFTWARE_VERSION);
+ } else {
+ assertThat(actionIdentifiers.getMode()).isEqualTo("sync");
+ }
}
}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/PnfConfigCdsControllerDETest.java
index 142cb53ed8..d8f607f6d9 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/PnfConfigCdsControllerDETest.java
@@ -37,11 +37,12 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {CdsControllerDE.class, ExceptionBuilder.class, AbstractCDSProcessingBBUtils.class})
-public class CdsControllerDETest {
+@ContextConfiguration(
+ classes = {PnfConfigCdsControllerDE.class, ExceptionBuilder.class, AbstractCDSProcessingBBUtils.class})
+public class PnfConfigCdsControllerDETest {
@Autowired
- private CdsControllerDE cdsControllerDE;
+ private PnfConfigCdsControllerDE pnfConfigCdsControllerDE;
@MockBean
private ControllerContext controllerContext;
@@ -52,20 +53,46 @@ public class CdsControllerDETest {
@Mock
private AbstractCDSProcessingBBUtils abstractCDSProcessingBBUtils;
- @Before
- public void setUp() {
+ @Test
+ public void testUnderstand_action_assign_TrueReturned() {
+ // when
+ when(controllerContext.getControllerActor()).thenReturn("cds");
+ when(controllerContext.getControllerScope()).thenReturn("pnf");
+ when(controllerContext.getControllerAction()).thenReturn("config-assign");
+
+ // verify
+ assertTrue(pnfConfigCdsControllerDE.understand(controllerContext));
+ }
+
+ @Test
+ public void testUnderstand_action_deploy_TrueReturned() {
+ // when
when(controllerContext.getControllerActor()).thenReturn("cds");
+ when(controllerContext.getControllerScope()).thenReturn("pnf");
+ when(controllerContext.getControllerAction()).thenReturn("config-deploy");
+
+ // verify
+ assertTrue(pnfConfigCdsControllerDE.understand(controllerContext));
}
@Test
- public void testUnderstand_validContext_TrueReturned() {
- assertTrue(cdsControllerDE.understand(controllerContext));
+ public void testUnderstand_action_any_FalseReturned() {
+ // when
+ when(controllerContext.getControllerActor()).thenReturn("cds");
+ when(controllerContext.getControllerScope()).thenReturn("pnf");
+ when(controllerContext.getControllerAction()).thenReturn("any-action");
+
+ // verify
+ assertFalse(pnfConfigCdsControllerDE.understand(controllerContext));
}
@Test
public void testUnderstand_invalidContext_FalseReturned() {
+ // when
when(controllerContext.getControllerActor()).thenReturn("appc");
- assertFalse(cdsControllerDE.understand(controllerContext));
+
+ // verify
+ assertFalse(pnfConfigCdsControllerDE.understand(controllerContext));
}
}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDETest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDETest.java
new file mode 100644
index 0000000000..c69adeec50
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDETest.java
@@ -0,0 +1,143 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
+import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
+import org.onap.so.client.cds.GeneratePayloadForCds;
+import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.skyscreamer.jsonassert.JSONAssert;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.rules.SpringClassRule;
+import org.springframework.test.context.junit4.rules.SpringMethodRule;
+import java.util.Arrays;
+import java.util.Collection;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.*;
+
+@RunWith(Parameterized.class)
+public class GenericPnfCDSProcessingDETest extends BaseTaskTest {
+
+ @ClassRule
+ public static final SpringClassRule springClassRule = new SpringClassRule();
+
+ @Rule
+ public final SpringMethodRule smr = new SpringMethodRule();
+
+ @InjectMocks
+ private GenericPnfCDSProcessingDE controllerRunnable;
+
+ @Mock
+ private GeneratePayloadForCds generatePayloadForCds;
+
+ @Mock
+ private AbstractCDSProcessingBBUtils cdsDispather;
+
+ private static final String PRECHECK_ACTION = "precheck";
+ private static final String DOWNLOAD_ACTION = "downloadNeSw";
+ private static final String ACTIVATE_ACTION = "activateNeSw";
+ private static final String POSTCHECK_ACTION = "postcheck";
+
+ private String description;
+ private String action;
+ private String scope;
+ private String expectedJson;
+
+ public GenericPnfCDSProcessingDETest(String desc, String action, String scope, String expectedJson) {
+ this.description = desc;
+ this.action = action;
+ this.scope = scope;
+ this.expectedJson = expectedJson;
+
+ }
+
+ @Parameterized.Parameters(name = "index {0}")
+ public static Collection<String[]> data() {
+ return Arrays.asList(new String[][] {
+ {"Test JSON for action:" + PRECHECK_ACTION + " scope:pnf", PRECHECK_ACTION, "pnf",
+ buildExpectedJson(PRECHECK_ACTION, "pnf")},
+ {"Test JSON for action:" + DOWNLOAD_ACTION + " scope:pnf", DOWNLOAD_ACTION, "pnf",
+ buildExpectedJson(DOWNLOAD_ACTION, "pnf")},
+ {"Test JSON for action:" + ACTIVATE_ACTION + " scope:pnf", ACTIVATE_ACTION, "pnf",
+ buildExpectedJson(ACTIVATE_ACTION, "pnf")},
+ {"Test JSON for action:" + POSTCHECK_ACTION + " scope:pnf", POSTCHECK_ACTION, "pnf",
+ buildExpectedJson(POSTCHECK_ACTION, "pnf")},});
+ }
+
+ private static String buildExpectedJson(String action, String scope) {
+ return "{\"" + action + "-request\":" + "{\"" + action + "-" + "properties\":"
+ + "{\"service-instance-id\":\"test_service_id\","
+ + "\"pnf-customization-uuid\":\"9acb3a83-8a52-412c-9a45-901764938144\","
+ + "\"pnf-id\":\"5df8b6de-2083-11e7-93ae-92361f002671\","
+ + "\"target-software-version\":\"demo-sw-ver2.0.0\"," + "\"pnf-name\":\"PNFDemo\","
+ + "\"service-model-uuid\":\"6bc0b04d-1873-4721-b53d-6615225b2a28\"}," + "\"resolution-key\":\"PNFDemo\""
+ + "}" + "}";
+ }
+
+ private DelegateExecution execution = new DelegateExecutionFake();
+
+ @Test
+ public void testExecution_validPnf_action_executionObjectCreated() {
+ try {
+
+ // given
+ ControllerContext controllerContext = new ControllerContext();
+ controllerContext.setExecution(execution);
+ controllerContext.setControllerActor("cds");
+ controllerContext.setControllerAction(this.action);
+ controllerContext.setControllerScope(this.scope);
+ AbstractCDSPropertiesBean bean = new AbstractCDSPropertiesBean();
+ doNothing().when(cdsDispather).constructExecutionServiceInputObject(execution);
+ doNothing().when(cdsDispather).sendRequestToCDSClient(execution);
+ doReturn(bean).when(generatePayloadForCds).buildCdsPropertiesBean(execution);
+
+ // when
+ Boolean isUnderstandable = controllerRunnable.understand(controllerContext);
+ Boolean isReady = controllerRunnable.ready(controllerContext);
+ controllerRunnable.prepare(controllerContext);
+ controllerRunnable.run(controllerContext);
+
+ // verify
+ assertEquals(isUnderstandable, true);
+ assertEquals(isReady, true);
+ Object executionObject = execution.getVariable(EXECUTION_OBJECT);
+ assertThat(executionObject).isNotNull();
+ assertThat(executionObject).isInstanceOf(AbstractCDSPropertiesBean.class);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception thrown" + e.getMessage());
+ }
+ }
+}