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