Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / vcpe / DoDeleteAllottedResourceTXCTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.openecomp.mso.bpmn.vcpe;
21
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;
30
31 import java.io.IOException;
32 import java.util.HashMap;
33 import java.util.Map;
34 import java.util.UUID;
35
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;
42
43
44 public class DoDeleteAllottedResourceTXCTest extends AbstractTestBase {
45
46         private static final String PROCNAME = "DoDeleteAllottedResourceTXC";
47         private final CallbackSet callbacks = new CallbackSet();
48         
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"));
54         }
55         
56         @Test
57         @Deployment(resources = {
58                         "subprocess/SDNCAdapterV1.bpmn",
59                         "subprocess/FalloutHandler.bpmn",
60                         "subprocess/DoDeleteAllottedResourceTXC.bpmn"})
61         public void testDoDeleteAllottedResourceTXC_Success() throws Exception {
62                 
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);
67                 mockSDNCAdapter(200);
68                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
69                 
70                 String businessKey = UUID.randomUUID().toString();
71                 Map<String, Object> variables = new HashMap<>();
72                 setVariablesSuccess(variables, "testRequestId1");
73                 
74                 invokeSubProcess(PROCNAME, businessKey, variables);
75                 
76                 injectSDNCCallbacks(callbacks, "deactivate");
77                 injectSDNCCallbacks(callbacks, "delete");
78                 injectSDNCCallbacks(callbacks, "unassign");
79
80                 waitForProcessEnd(businessKey, 10000);
81                 
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);
86         }
87         
88         @Test
89         @Deployment(resources = {
90                         "subprocess/SDNCAdapterV1.bpmn",
91                         "subprocess/FalloutHandler.bpmn",
92                         "subprocess/DoDeleteAllottedResourceTXC.bpmn"})
93         public void testDoDeleteAllottedResourceTXC_ARNotInSDNC() throws Exception {
94                 
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);
99                 mockSDNCAdapter(200);
100                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
101                 
102                 String businessKey = UUID.randomUUID().toString();
103                 Map<String, Object> variables = new HashMap<>();
104                 setVariablesSuccess(variables, "testRequestId1");
105
106                 variables.put("failNotFound", "false");
107                 
108                 invokeSubProcess(PROCNAME, businessKey, variables);
109                 
110                 injectSDNCCallbacks(callbacks, "deactivateNF");
111
112                 waitForProcessEnd(businessKey, 10000);
113                 
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);
118         }
119         
120         // TODO - exception is not caught
121         @Test
122         @Ignore
123         @Deployment(resources = {
124                         "subprocess/SDNCAdapterV1.bpmn",
125                         "subprocess/FalloutHandler.bpmn",
126                         "subprocess/DoDeleteAllottedResourceTXC.bpmn"})
127         public void testDoDeleteAllottedResourceTXC_SubProcessError() throws Exception {
128                 
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");
134
135                 mockSDNCAdapter(500);
136                 
137                 String businessKey = UUID.randomUUID().toString();
138                 Map<String, Object> variables = new HashMap<>();
139                 setVariablesSuccess(variables, "testRequestId1");
140                 
141                 invokeSubProcess(PROCNAME, businessKey, variables);
142
143                 waitForProcessEnd(businessKey, 10000);
144                 
145                 Assert.assertTrue(isProcessEnded(businessKey));
146                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
147                 System.out.println("workflowException:\n" + workflowException);
148                 assertNotNull(workflowException);
149         }
150
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);
157                 
158                 variables.put("serviceInstanceId", DEC_INST);
159                 variables.put("parentServiceInstanceId", DEC_PARENT_INST);
160         }
161
162 }