Change the header to SO
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / GenericDeleteVnfTest.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  * ONAP - SO 
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.MockDeleteGenericVnf;
30 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockDeleteGenericVnf_500;
31 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockDeleteVce;
32 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById;
33 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;
34 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetVceById;
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  * Please describe the GenericDeleteVnfTest.java class
45  *
46  */
47 public class GenericDeleteVnfTest extends WorkflowTest {
48
49         @Test
50         @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
51         public void testGenericDeleteVnf_success_genericVnf() throws Exception{
52                 MockDeleteGenericVnf("testVnfId123", "testReVer123");
53
54                 Map<String, String> variables = new HashMap<String, String>();
55                 setVariables(variables, "testVnfId123", "generic-vnf", "testReVer123");
56
57                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
58                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
59
60                 assertVariables("true", "true", "true", null);
61
62         }
63
64         @Test
65         @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
66         public void testGenericDeleteVnf_success_vce() throws Exception{
67                 MockDeleteVce("testVnfId123", "testReVer123", 204);
68
69                 Map<String, String> variables = new HashMap<String, String>();
70                 setVariables(variables, "testVnfId123", "vce", "testReVer123");
71
72                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
73                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
74
75                 assertVariables("true", "true", "true", null);
76
77         }
78
79         @Test
80         @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
81         public void testGenericDeleteVnf_success_genericVnfNoResourceVersion() throws Exception{
82
83                 MockGetGenericVnfById("/testVnfId123", "GenericFlows/getGenericVnfByNameResponse.xml", 200);
84                 MockDeleteGenericVnf("testVnfId123", "testReVer123");
85
86                 Map<String, String> variables = new HashMap<String, String>();
87                 setVariables(variables, "testVnfId123", "generic-vnf", "");
88
89                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
90                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
91
92                 assertVariables("true", "true", "false", null);
93
94         }
95
96         @Test
97         @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
98         public void testGenericDeleteVnf_success_vceNoResourceVersion() throws Exception{
99                 MockDeleteVce("testVnfId123", "testReVer123", 204);
100                 MockGetVceById("testVnfId123", "GenericFlows/getVceResponse.xml");
101
102                 Map<String, String> variables = new HashMap<String, String>();
103                 setVariables(variables, "testVnfId123", "vce", null);
104
105                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
106                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
107
108                 assertVariables("true", "true", "false", null);
109
110         }
111
112         @Test
113         @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
114         public void testGenericDeleteVnf_success_genericVnf404() throws Exception{
115                 MockDeleteGenericVnf("testVnfId123", "testReVer123", 404);
116
117                 Map<String, String> variables = new HashMap<String, String>();
118                 setVariables(variables, "testVnfId123", "generic-vnf", "testReVer123");
119
120                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
121                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
122
123                 assertVariables("true", "false", "true", null);
124
125         }
126
127         @Test
128         @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
129         public void testGenericDeleteVnf_success_vce404() throws Exception{
130                 MockDeleteVce("testVnfId123", "testReVer123", 404);
131
132                 Map<String, String> variables = new HashMap<String, String>();
133                 setVariables(variables, "testVnfId123", "vce", "testReVer123");
134
135                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
136                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
137
138                 assertVariables("true", "false", "true", null);
139
140         }
141
142         @Test
143         @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
144         public void testGenericDeleteVnf_success_genericVnfNoResourceVersion404() throws Exception{
145                 MockGetGenericVnfById_404("testVnfId123");
146
147                 Map<String, String> variables = new HashMap<String, String>();
148                 setVariables(variables, "testVnfId123", "generic-vnf", "");
149
150                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
151                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
152
153                 assertVariables("true", "false", "false", null);
154
155         }
156
157         @Test
158         @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
159         public void testGenericDeleteVnf_error_missingVariables() throws Exception{
160
161                 Map<String, String> variables = new HashMap<String, String>();
162                 setVariables(variables, "testVnfId123", "", "testReVer123");
163
164                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
165                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
166
167                 assertVariables("false", "false", "true", "WorkflowException[processKey=GenericDeleteVnf,errorCode=500,errorMessage=Incoming Required Variable is Missing or Null!]");
168
169         }
170
171         @Test
172         @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
173         public void testGenericDeleteVnf_error_genericVnf500() throws Exception{
174
175                 MockDeleteGenericVnf_500("testVnfId123", "testReVer123");
176                 Map<String, String> variables = new HashMap<String, String>();
177                 setVariables(variables, "testVnfId123", "generic-vnf", "testReVer123");
178
179                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
180                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
181
182                 assertVariables("false", "false", "true", "WorkflowException[processKey=GenericDeleteVnf,errorCode=500,errorMessage=Received a bad response from AAI]");
183
184         }
185
186         @Test
187         @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
188         public void testGenericDeleteVnf_error_genericVnf412() throws Exception{
189                 MockDeleteGenericVnf("testVnfId123", "testReVer123", 412);
190
191                 Map<String, String> variables = new HashMap<String, String>();
192                 setVariables(variables, "testVnfId123", "generic-vnf", "testReVer123");
193
194                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
195                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
196
197                 assertVariables("false", "false", "true", "WorkflowException[processKey=GenericDeleteVnf,errorCode=412,errorMessage=Delete Vnf Received a resource-version Mismatch Error Response from AAI]");
198
199         }
200
201         private void assertVariables(String exSuccessIndicator, String exFound, String exRVProvided, String exWorkflowException) {
202
203                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericDeleteVnf", "GENDV_SuccessIndicator");
204                 String found = BPMNUtil.getVariable(processEngineRule, "GenericDeleteVnf", "GENDV_FoundIndicator");
205                 String rvProvided = BPMNUtil.getVariable(processEngineRule, "GenericDeleteVnf", "GENDV_resourceVersionProvided");
206                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericDeleteVnf", "WorkflowException");
207
208                 assertEquals(exSuccessIndicator, successIndicator);
209                 assertEquals(exFound, found);
210                 assertEquals(exRVProvided, rvProvided);
211                 assertEquals(exWorkflowException, workflowException);
212         }
213
214         private void setVariables(Map<String, String> variables, String vnfId, String type, String resourceVer) {
215                 variables.put("isDebugLogEnabled", "true");
216                 variables.put("GENDV_vnfId", vnfId);
217                 variables.put("GENDV_type", type);
218                 variables.put("GENDV_resourceVersion", resourceVer);
219         }
220
221 }