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 org.junit.Assert;
19 import org.junit.Test;
20 import org.onap.so.bpmn.common.BPMNUtil;
21 import org.onap.so.bpmn.mock.FileUtil;
22 import java.util.HashMap;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.onap.so.bpmn.mock.StubResponseAAI.*;
27 import static org.onap.so.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
28 import static org.onap.so.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
31 public class DoDeleteAllottedResourceTXCIT extends AbstractTestBase {
33 private static final String PROCNAME = "DoDeleteAllottedResourceTXC";
34 private final CallbackSet callbacks = new CallbackSet();
36 public DoDeleteAllottedResourceTXCIT() {
37 callbacks.put("deactivate",
38 FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
39 callbacks.put("deactivateNF",
40 FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallbackNotFound.xml"));
41 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
42 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
46 public void testDoDeleteAllottedResourceTXC_Success() throws Exception {
48 MockQueryAllottedResourceById(wireMockServer, ARID, "GenericFlows/getARUrlById.xml");
49 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, ARID,
50 "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml");
51 MockPatchAllottedResource(wireMockServer, CUST, SVC, INST, ARID);
52 MockDeleteAllottedResource(wireMockServer, CUST, SVC, INST, ARID, ARVERS);
53 mockSDNCAdapter(wireMockServer, 200);
54 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
56 Map<String, Object> variables = new HashMap<>();
57 setVariablesSuccess(variables);
59 String processId = invokeSubProcess(PROCNAME, variables);
61 injectSDNCCallbacks(callbacks, "deactivate");
62 injectSDNCCallbacks(callbacks, "delete");
63 injectSDNCCallbacks(callbacks, "unassign");
65 BPMNUtil.waitForWorkflowToFinish(processEngine, processId);
67 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
68 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, "WorkflowException", processId);
69 System.out.println("workflowException:\n" + workflowException);
70 assertNull(workflowException);
75 public void testDoDeleteAllottedResourceTXC_ARNotInSDNC() throws Exception {
77 MockQueryAllottedResourceById(wireMockServer, ARID, "GenericFlows/getARUrlById.xml");
78 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, ARID,
79 "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml");
80 MockPatchAllottedResource(wireMockServer, CUST, SVC, INST, ARID);
81 MockDeleteAllottedResource(wireMockServer, CUST, SVC, INST, ARID, ARVERS);
82 mockSDNCAdapter(wireMockServer, 200);
83 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
85 Map<String, Object> variables = new HashMap<>();
86 setVariablesSuccess(variables);
88 variables.put("failNotFound", "false");
90 String processId = invokeSubProcess(PROCNAME, variables);
92 injectSDNCCallbacks(callbacks, "deactivateNF");
94 BPMNUtil.waitForWorkflowToFinish(processEngine, processId);
96 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
102 public void testDoDeleteAllottedResourceTXC_SubProcessError() throws Exception {
104 MockQueryAllottedResourceById(wireMockServer, ARID, "GenericFlows/getARUrlById.xml");
105 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, ARID,
106 "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml");
107 MockPatchAllottedResource(wireMockServer, CUST, SVC, INST, ARID);
108 MockDeleteAllottedResource(wireMockServer, CUST, SVC, INST, ARID, ARVERS);
109 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
111 mockSDNCAdapter(wireMockServer, 500);
113 Map<String, Object> variables = new HashMap<>();
114 setVariablesSuccess(variables);
116 String processId = invokeSubProcess(PROCNAME, variables);
118 BPMNUtil.waitForWorkflowToFinish(processEngine, processId);
120 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
121 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, "WorkflowException", processId);
122 System.out.println("workflowException:\n" + workflowException);
123 assertNotNull(workflowException);
127 private void setVariablesSuccess(Map<String, Object> variables) {
128 variables.put("isDebugLogEnabled", "true");
129 variables.put("failNotFound", "true");
130 variables.put("msoRequestId", "testRequestId1");
131 variables.put("mso-request-id", "requestId");
132 variables.put("allottedResourceId", ARID);
134 variables.put("serviceInstanceId", DEC_INST);
135 variables.put("parentServiceInstanceId", DEC_PARENT_INST);