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;
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf_Bad;
28 import java.io.IOException;
29 import java.util.HashMap;
31 import java.util.UUID;
33 import org.camunda.bpm.engine.test.Deployment;
34 import org.junit.Assert;
35 import org.junit.Test;
36 import org.openecomp.mso.bpmn.core.WorkflowException;
37 import org.openecomp.mso.bpmn.mock.FileUtil;
40 * Unit tests for UpdateAAIGenericVnf bpmn.
42 public class UpdateAAIGenericVnfTest extends WorkflowTest {
45 * Test the happy path through the flow.
48 @Deployment(resources = {
49 "subprocess/UpdateAAIGenericVnf.bpmn"
51 public void happyPath() throws IOException {
54 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
55 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
56 MockPutGenericVnf("/skask", 200);
58 String businessKey = UUID.randomUUID().toString();
59 Map<String, Object> variables = new HashMap<String, Object>();
60 variables.put("mso-request-id", "999-99-9999");
61 variables.put("isDebugLogEnabled","true");
62 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
63 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
65 Assert.assertTrue(isProcessEnded(businessKey));
66 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponse");
67 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponseCode");
68 System.out.println("Subflow response code: " + responseCode);
69 System.out.println("Subflow response: " + response);
70 Assert.assertEquals(200, responseCode.intValue());
76 * Test the happy path through the flow.
79 @Deployment(resources = {
80 "subprocess/UpdateAAIGenericVnf.bpmn"
82 public void personaMismatch() throws IOException {
86 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
87 updateAAIGenericVnfRequest = updateAAIGenericVnfRequest.replaceFirst("introvert", "extrovert");
89 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
91 String businessKey = UUID.randomUUID().toString();
92 Map<String, Object> variables = new HashMap<String, Object>();
93 variables.put("mso-request-id", "999-99-9999");
94 variables.put("isDebugLogEnabled","true");
95 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
96 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
98 Assert.assertTrue(isProcessEnded(businessKey));
99 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
100 System.out.println("Workflow Exception: " + workflowException);
101 Assert.assertNotNull(workflowException);
107 * Test the case where the GET to AAI returns a 404.
110 @Deployment(resources = {
111 "subprocess/UpdateAAIGenericVnf.bpmn"
113 public void badGet() throws IOException {
117 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
119 MockGetGenericVnfById_404("skask[?]depth=1");
121 String businessKey = UUID.randomUUID().toString();
122 Map<String, Object> variables = new HashMap<String, Object>();
123 variables.put("mso-request-id", "999-99-9999");
124 variables.put("isDebugLogEnabled","true");
125 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
126 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
128 Assert.assertTrue(isProcessEnded(businessKey));
129 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_getGenericVnfResponse");
130 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_getGenericVnfResponseCode");
131 System.out.println("Subflow response code: " + responseCode);
132 System.out.println("Subflow response: " + response);
133 Assert.assertEquals(404, responseCode.intValue());
139 * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.
142 @Deployment(resources = {
143 "subprocess/UpdateAAIGenericVnf.bpmn"
145 public void badPut() throws IOException {
149 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
151 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
152 MockPutGenericVnf_Bad("skask", 404);
154 String businessKey = UUID.randomUUID().toString();
155 Map<String, Object> variables = new HashMap<String, Object>();
156 variables.put("mso-request-id", "999-99-9999");
157 variables.put("isDebugLogEnabled","true");
158 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
159 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
161 Assert.assertTrue(isProcessEnded(businessKey));
162 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponse");
163 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponseCode");
164 System.out.println("Subflow response code: " + responseCode);
165 System.out.println("Subflow response: " + response);
166 Assert.assertEquals(404, responseCode.intValue());