80105bbb99538b17b2178f2c21f5a9e3e9dc8890
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / GenericGetVnfTest.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.junit.Assert.assertNotNull;
28 import static org.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow;
29 import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
30 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;
31 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_500;
32 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByNameWithDepth;
33 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVceByNameWithDepth;
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.Ignore;
41 import org.junit.Test;
42 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
43
44 /**
45  * Please describe the GenericGetVnfTest.java class
46  *
47  */
48 public class GenericGetVnfTest extends WorkflowTest {
49
50         @Test
51         @Deployment(resources = {"subprocess/GenericGetVnf.bpmn"})
52         public void testGenericGetVnf_success_genericVnf() throws Exception{
53                 MockGetGenericVnfByIdWithDepth("testVnfId123", 1, "GenericFlows/getGenericVnfByNameResponse.xml");
54
55                 Map<String, String> variables = new HashMap<String, String>();
56                 setVariables(variables, "testVnfId123", "testVnfName123", "generic-vnf");
57
58                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericGetVnf", variables);
59                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
60
61                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_SuccessIndicator");
62                 String found = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_FoundIndicator");
63                 String vnf = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_vnf");
64                 String byName = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_getVnfByName");
65                 String response = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "WorkflowResponse");
66                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "WorkflowException");
67
68                 assertEquals("true", successIndicator);
69                 assertEquals("true", found);
70                 assertEquals("false", byName);
71                 assertNotNull(response);
72                 assertNotNull(vnf);
73                 assertEquals(null, workflowException);
74
75         }
76
77         @Test
78         @Deployment(resources = {"subprocess/GenericGetVnf.bpmn"})
79         public void testGenericGetVnf_success_vce() throws Exception{
80                 MockGetVceById("testVnfId123[?]depth=1", "GenericFlows/getVceResponse.xml");
81
82                 Map<String, String> variables = new HashMap<String, String>();
83                 setVariables(variables, "testVnfId123", "testVnfName123", "vce");
84
85                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericGetVnf", variables);
86                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
87
88                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_SuccessIndicator");
89                 String found = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_FoundIndicator");
90                 String vnf = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_vnf");
91                 String byName = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_getVnfByName");
92                 String response = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "WorkflowResponse");
93                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "WorkflowException");
94
95                 assertEquals("true", successIndicator);
96                 assertEquals("true", found);
97                 assertEquals("false", byName);
98                 assertNotNull(response);
99                 assertNotNull(vnf);
100                 assertEquals(null, workflowException);
101
102         }
103
104         @Test
105         @Deployment(resources = {"subprocess/GenericGetVnf.bpmn"})
106         public void testGenericGetVnf_success_genericVnfByName() throws Exception{
107                 MockGetGenericVnfByNameWithDepth("testVnfName123", 1, "GenericFlows/getGenericVnfResponse.xml");
108
109                 Map<String, String> variables = new HashMap<String, String>();
110                 setVariables(variables, "", "testVnfName123", "generic-vnf");
111
112                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericGetVnf", variables);
113                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
114
115                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_SuccessIndicator");
116                 String found = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_FoundIndicator");
117                 String vnf = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_vnf");
118                 String byName = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_getVnfByName");
119                 String response = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "WorkflowResponse");
120                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "WorkflowException");
121
122                 assertEquals("true", successIndicator);
123                 assertEquals("true", found);
124                 assertEquals("true", byName);
125                 assertNotNull(response);
126                 assertNotNull(vnf);
127                 assertEquals(null, workflowException);
128
129         }
130
131         @Test
132         @Deployment(resources = {"subprocess/GenericGetVnf.bpmn"})
133         public void testGenericGetVnf_success_vceByName() throws Exception{
134                 MockGetGenericVceByNameWithDepth("testVnfName123", 1, "GenericFlows/getVceByNameResponse.xml");
135
136                 Map<String, String> variables = new HashMap<String, String>();
137                 setVariables(variables, null, "testVnfName123", "vce");
138
139                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericGetVnf", variables);
140                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
141
142                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_SuccessIndicator");
143                 String found = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_FoundIndicator");
144                 String vnf = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_vnf");
145                 String byName = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_getVnfByName");
146                 String response = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "WorkflowResponse");
147                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "WorkflowException");
148
149                 assertEquals("true", successIndicator);
150                 assertEquals("true", found);
151                 assertEquals("true", byName);
152                 assertNotNull(response);
153                 assertNotNull(vnf);
154                 assertEquals(null, workflowException);
155
156         }
157
158         @Test
159         @Ignore // BROKEN TEST (previously ignored)
160         @Deployment(resources = {"subprocess/GenericGetVnf.bpmn"})
161         public void testGenericGetVnf_error_genericVnf500() throws Exception{
162
163                 MockGetGenericVnfById_500("testVnfId123");
164
165                 Map<String, String> variables = new HashMap<String, String>();
166                 setVariables(variables, "testVnfId123", "testVnfName123", "generic-vnf");
167
168                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericGetVnf", variables);
169                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
170
171                 String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_SuccessIndicator");
172                 String found = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_FoundIndicator");
173                 String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "WorkflowException");
174                 String byName = BPMNUtil.getVariable(processEngineRule, "GenericGetVnf", "GENGV_getVnfByName");
175
176                 String expectedWorkflowException = "WorkflowException[processKey=GenericGetVnf,errorCode=500,errorMessage=Incoming VnfId and VnfName are null. VnfId or VnfName is required!]";
177
178                 assertEquals("false", successIndicator);
179                 assertEquals("false", found);
180                 assertEquals("false", byName);
181
182                 assertEquals(expectedWorkflowException, workflowException);
183         }
184
185         private void setVariables(Map<String, String> variables, String vnfId, String vnfName, String type) {
186                 variables.put("isDebugLogEnabled", "true");
187                 variables.put("GENGV_vnfId", vnfId);
188                 variables.put("GENGV_vnfName",vnfName);
189                 variables.put("GENGV_type", type);
190         }
191 }