2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.common;
25 import static org.onap.so.bpmn.mock.StubResponseAAI.MockAAIVfModuleBadPatch;
26 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;
27 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;
28 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchGenericVnf;
29 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
30 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutGenericVnf_Bad;
32 import java.io.IOException;
33 import java.util.HashMap;
35 import java.util.UUID;
37 import org.camunda.bpm.engine.test.Deployment;
38 import org.junit.Assert;
39 import org.junit.Ignore;
40 import org.junit.Test;
41 import org.onap.so.BaseIntegrationTest;
42 import org.onap.so.bpmn.core.WorkflowException;
43 import org.onap.so.bpmn.mock.FileUtil;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * Unit tests for UpdateAAIGenericVnf bpmn.
51 public class UpdateAAIGenericVnfIT extends BaseIntegrationTest {
53 Logger logger = LoggerFactory.getLogger(CreateAAIVfModuleIT.class);
57 * Test the happy path through the flow.
61 public void happyPath() throws IOException {
64 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
65 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
66 MockPutGenericVnf("/skask", 200);
67 MockPatchGenericVnf("skask");
69 String businessKey = UUID.randomUUID().toString();
70 Map<String, Object> variables = new HashMap<>();
71 variables.put("mso-request-id", UUID.randomUUID().toString());
72 variables.put("isDebugLogEnabled","true");
73 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
74 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
76 Assert.assertTrue(isProcessEnded(businessKey));
77 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponse");
78 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponseCode");
79 logger.debug("Subflow response code: {}", responseCode);
80 logger.debug("Subflow response: {}", response);
81 Assert.assertEquals(200, responseCode.intValue());
87 * Test the happy path through the flow.
91 public void personaMismatch() throws IOException {
95 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
96 updateAAIGenericVnfRequest = updateAAIGenericVnfRequest.replaceFirst("introvert", "extrovert");
98 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
100 String businessKey = UUID.randomUUID().toString();
101 Map<String, Object> variables = new HashMap<>();
102 variables.put("mso-request-id", UUID.randomUUID().toString());
103 variables.put("isDebugLogEnabled","true");
104 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
105 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
107 Assert.assertTrue(isProcessEnded(businessKey));
108 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
109 logger.debug("Workflow Exception: {}", workflowException);
110 Assert.assertNotNull(workflowException);
116 * Test the case where the GET to AAI returns a 404.
120 public void badGet() throws IOException {
124 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
126 MockGetGenericVnfById_404("skask[?]depth=1");
128 String businessKey = UUID.randomUUID().toString();
129 Map<String, Object> variables = new HashMap<>();
130 variables.put("mso-request-id", UUID.randomUUID().toString());
131 variables.put("isDebugLogEnabled","true");
132 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
133 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
135 Assert.assertTrue(isProcessEnded(businessKey));
136 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_getGenericVnfResponse");
137 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_getGenericVnfResponseCode");
138 logger.debug("Subflow response code: {}", responseCode);
139 logger.debug("Subflow response: {}", response);
140 Assert.assertEquals(404, responseCode.intValue());
146 * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.
150 public void badPatch() throws IOException {
154 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml");
156 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
157 MockPutGenericVnf_Bad("skask", 404);
158 MockAAIVfModuleBadPatch("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/skask", 404);
160 String businessKey = UUID.randomUUID().toString();
161 Map<String, Object> variables = new HashMap<>();
162 variables.put("mso-request-id", UUID.randomUUID().toString());
163 variables.put("isDebugLogEnabled","true");
164 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);
165 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);
167 Assert.assertTrue(isProcessEnded(businessKey));
168 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponse");
169 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponseCode");
170 logger.debug("Subflow response code: {}", responseCode);
171 logger.debug("Subflow response: {}", response);
172 Assert.assertEquals(404, responseCode.intValue());