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.MockPutGenericVnf;
30 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutVce;
32 import java.util.HashMap;
35 import org.camunda.bpm.engine.test.Deployment;
36 import org.junit.Test;
37 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
40 * Please describe the GenericPutVnf.java class
43 public class GenericPutVnfTest extends WorkflowTest {
45 private String genericVnfPayload = "<generic-vnf><vnf-id>testId</vnf-id></generic-vnf>";
46 private String vcePayload = "<vce><vnf-id>testId</vnf-id></vce>";
49 @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
50 public void testGenericPutVnf_success_genericVnf() throws Exception{
52 MockPutGenericVnf("testVnfId123");
54 Map<String, String> variables = new HashMap<String, String>();
55 setVariables(variables, "testVnfId123", genericVnfPayload, "generic-vnf");
57 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
58 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
60 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
61 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
63 assertEquals("true", successIndicator);
64 assertEquals(null, workflowException);
69 @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
70 public void testGenericPutVnf_success_vce() throws Exception{
72 MockPutVce("testVnfId123");
74 Map<String, String> variables = new HashMap<String, String>();
75 setVariables(variables, "testVnfId123", vcePayload, "vce");
77 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
78 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
80 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
81 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
83 assertEquals("true", successIndicator);
84 assertEquals(null, workflowException);
89 @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
90 public void testGenericPutVnf_error_missingType() throws Exception{
92 MockPutGenericVnf("testVnfId123");
94 Map<String, String> variables = new HashMap<String, String>();
95 setVariables(variables, "testVnfId123", genericVnfPayload, "");
97 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
98 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
100 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
101 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
103 String expectedWFEX = "WorkflowException[processKey=GenericPutVnf,errorCode=500,errorMessage=Incoming Vnf Payload and/or Type is null. These Variables are required!]";
105 assertEquals("false", successIndicator);
106 assertEquals(expectedWFEX, workflowException);
111 @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
112 public void testGenericPutVnf_error_missingPayload() throws Exception{
114 MockPutGenericVnf("testVnfId123");
116 Map<String, String> variables = new HashMap<String, String>();
117 setVariables(variables, "testVnfId123", genericVnfPayload, "");
119 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
120 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
122 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
123 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
125 String expectedWFEX = "WorkflowException[processKey=GenericPutVnf,errorCode=500,errorMessage=Incoming Vnf Payload and/or Type is null. These Variables are required!]";
127 assertEquals("false", successIndicator);
128 assertEquals(expectedWFEX, workflowException);
133 @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
134 public void testGenericPutVnf_error_404() throws Exception{
136 Map<String, String> variables = new HashMap<String, String>();
137 setVariables(variables, "testVnfId123", genericVnfPayload, "generic-vnf");
139 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
140 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
142 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
143 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
145 String expectedWFEX = "WorkflowException[processKey=GenericPutVnf,errorCode=404,errorMessage=Received a bad response from AAI]";
147 assertEquals("false", successIndicator);
148 assertEquals(expectedWFEX, workflowException);
152 @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
153 public void testGenericPutVnf_error_400() throws Exception{
155 MockPutGenericVnf("/testVnfId123", 400);
157 Map<String, String> variables = new HashMap<String, String>();
158 setVariables(variables, "testVnfId123", genericVnfPayload, "generic-vnf");
160 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
161 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
163 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
164 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
166 String expectedWFEX = "WorkflowException[processKey=GenericPutVnf,errorCode=400,errorMessage=Received a bad response from AAI]";
168 assertEquals("false", successIndicator);
169 assertEquals(expectedWFEX, workflowException);
174 private void setVariables(Map<String, String> variables, String vnfId, String payload, String type) {
175 variables.put("isDebugLogEnabled", "true");
176 variables.put("GENPV_vnfId", vnfId);
177 variables.put("GENPV_vnfPayload",payload);
178 variables.put("GENPV_type", type);