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