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.get;
25 import static com.github.tomakehurst.wiremock.client.WireMock.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.put;
27 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.assertTrue;
32 import static org.onap.so.bpmn.mock.StubResponseAAI.MockDeleteAllottedResource;
33 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource;
34 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetCustomer;
35 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;
36 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithPriority;
37 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetNetworkPolicyfqdn;
38 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
39 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetServiceInstance_500;
40 import static org.onap.so.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
41 import static org.onap.so.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceByName_404;
42 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource;
43 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchGenericVnf;
44 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutAllottedResource;
45 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
46 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutNetwork;
47 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutServiceInstance;
48 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutVfModuleIdNoResponse;
49 import static org.onap.so.bpmn.mock.StubResponseDatabase.MockGetServiceResourcesCatalogData;
50 import static org.onap.so.bpmn.mock.StubResponseDatabase.MockPostRequestDB;
51 import static org.onap.so.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
52 import static org.onap.so.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
53 import static org.onap.so.bpmn.mock.StubResponseVNFAdapter.mockVNFPost;
55 import java.io.IOException;
56 import java.util.HashMap;
58 import java.util.UUID;
60 import org.junit.Before;
61 import org.junit.Test;
62 import org.onap.so.bpmn.common.BPMNUtil;
63 import org.onap.so.bpmn.mock.FileUtil;
64 import org.onap.so.bpmn.mock.StubResponseOof;
67 public class CreateVcpeResCustServiceIT extends AbstractTestBase {
69 private static final String PROCNAME = "CreateVcpeResCustService";
70 private static final String Prefix = "CVRCS_";
72 private final CallbackSet callbacks = new CallbackSet();
73 private final String request;
77 BPMNUtil.cleanHistory(processEngine);
80 public CreateVcpeResCustServiceIT() throws IOException {
82 callbacks.put("oof", JSON, "oofResponse", FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/oofCallbackInfraVnf.json"));
83 callbacks.put("assign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyAssignCallback.xml"));
84 callbacks.put("create", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyCreateCallback.xml"));
85 callbacks.put("activate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyActivateCallback.xml"));
86 callbacks.put("queryTXC", FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/SDNCTopologyQueryTXCCallback.xml"));
87 callbacks.put("queryBRG", FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/SDNCTopologyQueryBRGCallback.xml"));
88 callbacks.put("deactivate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
89 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
90 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
92 callbacks.put("query", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyQueryCallback.xml"));
93 callbacks.put("queryVnf", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyQueryCallbackVnf.xml"));
94 callbacks.put("queryModuleNoVnf", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyQueryCallbackVfModuleNoVnf.xml"));
95 callbacks.put("queryModule", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyQueryCallbackVfModule.xml"));
96 callbacks.put("vnfCreate", FileUtil.readResourceFile("__files/VfModularity/VNFAdapterRestCreateCallback.xml"));
98 request = FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/requestNoSIName.json");
102 public void testCreateVcpeResCustService_Success() throws Exception {
103 System.out.println("starting: testCreateVcpeResCustService_Success\n");
104 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "2","VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
105 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
106 MockGetCustomer(CUST, "VCPE/CreateVcpeResCustService/getCustomer.xml");
107 StubResponseOof.mockOof();
108 // TODO: the SI should NOT have to be URL-encoded yet again!
109 MockPutServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
110 MockGetServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
112 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");
113 MockNodeQueryServiceInstanceById(PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
114 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
115 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
116 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
117 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
118 MockGetGenericVnfByIdWithDepth(".*", 1, "VCPE/CreateVcpeResCustService/GenericVnf.xml");
120 MockPutGenericVnf(".*");
121 MockPatchGenericVnf(".*");
123 MockGetGenericVnfByIdWithPriority(".*", ".*", 200, "VfModularity/VfModule-new.xml", 5);
124 // MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
125 MockPutVfModuleIdNoResponse(".*", "PCRF", ".*");
126 MockPutNetwork(".*", "VfModularity/AddNetworkPolicy_AAIResponse_Success.xml", 200);
128 MockGetNetworkPolicyfqdn(".*","CreateNetworkV2/createNetwork_queryNetworkPolicy_AAIResponse_Success.xml",200);
129 MockNodeQueryServiceInstanceByName_404(".*");
131 mockVNFPost("", 202, ".*");
133 stubFor(post(urlMatching("/services/rest/v1/vnfs" + ".*" + "/vf-modules" )).willReturn(aResponse().withStatus(202)));
134 stubFor(get(urlMatching(".*/business/owning-entities?.*")).willReturn(aResponse().withStatus(404)));
135 stubFor(put(urlMatching(".*/business/owning-entities/owning-entity/.*")).willReturn(aResponse().withStatus(200)));
136 stubFor(put(urlMatching(".*/business/owning-entities/owning-entity/038d99af-0427-42c2-9d15-971b99b9b489/relationship-list/relationship")).willReturn(aResponse().withStatus(200)));
137 stubFor(put(urlMatching(".*/query?.*")).willReturn(aResponse().withStatus(200)));
139 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
140 mockSDNCAdapter(200);
142 Map<String, Object> variables = setupVariables();
144 String businessKey = UUID.randomUUID().toString();
145 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
147 injectWorkflowMessages(callbacks, "oof");
149 injectSDNCCallbacks(callbacks, "assign");
151 injectSDNCCallbacks(callbacks, "assign");
152 injectSDNCCallbacks(callbacks, "create");
153 injectSDNCCallbacks(callbacks, "activate");
154 injectSDNCCallbacks(callbacks, "queryTXC");
157 injectSDNCCallbacks(callbacks, "assign");
158 injectSDNCCallbacks(callbacks, "assign");
159 injectSDNCCallbacks(callbacks, "queryModule");
160 injectSDNCCallbacks(callbacks, "activate");
162 injectSDNCCallbacks(callbacks, "queryModule");
163 injectSDNCCallbacks(callbacks, "assign");
164 injectSDNCCallbacks(callbacks, "queryModule");
165 injectSDNCCallbacks(callbacks, "queryModule");
166 injectSDNCCallbacks(callbacks, "assign");
167 injectSDNCCallbacks(callbacks, "queryModuleNoVnf");
168 injectVNFRestCallbacks(callbacks, "vnfCreate");
169 injectSDNCCallbacks(callbacks, "activate");
172 injectSDNCCallbacks(callbacks, "assign");
173 injectSDNCCallbacks(callbacks, "create");
174 injectSDNCCallbacks(callbacks, "activate");
175 injectSDNCCallbacks(callbacks, "queryBRG");
177 waitForProcessEnd(businessKey, 10000);
179 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
180 System.out.println("workflowException:\n" + workflowException);
182 String completionReq = BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+VAR_COMP_REQ);
183 System.out.println("completionReq:\n" + completionReq);
185 assertEquals("true", BPMNUtil.getVariable(processEngine, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
186 assertEquals("200", BPMNUtil.getVariable(processEngine, PROCNAME, VAR_RESP_CODE));
187 assertEquals(null, workflowException);
188 assertTrue(completionReq.indexOf("request-id>testRequestId<") >= 0);
189 assertTrue(completionReq.indexOf("action>CREATE<") >= 0);
190 assertTrue(completionReq.indexOf("source>VID<") >= 0);
192 assertEquals("1", BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+"VnfsCreatedCount"));
196 public void testCreateVcpeResCustService_NoParts() throws Exception {
197 System.out.println("starting: testCreateVcpeResCustService_NoParts\n" );
198 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "2", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesNoData.json");
199 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesNoData.json");
200 MockGetCustomer(CUST, "VCPE/CreateVcpeResCustService/getCustomer.xml");
202 // TODO: the SI should NOT have to be URL-encoded yet again!
203 MockPutServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
204 MockGetServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
206 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");
207 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
208 MockNodeQueryServiceInstanceById(PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
209 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
211 // TODO: should these really be PARENT_INST, or should they be INST?
212 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
213 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
215 mockSDNCAdapter(200);
216 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
218 StubResponseOof.mockOof();
219 stubFor(get(urlMatching(".*/business/owning-entities?.*")).willReturn(aResponse().withStatus(404)));
220 stubFor(put(urlMatching(".*/business/owning-entities/owning-entity/.*")).willReturn(aResponse().withStatus(200)));
221 stubFor(put(urlMatching(".*/business/owning-entities/owning-entity/038d99af-0427-42c2-9d15-971b99b9b489/relationship-list/relationship")).willReturn(aResponse().withStatus(200)));
222 stubFor(put(urlMatching(".*/query?.*")).willReturn(aResponse().withStatus(200)));
224 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
226 Map<String, Object> variables = setupVariables();
228 String businessKey = UUID.randomUUID().toString();
229 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
231 injectWorkflowMessages(callbacks, "oof");
233 injectSDNCCallbacks(callbacks, "assign");
235 waitForProcessEnd(businessKey, 10000);
237 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
238 System.out.println("workflowException:\n" + workflowException);
240 String completionReq = BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+VAR_COMP_REQ);
241 System.out.println("completionReq:\n" + completionReq);
243 assertEquals("true", BPMNUtil.getVariable(processEngine, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
244 assertEquals("200", BPMNUtil.getVariable(processEngine, PROCNAME, VAR_RESP_CODE));
245 assertEquals(null, workflowException);
246 assertTrue(completionReq.indexOf("request-id>testRequestId<") >= 0);
247 assertTrue(completionReq.indexOf("action>CREATE<") >= 0);
248 assertTrue(completionReq.indexOf("source>VID<") >= 0);
250 assertEquals("0", BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+"VnfsCreatedCount"));
254 public void testCreateVcpeResCustService_Fault_NoRollback() throws Exception {
255 System.out.println("starting: testCreateVcpeResCustService_Fault_NoRollback\n");
256 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "2", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
257 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
258 MockGetCustomer(CUST, "VCPE/CreateVcpeResCustService/getCustomer.xml");
260 // TODO: the SI should NOT have to be URL-encoded yet again!
261 MockPutServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
262 MockGetServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
264 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");
265 MockNodeQueryServiceInstanceById(PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
266 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
267 MockGetServiceInstance_500(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
268 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
269 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
271 mockSDNCAdapter(404);
272 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
274 StubResponseOof.mockOof();
275 stubFor(get(urlMatching(".*/business/owning-entities?.*")).willReturn(aResponse().withStatus(404)));
276 stubFor(put(urlMatching(".*/business/owning-entities/owning-entity/.*")).willReturn(aResponse().withStatus(200)));
277 stubFor(put(urlMatching(".*/business/owning-entities/owning-entity/038d99af-0427-42c2-9d15-971b99b9b489/relationship-list/relationship")).willReturn(aResponse().withStatus(200)));
278 stubFor(put(urlMatching(".*/query?.*")).willReturn(aResponse().withStatus(200)));
281 Map<String, Object> variables = setupVariables();
283 String businessKey = UUID.randomUUID().toString();
284 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
286 injectWorkflowMessages(callbacks, "oof");
288 waitForProcessEnd(businessKey, 100000);
290 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
291 System.out.println("workflowException:\n" + workflowException);
293 String completionReq = BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+VAR_COMP_REQ);
294 System.out.println("completionReq:\n" + completionReq);
296 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
297 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, VAR_RESP_CODE));
298 assertNotNull(workflowException);
300 BPMNUtil.assertNoProcessInstance(processEngine, "DoCreateAllottedResourceBRGRollback");
301 BPMNUtil.assertNoProcessInstance(processEngine, "DoCreateVnfAndModulesRollback");
302 BPMNUtil.assertNoProcessInstance(processEngine, "DoCreateAllottedResourceTXCRollback");
306 public void testCreateVcpeResCustService_Fault_Rollback() throws Exception {
307 System.out.println("starting: testCreateVcpeResCustService_Fault_Rollback\n");
308 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "2", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
309 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
310 MockGetCustomer(CUST, "VCPE/CreateVcpeResCustService/getCustomer.xml");
312 // TODO: the SI should NOT have to be URL-encoded yet again!
313 MockPutServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
314 MockGetServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
316 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");
317 MockNodeQueryServiceInstanceById(PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
318 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
319 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
320 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/CreateVcpeResCustService/arGetById.xml");
321 MockGetAllottedResource(CUST, SVC, PARENT_INST, ARID, "VCPE/CreateVcpeResCustService/arGetById.xml");
322 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
323 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
324 MockDeleteAllottedResource(CUST, SVC, PARENT_INST, ARID, ARVERS);
326 mockSDNCAdapter(200);
327 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
329 StubResponseOof.mockOof();
330 stubFor(get(urlMatching(".*/business/owning-entities?.*")).willReturn(aResponse().withStatus(404)));
331 stubFor(put(urlMatching(".*/business/owning-entities/owning-entity/.*")).willReturn(aResponse().withStatus(200)));
332 stubFor(put(urlMatching(".*/business/owning-entities/owning-entity/038d99af-0427-42c2-9d15-971b99b9b489/relationship-list/relationship")).willReturn(aResponse().withStatus(200)));
333 stubFor(put(urlMatching(".*/query?.*")).willReturn(aResponse().withStatus(200)));
335 String req = FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/requestRollback.json");
337 Map<String, Object> variables = setupVariables();
339 String businessKey = UUID.randomUUID().toString();
340 invokeAsyncProcess(PROCNAME, "v1", businessKey, req, variables);
342 injectWorkflowMessages(callbacks, "oof");
344 injectSDNCCallbacks(callbacks, "assign");
347 injectSDNCCallbacks(callbacks, "assign");
348 injectSDNCCallbacks(callbacks, "create");
350 waitForProcessEnd(businessKey, 10000);
352 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
353 System.out.println("workflowException:\n" + workflowException);
355 String completionReq = BPMNUtil.getVariable(processEngine, PROCNAME, Prefix+VAR_COMP_REQ);
356 System.out.println("completionReq:\n" + completionReq);
358 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
359 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, VAR_RESP_CODE));
360 assertEquals(null, completionReq);
361 assertNotNull(workflowException);
363 BPMNUtil.assertAnyProcessInstanceFinished(processEngine, "DoCreateServiceInstanceRollback");
371 private Map<String, Object> setupVariables() {
372 Map<String, Object> variables = new HashMap<>();
373 variables.put("requestId", "testRequestId");
374 variables.put("request-id", "testRequestId");
375 variables.put("serviceInstanceId", DEC_INST);
376 variables.put("allottedResourceId", ARID);
377 variables.put("URN_mso_workflow_aai_distribution_delay", "PT5S");