Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / vcpe / DoCreateAllottedResourceTXCIT.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 static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertTrue;
21 import static org.onap.so.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
22 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource;
23 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
24 import static org.onap.so.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
25 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource;
26 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutAllottedResource;
27 import static org.onap.so.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
28 import static org.onap.so.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
29 import java.io.IOException;
30 import java.util.HashMap;
31 import java.util.Map;
32 import java.util.UUID;
33 import org.camunda.bpm.engine.test.Deployment;
34 import org.junit.Assert;
35 import org.junit.Ignore;
36 import org.junit.Test;
37 import org.onap.so.bpmn.common.BPMNUtil;
38 import org.onap.so.bpmn.mock.FileUtil;
39
40 public class DoCreateAllottedResourceTXCIT extends AbstractTestBase {
41
42     private static final String PROCNAME = "DoCreateAllottedResourceTXC";
43     private final CallbackSet callbacks = new CallbackSet();
44
45     public DoCreateAllottedResourceTXCIT() throws IOException {
46         callbacks.put("assign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyAssignCallback.xml"));
47         callbacks.put("create", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyCreateCallback.xml"));
48         callbacks.put("activate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyActivateCallback.xml"));
49         callbacks.put("query",
50                 FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/SDNCTopologyQueryCallback.xml"));
51     }
52
53     @Test
54     public void testDoCreateAllottedResourceTXC_Success() throws Exception {
55         logStart();
56         // TODO: use INST instead of DEC_INST
57         /*
58          * should be INST instead of DEC_INST, but AAI utilities appear to have a bug in that they don't URL-encode the
59          * SI id before using it in the query
60          */
61         MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
62         MockNodeQueryServiceInstanceById(wireMockServer, DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
63
64         MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
65         MockGetServiceInstance(wireMockServer, CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
66         MockPutAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
67         MockPatchAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
68         mockSDNCAdapter(wireMockServer, 200);
69         mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
70
71         Map<String, Object> variables = new HashMap<>();
72         setVariablesSuccess(variables, "testRequestId123");
73
74         String processId = invokeSubProcess(PROCNAME, variables);
75
76         injectSDNCCallbacks(callbacks, "assign");
77         injectSDNCCallbacks(callbacks, "create");
78         injectSDNCCallbacks(callbacks, "activate");
79         injectSDNCCallbacks(callbacks, "query");
80
81         waitForWorkflowToFinish(processEngine, processId);
82
83         assertTrue(isProcessEndedByProcessInstanceId(processId));
84
85         String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX, processId);
86         assertEquals(null, workflowException);
87
88         assertEquals("namefromrequest",
89                 BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName", processId));
90         assertEquals("my-vni", BPMNUtil.getVariable(processEngine, PROCNAME, "vni", processId));
91         assertEquals("my-bearer-ip", BPMNUtil.getVariable(processEngine, PROCNAME, "vgmuxBearerIP", processId));
92         assertEquals("my-lan-ip", BPMNUtil.getVariable(processEngine, PROCNAME, "vgmuxLanIP", processId));
93         logEnd();
94     }
95
96     @Test
97     public void testDoCreateAllottedResourceTXC_NoSI() throws Exception {
98         logStart();
99         // TODO: use INST instead of DEC_INST
100         /*
101          * should be INST instead of DEC_INST, but AAI utilities appear to have a bug in that they don't URL-encode the
102          * SI id before using it in the query
103          */
104         MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getNotFound.xml");
105         MockNodeQueryServiceInstanceById(wireMockServer, DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
106
107         MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
108         MockGetServiceInstance(wireMockServer, CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
109         MockPutAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
110         MockPatchAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
111         mockSDNCAdapter(wireMockServer, 200);
112         mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
113
114         Map<String, Object> variables = new HashMap<>();
115         setVariablesSuccess(variables, "testRequestId123");
116
117         String processId = invokeSubProcess(PROCNAME, variables);
118
119         waitForWorkflowToFinish(processEngine, processId);
120
121         Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
122         String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX, processId);
123         assertNotNull(workflowException);
124
125         assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName", processId));
126         logEnd();
127     }
128
129     @Test
130     public void testDoCreateAllottedResourceTXC_ActiveAr() throws Exception {
131         logStart();
132         // TODO: use INST instead of DEC_INST
133         /*
134          * should be INST instead of DEC_INST, but AAI utilities appear to have a bug in that they don't URL-encode the
135          * SI id before using it in the query
136          */
137         MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
138         MockNodeQueryServiceInstanceById(wireMockServer, DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
139
140         MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "VCPE/DoCreateAllottedResourceTXC/getSIandAR.xml");
141         MockGetAllottedResource(wireMockServer, CUST, SVC, INST, ARID,
142                 "VCPE/DoCreateAllottedResourceTXC/getArTxc2.xml");
143         MockGetServiceInstance(wireMockServer, CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
144         MockPutAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
145         MockPatchAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
146         mockSDNCAdapter(wireMockServer, 200);
147         mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
148
149         Map<String, Object> variables = new HashMap<>();
150         setVariablesSuccess(variables, "testRequestId123");
151
152         variables.put("failExists", "false");
153
154         String processId = invokeSubProcess(PROCNAME, variables);
155
156         injectSDNCCallbacks(callbacks, "query");
157
158         waitForWorkflowToFinish(processEngine, processId);
159
160         assertTrue(isProcessEndedByProcessInstanceId(processId));
161         String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
162         assertEquals(null, workflowException);
163
164         assertEquals("namefromrequest",
165                 BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName", processId));
166         assertEquals("my-vni", BPMNUtil.getVariable(processEngine, PROCNAME, "vni", processId));
167         assertEquals("my-bearer-ip", BPMNUtil.getVariable(processEngine, PROCNAME, "vgmuxBearerIP", processId));
168         assertEquals("my-lan-ip", BPMNUtil.getVariable(processEngine, PROCNAME, "vgmuxLanIP", processId));
169         logEnd();
170     }
171
172     @Test
173     public void testDoCreateAllottedResourceTXC_NoParentSI() throws Exception {
174         logStart();
175         // TODO: use INST instead of DEC_INST
176         /*
177          * should be INST instead of DEC_INST, but AAI utilities appear to have a bug in that they don't URL-encode the
178          * SI id before using it in the query
179          */
180         MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
181
182         MockNodeQueryServiceInstanceById(wireMockServer, DEC_PARENT_INST, "GenericFlows/getNotFound.xml");
183
184         MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
185         MockGetServiceInstance(wireMockServer, CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
186         MockPutAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
187         MockPatchAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
188         mockSDNCAdapter(wireMockServer, 200);
189         mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
190
191         Map<String, Object> variables = new HashMap<>();
192         setVariablesSuccess(variables, "testRequestId123");
193
194         String processId = invokeSubProcess(PROCNAME, variables);
195
196         waitForWorkflowToFinish(processEngine, processId);
197
198         assertTrue(isProcessEndedByProcessInstanceId(processId));
199         String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX, processId);
200         assertNotNull(workflowException);
201
202         assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName", processId));
203         logEnd();
204     }
205
206     @Test
207     public void testDoCreateAllottedResourceTXC_SubProcessError() throws Exception {
208         logStart();
209         // TODO: use INST instead of DEC_INST
210         /*
211          * should be INST instead of DEC_INST, but AAI utilities appear to have a bug in that they don't URL-encode the
212          * SI id before using it in the query
213          */
214         MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
215         MockNodeQueryServiceInstanceById(wireMockServer, DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
216
217         MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
218         MockGetServiceInstance(wireMockServer, CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
219         MockPutAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
220         MockPatchAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
221         mockSDNCAdapter(wireMockServer, 404);
222         mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
223
224         Map<String, Object> variables = new HashMap<>();
225         setVariablesSuccess(variables, "testRequestId123");
226
227         String processId = invokeSubProcess(PROCNAME, variables);
228
229         waitForWorkflowToFinish(processEngine, processId);
230
231         assertTrue(isProcessEndedByProcessInstanceId(processId));
232         String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX, processId);
233         assertNotNull(workflowException);
234
235         assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName", processId));
236         logEnd();
237     }
238
239     private void setVariablesSuccess(Map<String, Object> variables, String requestId) {
240         // TODO: need all of these?
241         variables.put("isDebugLogEnabled", "true");
242         variables.put("failExists", "true");
243         variables.put("disableRollback", "true");
244         variables.put("msoRequestId", requestId);
245         variables.put("mso-request-id", "requestId");
246         variables.put("sourceNetworkId", "snId");
247         variables.put("sourceNetworkRole", "snRole");
248         variables.put("allottedResourceRole", "brg");
249         variables.put("allottedResourceType", "TXC");
250         variables.put("allottedResourceId", ARID);
251         variables.put("brgWanMacAddress", "wanmac");
252
253         variables.put("serviceInstanceId", DEC_INST);
254         variables.put("parentServiceInstanceId", DEC_PARENT_INST);
255
256         variables.put("serviceChainServiceInstanceId", "scsiId");
257
258         String arModelInfo = "{ " + "\"modelType\": \"allotted-resource\","
259                 + "\"modelInvariantUuid\": \"ff5256d2-5a33-55df-13ab-12abad84e7ff\","
260                 + "\"modelUuid\": \"fe6478e5-ea33-3346-ac12-ab121484a3fe\"," + "\"modelName\": \"vSAMP12\","
261                 + "\"modelVersion\": \"1.0\"," + "\"modelCustomizationUuid\": \"MODEL-ID-1234\"," + "}";
262         variables.put("allottedResourceModelInfo", arModelInfo);
263     }
264
265 }