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;
31 import java.io.IOException;
32 import java.util.HashMap;
34 import java.util.UUID;
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;
46 * Unit tests for PrepareUpdateAAIVfModule.bpmn.
49 public class PrepareUpdateAAIVfModuleIT extends BaseIntegrationTest {
51 Logger logger = LoggerFactory.getLogger(PrepareUpdateAAIVfModuleIT.class);
54 * Test the happy path through the flow.
58 public void happyPath() throws IOException {
62 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
64 MockGetGenericVnfByIdWithDepth(wireMockServer, "skask", 1, "VfModularity/GenericVnf.xml");
65 MockPutGenericVnf(wireMockServer, "/skask/vf-modules/vf-module/supercool", "PCRF", 200);
66 MockPatchVfModuleId(wireMockServer, "skask", "supercool");
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);
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);
89 * Test the case where the GET to AAI returns a 404.
93 public void badGet() throws IOException {
97 String prepareUpdateAAIVfModuleRequest = 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 = (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());
121 * Test the case where the validation of the VF Module fails.
125 public void failValidation1() throws IOException {
129 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "lukewarm");
131 MockGetGenericVnfByIdWithDepth(wireMockServer, "skask", 1, "VfModularity/GenericVnf.xml");
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);
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"));
149 * Test the case where the validation of the VF Module fails.
153 public void failValidation2() throws IOException {
157 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "notsocool");
159 MockGetGenericVnfByIdWithDepth(wireMockServer, "skask", 1, "VfModularity/GenericVnf.xml");
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);
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"));
177 * Test the case where the GET to AAI is successful, but the subsequent PUT returns 404.
181 public void badPatch() throws IOException {
185 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
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);
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);
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());