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 com.google.protobuf.Struct;
24 import org.camunda.bpm.engine.runtime.ProcessInstance;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
28 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
29 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
30 import org.onap.so.BaseBPMNTest;
31 import org.onap.so.GrpcNettyServer;
32 import org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames;
33 import org.onap.so.bpmn.mock.FileUtil;
34 import org.onap.so.client.aai.AAIVersion;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import java.io.IOException;
39 import java.util.HashMap;
40 import java.util.List;
42 import java.util.UUID;
43 import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
44 import static com.github.tomakehurst.wiremock.client.WireMock.get;
45 import static com.github.tomakehurst.wiremock.client.WireMock.put;
46 import static com.github.tomakehurst.wiremock.client.WireMock.post;
47 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
48 import static org.assertj.core.api.Assertions.fail;
49 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
52 * Basic Integration test for PNFSoftwareUpgrade.bpmn workflow.
54 public class PNFSoftwareUpgradeTest 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 = "PNFSoftwareUpgrade";
61 private static final AAIVersion VERSION = AAIVersion.LATEST;
62 private static final Map<String, Object> executionVariables = new HashMap();
63 private final String[] actionNames = new String[4];
64 private String requestObject;
65 private String responseObject;
68 private GrpcNettyServer grpcNettyServer;
71 public void setUp() throws IOException {
72 actionNames[0] = "preCheck";
73 actionNames[1] = "downloadNESw";
74 actionNames[2] = "activateNESw";
75 actionNames[3] = "postCheck";
77 executionVariables.clear();
79 requestObject = FileUtil.readResourceFile("request/" + getClass().getSimpleName() + ".json");
80 responseObject = FileUtil.readResourceFile("response/" + getClass().getSimpleName() + ".json");
82 executionVariables.put("bpmnRequest", requestObject);
85 * This variable indicates that the flow was invoked asynchronously. It's injected by {@link WorkflowProcessor}.
87 executionVariables.put("isAsyncProcess", "true");
88 executionVariables.put(ExecutionVariableNames.PRC_CUSTOMIZATION_UUID, "38dc9a92-214c-11e7-93ae-92361f002680");
91 * Temporary solution to add pnfCorrelationId to context. this value is getting from the request to SO api
92 * handler and then convert to CamudaInput
94 executionVariables.put(ExecutionVariableNames.PNF_CORRELATION_ID, "PNFDemo");
99 public void workflow_validInput_expectedOutput() throws InterruptedException {
104 final String msoRequestId = UUID.randomUUID().toString();
105 executionVariables.put(ExecutionVariableNames.MSO_REQUEST_ID, msoRequestId);
107 final String testBusinessKey = UUID.randomUUID().toString();
108 logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
111 runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, executionVariables);
114 while (!isProcessInstanceEnded() && waitCount >= 0) {
115 Thread.sleep(WORKFLOW_WAIT_TIME);
119 // Layout is to reflect the bpmn visual layout
120 assertThat(pi).isEnded().hasPassedInOrder("softwareUpgrade_startEvent", "ServiceTask_042uz7n",
121 "ServiceTask_0slpahe", "ExclusiveGateway_0x6h0ni", "ServiceTask_0x5cje8", "ExclusiveGateway_0v3l3wv",
122 "ServiceTask_02lxf48", "ExclusiveGateway_0ch3fef", "ServiceTask_0y2uysu", "ExclusiveGateway_1ny9b1z",
123 "softwareUpgrade_endEvent");
125 List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
126 assertThat(detailedMessages.size() == 4);
129 for (ExecutionServiceInput eSI : detailedMessages) {
130 for (String action : actionNames) {
131 if (action.equals(eSI.getActionIdentifiers().getActionName())
132 && eSI.getCommonHeader().getRequestId().equals(msoRequestId)) {
133 checkWithActionName(eSI, action);
138 } catch (Exception e) {
140 fail("PNFSoftwareUpgrade request exception", e);
142 assertThat(count == actionNames.length);
145 private boolean isProcessInstanceEnded() {
146 return runtimeService.createProcessInstanceQuery().processDefinitionKey(TEST_PROCESSINSTANCE_KEY)
147 .singleResult() == null;
150 private void checkWithActionName(ExecutionServiceInput executionServiceInput, String action) {
152 logger.info("Checking the " + action + " request");
153 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
156 * the fields of actionIdentifiers should match the one in the response/PNFSoftwareUpgrade_catalogdb.json.
158 assertThat(actionIdentifiers.getBlueprintName()).isEqualTo("test_pnf_software_upgrade_restconf");
159 assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo("1.0.0");
160 assertThat(actionIdentifiers.getActionName()).isEqualTo(action);
161 assertThat(actionIdentifiers.getMode()).isEqualTo("async");
163 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
164 assertThat(commonHeader.getOriginatorId()).isEqualTo("SO");
166 Struct payload = executionServiceInput.getPayload();
167 Struct requeststruct = payload.getFieldsOrThrow(action + "-request").getStructValue();
169 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).isEqualTo("PNFDemo");
170 Struct propertiesStruct = requeststruct.getFieldsOrThrow(action + "-properties").getStructValue();
172 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo("PNFDemo");
173 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
174 .isEqualTo("32daaac6-5017-4e1e-96c8-6a27dfbe1421");
175 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
176 .isEqualTo("38dc9a92-214c-11e7-93ae-92361f002680");
177 assertThat(propertiesStruct.getFieldsOrThrow("target-software-version").getStringValue())
178 .isEqualTo("demo-sw-ver2.0.0");
181 private void mockAai() {
184 "{ \n" + " \"pnf-name\":\"PNFDemo\",\n" + " \"pnf-id\":\"testtest\",\n" + " \"in-maint\":true,\n"
185 + " \"resource-version\":\"1541720264047\",\n" + " \"swVersion\":\"demo-1.1\",\n"
186 + " \"ipaddress-v4-oam\":\"1.1.1.1\",\n" + " \"ipaddress-v6-oam\":\"::/128\"\n" + "}";
189 * PUT the PNF correlation ID to AAI.
191 wireMockServer.stubFor(put(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")));
194 * Get the PNF entry from AAI.
196 wireMockServer.stubFor(
197 get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry)));
200 * Post the pnf to AAI
202 wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")));
206 * Mock the catalobdb rest interface.
208 private void mockCatalogDb() {
210 String catalogdbClientResponse =
211 FileUtil.readResourceFile("response/" + getClass().getSimpleName() + "_catalogdb.json");
215 * Return valid json for the model UUID in the request file.
218 .stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=32daaac6-5017-4e1e-96c8-6a27dfbe1421"))
219 .willReturn(okJson(responseObject)));
222 * Return valid json for the service model InvariantUUID as specified in the request file.
224 wireMockServer.stubFor(
225 get(urlEqualTo("/v2/serviceResources?serviceModelInvariantUuid=339b7a2f-9524-4dbf-9eee-f2e05521df3f"))
226 .willReturn(okJson(responseObject)));
229 * Return valid spring data rest json for the service model UUID as specified in the request file.
231 wireMockServer.stubFor(get(urlEqualTo(
232 "/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=32daaac6-5017-4e1e-96c8-6a27dfbe1421"))
233 .willReturn(okJson(catalogdbClientResponse)));