Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / vcpe / DoDeleteAllottedResourceTXCIT.java
1 /*
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
7  * 
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * 
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=========================================================
14  */
15
16 package org.onap.so.bpmn.vcpe;
17
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;
23 import java.util.Map;
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;
29
30
31 public class DoDeleteAllottedResourceTXCIT extends AbstractTestBase {
32
33     private static final String PROCNAME = "DoDeleteAllottedResourceTXC";
34     private final CallbackSet callbacks = new CallbackSet();
35
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"));
43     }
44
45     @Test
46     public void testDoDeleteAllottedResourceTXC_Success() throws Exception {
47         logStart();
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");
55
56         Map<String, Object> variables = new HashMap<>();
57         setVariablesSuccess(variables);
58
59         String processId = invokeSubProcess(PROCNAME, variables);
60
61         injectSDNCCallbacks(callbacks, "deactivate");
62         injectSDNCCallbacks(callbacks, "delete");
63         injectSDNCCallbacks(callbacks, "unassign");
64
65         BPMNUtil.waitForWorkflowToFinish(processEngine, processId);
66
67         Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
68         String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, "WorkflowException", processId);
69         System.out.println("workflowException:\n" + workflowException);
70         assertNull(workflowException);
71         logEnd();
72     }
73
74     @Test
75     public void testDoDeleteAllottedResourceTXC_ARNotInSDNC() throws Exception {
76         logStart();
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");
84
85         Map<String, Object> variables = new HashMap<>();
86         setVariablesSuccess(variables);
87
88         variables.put("failNotFound", "false");
89
90         String processId = invokeSubProcess(PROCNAME, variables);
91
92         injectSDNCCallbacks(callbacks, "deactivateNF");
93
94         BPMNUtil.waitForWorkflowToFinish(processEngine, processId);
95
96         Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
97         logEnd();
98     }
99
100
101     @Test
102     public void testDoDeleteAllottedResourceTXC_SubProcessError() throws Exception {
103         logStart();
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");
110
111         mockSDNCAdapter(wireMockServer, 500);
112
113         Map<String, Object> variables = new HashMap<>();
114         setVariablesSuccess(variables);
115
116         String processId = invokeSubProcess(PROCNAME, variables);
117
118         BPMNUtil.waitForWorkflowToFinish(processEngine, processId);
119
120         Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
121         String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, "WorkflowException", processId);
122         System.out.println("workflowException:\n" + workflowException);
123         assertNotNull(workflowException);
124         logEnd();
125     }
126
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);
133
134         variables.put("serviceInstanceId", DEC_INST);
135         variables.put("parentServiceInstanceId", DEC_PARENT_INST);
136     }
137
138 }