2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.common;
\r
23 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockAAIVfModuleBadPatch;
\r
24 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;
\r
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;
\r
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchVfModuleId;
\r
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
\r
29 import java.io.IOException;
\r
30 import java.util.HashMap;
\r
31 import java.util.Map;
\r
32 import java.util.UUID;
\r
34 import org.camunda.bpm.engine.test.Deployment;
\r
35 import org.junit.Assert;
\r
36 import org.junit.Test;
\r
37 import org.openecomp.mso.bpmn.core.WorkflowException;
\r
38 import org.openecomp.mso.bpmn.mock.FileUtil;
\r
41 * Unit tests for PrepareUpdateAAIVfModule.bpmn.
\r
43 public class PrepareUpdateAAIVfModuleTest extends WorkflowTest {
\r
46 * Test the happy path through the flow.
\r
49 @Deployment(resources = {
\r
50 "subprocess/PrepareUpdateAAIVfModule.bpmn"
\r
52 public void happyPath() throws IOException {
\r
56 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
\r
58 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
\r
59 MockPutGenericVnf("/skask/vf-modules/vf-module/supercool", "PCRF", 200);
\r
60 MockPatchVfModuleId("skask", "supercool");
\r
62 String businessKey = UUID.randomUUID().toString();
\r
63 Map<String, Object> variables = new HashMap<String, Object>();
\r
64 variables.put("mso-request-id", "999-99-9999");
\r
65 variables.put("isDebugLogEnabled","true");
\r
66 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
\r
67 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
\r
69 Assert.assertTrue(isProcessEnded(businessKey));
\r
70 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponse");
\r
71 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponseCode");
\r
72 System.out.println("Subflow response code: " + responseCode);
\r
73 System.out.println("Subflow response: " + response);
\r
74 Assert.assertEquals(200, responseCode.intValue());
\r
75 String heatStackId = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_heatStackId");
\r
76 System.out.println("Ouput heat-stack-id:" + heatStackId);
\r
77 Assert.assertEquals("slowburn", heatStackId);
\r
83 * Test the case where the GET to AAI returns a 404.
\r
86 @Deployment(resources = {
\r
87 "subprocess/PrepareUpdateAAIVfModule.bpmn"
\r
89 public void badGet() throws IOException {
\r
93 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
\r
94 MockGetGenericVnfById_404("skask[?]depth=1");
\r
96 String businessKey = UUID.randomUUID().toString();
\r
97 Map<String, Object> variables = new HashMap<String, Object>();
\r
98 variables.put("mso-request-id", "999-99-9999");
\r
99 variables.put("isDebugLogEnabled","true");
\r
100 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
\r
101 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
\r
103 Assert.assertTrue(isProcessEnded(businessKey));
\r
104 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_getVnfResponse");
\r
105 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_getVnfResponseCode");
\r
106 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
\r
107 System.out.println("Subflow response code: " + responseCode);
\r
108 System.out.println("Subflow response: " + response);
\r
109 Assert.assertEquals(404, responseCode.intValue());
\r
110 Assert.assertNotNull(workflowException);
\r
111 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
\r
117 * Test the case where the validation of the VF Module fails.
\r
120 @Deployment(resources = {
\r
121 "subprocess/PrepareUpdateAAIVfModule.bpmn"
\r
123 public void failValidation1() throws IOException {
\r
127 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "lukewarm");
\r
129 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
\r
131 String businessKey = UUID.randomUUID().toString();
\r
132 Map<String, Object> variables = new HashMap<String, Object>();
\r
133 variables.put("mso-request-id", "999-99-9999");
\r
134 variables.put("isDebugLogEnabled","true");
\r
135 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
\r
136 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
\r
138 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
\r
139 Assert.assertNotNull(workflowException);
\r
140 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
\r
141 Assert.assertTrue(workflowException.getErrorMessage().startsWith("VF Module validation error: Orchestration"));
\r
147 * Test the case where the validation of the VF Module fails.
\r
150 @Deployment(resources = {
\r
151 "subprocess/PrepareUpdateAAIVfModule.bpmn"
\r
153 public void failValidation2() throws IOException {
\r
157 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "notsocool");
\r
159 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
\r
161 String businessKey = UUID.randomUUID().toString();
\r
162 Map<String, Object> variables = new HashMap<String, Object>();
\r
163 variables.put("mso-request-id", "999-99-9999");
\r
164 variables.put("isDebugLogEnabled","true");
\r
165 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
\r
166 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
\r
168 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
\r
169 Assert.assertNotNull(workflowException);
\r
170 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
\r
171 Assert.assertTrue(workflowException.getErrorMessage().startsWith("VF Module validation error: VF Module"));
\r
177 * Test the case where the GET to AAI is successful, but the subsequent PUT returns 404.
\r
180 @Deployment(resources = {
\r
181 "subprocess/PrepareUpdateAAIVfModule.bpmn"
\r
183 public void badPatch() throws IOException {
\r
187 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml");
\r
189 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
\r
190 MockAAIVfModuleBadPatch("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/skask/vf-modules/vf-module/supercool", 404);
\r
192 String businessKey = UUID.randomUUID().toString();
\r
193 Map<String, Object> variables = new HashMap<String, Object>();
\r
194 variables.put("mso-request-id", "999-99-9999");
\r
195 variables.put("isDebugLogEnabled","true");
\r
196 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
\r
197 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
\r
199 Assert.assertTrue(isProcessEnded(businessKey));
\r
200 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponse");
\r
201 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponseCode");
\r
202 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
\r
203 System.out.println("Subflow response code: " + responseCode);
\r
204 System.out.println("Subflow response: " + response);
\r
205 Assert.assertEquals(404, responseCode.intValue());
\r
206 Assert.assertNotNull(workflowException);
\r
207 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
\r