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.onap.so.bpmn.common;
23 import static org.onap.so.bpmn.mock.StubResponseAAI.MockAAIVfModuleBadPatch;
24 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;
25 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;
26 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchGenericVnf;
27 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
28 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutGenericVnf_Bad;
30 import java.io.IOException;
31 import java.util.HashMap;
33 import java.util.UUID;
35 import org.camunda.bpm.engine.test.Deployment;
36 import org.junit.Assert;
37 import org.junit.Ignore;
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.onap.so.logger.MsoLogger;
45 * Unit tests for UpdateAAIGenericVnf bpmn.
48 public class UpdateAAIGenericVnfIT extends BaseIntegrationTest {
50 MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,CreateAAIVfModuleIT.class);
54 * Test the happy path through the flow.
58 public void happyPath() throws IOException {
61 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
62 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
63 MockPutGenericVnf("/skask", 200);
64 MockPatchGenericVnf("skask");
66 String businessKey = UUID.randomUUID().toString();
67 Map<String, Object> variables = new HashMap<>();
68 variables.put("mso-request-id", UUID.randomUUID().toString());
69 variables.put("isDebugLogEnabled","true");
70 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
71 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
73 Assert.assertTrue(isProcessEnded(businessKey));
74 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponse");
75 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponseCode");
76 logger.debug("Subflow response code: " + responseCode);
77 logger.debug("Subflow response: " + response);
78 Assert.assertEquals(200, responseCode.intValue());
84 * Test the happy path through the flow.
88 public void personaMismatch() throws IOException {
92 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
93 updateAAIGenericVnfRequest = updateAAIGenericVnfRequest.replaceFirst("introvert", "extrovert");
95 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
97 String businessKey = UUID.randomUUID().toString();
98 Map<String, Object> variables = new HashMap<>();
99 variables.put("mso-request-id", UUID.randomUUID().toString());
100 variables.put("isDebugLogEnabled","true");
101 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
102 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
104 Assert.assertTrue(isProcessEnded(businessKey));
105 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
106 logger.debug("Workflow Exception: " + workflowException);
107 Assert.assertNotNull(workflowException);
113 * Test the case where the GET to AAI returns a 404.
117 public void badGet() throws IOException {
121 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
123 MockGetGenericVnfById_404("skask[?]depth=1");
125 String businessKey = UUID.randomUUID().toString();
126 Map<String, Object> variables = new HashMap<>();
127 variables.put("mso-request-id", UUID.randomUUID().toString());
128 variables.put("isDebugLogEnabled","true");
129 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
130 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
132 Assert.assertTrue(isProcessEnded(businessKey));
133 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_getGenericVnfResponse");
134 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_getGenericVnfResponseCode");
135 logger.debug("Subflow response code: " + responseCode);
136 logger.debug("Subflow response: " + response);
137 Assert.assertEquals(404, responseCode.intValue());
143 * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.
147 public void badPatch() throws IOException {
151 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
153 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
154 MockPutGenericVnf_Bad("skask", 404);
155 MockAAIVfModuleBadPatch("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/skask", 404);
157 String businessKey = UUID.randomUUID().toString();
158 Map<String, Object> variables = new HashMap<>();
159 variables.put("mso-request-id", UUID.randomUUID().toString());
160 variables.put("isDebugLogEnabled","true");
161 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
162 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
164 Assert.assertTrue(isProcessEnded(businessKey));
165 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponse");
166 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponseCode");
167 logger.debug("Subflow response code: " + responseCode);
168 logger.debug("Subflow response: " + response);
169 Assert.assertEquals(404, responseCode.intValue());