e2babb7919ac6b0ac6d4f754518987835a2494b3
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / PrepareUpdateAAIVfModuleTest.java
1 /*- \r
2  * ============LICENSE_START======================================================= \r
3  * OPENECOMP - MSO \r
4  * ================================================================================ \r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. \r
6  * ================================================================================ \r
7  * Licensed under the Apache License, Version 2.0 (the "License"); \r
8  * you may not use this file except in compliance with the License. \r
9  * You may obtain a copy of the License at \r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0 \r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software \r
14  * distributed under the License is distributed on an "AS IS" BASIS, \r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \r
16  * See the License for the specific language governing permissions and \r
17  * limitations under the License. \r
18  * ============LICENSE_END========================================================= \r
19  */ \r
20 \r
21 package org.openecomp.mso.bpmn.common;\r
22 \r
23 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockAAIVfModuleBadPatch;\r
24 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;\r
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;\r
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchVfModuleId;\r
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf;\r
28 \r
29 import java.io.IOException;\r
30 import java.util.HashMap;\r
31 import java.util.Map;\r
32 import java.util.UUID;\r
33 \r
34 import org.camunda.bpm.engine.test.Deployment;\r
35 import org.junit.Assert;\r
36 import org.junit.Test;\r
37 import org.openecomp.mso.bpmn.core.WorkflowException;\r
38 import org.openecomp.mso.bpmn.mock.FileUtil;\r
39 \r
40 /**\r
41  * Unit tests for PrepareUpdateAAIVfModule.bpmn.\r
42  */\r
43 public class PrepareUpdateAAIVfModuleTest extends WorkflowTest {\r
44         \r
45         /**\r
46          * Test the happy path through the flow.\r
47          */\r
48         @Test   \r
49         @Deployment(resources = {\r
50                         "subprocess/PrepareUpdateAAIVfModule.bpmn"\r
51                 })\r
52         public void happyPath() throws IOException {\r
53                 \r
54                 logStart();\r
55                 \r
56                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml"); \r
57                 \r
58                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");\r
59                 MockPutGenericVnf("/skask/vf-modules/vf-module/supercool", "PCRF", 200);\r
60                 MockPatchVfModuleId("skask", "supercool");\r
61                 \r
62                 String businessKey = UUID.randomUUID().toString();\r
63                 Map<String, Object> variables = new HashMap<String, Object>();\r
64                 variables.put("mso-request-id", "999-99-9999");\r
65                 variables.put("isDebugLogEnabled","true");\r
66                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);\r
67                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);\r
68                 \r
69                 Assert.assertTrue(isProcessEnded(businessKey));\r
70                 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponse");\r
71                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponseCode");\r
72                 System.out.println("Subflow response code: " + responseCode);\r
73                 System.out.println("Subflow response: " + response);\r
74                 Assert.assertEquals(200, responseCode.intValue());\r
75                 String heatStackId = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_heatStackId");\r
76                 System.out.println("Ouput heat-stack-id:" + heatStackId);\r
77                 Assert.assertEquals("slowburn", heatStackId);\r
78                 \r
79                 logEnd();\r
80         }\r
81         \r
82         /**\r
83          * Test the case where the GET to AAI returns a 404.\r
84          */\r
85         @Test   \r
86         @Deployment(resources = {\r
87                         "subprocess/PrepareUpdateAAIVfModule.bpmn"\r
88                 })\r
89         public void badGet() throws IOException {\r
90                 \r
91                 logStart();\r
92                 \r
93                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml"); \r
94                 MockGetGenericVnfById_404("skask[?]depth=1");\r
95                 \r
96                 String businessKey = UUID.randomUUID().toString();\r
97                 Map<String, Object> variables = new HashMap<String, Object>();          \r
98                 variables.put("mso-request-id", "999-99-9999");\r
99                 variables.put("isDebugLogEnabled","true");\r
100                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);\r
101                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);\r
102                 \r
103                 Assert.assertTrue(isProcessEnded(businessKey));\r
104                 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_getVnfResponse");\r
105                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_getVnfResponseCode");\r
106                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");\r
107                 System.out.println("Subflow response code: " + responseCode);\r
108                 System.out.println("Subflow response: " + response);\r
109                 Assert.assertEquals(404, responseCode.intValue());\r
110                 Assert.assertNotNull(workflowException);\r
111                 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());\r
112                 \r
113                 logEnd();\r
114         }\r
115         \r
116         /**\r
117          * Test the case where the validation of the VF Module fails.\r
118          */\r
119         @Test   \r
120         @Deployment(resources = {\r
121                         "subprocess/PrepareUpdateAAIVfModule.bpmn"\r
122                 })\r
123         public void failValidation1() throws IOException {\r
124                 \r
125                 logStart();\r
126                 \r
127                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "lukewarm");\r
128                 \r
129                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");\r
130                 \r
131                 String businessKey = UUID.randomUUID().toString();\r
132                 Map<String, Object> variables = new HashMap<String, Object>();          \r
133                 variables.put("mso-request-id", "999-99-9999");\r
134                 variables.put("isDebugLogEnabled","true");\r
135                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);\r
136                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);\r
137                 \r
138                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");\r
139                 Assert.assertNotNull(workflowException);\r
140                 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());\r
141                 Assert.assertTrue(workflowException.getErrorMessage().startsWith("VF Module validation error: Orchestration"));\r
142                 \r
143                 logEnd();\r
144         }\r
145         \r
146         /**\r
147          * Test the case where the validation of the VF Module fails.\r
148          */\r
149         @Test   \r
150         @Deployment(resources = {\r
151                         "subprocess/PrepareUpdateAAIVfModule.bpmn"\r
152                 })\r
153         public void failValidation2() throws IOException {\r
154                 \r
155                 logStart();\r
156                 \r
157                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "notsocool");\r
158                 \r
159                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");              \r
160                 \r
161                 String businessKey = UUID.randomUUID().toString();\r
162                 Map<String, Object> variables = new HashMap<String, Object>();          \r
163                 variables.put("mso-request-id", "999-99-9999");\r
164                 variables.put("isDebugLogEnabled","true");\r
165                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);\r
166                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);\r
167                         \r
168                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");\r
169                 Assert.assertNotNull(workflowException);\r
170                 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());\r
171                 Assert.assertTrue(workflowException.getErrorMessage().startsWith("VF Module validation error: VF Module"));\r
172                 \r
173                 logEnd();\r
174         }\r
175 \r
176         /**\r
177          * Test the case where the GET to AAI is successful, but the subsequent PUT returns 404.\r
178          */\r
179         @Test   \r
180         @Deployment(resources = {\r
181                         "subprocess/PrepareUpdateAAIVfModule.bpmn"\r
182                 })\r
183         public void badPatch() throws IOException {\r
184                 \r
185                 logStart();\r
186                 \r
187                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml"); \r
188                 \r
189                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");\r
190                 MockAAIVfModuleBadPatch("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/skask/vf-modules/vf-module/supercool", 404);\r
191                 \r
192                 String businessKey = UUID.randomUUID().toString();\r
193                 Map<String, Object> variables = new HashMap<String, Object>();          \r
194                 variables.put("mso-request-id", "999-99-9999");\r
195                 variables.put("isDebugLogEnabled","true");\r
196                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);\r
197                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);\r
198                 \r
199                 Assert.assertTrue(isProcessEnded(businessKey));\r
200                 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponse");\r
201                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponseCode");\r
202                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");\r
203                 System.out.println("Subflow response code: " + responseCode);\r
204                 System.out.println("Subflow response: " + response);\r
205                 Assert.assertEquals(404, responseCode.intValue());\r
206                 Assert.assertNotNull(workflowException);\r
207                 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());\r
208                 \r
209                 logEnd();\r
210         }\r
211 }\r
212 \r