2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.process;
23 import static com.github.tomakehurst.wiremock.client.WireMock.get;
24 import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
25 import static com.github.tomakehurst.wiremock.client.WireMock.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.put;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
28 import static org.assertj.core.api.Assertions.fail;
29 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.assertThat;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertTrue;
32 import java.io.IOException;
33 import java.util.HashMap;
34 import java.util.List;
36 import java.util.UUID;
37 import org.camunda.bpm.engine.runtime.ProcessInstance;
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.onap.aaiclient.client.aai.AAIVersion;
41 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
42 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
43 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
44 import org.onap.so.BaseBPMNTest;
45 import org.onap.so.GrpcNettyServer;
46 import org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames;
47 import org.onap.so.bpmn.mock.FileUtil;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50 import org.springframework.beans.factory.annotation.Autowired;
51 import com.google.protobuf.Struct;
54 * Basic Integration test for ServiceLevelUpgrade.bpmn workflow.
56 public class ServiceLevelUpgradeTest extends BaseBPMNTest {
58 private final Logger logger = LoggerFactory.getLogger(getClass());
60 private static final long WORKFLOW_WAIT_TIME = 1000L;
62 private static final String TEST_PROCESSINSTANCE_KEY = "ServiceLevelUpgrade";
63 private static final AAIVersion VERSION = AAIVersion.LATEST;
64 private static final Map<String, Object> executionVariables = new HashMap();
65 private static final String REQUEST_ID = "50ae41ad-049c-4fe2-9950-539f111120f5";
66 private static final String SERVICE_INSTANCE_ID = "5df8b6de-2083-11e7-93ae-92361f002676";
67 private final String[] actionNames = new String[10];
68 private final String[] pnfNames = new String[10];
69 private final String CLASSNAME = getClass().getSimpleName();
70 private String requestObject;
71 private String responseObject;
74 private GrpcNettyServer grpcNettyServer;
77 public void setUp() throws IOException {
78 actionNames[0] = "healthCheck";
79 actionNames[1] = "healthCheck";
80 actionNames[2] = "preCheck";
81 actionNames[3] = "downloadNESw";
82 actionNames[4] = "activateNESw";
83 actionNames[5] = "postCheck";
84 actionNames[6] = "preCheck";
85 actionNames[7] = "downloadNESw";
86 actionNames[8] = "activateNESw";
87 actionNames[9] = "postCheck";
89 pnfNames[0] = "PNFDemo";
90 pnfNames[1] = "PNFDemo1";
91 pnfNames[2] = "PNFDemo";
92 pnfNames[3] = "PNFDemo";
93 pnfNames[4] = "PNFDemo";
94 pnfNames[5] = "PNFDemo";
95 pnfNames[6] = "PNFDemo1";
96 pnfNames[7] = "PNFDemo1";
97 pnfNames[8] = "PNFDemo1";
98 pnfNames[9] = "PNFDemo1";
100 executionVariables.clear();
102 requestObject = FileUtil.readResourceFile("request/" + CLASSNAME + ".json");
103 responseObject = FileUtil.readResourceFile("response/" + CLASSNAME + ".json");
105 executionVariables.put("bpmnRequest", requestObject);
106 executionVariables.put("requestId", REQUEST_ID);
107 executionVariables.put("serviceInstanceId", SERVICE_INSTANCE_ID);
111 * This variable indicates that the flow was invoked asynchronously. It's injected by {@link WorkflowProcessor}.
113 executionVariables.put("isAsyncProcess", "true");
114 executionVariables.put(ExecutionVariableNames.PRC_CUSTOMIZATION_UUID, "38dc9a92-214c-11e7-93ae-92361f002680");
117 * Temporary solution to add pnfCorrelationId to context. this value is getting from the request to SO api
118 * handler and then convert to CamudaInput
120 executionVariables.put(ExecutionVariableNames.PNF_CORRELATION_ID, "PNFDemo");
125 public void workflow_validInput_expectedOutput() throws InterruptedException {
130 grpcNettyServer.resetList();
132 final String msoRequestId = UUID.randomUUID().toString();
133 executionVariables.put(ExecutionVariableNames.MSO_REQUEST_ID, msoRequestId);
135 final String testBusinessKey = UUID.randomUUID().toString();
136 logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
139 runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, executionVariables);
142 while (!isProcessInstanceEnded() && waitCount >= 0) {
143 Thread.sleep(WORKFLOW_WAIT_TIME);
147 // Layout is to reflect the bpmn visual layout
148 assertThat(pi).isEnded().hasPassedInOrder("Event_02mc8tr", "Activity_18vue7u", "Activity_09bqns0",
149 "Activity_02vp5np", "Activity_0n17xou", "Gateway_1nr51kr", "Activity_0snmatn", "Activity_0e6w886",
150 "Activity_1q4o9fx", "Gateway_02fectw", "Activity_1hp67qz", "Gateway_18ch73t", "Activity_0ft7fa2",
151 "Gateway_1vq11i7", "Activity_0o2rrag", "Activity_1n4rk7m", "Activity_1lz38px", "Event_12983th");
153 List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
154 assertEquals(10, detailedMessages.size());
158 for (ExecutionServiceInput eSI : detailedMessages) {
159 action = actionNames[count];
160 if (action.equals(eSI.getActionIdentifiers().getActionName())
161 && eSI.getCommonHeader().getRequestId().equals(msoRequestId)) {
162 checkWithActionName(eSI, action, pnfNames[count]);
166 } catch (Exception e) {
168 fail("GenericPnfSoftwareUpgrade request exception", e);
170 assertTrue(count == actionNames.length);
173 private boolean isProcessInstanceEnded() {
174 return runtimeService.createProcessInstanceQuery().processDefinitionKey(TEST_PROCESSINSTANCE_KEY)
175 .singleResult() == null;
178 private void checkWithActionName(final ExecutionServiceInput executionServiceInput, final String action,
179 final String pnfName) {
181 logger.info("Checking the " + action + " request");
182 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
185 * the fields of actionIdentifiers should match the one in the response/PnfHealthCheck_catalogdb.json.
187 assertEquals("test_pnf_software_upgrade_restconf", actionIdentifiers.getBlueprintName());
188 assertEquals("1.0.0", actionIdentifiers.getBlueprintVersion());
189 assertEquals(action, actionIdentifiers.getActionName());
190 assertEquals("async", actionIdentifiers.getMode());
192 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
193 assertEquals("SO", commonHeader.getOriginatorId());
195 Struct payload = executionServiceInput.getPayload();
196 Struct requeststruct = payload.getFieldsOrThrow(action + "-request").getStructValue();
198 assertEquals(pnfName, requeststruct.getFieldsOrThrow("resolution-key").getStringValue());
199 Struct propertiesStruct = requeststruct.getFieldsOrThrow(action + "-properties").getStructValue();
201 assertEquals(pnfName, propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue());
202 assertEquals("d88da85c-d9e8-4f73-b837-3a72a431622b",
203 propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue());
204 assertEquals("38dc9a92-214c-11e7-93ae-92361f002680",
205 propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue());
208 private void mockAai() {
211 "/business/customers/customer/ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce/service-subscriptions/service-subscription/pNF/service-instances/service-instance/5df8b6de-2083-11e7-93ae-92361f002676";
212 final String aaiPnfDemoEntry = FileUtil.readResourceFile("response/PnfDemo_aai.json");
213 final String aaiPnfDemo1Entry = FileUtil.readResourceFile("response/PnfDemo1_aai.json");
214 final String aaiServiceInstanceEntry = FileUtil.readResourceFile("response/Service_instance_aai.json");
217 * PUT the PNF correlation ID PnfDemo to AAI.
219 wireMockServer.stubFor(put(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")));
222 * PUT the PNF correlation ID PnfDemo1 to AAI.
224 wireMockServer.stubFor(put(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo1")));
227 * Get the PNF entry PnfDemo from AAI.
229 wireMockServer.stubFor(
230 get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfDemoEntry)));
233 * Get the PNF entry PnfDemo1 from AAI.
235 wireMockServer.stubFor(
236 get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo1")).willReturn(okJson(aaiPnfDemo1Entry)));
239 * Post the pnf PnfDemo to AAI
241 wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")));
244 * Post the pnf PnfDemo1 to AAI
246 wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo1")));
249 * Get the Service Instance to AAI.
251 wireMockServer.stubFor(get(urlEqualTo("/aai/" + VERSION + sIUrl)).willReturn(okJson(aaiServiceInstanceEntry)));
254 * Post the Service Instance to AAI.
256 wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + sIUrl)));
259 private void mockRequestDb() {
263 wireMockServer.stubFor(put(urlEqualTo("/infraActiveRequests/" + REQUEST_ID)));
268 * Mock the catalobdb rest interface.
270 private void mockCatalogDb() {
272 String catalogdbClientResponse = FileUtil.readResourceFile("response/" + CLASSNAME + "_catalogdb.json");
276 * Return valid json for the model UUID in the request file.
279 .stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=d88da85c-d9e8-4f73-b837-3a72a431622b"))
280 .willReturn(okJson(responseObject)));
283 * Return valid json for the service model InvariantUUID as specified in the request file.
285 wireMockServer.stubFor(
286 get(urlEqualTo("/v2/serviceResources?serviceModelInvariantUuid=fe41489e-1563-46a3-b90a-1db629e4375b"))
287 .willReturn(okJson(responseObject)));
290 * Return valid spring data rest json for the service model UUID as specified in the request file.
292 wireMockServer.stubFor(get(urlEqualTo(
293 "/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=d88da85c-d9e8-4f73-b837-3a72a431622b"))
294 .willReturn(okJson(catalogdbClientResponse)));