2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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.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;
32 import com.google.protobuf.Struct;
33 import java.io.IOException;
34 import java.util.List;
35 import java.util.UUID;
36 import org.camunda.bpm.engine.runtime.Execution;
37 import org.camunda.bpm.engine.runtime.ProcessInstance;
38 import org.junit.Before;
39 import org.junit.Test;
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.mock.FileUtil;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48 import org.springframework.beans.factory.annotation.Autowired;
52 * Basic Integration test for createVcpeResCustService_Simplified.bpmn workflow.
54 public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
56 private Logger logger = LoggerFactory.getLogger(getClass());
58 private static final String TEST_PROCESSINSTANCE_KEY = "CreateVcpeResCustService_simplified";
60 private String testBusinessKey;
61 private String requestObject;
62 private String responseObject;
63 private String msoRequestId;
66 private GrpcNettyServer grpcNettyServer;
69 public void setUp() throws IOException {
71 requestObject = FileUtil.readResourceFile("request/" + getClass().getSimpleName() + ".json");
72 responseObject = FileUtil.readResourceFile("response/" + getClass().getSimpleName() + ".json");
74 variables.put("bpmnRequest", requestObject);
77 * This variable indicates that the flow was invoked asynchronously. It's injected by {@link WorkflowProcessor}.
79 variables.put("isAsyncProcess", "true");
82 * Temporary solution to add pnfCorrelationId to context. this value is getting from the request to SO api
83 * handler and then convert to CamudaInput
85 variables.put("pnfCorrelationId", "PNFDemo");
88 * Create mso-request-id.
90 msoRequestId = UUID.randomUUID().toString();
92 variables.put("mso-request-id", msoRequestId);
95 * Create Business key for the process instance
97 testBusinessKey = UUID.randomUUID().toString();
99 logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
104 public void workflow_validInput_expectedOuput() {
112 runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, variables);
113 assertThat(pi).isNotNull();
115 Execution execution = runtimeService.createExecutionQuery().processDefinitionKey("CreateAndActivatePnfResource")
116 .activityId("WaitForDmaapPnfReadyNotification").singleResult();
118 if (!execution.isSuspended() && !execution.isEnded()) {
121 runtimeService.signal(execution.getId());
122 } catch (Exception e) {
123 logger.info(e.getMessage(), e);
127 assertThat(pi).isStarted().hasPassedInOrder("createVCPE_startEvent", "preProcessRequest_ScriptTask",
128 "sendSyncAckResponse_ScriptTask", "ScriptTask_0cdtchu", "DecomposeService", "ScriptTask_0lpv2da",
129 "ScriptTask_1y241p8", "CallActivity_1vc4jeh", "ScriptTask_1y5lvl7", "GeneratePnfUuid", "Task_14l19kv",
130 "Pnf_Con", "setPONR_ScriptTask", "postProcessAndCompletionRequest_ScriptTask",
131 "callCompleteMsoProcess_CallActivity", "ScriptTask_2", "CreateVCPE_EndEvent");
133 assertThat(pi).isEnded();
135 List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
136 assertThat(detailedMessages).hasSize(2);
138 checkConfigAssign(detailedMessages.get(0));
139 checkConfigDeploy(detailedMessages.get(1));
140 } catch (Exception e) {
142 fail("ConfigAssign/deploy request exception", e);
146 private void checkConfigAssign(ExecutionServiceInput executionServiceInput) {
147 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
150 * the fields of actionIdentifiers should match the one in the
151 * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
153 assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf");
154 assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0");
155 assertThat(actionIdentifiers.getActionName()).matches("config-assign");
156 assertThat(actionIdentifiers.getMode()).matches("sync");
158 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
159 assertThat(commonHeader.getOriginatorId()).matches("SO");
160 assertThat(commonHeader.getRequestId()).matches(msoRequestId);
162 Struct payload = executionServiceInput.getPayload();
163 Struct requeststruct = payload.getFieldsOrThrow("config-assign-request").getStructValue();
165 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo");
166 Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-assign-properties").getStructValue();
168 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo");
169 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
170 .matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
171 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
172 .matches("68dc9a92-214c-11e7-93ae-92361f002680");
175 private void checkConfigDeploy(ExecutionServiceInput executionServiceInput) {
176 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
179 * the fields of actionIdentifiers should match the one in the
180 * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
182 assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf");
183 assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0");
184 assertThat(actionIdentifiers.getActionName()).matches("config-deploy");
185 assertThat(actionIdentifiers.getMode()).matches("async");
187 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
188 assertThat(commonHeader.getOriginatorId()).matches("SO");
189 assertThat(commonHeader.getRequestId()).matches(msoRequestId);
191 Struct payload = executionServiceInput.getPayload();
192 Struct requeststruct = payload.getFieldsOrThrow("config-deploy-request").getStructValue();
194 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo");
195 Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-deploy-properties").getStructValue();
197 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo");
198 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
199 .matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
200 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
201 .matches("68dc9a92-214c-11e7-93ae-92361f002680");
204 * IP addresses match the OAM ip addresses from AAI.
206 assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv4-address").getStringValue()).matches("1.1.1.1");
207 assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv6-address").getStringValue()).matches("::/128");
211 * Mock the Dmaap Rest interface for Pnf topic.
213 private void mockDmaapForPnf() {
215 String pnfResponse = "[{\"correlationId\": \"PNFDemo\",\"key1\":\"value1\"}]";
218 * Get the events from PNF topic
221 .stubFor(get(urlPathMatching("/events/pnfReady/consumerGroup.*")).willReturn(okJson(pnfResponse)));
224 private void mockAai() {
226 String aaiResponse = "{\n" + " \"results\": [\n" + " {\n"
227 + " \"resource-type\": \"service-instance\",\n"
228 + " \"resource-link\": \"https://localhost:8443/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/key3\"\n"
229 + " }\n" + " ]\n" + "}";
231 String aaiPnfEntry = "{ \n" + " \"pnf-name\":\"PNFDemo\",\n" + " \"pnf-id\":\"testtest\",\n"
232 + " \"in-maint\":true,\n" + " \"resource-version\":\"1541720264047\",\n"
233 + " \"ipaddress-v4-oam\":\"1.1.1.1\",\n" + " \"ipaddress-v6-oam\":\"::/128\"\n" + "}";
236 * Get the AAI entry for globalCustomerId as specified in the request file.
238 wireMockServer.stubFor(
239 get(urlPathMatching("/aai/v15/business/customers/customer/ADemoCustomerInCiti.*")).willReturn(ok()));
242 * PUT the service to AAI with globalCustomerId, service type as specified in the request file. Service instance
243 * id is generated during runtime, REGEX is used to represent the information.
245 wireMockServer.stubFor(put(urlPathMatching(
246 "/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/.*")));
248 wireMockServer.stubFor(get(urlPathMatching(
249 "/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/.*"))
250 .willReturn(okJson(aaiResponse)));
253 * Get the service from AAI
255 wireMockServer.stubFor(get(urlPathMatching("/aai/v15/nodes/service-instances/service-instance/.*"))
256 .willReturn(okJson(aaiResponse)));
259 * Put the project as specified in the request file to AAI.
261 wireMockServer.stubFor(put(urlEqualTo("/aai/v15/business/projects/project/Project-Demonstration")));
264 * GET the project as specified in the request file to AAI.
266 wireMockServer.stubFor(
267 get(urlPathMatching("/aai/v15/business/projects/project/Project-Demonstration")).willReturn(ok()));
270 * PUT the PNF correlation ID to AAI.
272 wireMockServer.stubFor(put(urlEqualTo("/aai/v15/network/pnfs/pnf/PNFDemo")));
275 * Get the PNF entry from AAI.
277 wireMockServer.stubFor(get(urlEqualTo("/aai/v15/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry)));
280 * Put the PNF relationship
282 wireMockServer.stubFor(put(
283 urlEqualTo("/aai/v15/business/projects/project/Project-Demonstration/relationship-list/relationship")));
287 * Mock the catalobdb rest interface.
289 private void mockCatalogDb() {
291 String catalogdbClientResponse =
292 FileUtil.readResourceFile("response/" + getClass().getSimpleName() + "_catalogdb.json");
295 * Return valid json for the model UUID in the request file.
298 .stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=f2daaac6-5017-4e1e-96c8-6a27dfbe1421"))
299 .willReturn(okJson(responseObject)));
302 * Return valid json for the service model InvariantUUID as specified in the request file.
304 wireMockServer.stubFor(
305 get(urlEqualTo("/v2/serviceResources?serviceModelInvariantUuid=539b7a2f-9524-4dbf-9eee-f2e05521df3f"))
306 .willReturn(okJson(responseObject)));
309 * Return valid spring data rest json for the service model UUID as specified in the request file.
311 wireMockServer.stubFor(get(urlEqualTo(
312 "/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=f2daaac6-5017-4e1e-96c8-6a27dfbe1421"))
313 .willReturn(okJson(catalogdbClientResponse)));
316 private void mockRequestDb() {
317 wireMockServer.stubFor(post(urlEqualTo("/dbadapters/RequestsDbAdapter")).willReturn(ok()));