13ca58be0384103d6d3ce6c2531ee127a4c4b83d
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / vcpe / DoDeleteAllottedResourceTXCIT.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.vcpe;
22
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;
27
28 import java.util.HashMap;
29 import java.util.Map;
30
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;
36
37
38 public class DoDeleteAllottedResourceTXCIT extends AbstractTestBase {
39
40         private static final String PROCNAME = "DoDeleteAllottedResourceTXC";
41         private final CallbackSet callbacks = new CallbackSet();
42         
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"));
48         }
49         
50         @Test
51         public void testDoDeleteAllottedResourceTXC_Success() throws Exception {
52                 logStart();
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");
59                 
60                 Map<String, Object> variables = new HashMap<>();
61                 setVariablesSuccess(variables);
62                 
63                 String processId = invokeSubProcess(PROCNAME, variables);
64                 
65                 injectSDNCCallbacks(callbacks, "deactivate");
66                 injectSDNCCallbacks(callbacks, "delete");
67                 injectSDNCCallbacks(callbacks, "unassign");
68
69                 BPMNUtil.waitForWorkflowToFinish(processEngine,processId);
70
71                 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
72                 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, "WorkflowException",processId);
73                 System.out.println("workflowException:\n" + workflowException);
74                 assertNull(workflowException);
75                 logEnd();
76         }
77         
78         @Test
79         public void testDoDeleteAllottedResourceTXC_ARNotInSDNC() throws Exception {
80                 logStart();
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");
87                 
88                 Map<String, Object> variables = new HashMap<>();
89                 setVariablesSuccess(variables);
90
91                 variables.put("failNotFound", "false");
92
93                 String processId = invokeSubProcess(PROCNAME, variables);
94                 
95                 injectSDNCCallbacks(callbacks, "deactivateNF");
96
97                 BPMNUtil.waitForWorkflowToFinish(processEngine,processId);
98
99                 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
100                 logEnd();
101         }
102         
103         
104         @Test
105         public void testDoDeleteAllottedResourceTXC_SubProcessError() throws Exception {
106                 logStart();
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");
112
113                 mockSDNCAdapter(wireMockServer, 500);
114                 
115                 Map<String, Object> variables = new HashMap<>();
116                 setVariablesSuccess(variables);
117
118                 String processId = invokeSubProcess(PROCNAME, variables);
119
120                 BPMNUtil.waitForWorkflowToFinish(processEngine,processId);
121
122                 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
123                 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, "WorkflowException",processId);
124                 System.out.println("workflowException:\n" + workflowException);
125                 assertNotNull(workflowException);
126                 logEnd();
127         }
128
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);
135                 
136                 variables.put("serviceInstanceId", DEC_INST);
137                 variables.put("parentServiceInstanceId", DEC_PARENT_INST);
138         }
139
140 }