2 * ============LICENSE_START======================================================= Copyright (C) 2020 Nokia. All rights
3 * reserved. ================================================================================ Licensed under the Apache
4 * License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain
5 * a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 * specific language governing permissions and limitations under the License.
12 * ============LICENSE_END=========================================================
15 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
17 import org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl;
18 import org.json.JSONObject;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.InjectMocks;
23 import org.mockito.Mock;
24 import org.mockito.junit.MockitoJUnitRunner;
25 import org.onap.so.bpmn.common.BuildingBlockExecution;
26 import org.onap.so.bpmn.common.DelegateExecutionImpl;
27 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
30 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
31 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
32 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
33 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoPnf;
34 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
35 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
36 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
37 import org.onap.so.client.exception.BBObjectNotFoundException;
38 import static org.assertj.core.api.Assertions.assertThat;
39 import static org.junit.Assert.assertEquals;
40 import static org.junit.Assert.assertTrue;
41 import static org.mockito.ArgumentMatchers.eq;
42 import static org.mockito.Mockito.when;
43 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.EXECUTION_OBJECT;
44 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MSO_REQUEST_ID;
45 import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_NAME;
46 import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_VERSION;
47 import static org.onap.so.client.cds.PayloadConstants.SCOPE;
49 @RunWith(MockitoJUnitRunner.class)
50 public class GenericPnfCDSControllerRunnableBBTest {
53 private ExtractPojosForBB extractPojosForBB;
56 private GenericPnfCDSControllerRunnableBB genericPnfCDSControllerRunnableBB;
58 private ControllerContext<BuildingBlockExecution> controllerContext;
59 private BuildingBlockExecution execution;
61 private final static String blueprintName = "blueprint_name";
62 private final static String blueprintVersion = "blueprint_version";
63 private final static String msoRequestId = "mso_request_id";
64 private final static String pnfID = "5df8b6de-2083-11e7-93ae-92361f002671";
65 private final static String serviceInstanceID = "test_service_id";
66 private final static String pnfName = "PNFDemo";
67 private final static String serviceModelUUID = "6bc0b04d-1873-4721-b53d-6615225b2a28";
68 private final static String pnfCustomizationUUID = "9acb3a83-8a52-412c-9a45-901764938144";
69 private final static String action = "action";
73 ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
74 BuildingBlock buildingBlock = new BuildingBlock();
76 buildingBlock.setBpmnAction(action);
77 executeBuildingBlock.setBuildingBlock(buildingBlock);
79 execution = new DelegateExecutionImpl(new ExecutionImpl());
80 execution.setVariable("buildingBlock", executeBuildingBlock);
81 execution.setVariable(PRC_BLUEPRINT_NAME, blueprintName);
82 execution.setVariable(PRC_BLUEPRINT_VERSION, blueprintVersion);
83 execution.setVariable(MSO_REQUEST_ID, msoRequestId);
84 execution.setVariable(SCOPE, "scope");
86 controllerContext = new ControllerContext<>();
87 controllerContext.setExecution(execution);
91 public void understandTest() {
93 controllerContext.setControllerScope("pnf");
94 controllerContext.setControllerActor("cds");
97 assertTrue(genericPnfCDSControllerRunnableBB.understand(controllerContext));
101 public void readyTest() {
103 assertTrue(genericPnfCDSControllerRunnableBB.ready(controllerContext));
107 public void prepareTest() throws BBObjectNotFoundException {
112 genericPnfCDSControllerRunnableBB.prepare(controllerContext);
115 final AbstractCDSPropertiesBean abstractCDSPropertiesBean = execution.getVariable(EXECUTION_OBJECT);
116 final JSONObject actionProperties = new JSONObject(abstractCDSPropertiesBean.getRequestObject())
117 .getJSONObject("action-request").getJSONObject("action-properties");
119 assertThat(abstractCDSPropertiesBean).isNotNull();
120 assertThat(abstractCDSPropertiesBean.getRequestObject()).isNotNull();
121 assertThat(abstractCDSPropertiesBean.getRequestObject()).isInstanceOf(String.class);
123 assertEquals(blueprintName, abstractCDSPropertiesBean.getBlueprintName());
124 assertEquals(blueprintVersion, abstractCDSPropertiesBean.getBlueprintVersion());
125 assertEquals(msoRequestId, abstractCDSPropertiesBean.getRequestId());
126 assertEquals(action, abstractCDSPropertiesBean.getActionName());
127 assertEquals("sync", abstractCDSPropertiesBean.getMode());
128 assertEquals("SO", abstractCDSPropertiesBean.getOriginatorId());
130 assertEquals(pnfID, actionProperties.get("pnf-id"));
131 assertEquals(serviceInstanceID, actionProperties.get("service-instance-id"));
132 assertEquals(serviceModelUUID, actionProperties.get("service-model-uuid"));
133 assertEquals(pnfName, actionProperties.get("pnf-name"));
134 assertEquals(pnfCustomizationUUID, actionProperties.get("pnf-customization-uuid"));
137 private void prepareData() throws BBObjectNotFoundException {
139 ServiceInstance serviceInstance = new ServiceInstance();
141 pnf.setPnfName(pnfName);
143 ModelInfoPnf modelInfoPnf = new ModelInfoPnf();
144 modelInfoPnf.setModelCustomizationUuid(pnfCustomizationUUID);
145 pnf.setModelInfoPnf(modelInfoPnf);
147 serviceInstance.setServiceInstanceId(serviceInstanceID);
148 ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
149 modelInfoServiceInstance.setModelUuid(serviceModelUUID);
150 serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
152 when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.PNF))).thenReturn(pnf);
153 when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.SERVICE_INSTANCE_ID)))
154 .thenReturn(serviceInstance);