2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.bpmn.common;
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;
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;
44 * Unit tests for PrepareUpdateAAIVfModule.bpmn.
47 public class PrepareUpdateAAIVfModuleIT extends BaseIntegrationTest {
49 Logger logger = LoggerFactory.getLogger(PrepareUpdateAAIVfModuleIT.class);
52 * Test the happy path through the flow.
56 public void happyPath() throws IOException {
60 String prepareUpdateAAIVfModuleRequest =
61 FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
63 MockGetGenericVnfByIdWithDepth(wireMockServer, "skask", 1, "VfModularity/GenericVnf.xml");
64 MockPutGenericVnf(wireMockServer, "/skask/vf-modules/vf-module/supercool", "PCRF", 200);
65 MockPatchVfModuleId(wireMockServer, "skask", "supercool");
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);
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);
88 * Test the case where the GET to AAI returns a 404.
92 public void badGet() throws IOException {
96 String prepareUpdateAAIVfModuleRequest =
97 FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
98 MockGetGenericVnfById_404(wireMockServer, "skask[?]depth=1");
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);
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());
122 * Test the case where the validation of the VF Module fails.
126 public void failValidation1() throws IOException {
130 String prepareUpdateAAIVfModuleRequest =
131 FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml")
132 .replaceFirst("supercool", "lukewarm");
134 MockGetGenericVnfByIdWithDepth(wireMockServer, "skask", 1, "VfModularity/GenericVnf.xml");
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);
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"));
153 * Test the case where the validation of the VF Module fails.
157 public void failValidation2() throws IOException {
161 String prepareUpdateAAIVfModuleRequest =
162 FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml")
163 .replaceFirst("supercool", "notsocool");
165 MockGetGenericVnfByIdWithDepth(wireMockServer, "skask", 1, "VfModularity/GenericVnf.xml");
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);
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"));
184 * Test the case where the GET to AAI is successful, but the subsequent PUT returns 404.
188 public void badPatch() throws IOException {
192 String prepareUpdateAAIVfModuleRequest =
193 FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
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);
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);
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());