2 * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
5 * ============LICENSE_START=======================================================
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.openecomp.mso.bpmn.common;
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;
36 import java.util.HashMap;
39 import org.camunda.bpm.engine.test.Deployment;
40 import org.junit.Test;
41 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
44 * Please describe the GenericDeleteVnfTest.java class
47 public class GenericDeleteVnfTest extends WorkflowTest {
50 @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
51 public void testGenericDeleteVnf_success_genericVnf() throws Exception{
52 MockDeleteGenericVnf("testVnfId123", "testReVer123");
54 Map<String, String> variables = new HashMap<String, String>();
55 setVariables(variables, "testVnfId123", "generic-vnf", "testReVer123");
57 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
58 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
60 assertVariables("true", "true", "true", null);
65 @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
66 public void testGenericDeleteVnf_success_vce() throws Exception{
67 MockDeleteVce("testVnfId123", "testReVer123", 204);
69 Map<String, String> variables = new HashMap<String, String>();
70 setVariables(variables, "testVnfId123", "vce", "testReVer123");
72 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
73 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
75 assertVariables("true", "true", "true", null);
80 @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
81 public void testGenericDeleteVnf_success_genericVnfNoResourceVersion() throws Exception{
83 MockGetGenericVnfById("/testVnfId123", "GenericFlows/getGenericVnfByNameResponse.xml", 200);
84 MockDeleteGenericVnf("testVnfId123", "testReVer123");
86 Map<String, String> variables = new HashMap<String, String>();
87 setVariables(variables, "testVnfId123", "generic-vnf", "");
89 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
90 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
92 assertVariables("true", "true", "false", null);
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");
102 Map<String, String> variables = new HashMap<String, String>();
103 setVariables(variables, "testVnfId123", "vce", null);
105 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
106 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
108 assertVariables("true", "true", "false", null);
113 @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
114 public void testGenericDeleteVnf_success_genericVnf404() throws Exception{
115 MockDeleteGenericVnf("testVnfId123", "testReVer123", 404);
117 Map<String, String> variables = new HashMap<String, String>();
118 setVariables(variables, "testVnfId123", "generic-vnf", "testReVer123");
120 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
121 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
123 assertVariables("true", "false", "true", null);
128 @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
129 public void testGenericDeleteVnf_success_vce404() throws Exception{
130 MockDeleteVce("testVnfId123", "testReVer123", 404);
132 Map<String, String> variables = new HashMap<String, String>();
133 setVariables(variables, "testVnfId123", "vce", "testReVer123");
135 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
136 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
138 assertVariables("true", "false", "true", null);
143 @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
144 public void testGenericDeleteVnf_success_genericVnfNoResourceVersion404() throws Exception{
145 MockGetGenericVnfById_404("testVnfId123");
147 Map<String, String> variables = new HashMap<String, String>();
148 setVariables(variables, "testVnfId123", "generic-vnf", "");
150 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
151 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
153 assertVariables("true", "false", "false", null);
158 @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
159 public void testGenericDeleteVnf_error_missingVariables() throws Exception{
161 Map<String, String> variables = new HashMap<String, String>();
162 setVariables(variables, "testVnfId123", "", "testReVer123");
164 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
165 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
167 assertVariables("false", "false", "true", "WorkflowException[processKey=GenericDeleteVnf,errorCode=500,errorMessage=Incoming Required Variable is Missing or Null!]");
172 @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
173 public void testGenericDeleteVnf_error_genericVnf500() throws Exception{
175 MockDeleteGenericVnf_500("testVnfId123", "testReVer123");
176 Map<String, String> variables = new HashMap<String, String>();
177 setVariables(variables, "testVnfId123", "generic-vnf", "testReVer123");
179 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
180 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
182 assertVariables("false", "false", "true", "WorkflowException[processKey=GenericDeleteVnf,errorCode=500,errorMessage=Received a bad response from AAI]");
187 @Deployment(resources = {"subprocess/GenericDeleteVnf.bpmn"})
188 public void testGenericDeleteVnf_error_genericVnf412() throws Exception{
189 MockDeleteGenericVnf("testVnfId123", "testReVer123", 412);
191 Map<String, String> variables = new HashMap<String, String>();
192 setVariables(variables, "testVnfId123", "generic-vnf", "testReVer123");
194 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericDeleteVnf", variables);
195 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
197 assertVariables("false", "false", "true", "WorkflowException[processKey=GenericDeleteVnf,errorCode=412,errorMessage=Delete Vnf Received a resource-version Mismatch Error Response from AAI]");
201 private void assertVariables(String exSuccessIndicator, String exFound, String exRVProvided, String exWorkflowException) {
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");
208 assertEquals(exSuccessIndicator, successIndicator);
209 assertEquals(exFound, found);
210 assertEquals(exRVProvided, rvProvided);
211 assertEquals(exWorkflowException, workflowException);
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);