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