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 DoCreateAllottedResourceTXCTest extends AbstractTestBase {
46 private static final String PROCNAME = "DoCreateAllottedResourceTXC";
47 private final CallbackSet callbacks = new CallbackSet();
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"));
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{
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"));
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"));
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{
113 // TODO: use INST instead of DEC_INST
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
119 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getNotFound.xml");
120 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
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");
129 String businessKey = UUID.randomUUID().toString();
130 Map<String, Object> variables = new HashMap<>();
131 setVariablesSuccess(variables, "testRequestId123");
133 invokeSubProcess(PROCNAME, businessKey, variables);
135 waitForProcessEnd(businessKey, 10000);
137 Assert.assertTrue(isProcessEnded(businessKey));
138 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
139 assertNotNull(workflowException);
141 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
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{
153 // TODO: use INST instead of DEC_INST
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
159 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
160 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
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");
170 String businessKey = UUID.randomUUID().toString();
171 Map<String, Object> variables = new HashMap<>();
172 setVariablesSuccess(variables, "testRequestId123");
174 variables.put("failExists", "false");
176 invokeSubProcess(PROCNAME, businessKey, variables);
178 injectSDNCCallbacks(callbacks, "query");
180 waitForProcessEnd(businessKey, 10000);
182 Assert.assertTrue(isProcessEnded(businessKey));
183 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
184 assertEquals(null, workflowException);
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"));
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{
201 // TODO: use INST instead of DEC_INST
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
207 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
209 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getNotFound.xml");
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");
218 String businessKey = UUID.randomUUID().toString();
219 Map<String, Object> variables = new HashMap<>();
220 setVariablesSuccess(variables, "testRequestId123");
222 invokeSubProcess(PROCNAME, businessKey, variables);
224 waitForProcessEnd(businessKey, 10000);
226 Assert.assertTrue(isProcessEnded(businessKey));
227 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
228 assertNotNull(workflowException);
230 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
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{
242 // TODO: use INST instead of DEC_INST
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
248 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
249 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
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");
258 String businessKey = UUID.randomUUID().toString();
259 Map<String, Object> variables = new HashMap<>();
260 setVariablesSuccess(variables, "testRequestId123");
262 invokeSubProcess(PROCNAME, businessKey, variables);
264 waitForProcessEnd(businessKey, 10000);
266 Assert.assertTrue(isProcessEnded(businessKey));
267 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
268 assertNotNull(workflowException);
270 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, "allotedResourceName"));
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");
287 variables.put("serviceInstanceId", DEC_INST);
288 variables.put("parentServiceInstanceId", DEC_PARENT_INST);
290 variables.put("serviceChainServiceInstanceId", "scsiId");
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\"," +
299 variables.put("allottedResourceModelInfo", arModelInfo);