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.Ignore;
40 import org.junit.Test;
41 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
42 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
43 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
44 import org.onap.so.BaseBPMNTest;
45 import org.onap.so.GrpcNettyServer;
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;
53 * Basic Integration test for createVcpeResCustService_Simplified.bpmn workflow.
56 public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
58 private static final long WORKFLOW_WAIT_TIME = 1000L;
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. It's injected by {@link WorkflowProcessor}.
82 variables.put("isAsyncProcess", "true");
85 * Temporary solution to add pnfCorrelationId to context. this value is getting from the request to SO api
86 * handler and then convert to CamudaInput
88 variables.put("pnfCorrelationId", "PNFDemo");
91 * Create mso-request-id.
93 msoRequestId = UUID.randomUUID().toString();
95 variables.put("mso-request-id", msoRequestId);
98 * Create Business key for the process instance
100 testBusinessKey = UUID.randomUUID().toString();
102 logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
107 public void workflow_validInput_expectedOuput() throws InterruptedException {
115 runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, variables);
116 assertThat(pi).isNotNull();
118 Thread.sleep(WORKFLOW_WAIT_TIME);
120 Execution execution = runtimeService.createExecutionQuery().processInstanceBusinessKey(testBusinessKey)
121 .messageEventSubscriptionName("WorkflowMessage").singleResult();
123 assertThat(execution).isNotNull();
126 while (!pi.isEnded() && waitCount >= 0) {
127 Thread.sleep(WORKFLOW_WAIT_TIME);
131 assertThat(pi).isEnded().hasPassedInOrder("createVCPE_startEvent", "preProcessRequest_ScriptTask",
132 "sendSyncAckResponse_ScriptTask", "ScriptTask_0cdtchu", "DecomposeService", "ScriptTask_0lpv2da",
133 "ScriptTask_1y241p8", "CallActivity_1vc4jeh", "ScriptTask_1y5lvl7", "GeneratePnfUuid", "Task_14l19kv",
134 "Pnf_Con", "setPONR_ScriptTask", "postProcessAndCompletionRequest_ScriptTask",
135 "callCompleteMsoProcess_CallActivity", "ScriptTask_2", "CreateVCPE_EndEvent");
137 List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
138 assertThat(detailedMessages).hasSize(2);
140 checkConfigAssign(detailedMessages.get(0));
141 checkConfigDeploy(detailedMessages.get(1));
142 } catch (Exception e) {
144 fail("ConfigAssign/deploy request exception", e);
148 private void checkConfigAssign(ExecutionServiceInput executionServiceInput) {
150 logger.info("Checking the configAssign request");
151 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
154 * the fields of actionIdentifiers should match the one in the
155 * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
157 assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf");
158 assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0");
159 assertThat(actionIdentifiers.getActionName()).matches("config-assign");
160 assertThat(actionIdentifiers.getMode()).matches("sync");
162 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
163 assertThat(commonHeader.getOriginatorId()).matches("SO");
164 assertThat(commonHeader.getRequestId()).matches(msoRequestId);
166 Struct payload = executionServiceInput.getPayload();
167 Struct requeststruct = payload.getFieldsOrThrow("config-assign-request").getStructValue();
169 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo");
170 Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-assign-properties").getStructValue();
172 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo");
173 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
174 .matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
175 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
176 .matches("68dc9a92-214c-11e7-93ae-92361f002680");
179 private void checkConfigDeploy(ExecutionServiceInput executionServiceInput) {
181 logger.info("Checking the configDeploy request");
182 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
185 * the fields of actionIdentifiers should match the one in the
186 * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
188 assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf");
189 assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0");
190 assertThat(actionIdentifiers.getActionName()).matches("config-deploy");
191 assertThat(actionIdentifiers.getMode()).matches("async");
193 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
194 assertThat(commonHeader.getOriginatorId()).matches("SO");
195 assertThat(commonHeader.getRequestId()).matches(msoRequestId);
197 Struct payload = executionServiceInput.getPayload();
198 Struct requeststruct = payload.getFieldsOrThrow("config-deploy-request").getStructValue();
200 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo");
201 Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-deploy-properties").getStructValue();
203 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo");
204 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
205 .matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
206 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
207 .matches("68dc9a92-214c-11e7-93ae-92361f002680");
210 * IP addresses match the OAM ip addresses from AAI.
212 assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv4-address").getStringValue()).matches("1.1.1.1");
213 assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv6-address").getStringValue()).matches("::/128");
217 * Mock the Dmaap Rest interface for Pnf topic.
219 private void mockDmaapForPnf() {
221 String pnfResponse = "[{\"correlationId\": \"PNFDemo\",\"key1\":\"value1\"}]";
224 * Get the events from PNF topic
227 .stubFor(get(urlPathMatching("/events/pnfReady/consumerGroup.*")).willReturn(okJson(pnfResponse)));
230 private void mockAai() {
232 String aaiResponse = "{\n" + " \"results\": [\n" + " {\n"
233 + " \"resource-type\": \"service-instance\",\n"
234 + " \"resource-link\": \"https://localhost:8443/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/key3\"\n"
235 + " }\n" + " ]\n" + "}";
237 String aaiPnfEntry = "{ \n" + " \"pnf-name\":\"PNFDemo\",\n" + " \"pnf-id\":\"testtest\",\n"
238 + " \"in-maint\":true,\n" + " \"resource-version\":\"1541720264047\",\n"
239 + " \"ipaddress-v4-oam\":\"1.1.1.1\",\n" + " \"ipaddress-v6-oam\":\"::/128\"\n" + "}";
242 * Get the AAI entry for globalCustomerId as specified in the request file.
244 wireMockServer.stubFor(
245 get(urlPathMatching("/aai/v15/business/customers/customer/ADemoCustomerInCiti.*")).willReturn(ok()));
248 * PUT the service to AAI with globalCustomerId, service type as specified in the request file. Service instance
249 * id is generated during runtime, REGEX is used to represent the information.
251 wireMockServer.stubFor(put(urlPathMatching(
252 "/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/.*")));
254 wireMockServer.stubFor(get(urlPathMatching(
255 "/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/.*"))
256 .willReturn(okJson(aaiResponse)));
259 * Get the service from AAI
261 wireMockServer.stubFor(get(urlPathMatching("/aai/v15/nodes/service-instances/service-instance/.*"))
262 .willReturn(okJson(aaiResponse)));
265 * Put the project as specified in the request file to AAI.
267 wireMockServer.stubFor(put(urlEqualTo("/aai/v15/business/projects/project/Project-Demonstration")));
270 * GET the project as specified in the request file to AAI.
272 wireMockServer.stubFor(
273 get(urlPathMatching("/aai/v15/business/projects/project/Project-Demonstration")).willReturn(ok()));
276 * PUT the PNF correlation ID to AAI.
278 wireMockServer.stubFor(put(urlEqualTo("/aai/v15/network/pnfs/pnf/PNFDemo")));
281 * Get the PNF entry from AAI.
283 wireMockServer.stubFor(get(urlEqualTo("/aai/v15/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry)));
286 * Put the PNF relationship
288 wireMockServer.stubFor(put(
289 urlEqualTo("/aai/v15/business/projects/project/Project-Demonstration/relationship-list/relationship")));
293 * Mock the catalobdb rest interface.
295 private void mockCatalogDb() {
297 String catalogdbClientResponse =
298 FileUtil.readResourceFile("response/" + getClass().getSimpleName() + "_catalogdb.json");
301 * Return valid json for the model UUID in the request file.
304 .stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=f2daaac6-5017-4e1e-96c8-6a27dfbe1421"))
305 .willReturn(okJson(responseObject)));
308 * Return valid json for the service model InvariantUUID as specified in the request file.
310 wireMockServer.stubFor(
311 get(urlEqualTo("/v2/serviceResources?serviceModelInvariantUuid=539b7a2f-9524-4dbf-9eee-f2e05521df3f"))
312 .willReturn(okJson(responseObject)));
315 * Return valid spring data rest json for the service model UUID as specified in the request file.
317 wireMockServer.stubFor(get(urlEqualTo(
318 "/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=f2daaac6-5017-4e1e-96c8-6a27dfbe1421"))
319 .willReturn(okJson(catalogdbClientResponse)));
322 private void mockRequestDb() {
323 wireMockServer.stubFor(post(urlEqualTo("/dbadapters/RequestsDbAdapter")).willReturn(ok()));