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