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.MockDeleteAllottedResource;
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource;
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchAllottedResource;
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockQueryAllottedResourceById;
28 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
29 import static org.openecomp.mso.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
31 import java.io.IOException;
32 import java.util.HashMap;
34 import java.util.UUID;
36 import org.camunda.bpm.engine.test.Deployment;
37 import org.junit.Assert;
38 import org.junit.Ignore;
39 import org.junit.Test;
40 import org.openecomp.mso.bpmn.common.BPMNUtil;
41 import org.openecomp.mso.bpmn.mock.FileUtil;
44 public class DoDeleteAllottedResourceTXCTest extends AbstractTestBase {
46 private static final String PROCNAME = "DoDeleteAllottedResourceTXC";
47 private final CallbackSet callbacks = new CallbackSet();
49 public DoDeleteAllottedResourceTXCTest() throws IOException {
50 callbacks.put("deactivate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
51 callbacks.put("deactivateNF", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallbackNotFound.xml"));
52 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
53 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
57 @Deployment(resources = {
58 "subprocess/SDNCAdapterV1.bpmn",
59 "subprocess/FalloutHandler.bpmn",
60 "subprocess/DoDeleteAllottedResourceTXC.bpmn"})
61 public void testDoDeleteAllottedResourceTXC_Success() throws Exception {
63 MockQueryAllottedResourceById(ARID, "GenericFlows/getARUrlById.xml");
64 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml");
65 MockPatchAllottedResource(CUST, SVC, INST, ARID);
66 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
68 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
70 String businessKey = UUID.randomUUID().toString();
71 Map<String, Object> variables = new HashMap<>();
72 setVariablesSuccess(variables, "testRequestId1");
74 invokeSubProcess(PROCNAME, businessKey, variables);
76 injectSDNCCallbacks(callbacks, "deactivate");
77 injectSDNCCallbacks(callbacks, "delete");
78 injectSDNCCallbacks(callbacks, "unassign");
80 waitForProcessEnd(businessKey, 10000);
82 Assert.assertTrue(isProcessEnded(businessKey));
83 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
84 System.out.println("workflowException:\n" + workflowException);
85 assertEquals(null, workflowException);
89 @Deployment(resources = {
90 "subprocess/SDNCAdapterV1.bpmn",
91 "subprocess/FalloutHandler.bpmn",
92 "subprocess/DoDeleteAllottedResourceTXC.bpmn"})
93 public void testDoDeleteAllottedResourceTXC_ARNotInSDNC() throws Exception {
95 MockQueryAllottedResourceById(ARID, "GenericFlows/getARUrlById.xml");
96 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml");
97 MockPatchAllottedResource(CUST, SVC, INST, ARID);
98 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
100 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
102 String businessKey = UUID.randomUUID().toString();
103 Map<String, Object> variables = new HashMap<>();
104 setVariablesSuccess(variables, "testRequestId1");
106 variables.put("failNotFound", "false");
108 invokeSubProcess(PROCNAME, businessKey, variables);
110 injectSDNCCallbacks(callbacks, "deactivateNF");
112 waitForProcessEnd(businessKey, 10000);
114 Assert.assertTrue(isProcessEnded(businessKey));
115 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
116 System.out.println("workflowException:\n" + workflowException);
117 assertEquals(null, workflowException);
120 // TODO - exception is not caught
123 @Deployment(resources = {
124 "subprocess/SDNCAdapterV1.bpmn",
125 "subprocess/FalloutHandler.bpmn",
126 "subprocess/DoDeleteAllottedResourceTXC.bpmn"})
127 public void testDoDeleteAllottedResourceTXC_SubProcessError() throws Exception {
129 MockQueryAllottedResourceById(ARID, "GenericFlows/getARUrlById.xml");
130 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml");
131 MockPatchAllottedResource(CUST, SVC, INST, ARID);
132 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
133 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
135 mockSDNCAdapter(500);
137 String businessKey = UUID.randomUUID().toString();
138 Map<String, Object> variables = new HashMap<>();
139 setVariablesSuccess(variables, "testRequestId1");
141 invokeSubProcess(PROCNAME, businessKey, variables);
143 waitForProcessEnd(businessKey, 10000);
145 Assert.assertTrue(isProcessEnded(businessKey));
146 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
147 System.out.println("workflowException:\n" + workflowException);
148 assertNotNull(workflowException);
151 private void setVariablesSuccess(Map<String, Object> variables, String requestId) {
152 variables.put("isDebugLogEnabled", "true");
153 variables.put("failNotFound", "true");
154 variables.put("msoRequestId", requestId);
155 variables.put("mso-request-id", "requestId");
156 variables.put("allottedResourceId", ARID);
158 variables.put("serviceInstanceId", DEC_INST);
159 variables.put("parentServiceInstanceId", DEC_PARENT_INST);