3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2019 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * 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.ok;
25 import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
26 import static com.github.tomakehurst.wiremock.client.WireMock.post;
27 import static com.github.tomakehurst.wiremock.client.WireMock.put;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
29 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
30 import static org.assertj.core.api.Assertions.fail;
31 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
33 import com.google.protobuf.Struct;
34 import com.google.protobuf.Value;
35 import java.io.IOException;
36 import java.util.List;
38 import java.util.UUID;
39 import org.camunda.bpm.engine.runtime.Execution;
40 import org.camunda.bpm.engine.runtime.ProcessInstance;
41 import org.junit.Before;
42 import org.junit.Test;
43 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
44 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
45 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
46 import org.onap.so.BaseBPMNTest;
47 import org.onap.so.GrpcNettyServer;
48 import org.onap.so.bpmn.mock.FileUtil;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import org.springframework.beans.factory.annotation.Autowired;
55 * Basic Integration test for createVcpeResCustService_Simplified.bpmn workflow.
57 public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
59 private Logger logger = LoggerFactory.getLogger(getClass());
61 private static final String TEST_PROCESSINSTANCE_KEY = "CreateVcpeResCustService_simplified";
63 private String testBusinessKey;
64 private String requestObject;
65 private String responseObject;
66 private String msoRequestId;
69 private GrpcNettyServer grpcNettyServer;
72 public void setUp() throws IOException {
74 requestObject = FileUtil.readResourceFile("request/" + getClass().getSimpleName() + ".json");
75 responseObject = FileUtil.readResourceFile("response/" + getClass().getSimpleName() + ".json");
77 variables.put("bpmnRequest", requestObject);
80 * This variable indicates that the flow was invoked asynchronously.
81 * It's injected by {@link WorkflowProcessor}.
83 variables.put("isAsyncProcess", "true");
86 * Temporary solution to add pnfCorrelationId to context.
87 * this value is getting from the request to SO api handler and then convert to CamudaInput
89 variables.put("pnfCorrelationId", "PNFDemo");
92 * Create mso-request-id.
94 msoRequestId = UUID.randomUUID().toString();
96 variables.put("mso-request-id", msoRequestId);
99 * Create Business key for the process instance
101 testBusinessKey = UUID.randomUUID().toString();
103 logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
108 public void workflow_validInput_expectedOuput() {
115 ProcessInstance pi = runtimeService
116 .startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, variables);
117 assertThat(pi).isNotNull();
119 Execution execution = runtimeService.createExecutionQuery().processDefinitionKey("CreateAndActivatePnfResource")
120 .activityId("WaitForDmaapPnfReadyNotification").singleResult();
122 if (!execution.isSuspended() && !execution.isEnded()) {
124 runtimeService.signal(execution.getId());
125 } catch (Exception e) {
126 logger.info(e.getMessage(), e);
130 assertThat(pi).isStarted().hasPassedInOrder(
131 "createVCPE_startEvent",
132 "preProcessRequest_ScriptTask",
133 "sendSyncAckResponse_ScriptTask",
134 "ScriptTask_0cdtchu",
136 "ScriptTask_0lpv2da",
137 "ScriptTask_1y241p8",
138 "CallActivity_1vc4jeh",
139 "ScriptTask_1y5lvl7",
143 "setPONR_ScriptTask",
144 "postProcessAndCompletionRequest_ScriptTask",
145 "callCompleteMsoProcess_CallActivity",
147 "CreateVCPE_EndEvent"
150 assertThat(pi).isEnded();
152 List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
153 assertThat(detailedMessages).hasSize(2);
155 checkConfigAssign(detailedMessages.get(0));
156 checkConfigDeploy(detailedMessages.get(1));
157 } catch(Exception e){
159 fail("ConfigAssign/deploy request exception", e);
163 private void checkConfigAssign(ExecutionServiceInput executionServiceInput) {
164 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
167 * the fields of actionIdentifiers should match the one in the response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
169 assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf");
170 assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0");
171 assertThat(actionIdentifiers.getActionName()).matches("config-assign");
172 assertThat(actionIdentifiers.getMode()).matches("sync");
174 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
175 assertThat(commonHeader.getOriginatorId()).matches("SO");
176 assertThat(commonHeader.getRequestId()).matches(msoRequestId);
178 Struct payload = executionServiceInput.getPayload();
179 Struct requeststruct = payload.getFieldsOrThrow("config-assign-request").getStructValue();
181 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo");
182 Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-assign-properties").getStructValue();
184 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo");
185 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()).matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
186 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue()).matches("68dc9a92-214c-11e7-93ae-92361f002680");
189 private void checkConfigDeploy(ExecutionServiceInput executionServiceInput) {
190 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
193 * the fields of actionIdentifiers should match the one in the response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
195 assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf");
196 assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0");
197 assertThat(actionIdentifiers.getActionName()).matches("config-deploy");
198 assertThat(actionIdentifiers.getMode()).matches("async");
200 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
201 assertThat(commonHeader.getOriginatorId()).matches("SO");
202 assertThat(commonHeader.getRequestId()).matches(msoRequestId);
204 Struct payload = executionServiceInput.getPayload();
205 Struct requeststruct = payload.getFieldsOrThrow("config-deploy-request").getStructValue();
207 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo");
208 Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-deploy-properties").getStructValue();
210 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo");
211 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()).matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
212 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue()).matches("68dc9a92-214c-11e7-93ae-92361f002680");
215 * IP addresses match the OAM ip addresses from AAI.
217 assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv4-address").getStringValue()).matches("1.1.1.1");
218 assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv6-address").getStringValue()).matches("::/128");
222 * Mock the Dmaap Rest interface for Pnf topic.
224 private void mockDmaapForPnf() {
226 String pnfResponse = "[{\"correlationId\": \"PNFDemo\",\"key1\":\"value1\"}]";
229 * Get the events from PNF topic
232 .stubFor(get(urlPathMatching("/events/pnfReady/consumerGroup.*")).willReturn(okJson(pnfResponse)));
235 private void mockAai() {
237 String aaiResponse = "{\n"
238 + " \"results\": [\n"
240 + " \"resource-type\": \"service-instance\",\n"
241 + " \"resource-link\": \"https://localhost:8443/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/key3\"\n"
246 String aaiPnfEntry = "{ \n"
247 + " \"pnf-name\":\"PNFDemo\",\n"
248 + " \"pnf-id\":\"testtest\",\n"
249 + " \"in-maint\":true,\n"
250 + " \"resource-version\":\"1541720264047\",\n"
251 + " \"ipaddress-v4-oam\":\"1.1.1.1\",\n"
252 + " \"ipaddress-v6-oam\":\"::/128\"\n"
256 * Get the AAI entry for globalCustomerId as specified in the request file.
258 wireMockServer.stubFor(
259 get(urlPathMatching("/aai/v15/business/customers/customer/ADemoCustomerInCiti.*")).willReturn(ok()));
262 * PUT the service to AAI with globalCustomerId, service type as specified in the request file.
263 * Service instance id is generated during runtime, REGEX is used to represent the information.
265 wireMockServer.stubFor(put(urlPathMatching(
266 "/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/.*")));
268 wireMockServer.stubFor(get(urlPathMatching(
269 "/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/.*"))
270 .willReturn(okJson(aaiResponse)));
273 * Get the service from AAI
275 wireMockServer.stubFor(get(urlPathMatching("/aai/v15/nodes/service-instances/service-instance/.*"))
276 .willReturn(okJson(aaiResponse)));
279 * Put the project as specified in the request file to AAI.
281 wireMockServer.stubFor(put(urlEqualTo("/aai/v15/business/projects/project/Project-Demonstration")));
284 * GET the project as specified in the request file to AAI.
287 .stubFor(get(urlPathMatching("/aai/v15/business/projects/project/Project-Demonstration")).willReturn(ok()));
290 * PUT the PNF correlation ID to AAI.
292 wireMockServer.stubFor(put(urlEqualTo("/aai/v15/network/pnfs/pnf/PNFDemo")));
295 * Get the PNF entry from AAI.
297 wireMockServer.stubFor(get(urlEqualTo("/aai/v15/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry)));
300 * Put the PNF relationship
302 wireMockServer.stubFor(
303 put(urlEqualTo("/aai/v15/business/projects/project/Project-Demonstration/relationship-list/relationship")));
307 * Mock the catalobdb rest interface.
309 private void mockCatalogDb() {
311 String catalogdbClientResponse = FileUtil
312 .readResourceFile("response/" + getClass().getSimpleName() + "_catalogdb.json");
315 * Return valid json for the model UUID in the request file.
318 .stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=f2daaac6-5017-4e1e-96c8-6a27dfbe1421"))
319 .willReturn(okJson(responseObject)));
322 * Return valid json for the service model InvariantUUID as specified in the request file.
324 wireMockServer.stubFor(
325 get(urlEqualTo("/v2/serviceResources?serviceModelInvariantUuid=539b7a2f-9524-4dbf-9eee-f2e05521df3f"))
326 .willReturn(okJson(responseObject)));
329 * Return valid spring data rest json for the service model UUID as specified in the request file.
331 wireMockServer.stubFor(get(urlEqualTo(
332 "/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=f2daaac6-5017-4e1e-96c8-6a27dfbe1421"))
333 .willReturn(okJson(catalogdbClientResponse)));
336 private void mockRequestDb() {
337 wireMockServer.stubFor(post(urlEqualTo("/dbadapters/RequestsDbAdapter")).willReturn(ok()));