f98e4477aaae5614e3b17b0498ca315e8d0b28f5
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / common / DeleteAAIVfModuleIT.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
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 
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0 
12  * 
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========================================================= 
19  */ 
20
21 package org.onap.so.bpmn.common;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
26 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
28
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.UUID;
32
33 import org.camunda.bpm.engine.RuntimeService;
34 import org.camunda.bpm.engine.test.Deployment;
35 import org.junit.Assert;
36 import org.junit.Test;
37 import org.onap.so.BaseIntegrationTest;
38 import org.onap.so.bpmn.core.WorkflowException;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 /**
43  * Unit test for DeleteAAIVfModule.bpmn.
44  */
45
46 public class DeleteAAIVfModuleIT extends BaseIntegrationTest {
47         private static final String EOL = "\n";
48         
49         Logger logger = LoggerFactory.getLogger(DeleteAAIVfModuleIT.class);
50         
51         @Test   
52         public void  TestDeleteGenericVnfSuccess_200() {
53                 // delete the Base Module and Generic Vnf
54                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c721, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a73
55                 new MockAAIGenericVnfSearch();
56                 new MockAAIDeleteGenericVnf();
57                 new MockAAIDeleteVfModule();
58                 
59                 Map<String, Object> variables = new HashMap<>();
60                 variables.put("isDebugLogEnabled","true");
61                 variables.put("mso-request-id", UUID.randomUUID().toString());
62                 variables.put("DeleteAAIVfModuleRequest","<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\"> <request-info> <action>DELETE_VF_MODULE</action> <source>PORTAL</source> </request-info> <vnf-inputs> <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c721</vnf-id> <vnf-name>STMTN5MMSC21</vnf-name> <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a73</vf-module-id> <vf-module-name>STMTN5MMSC21-MMSC::module-0-0</vf-module-name> </vnf-inputs> <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/> </vnf-request>");
63                 String processId = invokeSubProcess("DeleteAAIVfModule", variables);
64                 String response = BPMNUtil.getVariable(processEngine, "DeleteAAIVfModule", "DAAIVfMod_deleteGenericVnfResponseCode",processId);
65                 String responseCode = BPMNUtil.getVariable(processEngine, "DeleteAAIVfModule", "DAAIVfMod_deleteGenericVnfResponseCode",processId);
66                 Assert.assertEquals("200", responseCode);
67                 logger.debug(response);
68         }
69
70         @Test   
71         public void  TestDeleteVfModuleSuccess_200() {
72                 // delete Add-on Vf Module for existing Generic Vnf
73                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c720, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a75
74                 String request =
75                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
76                         "  <request-info>" + EOL +
77                         "    <action>DELETE_VF_MODULE</action>" + EOL +
78                         "    <source>PORTAL</source>" + EOL +
79                         "  </request-info>" + EOL +
80                         "  <vnf-inputs>" + EOL +
81                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c720</vnf-id>" + EOL +
82                         "    <vnf-name>STMTN5MMSC20</vnf-name>" + EOL +
83                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a75</vf-module-id>" + EOL +
84                         "    <vf-module-name>STMTN5MMSC20-MMSC::module-1-0</vf-module-name>" + EOL +
85                         "  </vnf-inputs>" + EOL +
86                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
87                         "</vnf-request>" + EOL;
88
89                 new MockAAIGenericVnfSearch();
90                 new MockAAIDeleteGenericVnf();
91                 new MockAAIDeleteVfModule();
92                 
93                 Map<String, Object> variables = new HashMap<>();
94                 variables.put("isDebugLogEnabled","true");
95                 variables.put("mso-request-id", UUID.randomUUID().toString());
96                 variables.put("DeleteAAIVfModuleRequest",request);
97                 String processId = invokeSubProcess("DeleteAAIVfModule", variables);
98                 String response = BPMNUtil.getVariable(processEngine, "DeleteAAIVfModule", "DAAIVfMod_deleteVfModuleResponseCode",processId);
99                 String responseCode = BPMNUtil.getVariable(processEngine, "DeleteAAIVfModule", "DAAIVfMod_deleteVfModuleResponseCode",processId);
100                 Assert.assertEquals("200", responseCode);
101                 logger.debug(response);
102         }
103
104         @Test   
105         public void  TestQueryGenericVnfFailure_5000() {
106                 // query Generic Vnf failure (non-404) with A&AI
107                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c723, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a71
108                 String request =
109                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
110                         "  <request-info>" + EOL +
111                         "    <action>DELETE_VF_MODULE</action>" + EOL +
112                         "    <source>PORTAL</source>" + EOL +
113                         "  </request-info>" + EOL +
114                         "  <vnf-inputs>" + EOL +
115                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c723</vnf-id>" + EOL +
116                         "    <vnf-name>STMTN5MMSC23</vnf-name>" + EOL +
117                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a71</vf-module-id>" + EOL +
118                         "    <vf-module-name>STMTN5MMSC20-MMSC::module-1-0</vf-module-name>" + EOL +
119                         "  </vnf-inputs>" + EOL +
120                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
121                         "</vnf-request>" + EOL;
122                 new MockAAIGenericVnfSearch();
123                 new MockAAIDeleteGenericVnf();
124                 new MockAAIDeleteVfModule();
125                 
126                 Map<String, Object> variables = new HashMap<>();
127                 variables.put("isDebugLogEnabled","true");
128                 variables.put("mso-request-id", UUID.randomUUID().toString());
129                 variables.put("DeleteAAIVfModuleRequest",request);
130                 String processId = invokeSubProcess("DeleteAAIVfModule", variables);
131                 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "DeleteAAIVfModule", "WorkflowException",processId);
132                 Assert.assertEquals(5000, exception.getErrorCode());
133                 Assert.assertEquals(true, exception.getErrorMessage().contains("<messageId>SVC3002</messageId>"));
134                 logger.debug(exception.getErrorMessage());
135         }
136
137         @Test   
138         public void  TestQueryGenericVnfFailure_1002() {
139                 // attempt to delete Vf Module for Generic Vnf that does not exist (A&AI returns 404)
140                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c722, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a72
141                 String request =
142                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
143                         "  <request-info>" + EOL +
144                         "    <action>DELETE_VF_MODULE</action>" + EOL +
145                         "    <source>PORTAL</source>" + EOL +
146                         "  </request-info>" + EOL +
147                         "  <vnf-inputs>" + EOL +
148                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c722</vnf-id>" + EOL +
149                         "    <vnf-name>STMTN5MMSC22</vnf-name>" + EOL +
150                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a72</vf-module-id>" + EOL +
151                         "    <vf-module-name>STMTN5MMSC22-MMSC::module-1-0</vf-module-name>" + EOL +
152                         "  </vnf-inputs>" + EOL +
153                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
154                         "</vnf-request>" + EOL;
155                 new MockAAIGenericVnfSearch();
156                 new MockAAIDeleteGenericVnf();
157                 new MockAAIDeleteVfModule();
158                 
159                 Map<String, Object> variables = new HashMap<>();
160                 variables.put("isDebugLogEnabled","true");
161                 variables.put("mso-request-id", UUID.randomUUID().toString());
162                 variables.put("DeleteAAIVfModuleRequest",request);
163                 String processId = invokeSubProcess("DeleteAAIVfModule", variables);
164                 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "DeleteAAIVfModule", "WorkflowException",processId);
165                 Assert.assertEquals(1002, exception.getErrorCode());
166                 Assert.assertEquals(true, exception.getErrorMessage().contains("Generic VNF Not Found"));
167                 logger.debug(exception.getErrorMessage());
168         }
169
170         @Test   
171         public void  TestDeleteGenericVnfFailure_5000() {
172                 // A&AI failure (non-200) when attempting to delete a Generic Vnf
173                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c718, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a78
174                 String request =
175                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
176                         "  <request-info>" + EOL +
177                         "    <action>DELETE_VF_MODULE</action>" + EOL +
178                         "    <source>PORTAL</source>" + EOL +
179                         "  </request-info>" + EOL +
180                         "  <vnf-inputs>" + EOL +
181                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c718</vnf-id>" + EOL +
182                         "    <vnf-name>STMTN5MMSC18</vnf-name>" + EOL +
183                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a78</vf-module-id>" + EOL +
184                         "    <vf-module-name>STMTN5MMSC18-MMSC::module-0-0</vf-module-name>" + EOL +
185                         "  </vnf-inputs>" + EOL +
186                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
187                         "</vnf-request>" + EOL;
188                 new MockAAIGenericVnfSearch();
189                 new MockAAIDeleteGenericVnf();
190                 new MockAAIDeleteVfModule();
191                 
192                 Map<String, Object> variables = new HashMap<>();
193                 variables.put("isDebugLogEnabled","true");
194                 variables.put("mso-request-id", UUID.randomUUID().toString());
195                 variables.put("DeleteAAIVfModuleRequest",request);
196                 String processId = invokeSubProcess("DeleteAAIVfModule", variables);
197                 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "DeleteAAIVfModule", "WorkflowException",processId);
198                 Assert.assertEquals(5000, exception.getErrorCode());
199                 Assert.assertEquals(true, exception.getErrorMessage().contains("<messageId>SVC3002</messageId>"));
200                 logger.debug(exception.getErrorMessage());
201         }
202         
203         @Test   
204         public void  TestDeleteVfModuleFailure_5000() {
205                 // A&AI failure (non-200) when attempting to delete a Vf Module
206                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c719, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a77
207                 String request =
208                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
209                         "  <request-info>" + EOL +
210                         "    <action>DELETE_VF_MODULE</action>" + EOL +
211                         "    <source>PORTAL</source>" + EOL +
212                         "  </request-info>" + EOL +
213                         "  <vnf-inputs>" + EOL +
214                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c719</vnf-id>" + EOL +
215                         "    <vnf-name>STMTN5MMSC19</vnf-name>" + EOL +
216                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a77</vf-module-id>" + EOL +
217                         "    <vf-module-name>STMTN5MMSC19-MMSC::module-1-0</vf-module-name>" + EOL +
218                         "  </vnf-inputs>" + EOL +
219                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
220                         "</vnf-request>" + EOL;
221                 new MockAAIGenericVnfSearch();
222                 new MockAAIDeleteGenericVnf();
223                 new MockAAIDeleteVfModule();
224                 
225                 Map<String, Object> variables = new HashMap<>();
226                 variables.put("isDebugLogEnabled","true");
227                 variables.put("mso-request-id", UUID.randomUUID().toString());
228                 variables.put("DeleteAAIVfModuleRequest",request);
229                 String processId = invokeSubProcess("DeleteAAIVfModule", variables);
230                 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "DeleteAAIVfModule", "WorkflowException",processId);
231                 Assert.assertEquals(5000, exception.getErrorCode());
232                 Assert.assertEquals(true, exception.getErrorMessage().contains("<messageId>SVC3002</messageId>"));
233                 logger.debug(exception.getErrorMessage());
234         }
235         
236         @Test   
237         public void  TestDeleteVfModuleFailure_1002_1() {
238                 // failure attempting to delete Base Module when not the last Vf Module
239                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c720, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a74
240                 String request =
241                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
242                         "  <request-info>" + EOL +
243                         "    <action>DELETE_VF_MODULE</action>" + EOL +
244                         "    <source>PORTAL</source>" + EOL +
245                         "  </request-info>" + EOL +
246                         "  <vnf-inputs>" + EOL +
247                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c720</vnf-id>" + EOL +
248                         "    <vnf-name>STMTN5MMSC20</vnf-name>" + EOL +
249                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a74</vf-module-id>" + EOL +
250                         "    <vf-module-name>STMTN5MMSC20-MMSC::module-0-0</vf-module-name>" + EOL +
251                         "  </vnf-inputs>" + EOL +
252                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
253                         "</vnf-request>" + EOL;
254                 new MockAAIGenericVnfSearch();
255                 new MockAAIDeleteGenericVnf();
256                 new MockAAIDeleteVfModule();
257                 
258                 Map<String, Object> variables = new HashMap<>();
259                 variables.put("isDebugLogEnabled","true");
260                 variables.put("mso-request-id", UUID.randomUUID().toString());
261                 variables.put("DeleteAAIVfModuleRequest",request);
262                 String processId = invokeSubProcess("DeleteAAIVfModule", variables);
263                 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "DeleteAAIVfModule", "WorkflowException",processId);
264                 Assert.assertEquals(1002, exception.getErrorCode());
265                 Assert.assertEquals(true, exception.getErrorMessage().contains("is Base Module, not Last Module"));
266                 logger.debug(exception.getErrorMessage());
267         }
268
269         @Test   
270         public void  TestDeleteVfModuleFailure_1002_2() {
271                 // failure attempting to delete a Vf Module that does not exist (A&AI returns 404)
272                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c720, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a76
273                 new MockAAIGenericVnfSearch();
274                 new MockAAIDeleteGenericVnf();
275                 new MockAAIDeleteVfModule();
276                 
277                 Map<String, Object> variables = new HashMap<>();
278                 variables.put("isDebugLogEnabled","true");
279                 variables.put("mso-request-id", UUID.randomUUID().toString());
280                 variables.put("DeleteAAIVfModuleRequest","<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\"> <request-info> <action>DELETE_VF_MODULE</action> <source>PORTAL</source> </request-info> <vnf-inputs> <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c720</vnf-id> <vnf-name>STMTN5MMSC20</vnf-name> <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a76</vf-module-id> <vf-module-name>STMTN5MMSC20-MMSC::module-2-0</vf-module-name> </vnf-inputs> <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/> </vnf-request>");
281                 String processId = invokeSubProcess("DeleteAAIVfModule", variables);
282                 WorkflowException exception = BPMNUtil.getRawVariable(processEngine, "DeleteAAIVfModule", "WorkflowException",processId);
283                 Assert.assertEquals(1002, exception.getErrorCode());
284                 Assert.assertEquals(true, exception.getErrorMessage().contains("does not exist for Generic Vnf Id"));
285                 logger.debug(exception.getErrorMessage());
286         }
287 }
288