2 * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
5 * ============LICENSE_START=======================================================
7 * ================================================================================
8 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.openecomp.mso.bpmn.infrastructure;
26 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
27 import static com.github.tomakehurst.wiremock.client.WireMock.get;
28 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
29 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
30 import static org.junit.Assert.assertEquals;
31 import static org.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow;
32 import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
33 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByName_404;
34 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
35 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
36 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById_404;
37 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
38 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.MockGetVnfCatalogDataCustomizationUuid;
39 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
40 import static org.openecomp.mso.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
42 import java.io.IOException;
43 import java.util.HashMap;
45 import java.util.UUID;
47 import org.camunda.bpm.engine.test.Deployment;
48 import org.junit.Ignore;
49 import org.junit.Test;
50 import org.openecomp.mso.bpmn.common.BPMNUtil;
51 import org.openecomp.mso.bpmn.common.WorkflowTest;
52 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
53 import org.openecomp.mso.bpmn.mock.FileUtil;
56 * Unit Test for the CreateVnfInfra Flow
58 public class CreateVnfInfraTest extends WorkflowTest {
60 private String createVnfInfraRequest;
61 private final CallbackSet callbacks = new CallbackSet();
64 public CreateVnfInfraTest() throws IOException {
65 createVnfInfraRequest = FileUtil.readResourceFile("__files/InfrastructureFlows/CreateVnfInfraRequest.json");
66 callbacks.put("assign", FileUtil.readResourceFile(
67 "__files/VfModularity/SDNCTopologyAssignCallback.xml"));
68 callbacks.put("activate", FileUtil.readResourceFile(
69 "__files/VfModularity/SDNCTopologyActivateCallback.xml"));
73 @Deployment(resources = {"subprocess/DoCreateVnf.bpmn",
74 "subprocess/GenericGetService.bpmn",
75 "subprocess/GenericGetVnf.bpmn",
76 "subprocess/GenericPutVnf.bpmn",
77 "subprocess/SDNCAdapterV1.bpmn",
78 "process/CreateVnfInfra.bpmn",
79 "subprocess/FalloutHandler.bpmn",
80 "subprocess/CompleteMsoProcess.bpmn"})
81 public void testCreateVnfInfra_success() throws Exception{
83 MockNodeQueryServiceInstanceById("MIS%2F1604%2F0026%2FSW_INTERNET", "GenericFlows/getSIUrlById.xml");
84 MockGetServiceInstance("SDN-ETHERNET-INTERNET", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceInstance.xml");
85 MockGetGenericVnfByName_404();
87 MockGetVnfCatalogDataCustomizationUuid("customizationId123", "VIPR/getCatalogVnfData.json");
88 mockSDNCAdapter("/SDNCAdapter", "vnf-type>STMTN", 200, "VfModularity/StandardSDNCSynchResponse.xml");
89 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
91 String businessKey = UUID.randomUUID().toString();
92 Map<String, Object> variables = new HashMap<>();
93 setVariablesSuccess(variables, createVnfInfraRequest, "testRequestId123", "MIS%2F1604%2F0026%2FSW_INTERNET");
94 TestAsyncResponse asyncResponse = invokeAsyncProcess("CreateVnfInfra",
95 "v1", businessKey, createVnfInfraRequest, variables);
97 WorkflowResponse response = receiveResponse(businessKey, asyncResponse, 10000);
99 String responseBody = response.getContent();
100 System.out.println("Workflow (Synch) Response:\n" + responseBody);
102 //injectSDNCCallbacks(callbacks, "assign, query");
103 //injectSDNCCallbacks(callbacks, "activate");
105 // TODO add appropriate assertions
107 waitForProcessEnd(businessKey, 10000);
108 String status = BPMNUtil.getVariable(processEngineRule, "CreateVnfInfra", "CreateVnfInfraStatus");
109 assertEquals("Success", status);
113 //WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "CreateVnfInfra", variables);
114 // injectSDNCCallbacks(callbacks, "assign");
115 // injectSDNCCallbacks(callbacks, "activate");
116 //waitForProcessEnd(businessKey, 10000);
117 //waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceId());
119 //assertVariables("true", "true", "false", "true", "Success", null);
124 @Deployment(resources = {"subprocess/GenericGetService.bpmn", "subprocess/GenericGetVnf.bpmn", "subprocess/GenericPutVnf.bpmn", "process/CreateVnfInfra.bpmn", "subprocess/FalloutHandler.bpmn", "subprocess/CompleteMsoProcess.bpmn"})
125 public void testCreateVnfInfra_error_badRequest() throws Exception{
127 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
129 Map<String, String> variables = new HashMap<>();
130 setVariables(variables, null, "testRequestId123", "MIS%2F1604%2F0026%2FSW_INTERNET");
132 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "CreateVnfInfra", variables);
133 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceId());
135 assertVariables(null, null, null, null, null, "WorkflowException[processKey=CreateVnfInfra,errorCode=2500,errorMessage=Internal Error - WorkflowException Object and/or RequestInfo is null! CreateVnfInfra]");
141 @Deployment(resources = {"subprocess/DoCreateVnf.bpmn", "subprocess/GenericGetService.bpmn", "subprocess/GenericGetVnf.bpmn", "subprocess/GenericPutVnf.bpmn", "process/CreateVnfInfra.bpmn", "subprocess/FalloutHandler.bpmn", "subprocess/CompleteMsoProcess.bpmn"})
142 public void testCreateVnfInfra_error_siNotFound() throws Exception{
144 MockNodeQueryServiceInstanceById_404("MIS%2F1604%2F0026%2FSW_INTERNET");
145 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
147 Map<String, String> variables = new HashMap<>();
148 setVariables(variables, createVnfInfraRequest, "testRequestId123", "MIS%2F1604%2F0026%2FSW_INTERNET");
150 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "CreateVnfInfra", variables);
151 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceId());
153 assertVariables(null, null, null, null, null, "WorkflowException[processKey=DoCreateVnf,errorCode=404,errorMessage=Service Instance Not Found]");
159 @Deployment(resources = {"subprocess/DoCreateVnf.bpmn",
160 "subprocess/GenericGetService.bpmn",
161 "subprocess/GenericGetVnf.bpmn",
162 "subprocess/GenericPutVnf.bpmn",
163 "process/CreateVnfInfra.bpmn",
164 "subprocess/FalloutHandler.bpmn",
165 "subprocess/CompleteMsoProcess.bpmn"})
166 public void testCreateVnfInfra_error_vnfExist() throws Exception{
167 MockNodeQueryServiceInstanceById("MIS%2F1604%2F0026%2FSW_INTERNET", "GenericFlows/getSIUrlById.xml");
168 MockGetServiceInstance("SDN-ETHERNET-INTERNET", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceInstance.xml");
170 stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf[?]vnf-name=testVnfName123&depth=1"))
171 .willReturn(aResponse()
173 .withHeader("Content-Type", "text/xml")
174 .withBodyFile("GenericFlows/getGenericVnfResponse.xml")));
177 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
179 Map<String, String> variables = new HashMap<>();
180 setVariables(variables, createVnfInfraRequest, "testRequestId123", "MIS%2F1604%2F0026%2FSW_INTERNET");
182 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "CreateVnfInfra", variables);
183 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceId());
185 assertVariables(null, null, null, null, null, "WorkflowException[processKey=DoCreateVnf,errorCode=5000,errorMessage=Generic Vnf Already Exist.]");
189 private void assertVariables(String exSIFound, String exSISucc, String exVnfFound, String exVnfSucc, String exResponse, String exWorkflowException) {
191 String siFound = BPMNUtil.getVariable(processEngineRule, "CreateVnfInfra", "GENGS_FoundIndicator");
192 String siSucc = BPMNUtil.getVariable(processEngineRule, "CreateVnfInfra", "GENGS_SuccessIndicator");
193 String vnfFound = BPMNUtil.getVariable(processEngineRule, "CreateVnfInfra", "GENGV_FoundIndicator");
194 String vnfSucc = BPMNUtil.getVariable(processEngineRule, "CreateVnfInfra", "GENGV_SuccessIndicator");
195 String response = BPMNUtil.getVariable(processEngineRule, "CreateVnfInfra", "WorkflowResponse");
196 String workflowException = BPMNUtil.getVariable(processEngineRule, "CreateVnfInfra", "SavedWorkflowException1");
198 assertEquals(exSIFound, siFound);
199 assertEquals(exSISucc, siSucc);
200 assertEquals(exVnfFound, vnfFound);
201 assertEquals(exVnfSucc, vnfSucc);
202 assertEquals(exResponse, response);
203 assertEquals(exWorkflowException, workflowException);
206 private void setVariables(Map<String, String> variables, String request, String requestId, String siId) {
207 variables.put("isDebugLogEnabled", "true");
208 variables.put("bpmnRequest", request);
209 variables.put("mso-request-id", requestId);
210 variables.put("serviceInstanceId",siId);
211 variables.put("testVnfId","testVnfId123");
212 variables.put("vnfType", "STMTN");
215 private void setVariablesSuccess(Map<String, Object> variables, String request, String requestId, String siId) {
216 variables.put("isDebugLogEnabled", "true");
217 //variables.put("bpmnRequest", request);
218 //variables.put("mso-request-id", requestId);
219 variables.put("serviceInstanceId",siId);
220 variables.put("requestId", requestId);
221 variables.put("testVnfId","testVnfId123");
222 variables.put("vnfType", "STMTN");