2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.bpmn.common;
23 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;
24 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
27 import java.io.IOException;
28 import java.util.HashMap;
30 import java.util.UUID;
32 import org.camunda.bpm.engine.test.Deployment;
33 import org.junit.Assert;
34 import org.junit.Test;
35 import org.openecomp.mso.bpmn.core.WorkflowException;
36 import org.openecomp.mso.bpmn.mock.FileUtil;
39 * Unit tests for PrepareUpdateAAIVfModule.bpmn.
41 public class PrepareUpdateAAIVfModuleTest extends WorkflowTest {
44 * Test the happy path through the flow.
47 @Deployment(resources = {
48 "subprocess/PrepareUpdateAAIVfModule.bpmn"
50 public void happyPath() throws IOException {
54 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
56 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
57 MockPutGenericVnf("/skask/vf-modules/vf-module/supercool", "PCRF", 200);
59 String businessKey = UUID.randomUUID().toString();
60 Map<String, Object> variables = new HashMap<String, Object>();
61 variables.put("mso-request-id", "999-99-9999");
62 variables.put("isDebugLogEnabled","true");
63 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
64 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
66 Assert.assertTrue(isProcessEnded(businessKey));
67 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponse");
68 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponseCode");
69 System.out.println("Subflow response code: " + responseCode);
70 System.out.println("Subflow response: " + response);
71 Assert.assertEquals(200, responseCode.intValue());
72 String heatStackId = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_heatStackId");
73 System.out.println("Ouput heat-stack-id:" + heatStackId);
74 Assert.assertEquals("slowburn", heatStackId);
80 * Test the case where the GET to AAI returns a 404.
83 @Deployment(resources = {
84 "subprocess/PrepareUpdateAAIVfModule.bpmn"
86 public void badGet() throws IOException {
90 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
91 MockGetGenericVnfById_404("skask[?]depth=1");
93 String businessKey = UUID.randomUUID().toString();
94 Map<String, Object> variables = new HashMap<String, Object>();
95 variables.put("mso-request-id", "999-99-9999");
96 variables.put("isDebugLogEnabled","true");
97 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
98 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
100 Assert.assertTrue(isProcessEnded(businessKey));
101 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_getVnfResponse");
102 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_getVnfResponseCode");
103 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
104 System.out.println("Subflow response code: " + responseCode);
105 System.out.println("Subflow response: " + response);
106 Assert.assertEquals(404, responseCode.intValue());
107 Assert.assertNotNull(workflowException);
108 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
114 * Test the case where the validation of the VF Module fails.
117 @Deployment(resources = {
118 "subprocess/PrepareUpdateAAIVfModule.bpmn"
120 public void failValidation1() throws IOException {
124 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "lukewarm");
126 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
128 String businessKey = UUID.randomUUID().toString();
129 Map<String, Object> variables = new HashMap<String, Object>();
130 variables.put("mso-request-id", "999-99-9999");
131 variables.put("isDebugLogEnabled","true");
132 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
133 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
135 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
136 Assert.assertNotNull(workflowException);
137 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
138 Assert.assertTrue(workflowException.getErrorMessage().startsWith("VF Module validation error: Orchestration"));
144 * Test the case where the validation of the VF Module fails.
147 @Deployment(resources = {
148 "subprocess/PrepareUpdateAAIVfModule.bpmn"
150 public void failValidation2() throws IOException {
154 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "notsocool");
156 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
158 String businessKey = UUID.randomUUID().toString();
159 Map<String, Object> variables = new HashMap<String, Object>();
160 variables.put("mso-request-id", "999-99-9999");
161 variables.put("isDebugLogEnabled","true");
162 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
163 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
165 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
166 Assert.assertNotNull(workflowException);
167 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
168 Assert.assertTrue(workflowException.getErrorMessage().startsWith("VF Module validation error: VF Module"));
174 * Test the case where the GET to AAI is successful, but the subsequent PUT returns 404.
177 @Deployment(resources = {
178 "subprocess/PrepareUpdateAAIVfModule.bpmn"
180 public void badPut() throws IOException {
184 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
186 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
188 String businessKey = UUID.randomUUID().toString();
189 Map<String, Object> variables = new HashMap<String, Object>();
190 variables.put("mso-request-id", "999-99-9999");
191 variables.put("isDebugLogEnabled","true");
192 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
193 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
195 Assert.assertTrue(isProcessEnded(businessKey));
196 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponse");
197 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponseCode");
198 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
199 System.out.println("Subflow response code: " + responseCode);
200 System.out.println("Subflow response: " + response);
201 Assert.assertEquals(404, responseCode.intValue());
202 Assert.assertNotNull(workflowException);
203 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());