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