e83a644914dbbf7dd070342adddd9a5c3f0fff9b
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / GenericDeleteServiceTest.java
1 /*
2  * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
3  */
4 /*- 
5  * ============LICENSE_START======================================================= 
6  * OPENECOMP - MSO 
7  * ================================================================================ 
8  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. 
9  * ================================================================================ 
10  * Licensed under the Apache License, Version 2.0 (the "License"); 
11  * you may not use this file except in compliance with the License. 
12  * You may obtain a copy of the License at 
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0 
15  * 
16  * Unless required by applicable law or agreed to in writing, software 
17  * distributed under the License is distributed on an "AS IS" BASIS, 
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
19  * See the License for the specific language governing permissions and 
20  * limitations under the License. 
21  * ============LICENSE_END========================================================= 
22  */ 
23
24 package org.openecomp.mso.bpmn.common;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow;
28 import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
29 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockDeleteServiceInstance;
30 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockDeleteServiceInstance_404;
31 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
32 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceInstance_404;
33 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceInstance_500;
34 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceSubscription;
35
36 import java.util.HashMap;
37 import java.util.Map;
38
39 import org.camunda.bpm.engine.test.Deployment;
40 import org.junit.Test;
41 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
42
43
44
45 /**
46  * Please describe the GenericDeleteServiceTest.java class
47  *
48  */
49 public class GenericDeleteServiceTest extends WorkflowTest {
50         @Test
51         @Deployment(resources = {"subprocess/GenericDeleteService.bpmn"})
52         public void testGenericDeleteService_success_serviceInstance() throws Exception{
53                 MockDeleteServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET", "1234");
54                 Map<String, String> variables = new HashMap<String, String>();
55                 setVariablesInstance(variables, "MIS%2F1604%2F0026%2FSW_INTERNET", "1604-MVM-26", "SDN-ETHERNET-INTERNET", "1234");
56                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteService", variables);
57                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
58                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_SuccessIndicator");
59                 String foundIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_FoundIndicator");
60                 String resourceVersionProvidedFlag = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_resourceVersionProvidedFlag");
61                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "WorkflowException");
62                 assertEquals("true", foundIndicator);
63                 assertEquals("true", successIndicator);
64                 assertEquals("true", resourceVersionProvidedFlag);
65                 assertEquals(null, workflowException);
66         }
67         @Test
68         @Deployment(resources = {"subprocess/GenericDeleteService.bpmn"})
69         public void testGenericDeleteService_success_serviceSubscription() throws Exception{
70
71                 MockDeleteServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "1234", 204);
72
73                 Map<String, String> variables = new HashMap<String, String>();
74                 setVariablesSubscription(variables, "", "1604-MVM-26", "SDN-ETHERNET-INTERNET", "1234");
75
76                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteService", variables);
77                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
78
79                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_SuccessIndicator");
80                 String foundIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_FoundIndicator");
81                 String resourceVersionProvidedFlag = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_resourceVersionProvidedFlag");
82                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "WorkflowException");
83
84                 assertEquals("true", foundIndicator);
85                 assertEquals("true", successIndicator);
86                 assertEquals("true", resourceVersionProvidedFlag);
87                 assertEquals(null, workflowException);
88
89         }
90
91         @Test
92         @Deployment(resources = {"subprocess/GenericDeleteService.bpmn"})
93         public void testGenericDeleteService_success_instanceNoResourceVersion() throws Exception {
94                 MockGetServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceSubscription.xml");
95                 MockDeleteServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET", "1234");
96
97                 Map<String, String> variables = new HashMap<String, String>();
98                 setVariablesInstance(variables, "MIS%2F1604%2F0026%2FSW_INTERNET", "1604-MVM-26", "SDN-ETHERNET-INTERNET", null);
99
100                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteService", variables);
101                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
102
103                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_SuccessIndicator");
104                 String foundIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_FoundIndicator");
105                 String resourceVersionProvidedFlag = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_resourceVersionProvidedFlag");
106                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "WorkflowException");
107
108                 assertEquals("true", foundIndicator);
109                 assertEquals("true", successIndicator);
110                 assertEquals("false", resourceVersionProvidedFlag);
111                 assertEquals(null, workflowException);
112
113         }
114
115         @Test
116         @Deployment(resources = {"subprocess/GenericDeleteService.bpmn"})
117         public void testGenericDeleteService_success_subscriptionNoResourceVersion() throws Exception{
118                 MockGetServiceSubscription("1604-MVM-26", "SDN-ETHERNET-INTERNET", "GenericFlows/getServiceSubscription.xml");
119                 MockDeleteServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "1234", 204);
120
121                 Map<String, String> variables = new HashMap<String, String>();
122                 setVariablesSubscription(variables, null, "1604-MVM-26", "SDN-ETHERNET-INTERNET", null);
123
124                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteService", variables);
125                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
126
127                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_SuccessIndicator");
128                 String foundIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_FoundIndicator");
129                 String resourceVersionProvidedFlag = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_resourceVersionProvidedFlag");
130                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "WorkflowException");
131
132                 assertEquals("true", foundIndicator);
133                 assertEquals("true", successIndicator);
134                 assertEquals("false", resourceVersionProvidedFlag);
135                 assertEquals(null, workflowException);
136
137         }
138
139         @Test
140         @Deployment(resources = {"subprocess/GenericDeleteService.bpmn"})
141         public void testGenericDeleteService_success_get404Response() throws Exception{
142
143                 MockGetServiceInstance_404("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET");
144
145                 Map<String, String> variables = new HashMap<String, String>();
146                 setVariablesInstance(variables, "MIS%2F1604%2F0026%2FSW_INTERNET", "1604-MVM-26", "SDN-ETHERNET-INTERNET", null);
147
148                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteService", variables);
149                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
150
151                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_SuccessIndicator");
152                 String foundIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_FoundIndicator");
153                 String resourceVersionProvidedFlag = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_resourceVersionProvidedFlag");
154                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "WorkflowException");
155
156                 assertEquals("false", foundIndicator);
157                 assertEquals("true", successIndicator);
158                 assertEquals("false", resourceVersionProvidedFlag);
159                 assertEquals(null, workflowException);
160         }
161
162         @Test
163         @Deployment(resources = {"subprocess/GenericDeleteService.bpmn"})
164         public void testGenericDeleteService_success_subscriptionGetEmpty200() throws Exception{
165                 MockGetServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "1234", 200);
166
167                 Map<String, String> variables = new HashMap<String, String>();
168                 setVariablesSubscription(variables, "", "1604-MVM-26", "SDN-ETHERNET-INTERNET", "");
169
170                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteService", variables);
171                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
172
173                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_SuccessIndicator");
174                 String foundIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_FoundIndicator");
175                 String resourceVersionProvidedFlag = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_resourceVersionProvidedFlag");
176                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "WorkflowException");
177
178                 assertEquals("false", foundIndicator);
179                 assertEquals("true", successIndicator);
180                 assertEquals("false", resourceVersionProvidedFlag);
181                 assertEquals(null, workflowException);
182
183         }
184
185         @Test
186         @Deployment(resources = {"subprocess/GenericDeleteService.bpmn"})
187         public void testGenericDeleteService_success_delete404Response() throws Exception{
188
189                 MockGetServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET", "GENDSI_getServiceInstanceResponse.xml");
190                 MockDeleteServiceInstance_404("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET", "1234");
191
192                 Map<String, String> variables = new HashMap<String, String>();
193                 setVariablesInstance(variables, "MIS%2F1604%2F0026%2FSW_INTERNET", "1604-MVM-26", "SDN-ETHERNET-INTERNET", "1234");
194
195                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteService", variables);
196                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
197
198                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_SuccessIndicator");
199                 String foundIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_FoundIndicator");
200                 String resourceVersionProvidedFlag = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_resourceVersionProvidedFlag");
201                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "WorkflowException");
202
203                 assertEquals("false", foundIndicator);
204                 assertEquals("true", successIndicator);
205                 assertEquals("true", resourceVersionProvidedFlag);
206                 assertEquals(null, workflowException);
207         }
208
209         @Test
210         @Deployment(resources = {"subprocess/GenericDeleteService.bpmn"})
211         public void testGenericDeleteService_error_invalidVariables() throws Exception{
212
213                 Map<String, String> variables = new HashMap<String, String>();
214                 setVariablesInstance(variables, "MIS%2F1604%2F0026%2FSW_INTERNET", null, "SDN-ETHERNET-INTERNET", "1234");
215
216                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteService", variables);
217                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
218
219                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_SuccessIndicator");
220                 String foundIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_FoundIndicator");
221                 String resourceVersionProvidedFlag = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_resourceVersionProvidedFlag");
222                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "WorkflowException");
223
224                 String expectedResponse = "WorkflowException[processKey=GenericDeleteService,errorCode=500,errorMessage=Incoming Required Variable is Missing or Null!]";
225
226                 assertEquals("false", foundIndicator);
227                 assertEquals("false", successIndicator);
228                 assertEquals("true", resourceVersionProvidedFlag);
229                 assertEquals(expectedResponse, workflowException);
230
231         }
232
233         @Test
234         @Deployment(resources = {"subprocess/GenericDeleteService.bpmn"})
235         public void testGenericDeleteService_error_getBadAAIResponse() throws Exception{
236
237                 MockGetServiceInstance_500("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET", "aaiFault.xml");
238
239                 Map<String, String> variables = new HashMap<String, String>();
240                 setVariablesInstance(variables, "MIS%2F1604%2F0026%2FSW_INTERNET", "1604-MVM-26", "SDN-ETHERNET-INTERNET", null);
241
242                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteService", variables);
243                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
244
245                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_SuccessIndicator");
246                 String foundIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_FoundIndicator");
247                 String resourceVersionProvidedFlag = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "GENDS_resourceVersionProvidedFlag");
248                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericDeleteService", "WorkflowException");
249
250                 String expectedResponse = "WorkflowException[processKey=GenericDeleteService,errorCode=500,errorMessage=<requestError><serviceException><messageId>SVC3002</messageId><text>Error writing output performing %1 on %2 (msg=%3) (ec=%4)</text><variables><variable>PUTcustomer</variable><variable>SubName01</variable><variable>Unexpected error reading/updating database:Adding this property for key [service-instance-id] and value [USSTU2CFCNC0101UJZZ01] violates a uniqueness constraint [service-instance-id]</variable><variable>ERR.5.4.5105</variable></variables></serviceException></requestError>" + "\n" +
251                 "]";
252
253                 assertEquals("false", foundIndicator);
254                 assertEquals("false", successIndicator);
255                 assertEquals("false", resourceVersionProvidedFlag);
256                 assertEquals(expectedResponse, workflowException);
257         }
258
259
260         private void setVariablesInstance(Map<String, String> variables, String siId, String globalCustId, String serviceType, String reVersion) {
261                 variables.put("isDebugLogEnabled", "true");
262                 variables.put("GENDS_serviceInstanceId", siId);
263                 variables.put("GENDS_globalCustomerId",globalCustId);
264                 variables.put("GENDS_serviceType", serviceType);
265                 variables.put("GENDS_resourceVersion", reVersion);
266                 variables.put("GENDS_type", "service-instance");
267         }
268
269         private void setVariablesSubscription(Map<String, String> variables, String siId, String globalCustId, String serviceType, String reVersion) {
270                 variables.put("isDebugLogEnabled", "true");
271                 variables.put("GENDS_serviceInstanceId", siId);
272                 variables.put("GENDS_globalCustomerId",globalCustId);
273                 variables.put("GENDS_serviceType", serviceType);
274                 variables.put("GENDS_resourceVersion", reVersion);
275                 variables.put("GENDS_type", "service-subscription");
276         }
277
278
279 }