2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.bpmn.vcpe;
22 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
23 import static com.github.tomakehurst.wiremock.client.WireMock.get;
24 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
25 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockDeleteAllottedResource;
30 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource;
31 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
32 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
33 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchAllottedResource;
34 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockQueryAllottedResourceById;
35 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
36 import static org.openecomp.mso.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
38 import java.io.IOException;
39 import java.io.UnsupportedEncodingException;
40 import java.util.HashMap;
42 import java.util.UUID;
44 import org.camunda.bpm.engine.test.Deployment;
45 import org.junit.Test;
46 import org.openecomp.mso.bpmn.common.BPMNUtil;
47 import org.openecomp.mso.bpmn.mock.FileUtil;
49 import com.github.tomakehurst.wiremock.stubbing.Scenario;
51 public class DeleteVcpeResCustServiceTest extends AbstractTestBase {
53 private static final String PROCNAME = "DeleteVcpeResCustService";
54 private static final String Prefix = "DVRCS_";
55 private static final String AR_BRG_ID = "ar-brgB";
56 private static final String AR_TXC_ID = "ar-txcA";
58 private final CallbackSet callbacks = new CallbackSet();
59 private final String request;
61 public DeleteVcpeResCustServiceTest() throws IOException {
62 callbacks.put("deactivate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
63 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
64 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
66 request = FileUtil.readResourceFile("__files/VCPE/DeleteVcpeResCustService/request.json");
70 @Deployment(resources = {
71 "process/DeleteVcpeResCustService.bpmn",
72 "subprocess/GenericGetService.bpmn",
73 "subprocess/GenericDeleteService.bpmn",
74 "subprocess/SDNCAdapterV1.bpmn",
75 "subprocess/FalloutHandler.bpmn",
76 "subprocess/DoDeleteServiceInstance.bpmn",
77 "subprocess/DoDeleteAllottedResourceBRG.bpmn",
78 "subprocess/DoDeleteAllottedResourceTXC.bpmn",
79 "subprocess/CompleteMsoProcess.bpmn",
82 "VCPE/stubprocess/DoDeleteVnfAndModules.bpmn"})
84 public void testDeleteVcpeResCustService_Success() throws Exception {
86 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");
88 // TODO: use INST instead of DEC_INST
90 * Seems to be a bug in GenericDeleteService (or its subflows) as they
91 * fail to URL-encode the SI id before performing the query so we'll
92 * add a stub for that case, too.
94 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
97 * cannot use MockGetServiceInstance(), because we need to return
98 * different responses as we traverse through the flow
101 // initially, the SI includes the ARs
102 stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST))
103 .inScenario("SI retrieval")
104 .whenScenarioStateIs(Scenario.STARTED)
105 .willReturn(aResponse()
107 .withHeader("Content-Type", "text/xml")
108 .withBodyFile("VCPE/DeleteVcpeResCustService/getSI.xml"))
109 .willSetStateTo("ARs Deleted"));
111 // once the ARs have been deleted, the SI should be empty
112 stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST))
113 .inScenario("SI retrieval")
114 .whenScenarioStateIs("ARs Deleted")
115 .willReturn(aResponse()
117 .withHeader("Content-Type", "text/xml")
118 .withBodyFile("VCPE/DeleteVcpeResCustService/getSIAfterDelArs.xml")));
121 MockQueryAllottedResourceById(AR_BRG_ID, "VCPE/DeleteVcpeResCustService/getBRGArUrlById.xml");
122 MockGetAllottedResource(CUST, SVC, INST, AR_BRG_ID, "VCPE/DeleteVcpeResCustService/arGetBRGById.xml");
123 MockPatchAllottedResource(CUST, SVC, INST, AR_BRG_ID);
124 MockDeleteAllottedResource(CUST, SVC, INST, AR_BRG_ID, ARVERS);
127 MockQueryAllottedResourceById(AR_TXC_ID, "VCPE/DeleteVcpeResCustService/getTXCArUrlById.xml");
128 MockGetAllottedResource(CUST, SVC, INST, AR_TXC_ID, "VCPE/DeleteVcpeResCustService/arGetTXCById.xml");
129 MockPatchAllottedResource(CUST, SVC, INST, AR_TXC_ID);
130 MockDeleteAllottedResource(CUST, SVC, INST, AR_TXC_ID, ARVERS);
132 mockSDNCAdapter(200);
133 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
135 Map<String, Object> variables = setupVariables();
137 String businessKey = UUID.randomUUID().toString();
138 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
141 injectSDNCCallbacks(callbacks, "deactivate");
142 injectSDNCCallbacks(callbacks, "delete");
143 injectSDNCCallbacks(callbacks, "unassign");
146 injectSDNCCallbacks(callbacks, "deactivate");
147 injectSDNCCallbacks(callbacks, "delete");
148 injectSDNCCallbacks(callbacks, "unassign");
151 injectSDNCCallbacks(callbacks, "deactivate");
152 injectSDNCCallbacks(callbacks, "delete");
154 waitForProcessEnd(businessKey, 10000);
156 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
157 System.out.println("workflowException:\n" + workflowException);
159 String completionReq = BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+VAR_COMP_REQ);
160 System.out.println("completionReq:\n" + completionReq);
162 assertEquals("true", BPMNUtil.getVariable(processEngineRule, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
163 assertEquals("200", BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_RESP_CODE));
164 assertEquals(null, workflowException);
165 assertTrue(completionReq.contains("<request-id>testRequestId<"));
166 assertTrue(completionReq.contains("<action>DELETE<"));
167 assertTrue(completionReq.contains("<source>VID<"));
169 assertEquals("2", BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+"vnfsDeletedCount"));
171 BPMNUtil.assertAnyProcessInstanceFinished(processEngineRule, "DoDeleteVnfAndModules");
175 @Deployment(resources = {
176 "process/DeleteVcpeResCustService.bpmn",
177 "subprocess/GenericGetService.bpmn",
178 "subprocess/GenericDeleteService.bpmn",
179 "subprocess/SDNCAdapterV1.bpmn",
180 "subprocess/FalloutHandler.bpmn",
181 "subprocess/DoDeleteServiceInstance.bpmn",
182 "subprocess/DoDeleteAllottedResourceBRG.bpmn",
183 "subprocess/DoDeleteAllottedResourceTXC.bpmn",
184 "subprocess/CompleteMsoProcess.bpmn",
187 "VCPE/stubprocess/DoDeleteVnfAndModules.bpmn"})
189 public void testDeleteVcpeResCustService_NoBRG_NoTXC_NoVNF() throws Exception {
191 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");
193 // TODO: use INST instead of DEC_INST
195 * Seems to be a bug in GenericDeleteService (or its subflows) as they
196 * fail to URL-encode the SI id before performing the query so we'll
197 * add a stub for that case, too.
199 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
201 MockGetServiceInstance(CUST, SVC, INST, "VCPE/DeleteVcpeResCustService/getSIAfterDelArs.xml");
203 mockSDNCAdapter(200);
204 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
206 Map<String, Object> variables = setupVariables();
208 String businessKey = UUID.randomUUID().toString();
209 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
212 injectSDNCCallbacks(callbacks, "deactivate");
213 injectSDNCCallbacks(callbacks, "delete");
215 waitForProcessEnd(businessKey, 10000);
217 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
218 System.out.println("workflowException:\n" + workflowException);
220 String completionReq = BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+VAR_COMP_REQ);
221 System.out.println("completionReq:\n" + completionReq);
223 assertEquals("true", BPMNUtil.getVariable(processEngineRule, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
224 assertEquals("200", BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_RESP_CODE));
225 assertEquals(null, workflowException);
226 assertTrue(completionReq.contains("<request-id>testRequestId<"));
227 assertTrue(completionReq.contains("<action>DELETE<"));
228 assertTrue(completionReq.contains("<source>VID<"));
230 assertEquals("0", BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+"vnfsDeletedCount"));
232 BPMNUtil.assertNoProcessInstance(processEngineRule, "DoDeleteVnfAndModules");
236 @Deployment(resources = {
237 "process/DeleteVcpeResCustService.bpmn",
238 "subprocess/GenericGetService.bpmn",
239 "subprocess/GenericDeleteService.bpmn",
240 "subprocess/SDNCAdapterV1.bpmn",
241 "subprocess/FalloutHandler.bpmn",
242 "subprocess/DoDeleteServiceInstance.bpmn",
243 "subprocess/DoDeleteAllottedResourceBRG.bpmn",
244 "subprocess/DoDeleteAllottedResourceTXC.bpmn",
245 "subprocess/CompleteMsoProcess.bpmn",
248 "VCPE/stubprocess/DoDeleteVnfAndModules.bpmn"})
250 public void testDeleteVcpeResCustService_Fault() throws Exception {
252 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");
254 // TODO: use INST instead of DEC_INST
256 * Seems to be a bug in GenericDeleteService (or its subflows) as they
257 * fail to URL-encode the SI id before performing the query so we'll
258 * add a stub for that case, too.
260 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
262 MockGetServiceInstance(CUST, SVC, INST, "VCPE/DeleteVcpeResCustService/getSIAfterDelArs.xml");
265 mockSDNCAdapter(404);
267 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
269 Map<String, Object> variables = setupVariables();
271 String businessKey = UUID.randomUUID().toString();
272 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
274 waitForProcessEnd(businessKey, 10000);
276 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
277 System.out.println("workflowException:\n" + workflowException);
279 String completionReq = BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+VAR_COMP_REQ);
280 System.out.println("completionReq:\n" + completionReq);
282 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
283 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_RESP_CODE));
284 assertNotNull(workflowException);
287 private Map<String, Object> setupVariables() throws UnsupportedEncodingException {
288 Map<String, Object> variables = new HashMap<>();
289 variables.put("isDebugLogEnabled", "true");
290 variables.put("requestId", "testRequestId");
291 variables.put("serviceInstanceId", DEC_INST);
292 variables.put("sdncVersion", "1802");
293 variables.put("serviceInstanceName", "some-junk-name");