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=========================================================
21 package org.onap.so.bpmn.vcpe;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertNull;
30 import static org.junit.Assert.assertTrue;
31 import static org.onap.so.bpmn.mock.StubResponseAAI.MockDeleteAllottedResource;
32 import static org.onap.so.bpmn.mock.StubResponseAAI.MockDeleteServiceInstance;
33 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource;
34 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
35 import static org.onap.so.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
36 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource;
37 import static org.onap.so.bpmn.mock.StubResponseAAI.MockQueryAllottedResourceById;
38 import static org.onap.so.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
39 import static org.onap.so.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
41 import java.io.IOException;
42 import java.io.UnsupportedEncodingException;
43 import java.util.HashMap;
45 import java.util.UUID;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.onap.so.bpmn.common.BPMNUtil;
50 import org.onap.so.bpmn.mock.FileUtil;
52 import com.github.tomakehurst.wiremock.stubbing.Scenario;
54 public class DeleteVcpeResCustServiceIT extends AbstractTestBase {
56 private static final String PROCNAME = "DeleteVcpeResCustService";
57 private static final String Prefix = "DVRCS_";
58 private static final String AR_BRG_ID = "ar-brgB";
59 private static final String AR_TXC_ID = "ar-txcA";
61 private final CallbackSet callbacks = new CallbackSet();
62 private final String request;
64 public DeleteVcpeResCustServiceIT() throws IOException {
65 callbacks.put("deactivate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
66 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
67 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
69 request = FileUtil.readResourceFile("__files/VCPE/DeleteVcpeResCustService/request.json");
74 BPMNUtil.cleanHistory(processEngine);
78 public void testDeleteVcpeResCustService_Success() throws Exception {
80 MockNodeQueryServiceInstanceById(wireMockServer, INST, "GenericFlows/getSIUrlById.xml");
82 // TODO: use INST instead of DEC_INST
84 * Seems to be a bug as they
85 * fail to URL-encode the SI id before performing the query so we'll
86 * add a stub for that case, too.
88 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
91 * cannot use MockGetServiceInstance(wireMockServer, ), because we need to return
92 * different responses as we traverse through the flow
95 // initially, the SI includes the ARs
96 wireMockServer.stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST))
97 .inScenario("SI retrieval")
98 .whenScenarioStateIs(Scenario.STARTED)
99 .willReturn(aResponse()
101 .withHeader("Content-Type", "text/xml")
102 .withBodyFile("VCPE/DeleteVcpeResCustService/getSI.xml"))
103 .willSetStateTo("ARs Deleted"));
105 // once the ARs have been deleted, the SI should be empty
106 wireMockServer.stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST))
107 .inScenario("SI retrieval")
108 .whenScenarioStateIs("ARs Deleted")
109 .willReturn(aResponse()
111 .withHeader("Content-Type", "text/xml")
112 .withBodyFile("VCPE/DeleteVcpeResCustService/getSIAfterDelArs.xml")));
115 MockQueryAllottedResourceById(wireMockServer, AR_BRG_ID, "VCPE/DeleteVcpeResCustService/getBRGArUrlById.xml");
116 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, AR_BRG_ID, "VCPE/DeleteVcpeResCustService/arGetBRGById.xml");
117 MockPatchAllottedResource(wireMockServer, CUST, SVC, INST, AR_BRG_ID);
118 MockDeleteAllottedResource(wireMockServer, CUST, SVC, INST, AR_BRG_ID, ARVERS);
121 MockQueryAllottedResourceById(wireMockServer, AR_TXC_ID, "VCPE/DeleteVcpeResCustService/getTXCArUrlById.xml");
122 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, AR_TXC_ID, "VCPE/DeleteVcpeResCustService/arGetTXCById.xml");
123 MockPatchAllottedResource(wireMockServer, CUST, SVC, INST, AR_TXC_ID);
124 MockDeleteAllottedResource(wireMockServer, CUST, SVC, INST, AR_TXC_ID, ARVERS);
126 //MockGetGenericVnfById("vnfX.*", "GenericFlows/getGenericVnfByNameResponse.xml");
127 wireMockServer.stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*"))
128 .willReturn(aResponse()
130 .withHeader("Content-Type", "text/xml")
131 .withBodyFile("GenericFlows/getGenericVnfByNameResponse.xml")));
134 wireMockServer.stubFor(delete(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*"))
135 .willReturn(aResponse()
137 .withHeader("Content-Type", "text/xml")));
139 MockDeleteServiceInstance(wireMockServer, CUST,SVC,INST,SVC);
141 mockSDNCAdapter(wireMockServer, 200);
142 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
144 String businessKey = UUID.randomUUID().toString();
145 Map<String, Object> variables = setupVariables(businessKey);
147 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
150 injectSDNCCallbacks(callbacks, "deactivate");
151 injectSDNCCallbacks(callbacks, "delete");
152 injectSDNCCallbacks(callbacks, "unassign");
155 injectSDNCCallbacks(callbacks, "deactivate");
156 injectSDNCCallbacks(callbacks, "unassign");
159 injectSDNCCallbacks(callbacks, "deactivate");
160 injectSDNCCallbacks(callbacks, "unassign");
163 injectSDNCCallbacks(callbacks, "deactivate");
164 injectSDNCCallbacks(callbacks, "delete");
165 injectSDNCCallbacks(callbacks, "unassign");
168 injectSDNCCallbacks(callbacks, "deactivate");
169 injectSDNCCallbacks(callbacks, "delete");
171 waitForProcessEnd(businessKey, 70000);
172 assertTrue(isProcessEnded(businessKey));
174 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
175 System.out.println("workflowException:\n" + workflowException);
177 String completionReq = BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+VAR_COMP_REQ);
178 System.out.println("completionReq:\n" + completionReq);
180 assertEquals("true", BPMNUtil.getVariable(processEngine, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
181 assertEquals("200", BPMNUtil.getVariable(processEngine, PROCNAME, VAR_RESP_CODE));
182 assertNull(workflowException);
183 assertTrue(completionReq.contains("<request-id>"+businessKey+"<"));
184 assertTrue(completionReq.contains("<action>DELETE<"));
185 assertTrue(completionReq.contains("<source>VID<"));
187 assertEquals("2", BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+"vnfsDeletedCount"));
189 BPMNUtil.assertAnyProcessInstanceFinished(processEngine, "DoDeleteVnfAndModules");
194 public void testDeleteVcpeResCustService_NoBRG_NoTXC_NoVNF() throws Exception {
196 MockNodeQueryServiceInstanceById(wireMockServer, INST, "GenericFlows/getSIUrlById.xml");
198 // TODO: use INST instead of DEC_INST
200 * Seems to be a bug as they
201 * fail to URL-encode the SI id before performing the query so we'll
202 * add a stub for that case, too.
204 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
206 MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "VCPE/DeleteVcpeResCustService/getSIAfterDelArs.xml");
208 mockSDNCAdapter(wireMockServer, 200);
209 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
211 String businessKey = UUID.randomUUID().toString();
212 Map<String, Object> variables = setupVariables(businessKey);
215 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
218 injectSDNCCallbacks(callbacks, "deactivate");
219 injectSDNCCallbacks(callbacks, "delete");
221 waitForProcessEnd(businessKey, 70000);
223 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
224 System.out.println("workflowException:\n" + workflowException);
226 String completionReq = BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+VAR_COMP_REQ);
227 System.out.println("completionReq:\n" + completionReq);
229 assertEquals("true", BPMNUtil.getVariable(processEngine, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
230 assertEquals("200", BPMNUtil.getVariable(processEngine, PROCNAME, VAR_RESP_CODE));
231 assertNull( workflowException);
232 assertTrue(completionReq.contains("<request-id>"+businessKey+"<"));
233 assertTrue(completionReq.contains("<action>DELETE<"));
234 assertTrue(completionReq.contains("<source>VID<"));
236 assertEquals("0", BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+"vnfsDeletedCount"));
238 BPMNUtil.assertNoProcessInstance(processEngine, "DoDeleteVnfAndModules");
243 public void testDeleteVcpeResCustService_Fault() throws Exception {
245 MockNodeQueryServiceInstanceById(wireMockServer, INST, "GenericFlows/getSIUrlById.xml");
247 // TODO: use INST instead of DEC_INST
249 * Seems to be a bug as they
250 * fail to URL-encode the SI id before performing the query so we'll
251 * add a stub for that case, too.
253 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
255 MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "VCPE/DeleteVcpeResCustService/getSIAfterDelArs.xml");
258 mockSDNCAdapter(wireMockServer, 404);
260 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
262 String businessKey = UUID.randomUUID().toString();
263 Map<String, Object> variables = setupVariables(businessKey);
265 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
267 waitForProcessEnd(businessKey, 70000);
269 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
270 System.out.println("workflowException:\n" + workflowException);
272 String completionReq = BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+VAR_COMP_REQ);
273 System.out.println("completionReq:\n" + completionReq);
275 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
276 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, VAR_RESP_CODE));
277 assertNotNull(workflowException);
281 private Map<String, Object> setupVariables(String requestId) throws UnsupportedEncodingException {
282 Map<String, Object> variables = new HashMap<>();
283 variables.put("isDebugLogEnabled", "true");
284 variables.put("requestId", requestId);
285 variables.put("serviceInstanceId", DEC_INST);
286 variables.put("sdncVersion", "1802");
287 variables.put("serviceInstanceName", "some-junk-name");