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=========================================================
21 package org.onap.so.bpmn.vcpe;
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;
35 import java.io.IOException;
36 import java.util.HashMap;
38 import java.util.UUID;
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;
47 public class DoCreateAllottedResourceTXCIT extends AbstractTestBase {
49 private static final String PROCNAME = "DoCreateAllottedResourceTXC";
50 private final CallbackSet callbacks = new CallbackSet();
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"));
60 public void testDoCreateAllottedResourceTXC_Success() throws Exception{
62 // TODO: use INST instead of DEC_INST
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
68 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
69 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
71 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
72 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
73 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
74 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
76 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
78 Map<String, Object> variables = new HashMap<>();
79 setVariablesSuccess(variables, "testRequestId123");
81 String processId = invokeSubProcess(PROCNAME, variables);
83 injectSDNCCallbacks(callbacks, "assign");
84 injectSDNCCallbacks(callbacks, "create");
85 injectSDNCCallbacks(callbacks, "activate");
86 injectSDNCCallbacks(callbacks, "query");
88 waitForWorkflowToFinish(processEngine,processId);
90 assertTrue(isProcessEndedByProcessInstanceId(processId));
92 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX,processId);
93 assertEquals(null, workflowException);
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));
103 public void testDoCreateAllottedResourceTXC_NoSI() throws Exception{
105 // TODO: use INST instead of DEC_INST
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
111 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getNotFound.xml");
112 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
114 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
115 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
116 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
117 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
118 mockSDNCAdapter(200);
119 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
121 Map<String, Object> variables = new HashMap<>();
122 setVariablesSuccess(variables, "testRequestId123");
124 String processId = invokeSubProcess(PROCNAME, variables);
126 waitForWorkflowToFinish(processEngine,processId);
128 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
129 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX,processId);
130 assertNotNull(workflowException);
132 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName",processId));
137 public void testDoCreateAllottedResourceTXC_ActiveAr() throws Exception{
139 // TODO: use INST instead of DEC_INST
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
145 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
146 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
148 MockGetServiceInstance(CUST, SVC, INST, "VCPE/DoCreateAllottedResourceTXC/getSIandAR.xml");
149 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc2.xml");
150 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
151 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
152 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
153 mockSDNCAdapter(200);
154 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
156 Map<String, Object> variables = new HashMap<>();
157 setVariablesSuccess(variables, "testRequestId123");
159 variables.put("failExists", "false");
161 String processId = invokeSubProcess(PROCNAME, variables);
163 injectSDNCCallbacks(callbacks, "query");
165 waitForWorkflowToFinish(processEngine,processId);
167 assertTrue(isProcessEndedByProcessInstanceId(processId));
168 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
169 assertEquals(null, workflowException);
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));
179 public void testDoCreateAllottedResourceTXC_NoParentSI() throws Exception{
181 // TODO: use INST instead of DEC_INST
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
187 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
189 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getNotFound.xml");
191 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
192 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
193 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
194 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
195 mockSDNCAdapter(200);
196 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
198 Map<String, Object> variables = new HashMap<>();
199 setVariablesSuccess(variables, "testRequestId123");
201 String processId = invokeSubProcess(PROCNAME, variables);
203 waitForWorkflowToFinish(processEngine,processId);
205 assertTrue(isProcessEndedByProcessInstanceId(processId));
206 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX,processId);
207 assertNotNull(workflowException);
209 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName",processId));
214 public void testDoCreateAllottedResourceTXC_SubProcessError() throws Exception{
216 // TODO: use INST instead of DEC_INST
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
222 MockNodeQueryServiceInstanceById(DEC_INST, "GenericFlows/getSIUrlById.xml");
223 MockNodeQueryServiceInstanceById(DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
225 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
226 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
227 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
228 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
229 mockSDNCAdapter(404);
230 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
232 Map<String, Object> variables = new HashMap<>();
233 setVariablesSuccess(variables, "testRequestId123");
235 String processId = invokeSubProcess(PROCNAME, variables);
237 waitForWorkflowToFinish(processEngine,processId);
239 assertTrue(isProcessEndedByProcessInstanceId(processId));
240 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX,processId);
241 assertNotNull(workflowException);
243 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName",processId));
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");
261 variables.put("serviceInstanceId", DEC_INST);
262 variables.put("parentServiceInstanceId", DEC_PARENT_INST);
264 variables.put("serviceChainServiceInstanceId", "scsiId");
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\"," +
273 variables.put("allottedResourceModelInfo", arModelInfo);