2 * ============LICENSE_START======================================================= ONAP - SO
3 * ================================================================================ Copyright (C) 2017 AT&T Intellectual
4 * Property. All rights reserved. ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 * specific language governing permissions and limitations under the License.
13 * ============LICENSE_END=========================================================
16 package org.onap.so.bpmn.vcpe;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertTrue;
21 import static org.onap.so.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
22 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource;
23 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
24 import static org.onap.so.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
25 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource;
26 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutAllottedResource;
27 import static org.onap.so.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
28 import static org.onap.so.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
29 import java.io.IOException;
30 import java.util.HashMap;
32 import java.util.UUID;
33 import org.camunda.bpm.engine.test.Deployment;
34 import org.junit.Assert;
35 import org.junit.Ignore;
36 import org.junit.Test;
37 import org.onap.so.bpmn.common.BPMNUtil;
38 import org.onap.so.bpmn.mock.FileUtil;
40 public class DoCreateAllottedResourceTXCIT extends AbstractTestBase {
42 private static final String PROCNAME = "DoCreateAllottedResourceTXC";
43 private final CallbackSet callbacks = new CallbackSet();
45 public DoCreateAllottedResourceTXCIT() throws IOException {
46 callbacks.put("assign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyAssignCallback.xml"));
47 callbacks.put("create", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyCreateCallback.xml"));
48 callbacks.put("activate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyActivateCallback.xml"));
49 callbacks.put("query",
50 FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/SDNCTopologyQueryCallback.xml"));
54 public void testDoCreateAllottedResourceTXC_Success() throws Exception {
56 // TODO: use INST instead of DEC_INST
58 * should be INST instead of DEC_INST, but AAI utilities appear to have a bug in that they don't URL-encode the
59 * SI id before using it in the query
61 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
62 MockNodeQueryServiceInstanceById(wireMockServer, DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
64 MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
65 MockGetServiceInstance(wireMockServer, CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
66 MockPutAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
67 MockPatchAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
68 mockSDNCAdapter(wireMockServer, 200);
69 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
71 Map<String, Object> variables = new HashMap<>();
72 setVariablesSuccess(variables, "testRequestId123");
74 String processId = invokeSubProcess(PROCNAME, variables);
76 injectSDNCCallbacks(callbacks, "assign");
77 injectSDNCCallbacks(callbacks, "create");
78 injectSDNCCallbacks(callbacks, "activate");
79 injectSDNCCallbacks(callbacks, "query");
81 waitForWorkflowToFinish(processEngine, processId);
83 assertTrue(isProcessEndedByProcessInstanceId(processId));
85 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX, processId);
86 assertEquals(null, workflowException);
88 assertEquals("namefromrequest",
89 BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName", processId));
90 assertEquals("my-vni", BPMNUtil.getVariable(processEngine, PROCNAME, "vni", processId));
91 assertEquals("my-bearer-ip", BPMNUtil.getVariable(processEngine, PROCNAME, "vgmuxBearerIP", processId));
92 assertEquals("my-lan-ip", BPMNUtil.getVariable(processEngine, PROCNAME, "vgmuxLanIP", processId));
97 public void testDoCreateAllottedResourceTXC_NoSI() throws Exception {
99 // TODO: use INST instead of DEC_INST
101 * should be INST instead of DEC_INST, but AAI utilities appear to have a bug in that they don't URL-encode the
102 * SI id before using it in the query
104 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getNotFound.xml");
105 MockNodeQueryServiceInstanceById(wireMockServer, DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
107 MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
108 MockGetServiceInstance(wireMockServer, CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
109 MockPutAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
110 MockPatchAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
111 mockSDNCAdapter(wireMockServer, 200);
112 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
114 Map<String, Object> variables = new HashMap<>();
115 setVariablesSuccess(variables, "testRequestId123");
117 String processId = invokeSubProcess(PROCNAME, variables);
119 waitForWorkflowToFinish(processEngine, processId);
121 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
122 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX, processId);
123 assertNotNull(workflowException);
125 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName", processId));
130 public void testDoCreateAllottedResourceTXC_ActiveAr() throws Exception {
132 // TODO: use INST instead of DEC_INST
134 * should be INST instead of DEC_INST, but AAI utilities appear to have a bug in that they don't URL-encode the
135 * SI id before using it in the query
137 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
138 MockNodeQueryServiceInstanceById(wireMockServer, DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
140 MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "VCPE/DoCreateAllottedResourceTXC/getSIandAR.xml");
141 MockGetAllottedResource(wireMockServer, CUST, SVC, INST, ARID,
142 "VCPE/DoCreateAllottedResourceTXC/getArTxc2.xml");
143 MockGetServiceInstance(wireMockServer, CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
144 MockPutAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
145 MockPatchAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
146 mockSDNCAdapter(wireMockServer, 200);
147 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
149 Map<String, Object> variables = new HashMap<>();
150 setVariablesSuccess(variables, "testRequestId123");
152 variables.put("failExists", "false");
154 String processId = invokeSubProcess(PROCNAME, variables);
156 injectSDNCCallbacks(callbacks, "query");
158 waitForWorkflowToFinish(processEngine, processId);
160 assertTrue(isProcessEndedByProcessInstanceId(processId));
161 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
162 assertEquals(null, workflowException);
164 assertEquals("namefromrequest",
165 BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName", processId));
166 assertEquals("my-vni", BPMNUtil.getVariable(processEngine, PROCNAME, "vni", processId));
167 assertEquals("my-bearer-ip", BPMNUtil.getVariable(processEngine, PROCNAME, "vgmuxBearerIP", processId));
168 assertEquals("my-lan-ip", BPMNUtil.getVariable(processEngine, PROCNAME, "vgmuxLanIP", processId));
173 public void testDoCreateAllottedResourceTXC_NoParentSI() throws Exception {
175 // TODO: use INST instead of DEC_INST
177 * should be INST instead of DEC_INST, but AAI utilities appear to have a bug in that they don't URL-encode the
178 * SI id before using it in the query
180 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
182 MockNodeQueryServiceInstanceById(wireMockServer, DEC_PARENT_INST, "GenericFlows/getNotFound.xml");
184 MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
185 MockGetServiceInstance(wireMockServer, CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
186 MockPutAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
187 MockPatchAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
188 mockSDNCAdapter(wireMockServer, 200);
189 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
191 Map<String, Object> variables = new HashMap<>();
192 setVariablesSuccess(variables, "testRequestId123");
194 String processId = invokeSubProcess(PROCNAME, variables);
196 waitForWorkflowToFinish(processEngine, processId);
198 assertTrue(isProcessEndedByProcessInstanceId(processId));
199 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX, processId);
200 assertNotNull(workflowException);
202 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName", processId));
207 public void testDoCreateAllottedResourceTXC_SubProcessError() throws Exception {
209 // TODO: use INST instead of DEC_INST
211 * should be INST instead of DEC_INST, but AAI utilities appear to have a bug in that they don't URL-encode the
212 * SI id before using it in the query
214 MockNodeQueryServiceInstanceById(wireMockServer, DEC_INST, "GenericFlows/getSIUrlById.xml");
215 MockNodeQueryServiceInstanceById(wireMockServer, DEC_PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
217 MockGetServiceInstance(wireMockServer, CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
218 MockGetServiceInstance(wireMockServer, CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
219 MockPutAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
220 MockPatchAllottedResource(wireMockServer, CUST, SVC, PARENT_INST, ARID);
221 mockSDNCAdapter(wireMockServer, 404);
222 mockUpdateRequestDB(wireMockServer, 200, "Database/DBUpdateResponse.xml");
224 Map<String, Object> variables = new HashMap<>();
225 setVariablesSuccess(variables, "testRequestId123");
227 String processId = invokeSubProcess(PROCNAME, variables);
229 waitForWorkflowToFinish(processEngine, processId);
231 assertTrue(isProcessEndedByProcessInstanceId(processId));
232 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX, processId);
233 assertNotNull(workflowException);
235 assertEquals(null, BPMNUtil.getVariable(processEngine, PROCNAME, "allotedResourceName", processId));
239 private void setVariablesSuccess(Map<String, Object> variables, String requestId) {
240 // TODO: need all of these?
241 variables.put("isDebugLogEnabled", "true");
242 variables.put("failExists", "true");
243 variables.put("disableRollback", "true");
244 variables.put("msoRequestId", requestId);
245 variables.put("mso-request-id", "requestId");
246 variables.put("sourceNetworkId", "snId");
247 variables.put("sourceNetworkRole", "snRole");
248 variables.put("allottedResourceRole", "brg");
249 variables.put("allottedResourceType", "TXC");
250 variables.put("allottedResourceId", ARID);
251 variables.put("brgWanMacAddress", "wanmac");
253 variables.put("serviceInstanceId", DEC_INST);
254 variables.put("parentServiceInstanceId", DEC_PARENT_INST);
256 variables.put("serviceChainServiceInstanceId", "scsiId");
258 String arModelInfo = "{ " + "\"modelType\": \"allotted-resource\","
259 + "\"modelInvariantUuid\": \"ff5256d2-5a33-55df-13ab-12abad84e7ff\","
260 + "\"modelUuid\": \"fe6478e5-ea33-3346-ac12-ab121484a3fe\"," + "\"modelName\": \"vSAMP12\","
261 + "\"modelVersion\": \"1.0\"," + "\"modelCustomizationUuid\": \"MODEL-ID-1234\"," + "}";
262 variables.put("allottedResourceModelInfo", arModelInfo);