replace all fixed wiremock ports
[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
31 import java.io.IOException;
32 import java.util.HashMap;
33 import java.util.Map;
34 import java.util.UUID;
35
36 import org.camunda.bpm.engine.test.Deployment;
37 import org.junit.Assert;
38 import org.junit.Test;
39 import org.onap.so.BaseIntegrationTest;
40 import org.onap.so.bpmn.core.WorkflowException;
41 import org.onap.so.bpmn.mock.FileUtil;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 /**
46  * Unit tests for PrepareUpdateAAIVfModule.bpmn.
47  */
48
49 public class PrepareUpdateAAIVfModuleIT extends BaseIntegrationTest {
50         
51         Logger logger = LoggerFactory.getLogger(PrepareUpdateAAIVfModuleIT.class);
52         
53         /**
54          * Test the happy path through the flow.
55          */
56         @Test   
57         
58         public void happyPath() throws IOException {
59                 
60                 logStart();
61                 
62                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml"); 
63                 
64                 MockGetGenericVnfByIdWithDepth(wireMockServer, "skask", 1, "VfModularity/GenericVnf.xml");
65                 MockPutGenericVnf(wireMockServer, "/skask/vf-modules/vf-module/supercool", "PCRF", 200);
66                 MockPatchVfModuleId(wireMockServer, "skask", "supercool");
67                 
68                 String businessKey = UUID.randomUUID().toString();
69                 Map<String, Object> variables = new HashMap<>();
70         variables.put("mso-request-id", UUID.randomUUID().toString());
71                 variables.put("isDebugLogEnabled","true");
72                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
73                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
74                 
75                 Assert.assertTrue(isProcessEnded(businessKey));
76                 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponse");
77                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponseCode");
78                 logger.debug("Subflow response code: {}", responseCode);
79                 logger.debug("Subflow response: {}", response);
80                 Assert.assertEquals(200, responseCode.intValue());
81                 String heatStackId = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_heatStackId");
82                 logger.debug("Ouput heat-stack-id:{}", heatStackId);
83                 Assert.assertEquals("slowburn", heatStackId);
84                 
85                 logEnd();
86         }
87         
88         /**
89          * Test the case where the GET to AAI returns a 404.
90          */
91         @Test   
92         
93         public void badGet() throws IOException {
94                 
95                 logStart();
96                 
97                 String prepareUpdateAAIVfModuleRequest = 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 = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
111                 logger.debug("Subflow response code: {}", responseCode);
112                 logger.debug("Subflow response: {}", response);
113                 Assert.assertEquals(404, responseCode.intValue());
114                 Assert.assertNotNull(workflowException);
115                 logger.debug("Subflow WorkflowException error message: {}", workflowException.getErrorMessage());
116                 
117                 logEnd();
118         }
119         
120         /**
121          * Test the case where the validation of the VF Module fails.
122          */
123         @Test   
124         
125         public void failValidation1() throws IOException {
126                 
127                 logStart();
128                 
129                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "lukewarm");
130                 
131                 MockGetGenericVnfByIdWithDepth(wireMockServer, "skask", 1, "VfModularity/GenericVnf.xml");
132                 
133                 String businessKey = UUID.randomUUID().toString();
134                 Map<String, Object> variables = new HashMap<>();
135         variables.put("mso-request-id", UUID.randomUUID().toString());
136                 variables.put("isDebugLogEnabled","true");
137                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
138                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
139                 
140                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
141                 Assert.assertNotNull(workflowException);
142                 logger.debug("Subflow WorkflowException error message: {}", workflowException.getErrorMessage());
143                 Assert.assertTrue(workflowException.getErrorMessage().startsWith("VF Module validation error: Orchestration"));
144                 
145                 logEnd();
146         }
147         
148         /**
149          * Test the case where the validation of the VF Module fails.
150          */
151         @Test   
152         
153         public void failValidation2() throws IOException {
154                 
155                 logStart();
156                 
157                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "notsocool");
158                 
159                 MockGetGenericVnfByIdWithDepth(wireMockServer, "skask", 1, "VfModularity/GenericVnf.xml");              
160                 
161                 String businessKey = UUID.randomUUID().toString();
162                 Map<String, Object> variables = new HashMap<>();
163         variables.put("mso-request-id", UUID.randomUUID().toString());
164                 variables.put("isDebugLogEnabled","true");
165                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
166                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
167                         
168                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
169                 Assert.assertNotNull(workflowException);
170                 logger.debug("Subflow WorkflowException error message: {}", workflowException.getErrorMessage());
171                 Assert.assertTrue(workflowException.getErrorMessage().startsWith("VF Module validation error: VF Module"));
172                 
173                 logEnd();
174         }
175
176         /**
177          * Test the case where the GET to AAI is successful, but the subsequent PUT returns 404.
178          */
179         @Test   
180         
181         public void badPatch() throws IOException {
182                 
183                 logStart();
184                 
185                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml"); 
186                 
187                 MockGetGenericVnfByIdWithDepth(wireMockServer, "skask", 1, "VfModularity/GenericVnf.xml");
188                 MockAAIVfModuleBadPatch(wireMockServer, "/aai/v[0-9]+/network/generic-vnfs/generic-vnf/skask/vf-modules/vf-module/supercool", 404);
189                 
190                 String businessKey = UUID.randomUUID().toString();
191                 Map<String, Object> variables = new HashMap<>();
192                 variables.put("mso-request-id", UUID.randomUUID().toString());
193                 variables.put("isDebugLogEnabled","true");
194                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
195                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
196                 
197                 Assert.assertTrue(isProcessEnded(businessKey));
198                 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponse");
199                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponseCode");
200                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
201                 logger.debug("Subflow response code: {}", responseCode);
202                 logger.debug("Subflow response: {}", response);
203                 Assert.assertEquals(404, responseCode.intValue());
204                 Assert.assertNotNull(workflowException);
205                 logger.debug("Subflow WorkflowException error message: {}", workflowException.getErrorMessage());
206                 
207                 logEnd();
208         }
209 }
210