3 * ============LICENSE_START======================================================= Copyright (C) 2019 Nordix
4 * Foundation. ================================================================================ Licensed under the
5 * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may
6 * obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 * either express or implied. See the License for the specific language governing permissions and limitations under the
13 * SPDX-License-Identifier: Apache-2.0 ============LICENSE_END=========================================================
16 package org.onap.so.bpmn.infrastructure.process;
18 import static com.github.tomakehurst.wiremock.client.WireMock.get;
19 import static com.github.tomakehurst.wiremock.client.WireMock.ok;
20 import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
21 import static com.github.tomakehurst.wiremock.client.WireMock.post;
22 import static com.github.tomakehurst.wiremock.client.WireMock.put;
23 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
24 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
25 import static org.assertj.core.api.Assertions.fail;
26 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
27 import com.google.protobuf.Struct;
28 import com.google.protobuf.Value;
29 import java.io.IOException;
30 import java.util.List;
32 import java.util.UUID;
33 import org.camunda.bpm.engine.runtime.Execution;
34 import org.camunda.bpm.engine.runtime.ProcessInstance;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
38 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
39 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
40 import org.onap.so.BaseBPMNTest;
41 import org.onap.so.GrpcNettyServer;
42 import org.onap.so.bpmn.mock.FileUtil;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45 import org.springframework.beans.factory.annotation.Autowired;
49 * Basic Integration test for createVcpeResCustService_Simplified.bpmn workflow.
51 public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
53 private Logger logger = LoggerFactory.getLogger(getClass());
55 private static final String TEST_PROCESSINSTANCE_KEY = "CreateVcpeResCustService_simplified";
57 private String testBusinessKey;
58 private String requestObject;
59 private String responseObject;
60 private String msoRequestId;
63 private GrpcNettyServer grpcNettyServer;
66 public void setUp() throws IOException {
68 requestObject = FileUtil.readResourceFile("request/" + getClass().getSimpleName() + ".json");
69 responseObject = FileUtil.readResourceFile("response/" + getClass().getSimpleName() + ".json");
71 variables.put("bpmnRequest", requestObject);
74 * This variable indicates that the flow was invoked asynchronously. It's injected by {@link WorkflowProcessor}.
76 variables.put("isAsyncProcess", "true");
79 * Temporary solution to add pnfCorrelationId to context. this value is getting from the request to SO api
80 * handler and then convert to CamudaInput
82 variables.put("pnfCorrelationId", "PNFDemo");
85 * Create mso-request-id.
87 msoRequestId = UUID.randomUUID().toString();
89 variables.put("mso-request-id", msoRequestId);
92 * Create Business key for the process instance
94 testBusinessKey = UUID.randomUUID().toString();
96 logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
101 public void workflow_validInput_expectedOuput() {
109 runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, variables);
110 assertThat(pi).isNotNull();
112 Execution execution = runtimeService.createExecutionQuery().processDefinitionKey("CreateAndActivatePnfResource")
113 .activityId("WaitForDmaapPnfReadyNotification").singleResult();
115 if (!execution.isSuspended() && !execution.isEnded()) {
117 runtimeService.signal(execution.getId());
118 } catch (Exception e) {
119 logger.info(e.getMessage(), e);
123 assertThat(pi).isStarted().hasPassedInOrder("createVCPE_startEvent", "preProcessRequest_ScriptTask",
124 "sendSyncAckResponse_ScriptTask", "ScriptTask_0cdtchu", "DecomposeService", "ScriptTask_0lpv2da",
125 "ScriptTask_1y241p8", "CallActivity_1vc4jeh", "ScriptTask_1y5lvl7", "GeneratePnfUuid", "Task_14l19kv",
126 "Pnf_Con", "setPONR_ScriptTask", "postProcessAndCompletionRequest_ScriptTask",
127 "callCompleteMsoProcess_CallActivity", "ScriptTask_2", "CreateVCPE_EndEvent");
129 assertThat(pi).isEnded();
131 List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
132 assertThat(detailedMessages).hasSize(2);
134 checkConfigAssign(detailedMessages.get(0));
135 checkConfigDeploy(detailedMessages.get(1));
136 } catch (Exception e) {
138 fail("ConfigAssign/deploy request exception", e);
142 private void checkConfigAssign(ExecutionServiceInput executionServiceInput) {
143 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
146 * the fields of actionIdentifiers should match the one in the
147 * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
149 assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf");
150 assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0");
151 assertThat(actionIdentifiers.getActionName()).matches("config-assign");
152 assertThat(actionIdentifiers.getMode()).matches("sync");
154 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
155 assertThat(commonHeader.getOriginatorId()).matches("SO");
156 assertThat(commonHeader.getRequestId()).matches(msoRequestId);
158 Struct payload = executionServiceInput.getPayload();
159 Struct requeststruct = payload.getFieldsOrThrow("config-assign-request").getStructValue();
161 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo");
162 Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-assign-properties").getStructValue();
164 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo");
165 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
166 .matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
167 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
168 .matches("68dc9a92-214c-11e7-93ae-92361f002680");
171 private void checkConfigDeploy(ExecutionServiceInput executionServiceInput) {
172 ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
175 * the fields of actionIdentifiers should match the one in the
176 * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
178 assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf");
179 assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0");
180 assertThat(actionIdentifiers.getActionName()).matches("config-deploy");
181 assertThat(actionIdentifiers.getMode()).matches("async");
183 CommonHeader commonHeader = executionServiceInput.getCommonHeader();
184 assertThat(commonHeader.getOriginatorId()).matches("SO");
185 assertThat(commonHeader.getRequestId()).matches(msoRequestId);
187 Struct payload = executionServiceInput.getPayload();
188 Struct requeststruct = payload.getFieldsOrThrow("config-deploy-request").getStructValue();
190 assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo");
191 Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-deploy-properties").getStructValue();
193 assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo");
194 assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
195 .matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
196 assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
197 .matches("68dc9a92-214c-11e7-93ae-92361f002680");
200 * IP addresses match the OAM ip addresses from AAI.
202 assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv4-address").getStringValue()).matches("1.1.1.1");
203 assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv6-address").getStringValue()).matches("::/128");
207 * Mock the Dmaap Rest interface for Pnf topic.
209 private void mockDmaapForPnf() {
211 String pnfResponse = "[{\"correlationId\": \"PNFDemo\",\"key1\":\"value1\"}]";
214 * Get the events from PNF topic
217 .stubFor(get(urlPathMatching("/events/pnfReady/consumerGroup.*")).willReturn(okJson(pnfResponse)));
220 private void mockAai() {
222 String aaiResponse = "{\n" + " \"results\": [\n" + " {\n"
223 + " \"resource-type\": \"service-instance\",\n"
224 + " \"resource-link\": \"https://localhost:8443/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/key3\"\n"
225 + " }\n" + " ]\n" + "}";
227 String aaiPnfEntry = "{ \n" + " \"pnf-name\":\"PNFDemo\",\n" + " \"pnf-id\":\"testtest\",\n"
228 + " \"in-maint\":true,\n" + " \"resource-version\":\"1541720264047\",\n"
229 + " \"ipaddress-v4-oam\":\"1.1.1.1\",\n" + " \"ipaddress-v6-oam\":\"::/128\"\n" + "}";
232 * Get the AAI entry for globalCustomerId as specified in the request file.
234 wireMockServer.stubFor(
235 get(urlPathMatching("/aai/v15/business/customers/customer/ADemoCustomerInCiti.*")).willReturn(ok()));
238 * PUT the service to AAI with globalCustomerId, service type as specified in the request file. Service instance
239 * id is generated during runtime, REGEX is used to represent the information.
241 wireMockServer.stubFor(put(urlPathMatching(
242 "/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/.*")));
244 wireMockServer.stubFor(get(urlPathMatching(
245 "/aai/v15/business/customers/customer/ADemoCustomerInCiti/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/.*"))
246 .willReturn(okJson(aaiResponse)));
249 * Get the service from AAI
251 wireMockServer.stubFor(get(urlPathMatching("/aai/v15/nodes/service-instances/service-instance/.*"))
252 .willReturn(okJson(aaiResponse)));
255 * Put the project as specified in the request file to AAI.
257 wireMockServer.stubFor(put(urlEqualTo("/aai/v15/business/projects/project/Project-Demonstration")));
260 * GET the project as specified in the request file to AAI.
262 wireMockServer.stubFor(
263 get(urlPathMatching("/aai/v15/business/projects/project/Project-Demonstration")).willReturn(ok()));
266 * PUT the PNF correlation ID to AAI.
268 wireMockServer.stubFor(put(urlEqualTo("/aai/v15/network/pnfs/pnf/PNFDemo")));
271 * Get the PNF entry from AAI.
273 wireMockServer.stubFor(get(urlEqualTo("/aai/v15/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry)));
276 * Put the PNF relationship
278 wireMockServer.stubFor(put(
279 urlEqualTo("/aai/v15/business/projects/project/Project-Demonstration/relationship-list/relationship")));
283 * Mock the catalobdb rest interface.
285 private void mockCatalogDb() {
287 String catalogdbClientResponse =
288 FileUtil.readResourceFile("response/" + getClass().getSimpleName() + "_catalogdb.json");
291 * Return valid json for the model UUID in the request file.
294 .stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=f2daaac6-5017-4e1e-96c8-6a27dfbe1421"))
295 .willReturn(okJson(responseObject)));
298 * Return valid json for the service model InvariantUUID as specified in the request file.
300 wireMockServer.stubFor(
301 get(urlEqualTo("/v2/serviceResources?serviceModelInvariantUuid=539b7a2f-9524-4dbf-9eee-f2e05521df3f"))
302 .willReturn(okJson(responseObject)));
305 * Return valid spring data rest json for the service model UUID as specified in the request file.
307 wireMockServer.stubFor(get(urlEqualTo(
308 "/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=f2daaac6-5017-4e1e-96c8-6a27dfbe1421"))
309 .willReturn(okJson(catalogdbClientResponse)));
312 private void mockRequestDb() {
313 wireMockServer.stubFor(post(urlEqualTo("/dbadapters/RequestsDbAdapter")).willReturn(ok()));