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