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.put;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
29 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
31 import java.io.IOException;
32 import java.util.List;
33 import java.util.UUID;
34 import org.camunda.bpm.engine.runtime.Execution;
35 import org.camunda.bpm.engine.runtime.ProcessInstance;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.so.BaseBPMNTest;
39 import org.onap.so.GrpcNettyServer;
40 import org.onap.so.bpmn.mock.FileUtil;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.springframework.beans.factory.annotation.Autowired;
47 * Basic Integration test for createVcpeResCustService_Simplified.bpmn workflow.
49 public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
51 private Logger logger = LoggerFactory.getLogger(getClass());
53 private static final String TEST_PROCESSINSTANCE_KEY = "CreateVcpeResCustService_simplified";
55 private String testBusinessKey;
56 private String requestObject;
57 private String responseObject;
60 private GrpcNettyServer grpcNettyServer;
63 public void setUp() throws IOException {
65 requestObject = FileUtil.readResourceFile("request/" + getClass().getSimpleName() + ".json");
66 responseObject = FileUtil.readResourceFile("response/" + getClass().getSimpleName() + ".json");
68 variables.put("bpmnRequest", requestObject);
71 * This variable indicates that the flow was invoked asynchronously.
72 * It's injected by {@link WorkflowProcessor}.
74 variables.put("isAsyncProcess", "true");
77 * Temporary solution to add pnfCorrelationId to context.
78 * this value is getting from the request to SO api handler and then convert to CamudaInput
80 variables.put("pnfCorrelationId", "PNFDemo");
83 * Create mso-request-id.
85 String msoRequestId = UUID.randomUUID().toString();
87 variables.put("mso-request-id", msoRequestId);
90 * Create Business key for the process instance
92 testBusinessKey = UUID.randomUUID().toString();
94 logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
99 public void workflow_validInput_expectedOuput() {
105 ProcessInstance pi = runtimeService
106 .startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, variables);
107 assertThat(pi).isNotNull();
109 Execution execution = runtimeService.createExecutionQuery().processDefinitionKey("CreateAndActivatePnfResource")
110 .activityId("WaitForDmaapPnfReadyNotification").singleResult();
112 if (!execution.isSuspended() && !execution.isEnded()) {
115 runtimeService.signal(execution.getId());
116 } catch (Exception e) {
117 logger.info(e.getMessage(), e);
121 assertThat(pi).isStarted().hasPassedInOrder(
122 "createVCPE_startEvent",
123 "preProcessRequest_ScriptTask",
124 "sendSyncAckResponse_ScriptTask",
125 "ScriptTask_0cdtchu",
127 "ScriptTask_0lpv2da",
128 "ScriptTask_1y241p8",
129 "CallActivity_1vc4jeh",
130 "ScriptTask_1y5lvl7",
134 "setPONR_ScriptTask",
135 "postProcessAndCompletionRequest_ScriptTask",
136 "callCompleteMsoProcess_CallActivity",
138 "CreateVCPE_EndEvent"
141 assertThat(pi).isEnded();
143 List<String> messagesDelivered = grpcNettyServer.getMessagesDelivered();
144 assertThat(messagesDelivered).containsSequence("config-assign", "config-deploy");
148 * Mock the Dmaap Rest interface for Pnf topic.
150 private void mockDmaapForPnf() {
152 String pnfResponse = "[{\"correlationId\": \"PNFDemo\",\"key1\":\"value1\"}]";
155 * Get the events from PNF topic
158 .stubFor(get(urlPathMatching("/events/pnfReady/consumerGroup.*")).willReturn(okJson(pnfResponse)));
161 private void mockAai() {
163 String aaiResponse = "{\n"
164 + " \"results\": [\n"
166 + " \"resource-type\": \"service-instance\",\n"
167 + " \"resource-link\": \"https://localhost:8443/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/key3\"\n"
172 String aaiPnfEntry = "{ \n"
173 + " \"pnf-name\":\"PNFDemo\",\n"
174 + " \"pnf-id\":\"testtest\",\n"
175 + " \"in-maint\":true,\n"
176 + " \"resource-version\":\"1541720264047\",\n"
177 + " \"pnf-ipv4-address\":\"1.1.1.1\",\n"
178 + " \"pnf-ipv6-address\":\"ipv6\"\n"
182 * Get the AAI entry for globalCustomerId as specified in the request file.
184 wireMockServer.stubFor(
185 get(urlPathMatching("/aai/v15/business/customers/customer/ADemoCustomerInCiti.*")).willReturn(ok()));
188 * PUT the service to AAI with globalCustomerId, service type as specified in the request file.
189 * Service instance id is generated during runtime, REGEX is used to represent the information.
191 wireMockServer.stubFor(put(urlPathMatching(
192 "/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/.*")));
194 wireMockServer.stubFor(get(urlPathMatching(
195 "/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/.*"))
196 .willReturn(okJson(aaiResponse)));
199 * Get the service from AAI
201 wireMockServer.stubFor(get(urlPathMatching("/aai/v15/nodes/service-instances/service-instance/.*"))
202 .willReturn(okJson(aaiResponse)));
205 * Put the project as specified in the request file to AAI.
207 wireMockServer.stubFor(put(urlEqualTo("/aai/v15/business/projects/project/Project-Demonstration")));
210 * GET the project as specified in the request file to AAI.
213 .stubFor(get(urlPathMatching("/aai/v15/business/projects/project/Project-Demonstration")).willReturn(ok()));
216 * PUT the PNF correlation ID to AAI.
218 wireMockServer.stubFor(put(urlEqualTo("/aai/v15/network/pnfs/pnf/PNFDemo")));
221 * Get the PNF entry from AAI.
223 wireMockServer.stubFor(get(urlEqualTo("/aai/v15/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry)));
226 * Put the PNF relationship
228 wireMockServer.stubFor(
229 put(urlEqualTo("/aai/v15/business/projects/project/Project-Demonstration/relationship-list/relationship")));
233 * Mock the catalobdb rest interface.
235 private void mockCatalogDb() {
237 String catalogdbClientResponse = FileUtil
238 .readResourceFile("response/" + getClass().getSimpleName() + "_catalogdb.json");
241 * Return valid json for the model UUID in the request file.
244 .stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=f2daaac6-5017-4e1e-96c8-6a27dfbe1421"))
245 .willReturn(okJson(responseObject)));
248 * Return valid json for the service model InvariantUUID as specified in the request file.
250 wireMockServer.stubFor(
251 get(urlEqualTo("/v2/serviceResources?serviceModelInvariantUuid=539b7a2f-9524-4dbf-9eee-f2e05521df3f"))
252 .willReturn(okJson(responseObject)));
255 * Return valid spring data rest json for the service model UUID as specified in the request file.
257 wireMockServer.stubFor(get(urlEqualTo(
258 "/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=f2daaac6-5017-4e1e-96c8-6a27dfbe1421"))
259 .willReturn(okJson(catalogdbClientResponse)));