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 org.junit.Assert;
24 import org.junit.Test;
25 import org.onap.so.bpmn.common.BPMNUtil;
26 import org.onap.so.bpmn.mock.FileUtil;
28 import java.util.HashMap;
31 import static org.junit.Assert.assertNotNull;
32 import static org.junit.Assert.assertNull;
33 import static org.onap.so.bpmn.mock.StubResponseAAI.*;
34 import static org.onap.so.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
35 import static org.onap.so.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
38 public class DoDeleteAllottedResourceTXCIT extends AbstractTestBase {
40 private static final String PROCNAME = "DoDeleteAllottedResourceTXC";
41 private final CallbackSet callbacks = new CallbackSet();
43 public DoDeleteAllottedResourceTXCIT() {
44 callbacks.put("deactivate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
45 callbacks.put("deactivateNF", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallbackNotFound.xml"));
46 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
47 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
51 public void testDoDeleteAllottedResourceTXC_Success() throws Exception {
53 MockQueryAllottedResourceById(wireMockServer, ARID, "GenericFlows/getARUrlById.xml");
54 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml");
55 MockPatchAllottedResource(wireMockServer, CUST, SVC, INST, ARID);
56 MockDeleteAllottedResource(wireMockServer, CUST, SVC, INST, ARID, ARVERS);
57 mockSDNCAdapter(wireMockServer, 200);
58 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
60 Map<String, Object> variables = new HashMap<>();
61 setVariablesSuccess(variables);
63 String processId = invokeSubProcess(PROCNAME, variables);
65 injectSDNCCallbacks(callbacks, "deactivate");
66 injectSDNCCallbacks(callbacks, "delete");
67 injectSDNCCallbacks(callbacks, "unassign");
69 BPMNUtil.waitForWorkflowToFinish(processEngine,processId);
71 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
72 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, "WorkflowException",processId);
73 System.out.println("workflowException:\n" + workflowException);
74 assertNull(workflowException);
79 public void testDoDeleteAllottedResourceTXC_ARNotInSDNC() throws Exception {
81 MockQueryAllottedResourceById(wireMockServer, ARID, "GenericFlows/getARUrlById.xml");
82 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml");
83 MockPatchAllottedResource(wireMockServer, CUST, SVC, INST, ARID);
84 MockDeleteAllottedResource(wireMockServer, CUST, SVC, INST, ARID, ARVERS);
85 mockSDNCAdapter(wireMockServer, 200);
86 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
88 Map<String, Object> variables = new HashMap<>();
89 setVariablesSuccess(variables);
91 variables.put("failNotFound", "false");
93 String processId = invokeSubProcess(PROCNAME, variables);
95 injectSDNCCallbacks(callbacks, "deactivateNF");
97 BPMNUtil.waitForWorkflowToFinish(processEngine,processId);
99 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
105 public void testDoDeleteAllottedResourceTXC_SubProcessError() throws Exception {
107 MockQueryAllottedResourceById(wireMockServer, ARID, "GenericFlows/getARUrlById.xml");
108 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml");
109 MockPatchAllottedResource(wireMockServer, CUST, SVC, INST, ARID);
110 MockDeleteAllottedResource(wireMockServer, CUST, SVC, INST, ARID, ARVERS);
111 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
113 mockSDNCAdapter(wireMockServer, 500);
115 Map<String, Object> variables = new HashMap<>();
116 setVariablesSuccess(variables);
118 String processId = invokeSubProcess(PROCNAME, variables);
120 BPMNUtil.waitForWorkflowToFinish(processEngine,processId);
122 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
123 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, "WorkflowException",processId);
124 System.out.println("workflowException:\n" + workflowException);
125 assertNotNull(workflowException);
129 private void setVariablesSuccess(Map<String, Object> variables) {
130 variables.put("isDebugLogEnabled", "true");
131 variables.put("failNotFound", "true");
132 variables.put("msoRequestId", "testRequestId1");
133 variables.put("mso-request-id", "requestId");
134 variables.put("allottedResourceId", ARID);
136 variables.put("serviceInstanceId", DEC_INST);
137 variables.put("parentServiceInstanceId", DEC_PARENT_INST);