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[5];
66 private final String CLASSNAME = getClass().getSimpleName();
67 private String requestObject;
68 private String responseObject;
71 private GrpcNettyServer grpcNettyServer;
74 public void setUp() throws IOException {
75 actionNames[0] = "healthCheck";
76 actionNames[1] = "preCheck";
77 actionNames[2] = "downloadNESw";
78 actionNames[3] = "activateNESw";
79 actionNames[4] = "postCheck";
81 executionVariables.clear();
83 requestObject = FileUtil.readResourceFile("request/" + CLASSNAME + ".json");
84 responseObject = FileUtil.readResourceFile("response/" + CLASSNAME + ".json");
86 executionVariables.put("bpmnRequest", requestObject);
87 executionVariables.put("requestId", REQUEST_ID);
88 executionVariables.put("serviceInstanceId", SERVICE_INSTANCE_ID);
92 * This variable indicates that the flow was invoked asynchronously. It's injected by {@link WorkflowProcessor}.
94 executionVariables.put("isAsyncProcess", "true");
95 executionVariables.put(ExecutionVariableNames.PRC_CUSTOMIZATION_UUID, "38dc9a92-214c-11e7-93ae-92361f002680");
98 * Temporary solution to add pnfCorrelationId to context. this value is getting from the request to SO api
99 * handler and then convert to CamudaInput
101 executionVariables.put(ExecutionVariableNames.PNF_CORRELATION_ID, "PNFDemo");
106 public void workflow_validInput_expectedOutput() throws InterruptedException {
112 final String msoRequestId = UUID.randomUUID().toString();
113 executionVariables.put(ExecutionVariableNames.MSO_REQUEST_ID, msoRequestId);
115 final String testBusinessKey = UUID.randomUUID().toString();
116 logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
119 runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, executionVariables);
122 while (!isProcessInstanceEnded() && waitCount >= 0) {
123 Thread.sleep(WORKFLOW_WAIT_TIME);
127 // Layout is to reflect the bpmn visual layout
128 assertThat(pi).isEnded().hasPassedInOrder("Event_02mc8tr", "Activity_18vue7u", "Activity_0qgmx7a",
129 "Activity_09bqns0", "Activity_0n17xou", "Gateway_1nr51kr", "Activity_0snmatn", "Activity_1q4o9fx",
130 "Gateway_02fectw", "Activity_1hp67qz", "Gateway_18ch73t", "Activity_0ft7fa2", "Gateway_1vq11i7",
131 "Activity_1n4rk7m", "Activity_1lz38px", "Event_12983th");
133 List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
134 assertThat(detailedMessages.size() == 5);
137 for (ExecutionServiceInput eSI : detailedMessages) {
138 for (String action : actionNames) {
139 if (action.equals(eSI.getActionIdentifiers().getActionName())
140 && eSI.getCommonHeader().getRequestId().equals(msoRequestId)) {
141 checkWithActionName(eSI, action);
146 } catch (Exception e) {
148 fail("GenericPnfSoftwareUpgrade request exception", e);
150 assertThat(count == actionNames.length);
153 private boolean isProcessInstanceEnded() {
154 return runtimeService.createProcessInstanceQuery().processDefinitionKey(TEST_PROCESSINSTANCE_KEY)
155 .singleResult() == null;
158 private void checkWithActionName(ExecutionServiceInput executionServiceInput, String action) {
160 logger.info("Checking the " + action + " request");
161 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
164 * the fields of actionIdentifiers should match the one in the response/PnfHealthCheck_catalogdb.json.
166 assertThat(actionIdentifiers.getBlueprintName()).isEqualTo("test_pnf_software_upgrade_restconf");
167 assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo("1.0.0");
168 assertThat(actionIdentifiers.getActionName()).isEqualTo(action);
169 assertThat(actionIdentifiers.getMode()).isEqualTo("async");
171 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
172 assertThat(commonHeader.getOriginatorId()).isEqualTo("SO");
174 Struct payload = executionServiceInput.getPayload();
175 Struct requeststruct = payload.getFieldsOrThrow(action + "-request").getStructValue();
177 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).isEqualTo("PNFDemo");
178 Struct propertiesStruct = requeststruct.getFieldsOrThrow(action + "-properties").getStructValue();
180 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo("PNFDemo");
181 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
182 .isEqualTo("d88da85c-d9e8-4f73-b837-3a72a431622b");
183 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
184 .isEqualTo("38dc9a92-214c-11e7-93ae-92361f002680");
187 private void mockAai() {
190 "/business/customers/customer/5df8b6de-2083-11e7-93ae-92361f002676/service-subscriptions/service-subscription/pNF/service-instances/service-instance/ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce";
191 final String aaiPnfEntry = FileUtil.readResourceFile("response/Pnf_aai.json");
192 final String aaiServiceInstanceEntry = FileUtil.readResourceFile("response/Service_instance_aai.json");
195 * PUT the PNF correlation ID to AAI.
197 wireMockServer.stubFor(put(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")));
200 * Get the PNF entry from AAI.
202 wireMockServer.stubFor(
203 get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry)));
206 * Post the pnf to AAI
208 wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")));
211 * Get the Service Instance to AAI.
213 wireMockServer.stubFor(get(urlEqualTo("/aai/" + VERSION + sIUrl)).willReturn(okJson(aaiServiceInstanceEntry)));
216 * Post the Service Instance to AAI.
218 wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + sIUrl)));
221 private void mockRequestDb() {
225 wireMockServer.stubFor(put(urlEqualTo("/infraActiveRequests/" + REQUEST_ID)));
230 * Mock the catalobdb rest interface.
232 private void mockCatalogDb() {
234 String catalogdbClientResponse = FileUtil.readResourceFile("response/" + CLASSNAME + "_catalogdb.json");
238 * Return valid json for the model UUID in the request file.
241 .stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=d88da85c-d9e8-4f73-b837-3a72a431622b"))
242 .willReturn(okJson(responseObject)));
245 * Return valid json for the service model InvariantUUID as specified in the request file.
247 wireMockServer.stubFor(
248 get(urlEqualTo("/v2/serviceResources?serviceModelInvariantUuid=fe41489e-1563-46a3-b90a-1db629e4375b"))
249 .willReturn(okJson(responseObject)));
252 * Return valid spring data rest json for the service model UUID as specified in the request file.
254 wireMockServer.stubFor(get(urlEqualTo(
255 "/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=d88da85c-d9e8-4f73-b837-3a72a431622b"))
256 .willReturn(okJson(catalogdbClientResponse)));