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.MockPatchGenericVnf;
\r
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
\r
28 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf_Bad;
\r
30 import java.io.IOException;
\r
31 import java.util.HashMap;
\r
32 import java.util.Map;
\r
33 import java.util.UUID;
\r
35 import org.camunda.bpm.engine.test.Deployment;
\r
36 import org.junit.Assert;
\r
37 import org.junit.Test;
\r
38 import org.openecomp.mso.bpmn.core.WorkflowException;
\r
39 import org.openecomp.mso.bpmn.mock.FileUtil;
\r
42 * Unit tests for UpdateAAIGenericVnf bpmn.
\r
44 public class UpdateAAIGenericVnfTest extends WorkflowTest {
\r
47 * Test the happy path through the flow.
\r
50 @Deployment(resources = {
\r
51 "subprocess/UpdateAAIGenericVnf.bpmn"
\r
53 public void happyPath() throws IOException {
\r
56 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
\r
57 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
\r
58 MockPutGenericVnf("/skask", 200);
\r
59 MockPatchGenericVnf("skask");
\r
61 String businessKey = UUID.randomUUID().toString();
\r
62 Map<String, Object> variables = new HashMap<>();
\r
63 variables.put("mso-request-id", "999-99-9999");
\r
64 variables.put("isDebugLogEnabled","true");
\r
65 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
\r
66 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
\r
68 Assert.assertTrue(isProcessEnded(businessKey));
\r
69 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponse");
\r
70 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponseCode");
\r
71 System.out.println("Subflow response code: " + responseCode);
\r
72 System.out.println("Subflow response: " + response);
\r
73 Assert.assertEquals(200, responseCode.intValue());
\r
79 * Test the happy path through the flow.
\r
82 @Deployment(resources = {
\r
83 "subprocess/UpdateAAIGenericVnf.bpmn"
\r
85 public void personaMismatch() throws IOException {
\r
89 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
\r
90 updateAAIGenericVnfRequest = updateAAIGenericVnfRequest.replaceFirst("introvert", "extrovert");
\r
92 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
\r
94 String businessKey = UUID.randomUUID().toString();
\r
95 Map<String, Object> variables = new HashMap<>();
\r
96 variables.put("mso-request-id", "999-99-9999");
\r
97 variables.put("isDebugLogEnabled","true");
\r
98 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
\r
99 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
\r
101 Assert.assertTrue(isProcessEnded(businessKey));
\r
102 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
\r
103 System.out.println("Workflow Exception: " + workflowException);
\r
104 Assert.assertNotNull(workflowException);
\r
110 * Test the case where the GET to AAI returns a 404.
\r
113 @Deployment(resources = {
\r
114 "subprocess/UpdateAAIGenericVnf.bpmn"
\r
116 public void badGet() throws IOException {
\r
120 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
\r
122 MockGetGenericVnfById_404("skask[?]depth=1");
\r
124 String businessKey = UUID.randomUUID().toString();
\r
125 Map<String, Object> variables = new HashMap<>();
\r
126 variables.put("mso-request-id", "999-99-9999");
\r
127 variables.put("isDebugLogEnabled","true");
\r
128 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
\r
129 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
\r
131 Assert.assertTrue(isProcessEnded(businessKey));
\r
132 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_getGenericVnfResponse");
\r
133 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_getGenericVnfResponseCode");
\r
134 System.out.println("Subflow response code: " + responseCode);
\r
135 System.out.println("Subflow response: " + response);
\r
136 Assert.assertEquals(404, responseCode.intValue());
\r
142 * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.
\r
145 @Deployment(resources = {
\r
146 "subprocess/UpdateAAIGenericVnf.bpmn"
\r
148 public void badPatch() throws IOException {
\r
152 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
\r
154 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
\r
155 MockPutGenericVnf_Bad("skask", 404);
\r
156 MockAAIVfModuleBadPatch("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/skask", 404);
\r
158 String businessKey = UUID.randomUUID().toString();
\r
159 Map<String, Object> variables = new HashMap<>();
\r
160 variables.put("mso-request-id", "999-99-9999");
\r
161 variables.put("isDebugLogEnabled","true");
\r
162 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
\r
163 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
\r
165 Assert.assertTrue(isProcessEnded(businessKey));
\r
166 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponse");
\r
167 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponseCode");
\r
168 System.out.println("Subflow response code: " + responseCode);
\r
169 System.out.println("Subflow response: " + response);
\r
170 Assert.assertEquals(404, responseCode.intValue());
\r