2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.openecomp.mso.bpmn.vcpe;
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;
32 import java.io.IOException;
33 import java.util.HashMap;
35 import java.util.UUID;
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;
44 public class DoCreateAllottedResourceBRGTest extends AbstractTestBase {
46 private static final String PROCNAME = "DoCreateAllottedResourceBRG";
47 private final CallbackSet callbacks = new CallbackSet();
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"));
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{
65 // TODO: use INST instead of DEC_INST
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
71 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
72 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
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);
79 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
81 String businessKey = UUID.randomUUID().toString();
82 Map<String, Object> variables = new HashMap<>();
83 setVariablesSuccess(variables, "testRequestId123");
85 invokeSubProcess(PROCNAME, businessKey, variables);
87 injectSDNCCallbacks(callbacks, "assign");
88 injectSDNCCallbacks(callbacks, "create");
89 injectSDNCCallbacks(callbacks, "activate");
90 injectSDNCCallbacks(callbacks, "query");
92 waitForProcessEnd(businessKey, 10000);
94 Assert.assertTrue(isProcessEnded(businessKey));
95 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
96 assertEquals(null, workflowException);
98 assertEquals("namefromrequest", BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
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{
110 // TODO: use INST instead of DEC_INST
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
116 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getNotFound.xml");
117 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
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");
126 String businessKey = UUID.randomUUID().toString();
127 Map<String, Object> variables = new HashMap<>();
128 setVariablesSuccess(variables, "testRequestId123");
130 invokeSubProcess(PROCNAME, businessKey, variables);
132 waitForProcessEnd(businessKey, 10000);
134 Assert.assertTrue(isProcessEnded(businessKey));
135 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
136 assertNotNull(workflowException);
138 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
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{
150 // TODO: use INST instead of DEC_INST
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
156 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
157 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
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");
167 String businessKey = UUID.randomUUID().toString();
168 Map<String, Object> variables = new HashMap<>();
169 setVariablesSuccess(variables, "testRequestId123");
171 variables.put("failExists", "false");
173 invokeSubProcess(PROCNAME, businessKey, variables);
175 injectSDNCCallbacks(callbacks, "query");
177 waitForProcessEnd(businessKey, 10000);
179 Assert.assertTrue(isProcessEnded(businessKey));
180 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
181 assertEquals(null, workflowException);
183 assertEquals("namefromrequest", BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
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{
195 // TODO: use INST instead of DEC_INST
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
201 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
202 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getNotFound.xml");
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");
211 String businessKey = UUID.randomUUID().toString();
212 Map<String, Object> variables = new HashMap<>();
213 setVariablesSuccess(variables, "testRequestId123");
215 invokeSubProcess(PROCNAME, businessKey, variables);
217 waitForProcessEnd(businessKey, 10000);
219 Assert.assertTrue(isProcessEnded(businessKey));
220 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
221 assertNotNull(workflowException);
223 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
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{
235 // TODO: use INST instead of DEC_INST
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
241 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
242 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
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");
251 String businessKey = UUID.randomUUID().toString();
252 Map<String, Object> variables = new HashMap<>();
253 setVariablesSuccess(variables, "testRequestId123");
255 invokeSubProcess(PROCNAME, businessKey, variables);
257 waitForProcessEnd(businessKey, 10000);
259 Assert.assertTrue(isProcessEnded(businessKey));
260 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
261 assertNotNull(workflowException);
263 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
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");
281 variables.put("serviceInstanceId", DEC_INST);
282 variables.put("parentServiceInstanceId", DEC_PARENT_INST);
284 variables.put("serviceChainServiceInstanceId", "scsiId");
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\"," +
293 variables.put("allottedResourceModelInfo", arModelInfo);