diff options
author | mharazin <mateusz.harazin@nokia.com> | 2020-02-24 14:47:54 +0100 |
---|---|---|
committer | mharazin <mateusz.harazin@nokia.com> | 2020-03-12 16:02:37 +0100 |
commit | 3cfae67b1627fad4845bc09f6174798f4a9ddf1f (patch) | |
tree | 6c3ac24c986adae7d631a9c2b80772146be2bbd1 /bpmn/so-bpmn-tasks/src/test | |
parent | df40976f9f92f24096021144f7618e8779fe5f1c (diff) |
Implementation of GenericPnfCDSProcessingBB
Issue-ID: SO-2646
Signed-off-by: Mateusz Harazin <mateusz.harazin@nokia.com>
Change-Id: Ie146210b2cc0ea15f02d19261510d24a7bc50043
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test')
2 files changed, 156 insertions, 4 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBBTest.java new file mode 100644 index 0000000000..d6a28cba25 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBBTest.java @@ -0,0 +1,156 @@ +/* + * ============LICENSE_START======================================================= Copyright (C) 2020 Nokia. All rights + * reserved. ================================================================================ 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.flowspecific.tasks; + +import org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoPnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; +import org.onap.so.client.exception.BBObjectNotFoundException; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.EXECUTION_OBJECT; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MSO_REQUEST_ID; +import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_NAME; +import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_VERSION; +import static org.onap.so.client.cds.PayloadConstants.SCOPE; + +@RunWith(MockitoJUnitRunner.class) +public class GenericPnfCDSControllerRunnableBBTest { + + @Mock + private ExtractPojosForBB extractPojosForBB; + + @InjectMocks + private GenericPnfCDSControllerRunnableBB genericPnfCDSControllerRunnableBB; + + private ControllerContext<BuildingBlockExecution> controllerContext; + private BuildingBlockExecution execution; + + private final static String blueprintName = "blueprint_name"; + private final static String blueprintVersion = "blueprint_version"; + private final static String msoRequestId = "mso_request_id"; + private final static String pnfID = "5df8b6de-2083-11e7-93ae-92361f002671"; + private final static String serviceInstanceID = "test_service_id"; + private final static String pnfName = "PNFDemo"; + private final static String serviceModelUUID = "6bc0b04d-1873-4721-b53d-6615225b2a28"; + private final static String pnfCustomizationUUID = "9acb3a83-8a52-412c-9a45-901764938144"; + private final static String action = "action"; + + @Before + public void setUp() { + ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock(); + BuildingBlock buildingBlock = new BuildingBlock(); + + buildingBlock.setBpmnAction(action); + executeBuildingBlock.setBuildingBlock(buildingBlock); + + execution = new DelegateExecutionImpl(new ExecutionImpl()); + execution.setVariable("buildingBlock", executeBuildingBlock); + execution.setVariable(PRC_BLUEPRINT_NAME, blueprintName); + execution.setVariable(PRC_BLUEPRINT_VERSION, blueprintVersion); + execution.setVariable(MSO_REQUEST_ID, msoRequestId); + execution.setVariable(SCOPE, "scope"); + + controllerContext = new ControllerContext<>(); + controllerContext.setExecution(execution); + } + + @Test + public void understandTest() { + // given + controllerContext.setControllerScope("pnf"); + controllerContext.setControllerActor("cds"); + + // when, then + assertTrue(genericPnfCDSControllerRunnableBB.understand(controllerContext)); + } + + @Test + public void readyTest() { + // when, then + assertTrue(genericPnfCDSControllerRunnableBB.ready(controllerContext)); + } + + @Test + public void prepareTest() throws BBObjectNotFoundException { + // given + prepareData(); + + // when + genericPnfCDSControllerRunnableBB.prepare(controllerContext); + + // then + final AbstractCDSPropertiesBean abstractCDSPropertiesBean = execution.getVariable(EXECUTION_OBJECT); + final JSONObject actionProperties = new JSONObject(abstractCDSPropertiesBean.getRequestObject()) + .getJSONObject("action-request").getJSONObject("action-properties"); + + assertThat(abstractCDSPropertiesBean).isNotNull(); + assertThat(abstractCDSPropertiesBean.getRequestObject()).isNotNull(); + assertThat(abstractCDSPropertiesBean.getRequestObject()).isInstanceOf(String.class); + + assertEquals(blueprintName, abstractCDSPropertiesBean.getBlueprintName()); + assertEquals(blueprintVersion, abstractCDSPropertiesBean.getBlueprintVersion()); + assertEquals(msoRequestId, abstractCDSPropertiesBean.getRequestId()); + assertEquals(action, abstractCDSPropertiesBean.getActionName()); + assertEquals("sync", abstractCDSPropertiesBean.getMode()); + assertEquals("SO", abstractCDSPropertiesBean.getOriginatorId()); + + assertEquals(pnfID, actionProperties.get("pnf-id")); + assertEquals(serviceInstanceID, actionProperties.get("service-instance-id")); + assertEquals(serviceModelUUID, actionProperties.get("service-model-uuid")); + assertEquals(pnfName, actionProperties.get("pnf-name")); + assertEquals(pnfCustomizationUUID, actionProperties.get("pnf-customization-uuid")); + } + + private void prepareData() throws BBObjectNotFoundException { + Pnf pnf = new Pnf(); + ServiceInstance serviceInstance = new ServiceInstance(); + + pnf.setPnfName(pnfName); + pnf.setPnfId(pnfID); + ModelInfoPnf modelInfoPnf = new ModelInfoPnf(); + modelInfoPnf.setModelCustomizationUuid(pnfCustomizationUUID); + pnf.setModelInfoPnf(modelInfoPnf); + + serviceInstance.setServiceInstanceId(serviceInstanceID); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelUuid(serviceModelUUID); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + + when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.PNF))).thenReturn(pnf); + when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.SERVICE_INSTANCE_ID))) + .thenReturn(serviceInstance); + } +} 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 index 583e139edd..ae5f4370e6 100644 --- 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 @@ -20,7 +20,6 @@ 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; @@ -33,9 +32,6 @@ 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; |