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 com.github.tomakehurst.wiremock.client.WireMock.aResponse;
26 import static com.github.tomakehurst.wiremock.client.WireMock.containing;
27 import static com.github.tomakehurst.wiremock.client.WireMock.put;
28 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
29 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
32 import java.util.HashMap;
34 import java.util.UUID;
36 import org.junit.Assert;
37 import org.junit.Test;
38 import org.onap.so.BaseIntegrationTest;
39 import org.onap.so.bpmn.core.WorkflowException;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * Unit test for CreateAAIVfModule.bpmn.
47 public class CreateAAIVfModuleIT extends BaseIntegrationTest {
49 Logger logger = LoggerFactory.getLogger(CreateAAIVfModuleIT.class);
52 public void TestCreateGenericVnfSuccess_200() {
54 new MockAAIGenericVnfSearch();
55 MockAAICreateGenericVnf();
56 MockAAIVfModulePUT(true);
58 Map<String, Object> variables = new HashMap<>();
59 variables.put("mso-request-id", UUID.randomUUID().toString());
60 variables.put("isDebugLogEnabled","true");
61 variables.put("isVidRequest", "false");
62 variables.put("vnfName", "STMTN5MMSC22");
63 variables.put("serviceId", "00000000-0000-0000-0000-000000000000");
64 variables.put("personaModelId", "973ed047-d251-4fb9-bf1a-65b8949e0a73");
65 variables.put("personaModelVersion", "1.0");
66 variables.put("vfModuleName", "STMTN5MMSC22-MMSC::module-0-0");
67 variables.put("vfModuleModelName", "MMSC::module-0");
69 String processId = invokeSubProcess("CreateAAIVfModule", variables);
70 String response = BPMNUtil.getVariable(processEngine, "CreateAAIVfModule", "CAAIVfMod_createVfModuleResponseCode",processId);
71 String responseCode = BPMNUtil.getVariable(processEngine, "CreateAAIVfModule", "CAAIVfMod_createVfModuleResponseCode",processId);
72 Assert.assertEquals("201", responseCode);
73 logger.debug(response);
77 public void TestCreateVfModuleSuccess_200() {
78 // create Add-on VF Module for existing Generic VNF
79 new MockAAIGenericVnfSearch();
80 MockAAICreateGenericVnf();
81 MockAAIVfModulePUT(true);
82 Map<String, Object> variables = new HashMap<>();
83 variables.put("mso-request-id", UUID.randomUUID().toString());
84 variables.put("isDebugLogEnabled","true");
85 variables.put("isVidRequest", "false");
86 variables.put("vnfId", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
87 variables.put("serviceId", "00000000-0000-0000-0000-000000000000");
88 variables.put("personaModelId", "973ed047-d251-4fb9-bf1a-65b8949e0a73");
89 variables.put("personaModelVersion", "1.0");
90 variables.put("vfModuleName", "STMTN5MMSC21-MMSC::module-1-0");
91 variables.put("vfModuleModelName", "STMTN5MMSC21-MMSC::model-1-0");
92 String processId = invokeSubProcess("CreateAAIVfModule", variables);
93 String response = BPMNUtil.getVariable(processEngine, "CreateAAIVfModule", "CAAIVfMod_createVfModuleResponseCode",processId);
94 String responseCode = BPMNUtil.getVariable(processEngine, "CreateAAIVfModule", "CAAIVfMod_createVfModuleResponseCode",processId);
95 Assert.assertEquals("201", responseCode);
96 logger.debug(response);
100 public void TestQueryGenericVnfFailure_5000() {
101 new MockAAIGenericVnfSearch();
102 MockAAICreateGenericVnf();
103 MockAAIVfModulePUT(true);
105 Map<String, Object> variables = new HashMap<>();
106 variables.put("mso-request-id", UUID.randomUUID().toString());
107 variables.put("isDebugLogEnabled","true");
108 variables.put("isVidRequest", "false");
109 variables.put("vnfName", "STMTN5MMSC23");
110 variables.put("serviceId", "00000000-0000-0000-0000-000000000000");
111 variables.put("personaModelId", "973ed047-d251-4fb9-bf1a-65b8949e0a73");
112 variables.put("personaModelVersion", "1.0");
113 variables.put("vfModuleName", "STMTN5MMSC23-MMSC::module-0-0");
114 variables.put("vfModuleModelName", "MMSC::module-0");
115 String processId = invokeSubProcess("CreateAAIVfModule", variables);
116 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "CreateAAIVfModule", "WorkflowException",processId);
117 Assert.assertEquals(500, exception.getErrorCode());
118 Assert.assertEquals(true, exception.getErrorMessage().contains("Error occurred attempting to query AAI"));
119 logger.debug(exception.getErrorMessage());
123 public void TestCreateDupGenericVnfFailure_1002() {
124 new MockAAIGenericVnfSearch();
125 MockAAICreateGenericVnf();
126 MockAAIVfModulePUT(true);
128 Map<String, Object> variables = new HashMap<>();
129 variables.put("mso-request-id", UUID.randomUUID().toString());
130 variables.put("isDebugLogEnabled","true");
131 variables.put("isVidRequest", "false");
132 variables.put("vnfName", "STMTN5MMSC21");
133 variables.put("serviceId", "00000000-0000-0000-0000-000000000000");
134 variables.put("personaModelId", "973ed047-d251-4fb9-bf1a-65b8949e0a73");
135 variables.put("personaModelVersion", "1.0");
136 variables.put("vfModuleName", "STMTN5MMSC21-MMSC::module-0-0");
137 variables.put("vfModuleModelName", "MMSC::module-0");
138 String processId = invokeSubProcess("CreateAAIVfModule", variables);
139 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "CreateAAIVfModule", "WorkflowException",processId);
140 Assert.assertEquals(1002, exception.getErrorCode());
141 Assert.assertEquals(true, exception.getErrorMessage().contains("Invalid request for new Generic VNF which already exists"));
142 logger.debug(exception.getErrorMessage());
146 public void TestCreateDupVfModuleFailure_1002() {
147 new MockAAIGenericVnfSearch();
148 MockAAICreateGenericVnf();
149 MockAAIVfModulePUT(true);
151 Map<String, Object> variables = new HashMap<>();
152 variables.put("mso-request-id", UUID.randomUUID().toString());
153 variables.put("isDebugLogEnabled","true");
154 variables.put("isVidRequest", "false");
155 variables.put("vnfId", "2f6aee38-1e2a-11e6-82d1-ffc7d9ee8aa4");
156 variables.put("serviceId", "00000000-0000-0000-0000-000000000000");
157 variables.put("personaModelId", "973ed047-d251-4fb9-bf1a-65b8949e0a73");
158 variables.put("personaModelVersion", "1.0");
159 variables.put("vfModuleName", "STMTN5MMSC20-MMSC::module-1-0");
160 variables.put("vfModuleModelName", "STMTN5MMSC20-MMSC::model-1-0");
161 String processId = invokeSubProcess("CreateAAIVfModule", variables);
162 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "CreateAAIVfModule", "WorkflowException",processId);
163 Assert.assertEquals(1002, exception.getErrorCode());
164 Assert.assertEquals(true, exception.getErrorMessage().contains("already exists for Generic VNF"));
165 logger.debug(exception.getErrorMessage());
169 public void TestCreateGenericVnfFailure_5000() {
170 new MockAAIGenericVnfSearch();
171 MockAAICreateGenericVnf();
172 MockAAIVfModulePUT(true);
174 Map<String, Object> variables = new HashMap<>();
175 variables.put("mso-request-id", UUID.randomUUID().toString());
176 variables.put("isDebugLogEnabled","true");
177 variables.put("isVidRequest", "false");
178 variables.put("vnfName", "STMTN5MMSC22");
179 variables.put("serviceId", "99999999-9999-9999-9999-999999999999");
180 variables.put("personaModelId", "973ed047-d251-4fb9-bf1a-65b8949e0a73");
181 variables.put("personaModelVersion", "1.0");
182 variables.put("vfModuleName", "STMTN5MMSC22-PCRF::module-1-0");
183 variables.put("vfModuleModelName", "PCRF::module-0");
184 String processId = invokeSubProcess("CreateAAIVfModule", variables);
185 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "CreateAAIVfModule", "WorkflowException",processId);
186 Assert.assertEquals(5000, exception.getErrorCode());
187 Assert.assertEquals(true, exception.getErrorMessage().contains("<messageId>SVC3002</messageId>"));
188 logger.debug(exception.getErrorMessage());
192 public void TestCreateGenericVnfFailure_1002() {
193 new MockAAIGenericVnfSearch();
194 MockAAICreateGenericVnf();
195 MockAAIVfModulePUT(true);
197 Map<String, Object> variables = new HashMap<>();
198 variables.put("mso-request-id", UUID.randomUUID().toString());
199 variables.put("isDebugLogEnabled","true");
200 variables.put("isVidRequest", "false");
201 variables.put("vnfId", "768073c7-f41f-4822-9323-b75962763d74");
202 variables.put("serviceId", "00000000-0000-0000-0000-000000000000");
203 variables.put("personaModelId", "973ed047-d251-4fb9-bf1a-65b8949e0a73");
204 variables.put("personaModelVersion", "1.0");
205 variables.put("vfModuleName", "STMTN5MMSC22-PCRF::module-1-0");
206 variables.put("vfModuleModelName", "PCRF::module-0");
207 String processId = invokeSubProcess("CreateAAIVfModule", variables);
208 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "CreateAAIVfModule", "WorkflowException",processId);
209 Assert.assertEquals(1002, exception.getErrorCode());
210 Assert.assertEquals(true, exception.getErrorMessage().contains("Generic VNF Not Found"));
211 logger.debug(exception.getErrorMessage());
215 public void TestCreateVfModuleFailure_5000() {
216 new MockAAIGenericVnfSearch();
217 MockAAICreateGenericVnf();
218 MockAAIVfModulePUT(true);
220 Map<String, Object> variables = new HashMap<>();
221 variables.put("isDebugLogEnabled","true");
222 variables.put("isVidRequest", "false");
223 variables.put("vnfId", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
224 variables.put("serviceId", "99999999-9999-9999-9999-999999999999");
225 variables.put("personaModelId", "973ed047-d251-4fb9-bf1a-65b8949e0a73");
226 variables.put("personaModelVersion", "1.0");
227 variables.put("vfModuleName", "STMTN5MMSC21-PCRF::module-1-0");
228 variables.put("vfModuleModelName", "STMTN5MMSC21-PCRF::model-1-0");
229 variables.put("mso-request-id", UUID.randomUUID().toString());
230 String processId = invokeSubProcess("CreateAAIVfModule", variables);
231 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "CreateAAIVfModule", "WorkflowException",processId);
232 Assert.assertEquals(5000, exception.getErrorCode());
233 Assert.assertEquals(true, exception.getErrorMessage().contains("<messageId>SVC3002</messageId>"));
234 logger.debug(exception.getErrorMessage());
237 public static void MockAAICreateGenericVnf(){
238 stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*"))
239 .withRequestBody(containing("<service-id>00000000-0000-0000-0000-000000000000</service-id>"))
240 .willReturn(aResponse()
242 stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*"))
243 .withRequestBody(containing("<service-id>99999999-9999-9999-9999-999999999999</service-id>"))
244 .willReturn(aResponse()
246 .withHeader("Content-Type", "text/xml")
247 .withBodyFile("aaiFault.xml")));
250 // start of mocks used locally and by other VF Module unit tests
251 public static void MockAAIVfModulePUT(boolean isCreate){
252 stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*/vf-modules/vf-module/.*"))
253 .withRequestBody(containing("MMSC"))
254 .willReturn(aResponse()
255 .withStatus(isCreate ? 201 : 200)));
256 stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*/vf-modules/vf-module/.*"))
257 .withRequestBody(containing("PCRF"))
258 .willReturn(aResponse()
260 .withHeader("Content-Type", "text/xml")
261 .withBodyFile("aaiFault.xml")));
262 stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/a27ce5a9-29c4-4c22-a017-6615ac73c721"))
263 .willReturn(aResponse()