2 * ============LICENSE_START======================================================= ONAP - SO
3 * ================================================================================ Copyright (C) 2017 AT&T Intellectual
4 * Property. All rights reserved. ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 * specific language governing permissions and limitations under the License.
13 * ============LICENSE_END=========================================================
16 package org.onap.so.bpmn.vcpe;
18 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
19 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
20 import static com.github.tomakehurst.wiremock.client.WireMock.get;
21 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.onap.so.bpmn.mock.StubResponseAAI.MockDeleteAllottedResource;
27 import static org.onap.so.bpmn.mock.StubResponseAAI.MockDeleteServiceInstance;
28 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource;
29 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
30 import static org.onap.so.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
31 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource;
32 import static org.onap.so.bpmn.mock.StubResponseAAI.MockQueryAllottedResourceById;
33 import static org.onap.so.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
34 import static org.onap.so.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
35 import java.io.IOException;
36 import java.io.UnsupportedEncodingException;
37 import java.util.HashMap;
39 import java.util.UUID;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.onap.so.bpmn.common.BPMNUtil;
43 import org.onap.so.bpmn.mock.FileUtil;
44 import com.github.tomakehurst.wiremock.stubbing.Scenario;
46 public class DeleteVcpeResCustServiceIT extends AbstractTestBase {
48 private static final String PROCNAME = "DeleteVcpeResCustService";
49 private static final String Prefix = "DVRCS_";
50 private static final String AR_BRG_ID = "ar-brgB";
51 private static final String AR_TXC_ID = "ar-txcA";
53 private final CallbackSet callbacks = new CallbackSet();
54 private final String request;
56 public DeleteVcpeResCustServiceIT() throws IOException {
57 callbacks.put("deactivate",
58 FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
59 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
60 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
62 request = FileUtil.readResourceFile("__files/VCPE/DeleteVcpeResCustService/request.json");
67 BPMNUtil.cleanHistory(processEngine);
71 public void testDeleteVcpeResCustService_Success() throws Exception {
73 MockNodeQueryServiceInstanceById(wireMockServer, INST, "GenericFlows/getSIUrlById.xml");
75 // TODO: use INST instead of DEC_INST
77 * Seems to be a bug as they fail to URL-encode the SI id before performing the query so we'll add a stub for
80 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
83 * cannot use MockGetServiceInstance(wireMockServer, ), because we need to return different responses as we
84 * traverse through the flow
87 // initially, the SI includes the ARs
88 wireMockServer.stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + CUST
89 + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST))
90 .inScenario("SI retrieval").whenScenarioStateIs(Scenario.STARTED)
91 .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml")
92 .withBodyFile("VCPE/DeleteVcpeResCustService/getSI.xml"))
93 .willSetStateTo("ARs Deleted"));
95 // once the ARs have been deleted, the SI should be empty
96 wireMockServer.stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + CUST
97 + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST))
98 .inScenario("SI retrieval").whenScenarioStateIs("ARs Deleted")
99 .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml")
100 .withBodyFile("VCPE/DeleteVcpeResCustService/getSIAfterDelArs.xml")));
103 MockQueryAllottedResourceById(wireMockServer, AR_BRG_ID, "VCPE/DeleteVcpeResCustService/getBRGArUrlById.xml");
104 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, AR_BRG_ID,
105 "VCPE/DeleteVcpeResCustService/arGetBRGById.xml");
106 MockPatchAllottedResource(wireMockServer, CUST, SVC, INST, AR_BRG_ID);
107 MockDeleteAllottedResource(wireMockServer, CUST, SVC, INST, AR_BRG_ID, ARVERS);
110 MockQueryAllottedResourceById(wireMockServer, AR_TXC_ID, "VCPE/DeleteVcpeResCustService/getTXCArUrlById.xml");
111 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, AR_TXC_ID,
112 "VCPE/DeleteVcpeResCustService/arGetTXCById.xml");
113 MockPatchAllottedResource(wireMockServer, CUST, SVC, INST, AR_TXC_ID);
114 MockDeleteAllottedResource(wireMockServer, CUST, SVC, INST, AR_TXC_ID, ARVERS);
116 // MockGetGenericVnfById("vnfX.*", "GenericFlows/getGenericVnfByNameResponse.xml");
117 wireMockServer.stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*"))
118 .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml")
119 .withBodyFile("GenericFlows/getGenericVnfByNameResponse.xml")));
122 wireMockServer.stubFor(delete(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*"))
123 .willReturn(aResponse().withStatus(204).withHeader("Content-Type", "text/xml")));
125 MockDeleteServiceInstance(wireMockServer, CUST, SVC, INST, SVC);
127 mockSDNCAdapter(wireMockServer, 200);
128 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
130 String businessKey = UUID.randomUUID().toString();
131 Map<String, Object> variables = setupVariables(businessKey);
133 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
136 injectSDNCCallbacks(callbacks, "deactivate");
137 injectSDNCCallbacks(callbacks, "delete");
138 injectSDNCCallbacks(callbacks, "unassign");
141 injectSDNCCallbacks(callbacks, "deactivate");
142 injectSDNCCallbacks(callbacks, "unassign");
145 injectSDNCCallbacks(callbacks, "deactivate");
146 injectSDNCCallbacks(callbacks, "unassign");
149 injectSDNCCallbacks(callbacks, "deactivate");
150 injectSDNCCallbacks(callbacks, "delete");
151 injectSDNCCallbacks(callbacks, "unassign");
154 injectSDNCCallbacks(callbacks, "deactivate");
155 injectSDNCCallbacks(callbacks, "delete");
157 waitForProcessEnd(businessKey, 70000);
158 assertTrue(isProcessEnded(businessKey));
160 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
161 System.out.println("workflowException:\n" + workflowException);
163 String completionReq = BPMNUtil.getVariable(processEngine, PROCNAME, Prefix + VAR_COMP_REQ);
164 System.out.println("completionReq:\n" + completionReq);
166 assertEquals("true", BPMNUtil.getVariable(processEngine, PROCNAME, PROCNAME + VAR_SUCCESS_IND));
167 assertEquals("200", BPMNUtil.getVariable(processEngine, PROCNAME, VAR_RESP_CODE));
168 assertNull(workflowException);
169 assertTrue(completionReq.contains("<request-id>" + businessKey + "<"));
170 assertTrue(completionReq.contains("<action>DELETE<"));
171 assertTrue(completionReq.contains("<source>VID<"));
173 assertEquals("2", BPMNUtil.getVariable(processEngine, PROCNAME, Prefix + "vnfsDeletedCount"));
175 BPMNUtil.assertAnyProcessInstanceFinished(processEngine, "DoDeleteVnfAndModules");
180 public void testDeleteVcpeResCustService_NoBRG_NoTXC_NoVNF() throws Exception {
182 MockNodeQueryServiceInstanceById(wireMockServer, INST, "GenericFlows/getSIUrlById.xml");
184 // TODO: use INST instead of DEC_INST
186 * Seems to be a bug as they fail to URL-encode the SI id before performing the query so we'll add a stub for
189 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
191 MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "VCPE/DeleteVcpeResCustService/getSIAfterDelArs.xml");
193 mockSDNCAdapter(wireMockServer, 200);
194 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
196 String businessKey = UUID.randomUUID().toString();
197 Map<String, Object> variables = setupVariables(businessKey);
200 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
203 injectSDNCCallbacks(callbacks, "deactivate");
204 injectSDNCCallbacks(callbacks, "delete");
206 waitForProcessEnd(businessKey, 70000);
208 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
209 System.out.println("workflowException:\n" + workflowException);
211 String completionReq = BPMNUtil.getVariable(processEngine, PROCNAME, Prefix + VAR_COMP_REQ);
212 System.out.println("completionReq:\n" + completionReq);
214 assertEquals("true", BPMNUtil.getVariable(processEngine, PROCNAME, PROCNAME + VAR_SUCCESS_IND));
215 assertEquals("200", BPMNUtil.getVariable(processEngine, PROCNAME, VAR_RESP_CODE));
216 assertNull(workflowException);
217 assertTrue(completionReq.contains("<request-id>" + businessKey + "<"));
218 assertTrue(completionReq.contains("<action>DELETE<"));
219 assertTrue(completionReq.contains("<source>VID<"));
221 assertEquals("0", BPMNUtil.getVariable(processEngine, PROCNAME, Prefix + "vnfsDeletedCount"));
223 BPMNUtil.assertNoProcessInstance(processEngine, "DoDeleteVnfAndModules");
228 public void testDeleteVcpeResCustService_Fault() throws Exception {
230 MockNodeQueryServiceInstanceById(wireMockServer, INST, "GenericFlows/getSIUrlById.xml");
232 // TODO: use INST instead of DEC_INST
234 * Seems to be a bug as they fail to URL-encode the SI id before performing the query so we'll add a stub for
237 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
239 MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "VCPE/DeleteVcpeResCustService/getSIAfterDelArs.xml");
242 mockSDNCAdapter(wireMockServer, 404);
244 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
246 String businessKey = UUID.randomUUID().toString();
247 Map<String, Object> variables = setupVariables(businessKey);
249 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
251 waitForProcessEnd(businessKey, 70000);
253 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
254 System.out.println("workflowException:\n" + workflowException);
256 String completionReq = BPMNUtil.getVariable(processEngine, PROCNAME, Prefix + VAR_COMP_REQ);
257 System.out.println("completionReq:\n" + completionReq);
259 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, PROCNAME + VAR_SUCCESS_IND));
260 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, VAR_RESP_CODE));
261 assertNotNull(workflowException);
265 private Map<String, Object> setupVariables(String requestId) throws UnsupportedEncodingException {
266 Map<String, Object> variables = new HashMap<>();
267 variables.put("isDebugLogEnabled", "true");
268 variables.put("requestId", requestId);
269 variables.put("serviceInstanceId", DEC_INST);
270 variables.put("sdncVersion", "1802");
271 variables.put("serviceInstanceName", "some-junk-name");