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.BpmnAwareAssertions.assertThat;
30 import com.google.protobuf.Struct;
31 import java.io.IOException;
32 import java.util.HashMap;
33 import java.util.List;
35 import java.util.UUID;
36 import org.camunda.bpm.engine.runtime.ProcessInstance;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.onap.aaiclient.client.aai.AAIVersion;
40 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
41 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
42 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
43 import org.onap.so.BaseBPMNTest;
44 import org.onap.so.GrpcNettyServer;
45 import org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames;
46 import org.onap.so.bpmn.mock.FileUtil;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49 import org.springframework.beans.factory.annotation.Autowired;
52 * Basic Integration test for ServiceLevelUpgrade.bpmn workflow.
54 public class ServiceLevelUpgradeTest extends BaseBPMNTest {
56 private final Logger logger = LoggerFactory.getLogger(getClass());
58 private static final long WORKFLOW_WAIT_TIME = 1000L;
60 private static final String TEST_PROCESSINSTANCE_KEY = "ServiceLevelUpgrade";
61 private static final AAIVersion VERSION = AAIVersion.LATEST;
62 private static final Map<String, Object> executionVariables = new HashMap();
63 private static final String REQUEST_ID = "50ae41ad-049c-4fe2-9950-539f111120f5";
64 private static final String SERVICE_INSTANCE_ID = "5df8b6de-2083-11e7-93ae-92361f002676";
65 private final String[] actionNames = new String[10];
66 private final String[] pnfNames = new String[10];
67 private final String CLASSNAME = getClass().getSimpleName();
68 private String requestObject;
69 private String responseObject;
72 private GrpcNettyServer grpcNettyServer;
75 public void setUp() throws IOException {
76 actionNames[0] = "healthCheck";
77 actionNames[1] = "healthCheck";
78 actionNames[2] = "preCheck";
79 actionNames[3] = "downloadNESw";
80 actionNames[4] = "activateNESw";
81 actionNames[5] = "postCheck";
82 actionNames[6] = "preCheck";
83 actionNames[7] = "downloadNESw";
84 actionNames[8] = "activateNESw";
85 actionNames[9] = "postCheck";
87 pnfNames[0] = "PNFDemo";
88 pnfNames[1] = "PNFDemo1";
89 pnfNames[2] = "PNFDemo";
90 pnfNames[3] = "PNFDemo";
91 pnfNames[4] = "PNFDemo";
92 pnfNames[5] = "PNFDemo";
93 pnfNames[6] = "PNFDemo1";
94 pnfNames[7] = "PNFDemo1";
95 pnfNames[8] = "PNFDemo1";
96 pnfNames[9] = "PNFDemo1";
98 executionVariables.clear();
100 requestObject = FileUtil.readResourceFile("request/" + CLASSNAME + ".json");
101 responseObject = FileUtil.readResourceFile("response/" + CLASSNAME + ".json");
103 executionVariables.put("bpmnRequest", requestObject);
104 executionVariables.put("requestId", REQUEST_ID);
105 executionVariables.put("serviceInstanceId", SERVICE_INSTANCE_ID);
109 * This variable indicates that the flow was invoked asynchronously. It's injected by {@link WorkflowProcessor}.
111 executionVariables.put("isAsyncProcess", "true");
112 executionVariables.put(ExecutionVariableNames.PRC_CUSTOMIZATION_UUID, "38dc9a92-214c-11e7-93ae-92361f002680");
115 * Temporary solution to add pnfCorrelationId to context. this value is getting from the request to SO api
116 * handler and then convert to CamudaInput
118 executionVariables.put(ExecutionVariableNames.PNF_CORRELATION_ID, "PNFDemo");
123 public void workflow_validInput_expectedOutput() throws InterruptedException {
129 final String msoRequestId = UUID.randomUUID().toString();
130 executionVariables.put(ExecutionVariableNames.MSO_REQUEST_ID, msoRequestId);
132 final String testBusinessKey = UUID.randomUUID().toString();
133 logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
136 runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, executionVariables);
139 while (!isProcessInstanceEnded() && waitCount >= 0) {
140 Thread.sleep(WORKFLOW_WAIT_TIME);
144 // Layout is to reflect the bpmn visual layout
145 assertThat(pi).isEnded().hasPassedInOrder("Event_02mc8tr", "Activity_18vue7u", "Activity_09bqns0",
146 "Activity_02vp5np", "Activity_0n17xou", "Gateway_1nr51kr", "Activity_0snmatn", "Activity_0e6w886",
147 "Activity_1q4o9fx", "Gateway_02fectw", "Activity_1hp67qz", "Gateway_18ch73t", "Activity_0ft7fa2",
148 "Gateway_1vq11i7", "Activity_1n4rk7m", "Activity_1lz38px", "Event_12983th");
150 List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
151 assertThat(detailedMessages.size() == 5);
155 for (ExecutionServiceInput eSI : detailedMessages) {
156 action = actionNames[count];
157 if (action.equals(eSI.getActionIdentifiers().getActionName())
158 && eSI.getCommonHeader().getRequestId().equals(msoRequestId)) {
159 checkWithActionName(eSI, action, pnfNames[count]);
163 } catch (Exception e) {
165 fail("GenericPnfSoftwareUpgrade request exception", e);
167 assertThat(count == actionNames.length);
170 private boolean isProcessInstanceEnded() {
171 return runtimeService.createProcessInstanceQuery().processDefinitionKey(TEST_PROCESSINSTANCE_KEY)
172 .singleResult() == null;
175 private void checkWithActionName(final ExecutionServiceInput executionServiceInput, final String action,
176 final String pnfName) {
178 logger.info("Checking the " + action + " request");
179 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
182 * the fields of actionIdentifiers should match the one in the response/PnfHealthCheck_catalogdb.json.
184 assertThat(actionIdentifiers.getBlueprintName()).isEqualTo("test_pnf_software_upgrade_restconf");
185 assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo("1.0.0");
186 assertThat(actionIdentifiers.getActionName()).isEqualTo(action);
187 assertThat(actionIdentifiers.getMode()).isEqualTo("async");
189 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
190 assertThat(commonHeader.getOriginatorId()).isEqualTo("SO");
192 Struct payload = executionServiceInput.getPayload();
193 Struct requeststruct = payload.getFieldsOrThrow(action + "-request").getStructValue();
195 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).isEqualTo(pnfName);
196 Struct propertiesStruct = requeststruct.getFieldsOrThrow(action + "-properties").getStructValue();
198 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo(pnfName);
199 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
200 .isEqualTo("d88da85c-d9e8-4f73-b837-3a72a431622b");
201 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
202 .isEqualTo("38dc9a92-214c-11e7-93ae-92361f002680");
205 private void mockAai() {
208 "/business/customers/customer/5df8b6de-2083-11e7-93ae-92361f002676/service-subscriptions/service-subscription/pNF/service-instances/service-instance/ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce";
209 final String aaiPnfDemoEntry = FileUtil.readResourceFile("response/PnfDemo_aai.json");
210 final String aaiPnfDemo1Entry = FileUtil.readResourceFile("response/PnfDemo1_aai.json");
211 final String aaiServiceInstanceEntry = FileUtil.readResourceFile("response/Service_instance_aai.json");
214 * PUT the PNF correlation ID PnfDemo to AAI.
216 wireMockServer.stubFor(put(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")));
219 * PUT the PNF correlation ID PnfDemo1 to AAI.
221 wireMockServer.stubFor(put(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo1")));
224 * Get the PNF entry PnfDemo from AAI.
226 wireMockServer.stubFor(
227 get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfDemoEntry)));
230 * Get the PNF entry PnfDemo1 from AAI.
232 wireMockServer.stubFor(
233 get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo1")).willReturn(okJson(aaiPnfDemo1Entry)));
236 * Post the pnf PnfDemo to AAI
238 wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")));
241 * Post the pnf PnfDemo1 to AAI
243 wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo1")));
246 * Get the Service Instance to AAI.
248 wireMockServer.stubFor(get(urlEqualTo("/aai/" + VERSION + sIUrl)).willReturn(okJson(aaiServiceInstanceEntry)));
251 * Post the Service Instance to AAI.
253 wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + sIUrl)));
256 private void mockRequestDb() {
260 wireMockServer.stubFor(put(urlEqualTo("/infraActiveRequests/" + REQUEST_ID)));
265 * Mock the catalobdb rest interface.
267 private void mockCatalogDb() {
269 String catalogdbClientResponse = FileUtil.readResourceFile("response/" + CLASSNAME + "_catalogdb.json");
273 * Return valid json for the model UUID in the request file.
276 .stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=d88da85c-d9e8-4f73-b837-3a72a431622b"))
277 .willReturn(okJson(responseObject)));
280 * Return valid json for the service model InvariantUUID as specified in the request file.
282 wireMockServer.stubFor(
283 get(urlEqualTo("/v2/serviceResources?serviceModelInvariantUuid=fe41489e-1563-46a3-b90a-1db629e4375b"))
284 .willReturn(okJson(responseObject)));
287 * Return valid spring data rest json for the service model UUID as specified in the request file.
289 wireMockServer.stubFor(get(urlEqualTo(
290 "/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=d88da85c-d9e8-4f73-b837-3a72a431622b"))
291 .willReturn(okJson(catalogdbClientResponse)));