248cb978dcd0c5390ba7d2eef3875663c8e88e41
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / GenericPutVnfTest.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.MockPutGenericVnf;
30 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutVce;
31
32 import java.util.HashMap;
33 import java.util.Map;
34
35 import org.camunda.bpm.engine.test.Deployment;
36 import org.junit.Test;
37 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
38
39 /**
40  * Please describe the GenericPutVnf.java class
41  *
42  */
43 public class GenericPutVnfTest extends WorkflowTest {
44
45         private String genericVnfPayload = "<generic-vnf><vnf-id>testId</vnf-id></generic-vnf>";
46         private String vcePayload = "<vce><vnf-id>testId</vnf-id></vce>";
47
48         @Test
49         @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
50         public void testGenericPutVnf_success_genericVnf() throws Exception{
51
52                 MockPutGenericVnf("testVnfId123");
53
54                 Map<String, String> variables = new HashMap<String, String>();
55                 setVariables(variables, "testVnfId123", genericVnfPayload, "generic-vnf");
56
57                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
58                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
59
60                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
61                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
62
63                 assertEquals("true", successIndicator);
64                 assertEquals(null, workflowException);
65
66         }
67
68         @Test
69         @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
70         public void testGenericPutVnf_success_vce() throws Exception{
71
72                 MockPutVce("testVnfId123");
73
74                 Map<String, String> variables = new HashMap<String, String>();
75                 setVariables(variables, "testVnfId123", vcePayload, "vce");
76
77                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
78                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
79
80                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
81                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
82
83                 assertEquals("true", successIndicator);
84                 assertEquals(null, workflowException);
85
86         }
87
88         @Test
89         @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
90         public void testGenericPutVnf_error_missingType() throws Exception{
91
92                 MockPutGenericVnf("testVnfId123");
93
94                 Map<String, String> variables = new HashMap<String, String>();
95                 setVariables(variables, "testVnfId123", genericVnfPayload, "");
96
97                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
98                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
99
100                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
101                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
102
103                 String expectedWFEX = "WorkflowException[processKey=GenericPutVnf,errorCode=500,errorMessage=Incoming Vnf Payload and/or Type is null. These Variables are required!]";
104
105                 assertEquals("false", successIndicator);
106                 assertEquals(expectedWFEX, workflowException);
107
108         }
109
110         @Test
111         @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
112         public void testGenericPutVnf_error_missingPayload() throws Exception{
113
114                 MockPutGenericVnf("testVnfId123");
115
116                 Map<String, String> variables = new HashMap<String, String>();
117                 setVariables(variables, "testVnfId123", genericVnfPayload, "");
118
119                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
120                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
121
122                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
123                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
124
125                 String expectedWFEX = "WorkflowException[processKey=GenericPutVnf,errorCode=500,errorMessage=Incoming Vnf Payload and/or Type is null. These Variables are required!]";
126
127                 assertEquals("false", successIndicator);
128                 assertEquals(expectedWFEX, workflowException);
129
130         }
131
132         @Test
133         @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
134         public void testGenericPutVnf_error_404() throws Exception{
135
136                 Map<String, String> variables = new HashMap<String, String>();
137                 setVariables(variables, "testVnfId123", genericVnfPayload, "generic-vnf");
138
139                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
140                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
141
142                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
143                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
144
145                 String expectedWFEX = "WorkflowException[processKey=GenericPutVnf,errorCode=404,errorMessage=Received a bad response from AAI]";
146
147                 assertEquals("false", successIndicator);
148                 assertEquals(expectedWFEX, workflowException);
149         }
150
151         @Test
152         @Deployment(resources = {"subprocess/GenericPutVnf.bpmn"})
153         public void testGenericPutVnf_error_400() throws Exception{
154
155                 MockPutGenericVnf("/testVnfId123", 400);
156
157                 Map<String, String> variables = new HashMap<String, String>();
158                 setVariables(variables, "testVnfId123", genericVnfPayload, "generic-vnf");
159
160                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericPutVnf", variables);
161                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
162
163                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "GENPV_SuccessIndicator");
164                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericPutVnf", "WorkflowException");
165
166                 String expectedWFEX = "WorkflowException[processKey=GenericPutVnf,errorCode=400,errorMessage=Received a bad response from AAI]";
167
168                 assertEquals("false", successIndicator);
169                 assertEquals(expectedWFEX, workflowException);
170
171
172         }
173
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);
179         }
180
181
182 }