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