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 org.junit.Assert;
24 import org.junit.Test;
25 import org.onap.so.bpmn.common.BPMNUtil;
26 import org.onap.so.bpmn.mock.FileUtil;
28 import java.util.HashMap;
30 import java.util.UUID;
32 import static org.junit.Assert.*;
33 import static org.onap.so.bpmn.mock.StubResponseAAI.*;
34 import static org.onap.so.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
35 import static org.onap.so.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
38 public class DoDeleteAllottedResourceBRGIT extends AbstractTestBase {
40 private static final String PROCNAME = "DoDeleteAllottedResourceBRG";
41 private final CallbackSet callbacks = new CallbackSet();
43 public DoDeleteAllottedResourceBRGIT() {
44 callbacks.put("deactivate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
45 callbacks.put("deactivateNF", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallbackNotFound.xml"));
46 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
47 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
51 public void testDoDeleteAllottedResourceBRG_Success() {
53 MockQueryAllottedResourceById(ARID, "GenericFlows/getARUrlById.xml");
54 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml");
55 MockPatchAllottedResource(CUST, SVC, INST, ARID);
56 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
58 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
60 String businessKey = UUID.randomUUID().toString();
61 Map<String, Object> variables = new HashMap<>();
62 setVariablesSuccess(variables);
64 invokeSubProcess(PROCNAME, businessKey, variables);
66 injectSDNCCallbacks(callbacks, "deactivate");
67 injectSDNCCallbacks(callbacks, "delete");
68 injectSDNCCallbacks(callbacks, "unassign");
70 waitForProcessEnd(businessKey, 10000);
72 Assert.assertTrue(isProcessEnded(businessKey));
73 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
74 System.out.println("workflowException:\n" + workflowException);
75 assertNull(workflowException);
80 public void testDoDeleteAllottedResourceBRG_ARNotInSDNC() {
82 MockQueryAllottedResourceById(ARID, "GenericFlows/getARUrlById.xml");
83 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml");
84 MockPatchAllottedResource(CUST, SVC, INST, ARID);
85 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
87 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
89 String businessKey = UUID.randomUUID().toString();
90 Map<String, Object> variables = new HashMap<>();
91 setVariablesSuccess(variables);
93 variables.put("failNotFound", "false");
95 invokeSubProcess(PROCNAME, businessKey, variables);
97 injectSDNCCallbacks(callbacks, "deactivateNF");
99 waitForProcessEnd(businessKey, 10000);
101 Assert.assertTrue(isProcessEnded(businessKey));
102 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
103 System.out.println("workflowException:\n" + workflowException);
104 assertNull(workflowException);
110 public void testDoDeleteAllottedResourceBRG_SubProcessError() throws Exception {
112 MockQueryAllottedResourceById(ARID, "GenericFlows/getARUrlById.xml");
113 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml");
114 MockPatchAllottedResource(CUST, SVC, INST, ARID);
115 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
116 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
118 mockSDNCAdapter(500);
120 Map<String, Object> variables = new HashMap<>();
121 setVariablesSuccess(variables);
123 String processId = invokeSubProcess(PROCNAME, variables);
126 BPMNUtil.waitForWorkflowToFinish(processEngine,processId);
128 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
129 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, "WorkflowException",processId);
130 System.out.println("workflowException:\n" + workflowException);
131 assertNotNull(workflowException);
135 private void setVariablesSuccess(Map<String, Object> variables) {
136 variables.put("isDebugLogEnabled", "true");
137 variables.put("failNotFound", "true");
138 variables.put("msoRequestId", "testRequestId1");
139 variables.put("mso-request-id", "requestId");
140 variables.put("allottedResourceId", ARID);
141 variables.put("serviceInstanceId", DEC_INST);
142 variables.put("parentServiceInstanceId", DEC_PARENT_INST);