7b858c464e465f2c60c5895c3df5dab333cec74d
[so.git] /
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 DoCreateAllottedResourceBRGTest extends AbstractTestBase {
45
46     private static final String PROCNAME = "DoCreateAllottedResourceBRG";
47     private final CallbackSet callbacks = new CallbackSet();
48
49     public DoCreateAllottedResourceBRGTest() 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/DoCreateAllottedResourceBRG/SDNCTopologyQueryCallback.xml"));
54     }
55
56     @Test
57     @Deployment(resources = {
58             "subprocess/GenericGetService.bpmn",
59             "subprocess/SDNCAdapterV1.bpmn",
60             "subprocess/FalloutHandler.bpmn",
61             "subprocess/DoCreateAllottedResourceBRG.bpmn",
62             "subprocess/DoCreateAllottedResourceBRGRollback.bpmn"})
63     public void testDoCreateAllottedResourceBRG_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     }
100
101     @Test
102     @Deployment(resources = {
103             "subprocess/GenericGetService.bpmn",
104             "subprocess/SDNCAdapterV1.bpmn",
105             "subprocess/FalloutHandler.bpmn",
106             "subprocess/DoCreateAllottedResourceBRG.bpmn",
107             "subprocess/DoCreateAllottedResourceBRGRollback.bpmn"})
108     public void testDoCreateAllottedResourceBRG_NoSI() throws Exception {
109
110         // TODO: use INST instead of DEC_INST
111                 /*
112                  * should be INST instead of DEC_INST, but AAI utilities appear to
113                  * have a bug in that they don't URL-encode the SI id before using
114                  * it in the query
115                  */
116         MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getNotFound.xml");
117         MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
118
119         MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
120         MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
121         MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
122         MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
123         mockSDNCAdapter(200);
124         mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
125
126         String businessKey = UUID.randomUUID().toString();
127         Map<String, Object> variables = new HashMap<>();
128         setVariablesSuccess(variables, "testRequestId123");
129
130         invokeSubProcess(PROCNAME, businessKey, variables);
131
132         waitForProcessEnd(businessKey, 10000);
133
134         Assert.assertTrue(isProcessEnded(businessKey));
135         String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
136         assertNotNull(workflowException);
137
138         assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
139     }
140
141     @Test
142     @Deployment(resources = {
143             "subprocess/GenericGetService.bpmn",
144             "subprocess/SDNCAdapterV1.bpmn",
145             "subprocess/FalloutHandler.bpmn",
146             "subprocess/DoCreateAllottedResourceBRG.bpmn",
147             "subprocess/DoCreateAllottedResourceBRGRollback.bpmn"})
148     public void testDoCreateAllottedResourceBRG_ActiveAr() throws Exception {
149
150         // TODO: use INST instead of DEC_INST
151                 /*
152                  * should be INST instead of DEC_INST, but AAI utilities appear to
153                  * have a bug in that they don't URL-encode the SI id before using
154                  * it in the query
155                  */
156         MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
157         MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
158
159         MockGetServiceInstance(CUST, SVC, INST, "VCPE/DoCreateAllottedResourceBRG/getSIandAR.xml");
160         MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg2.xml");
161         MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
162         MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
163         MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
164         mockSDNCAdapter(200);
165         mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
166
167         String businessKey = UUID.randomUUID().toString();
168         Map<String, Object> variables = new HashMap<>();
169         setVariablesSuccess(variables, "testRequestId123");
170
171         variables.put("failExists", "false");
172
173         invokeSubProcess(PROCNAME, businessKey, variables);
174
175         injectSDNCCallbacks(callbacks, "query");
176
177         waitForProcessEnd(businessKey, 10000);
178
179         Assert.assertTrue(isProcessEnded(businessKey));
180         String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
181         assertEquals(null, workflowException);
182
183         assertEquals("namefromrequest", BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
184     }
185
186     @Test
187     @Deployment(resources = {
188             "subprocess/GenericGetService.bpmn",
189             "subprocess/SDNCAdapterV1.bpmn",
190             "subprocess/FalloutHandler.bpmn",
191             "subprocess/DoCreateAllottedResourceBRG.bpmn",
192             "subprocess/DoCreateAllottedResourceBRGRollback.bpmn"})
193     public void testDoCreateAllottedResourceBRG_NoParentSI() throws Exception {
194
195         // TODO: use INST instead of DEC_INST
196                 /*
197                  * should be INST instead of DEC_INST, but AAI utilities appear to
198                  * have a bug in that they don't URL-encode the SI id before using
199                  * it in the query
200                  */
201         MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
202         MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getNotFound.xml");
203
204         MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
205         MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
206         MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
207         MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
208         mockSDNCAdapter(200);
209         mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
210
211         String businessKey = UUID.randomUUID().toString();
212         Map<String, Object> variables = new HashMap<>();
213         setVariablesSuccess(variables, "testRequestId123");
214
215         invokeSubProcess(PROCNAME, businessKey, variables);
216
217         waitForProcessEnd(businessKey, 10000);
218
219         Assert.assertTrue(isProcessEnded(businessKey));
220         String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
221         assertNotNull(workflowException);
222
223         assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
224     }
225
226     @Test
227     @Deployment(resources = {
228             "subprocess/GenericGetService.bpmn",
229             "subprocess/SDNCAdapterV1.bpmn",
230             "subprocess/FalloutHandler.bpmn",
231             "subprocess/DoCreateAllottedResourceBRG.bpmn",
232             "subprocess/DoCreateAllottedResourceBRGRollback.bpmn"})
233     public void testDoCreateAllottedResourceBRG_SubProcessError() throws Exception {
234
235         // TODO: use INST instead of DEC_INST
236                 /*
237                  * should be INST instead of DEC_INST, but AAI utilities appear to
238                  * have a bug in that they don't URL-encode the SI id before using
239                  * it in the query
240                  */
241         MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
242         MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
243
244         MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
245         MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
246         MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
247         MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
248         mockSDNCAdapter(404);
249         mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
250
251         String businessKey = UUID.randomUUID().toString();
252         Map<String, Object> variables = new HashMap<>();
253         setVariablesSuccess(variables, "testRequestId123");
254
255         invokeSubProcess(PROCNAME, businessKey, variables);
256
257         waitForProcessEnd(businessKey, 10000);
258
259         Assert.assertTrue(isProcessEnded(businessKey));
260         String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
261         assertNotNull(workflowException);
262
263         assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
264     }
265
266     private void setVariablesSuccess(Map<String, Object> variables, String requestId) {
267         variables.put("isDebugLogEnabled", "true");
268         variables.put("failExists", "true");
269         variables.put("disableRollback", "true");
270         variables.put("msoRequestId", requestId);
271         variables.put("mso-request-id", "requestId");
272         variables.put("sourceNetworkId", "snId");
273         variables.put("sourceNetworkRole", "snRole");
274         variables.put("allottedResourceRole", "txc");
275         variables.put("allottedResourceType", "BRG");
276         variables.put("allottedResourceId", ARID);
277         variables.put("vni", "BRG");
278         variables.put("vgmuxBearerIP", "bearerip");
279         variables.put("brgWanMacAddress", "wanmac");
280
281         variables.put("serviceInstanceId", DEC_INST);
282         variables.put("parentServiceInstanceId", DEC_PARENT_INST);
283
284         variables.put("serviceChainServiceInstanceId", "scsiId");
285
286         String arModelInfo = "{ " + "\"modelType\": \"allotted-resource\"," +
287                 "\"modelInvariantUuid\": \"ff5256d2-5a33-55df-13ab-12abad84e7ff\"," +
288                 "\"modelUuid\": \"fe6478e5-ea33-3346-ac12-ab121484a3fe\"," +
289                 "\"modelName\": \"vSAMP12\"," +
290                 "\"modelVersion\": \"1.0\"," +
291                 "\"modelCustomizationUuid\": \"MODEL-ID-1234\"," +
292                 "}";
293         variables.put("allottedResourceModelInfo", arModelInfo);
294     }
295
296 }