[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / DoDeleteVfModuleTest.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * OPENECOMP - MSO 
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.openecomp.mso.bpmn.infrastructure;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.containing;
25 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
26 import static com.github.tomakehurst.wiremock.client.WireMock.post;
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.urlEqualTo;
30 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
31 import static org.openecomp.mso.bpmn.common.DeleteAAIVfModuleTest.MockAAIDeleteGenericVnf;
32 import static org.openecomp.mso.bpmn.common.DeleteAAIVfModuleTest.MockAAIDeleteVfModule;
33 import static org.openecomp.mso.bpmn.common.DeleteAAIVfModuleTest.MockAAIGenericVnfSearch;
34
35 import java.io.IOException;
36 import java.util.HashMap;
37 import java.util.Map;
38 import java.util.UUID;
39
40 import org.camunda.bpm.engine.test.Deployment;
41 import org.junit.Assert;
42 import org.junit.Test;
43 import org.openecomp.mso.bpmn.common.WorkflowTest;
44 import org.openecomp.mso.bpmn.common.WorkflowTest.CallbackSet;
45 import org.openecomp.mso.bpmn.core.WorkflowException;
46
47 /**
48  * Unit test for DoDeleteVfModule.bpmn.
49  */
50 public class DoDeleteVfModuleTest extends WorkflowTest {
51         private final CallbackSet callbacks = new CallbackSet();
52         
53         private static final String EOL = "\n";
54
55         private final String vnfAdapterDeleteCallback = 
56                 "<deleteVfModuleResponse>" + EOL +
57                 "    <vnfId>a27ce5a9-29c4-4c22-a017-6615ac73c721</vnfId>" + EOL +
58                 "    <vfModuleId>973ed047-d251-4fb9-bf1a-65b8949e0a73</vfModuleId>" + EOL +
59                 "    <vfModuleDeleted>true</vfModuleDeleted>" + EOL +
60                 "    <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
61                 "</deleteVfModuleResponse>" + EOL;
62                         
63         private final String vnfAdapterDeleteCallbackFail = 
64                         "<vfModuleException>" + EOL +
65                         "    <message>Error processing request to VNF-Async. Not Found.</message>" + EOL +
66                         "    <category>INTERNAL</category>" + EOL +
67                         "    <rolledBack>false</rolledBack>" + EOL +
68                         "    <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
69                         "</vfModuleException>" + EOL;
70                                 
71         private final String sdncAdapterDeleteCallback =
72                 "<output xmlns=\"org:openecomp:sdnctl:l3api\">" + EOL +
73                 "  <svc-request-id>{{REQUEST-ID}}</svc-request-id>" + EOL +
74                 "  <ack-final-indicator>Y</ack-final-indicator>" + EOL +
75                 "</output>" + EOL;
76         
77         public DoDeleteVfModuleTest() throws IOException {
78                 callbacks.put("sdncChangeDelete", sdncAdapterDeleteCallback);
79                 callbacks.put("sdncDelete", sdncAdapterDeleteCallback);
80                 callbacks.put("vnfDelete", vnfAdapterDeleteCallback);
81                 callbacks.put("vnfDeleteFail", vnfAdapterDeleteCallbackFail);
82         }
83         
84         private final String wfeString = "WorkflowException";
85
86         @Test
87         @Deployment(resources = {
88                         "subprocess/DoDeleteVfModule.bpmn",
89                         "subprocess/PrepareUpdateAAIVfModule.bpmn",
90                         "subprocess/UpdateAAIVfModule.bpmn",
91                         "subprocess/UpdateAAIGenericVnf.bpmn",
92                         "subprocess/DeleteAAIVfModule.bpmn",
93                         "subprocess/SDNCAdapterV1.bpmn",
94                         "subprocess/VnfAdapterRestV1.bpmn"
95                 })
96         public void  TestDoDeleteVfModuleSuccess() {
97                 // delete the Base Module and Generic Vnf
98                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c721, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a73
99                 String request =
100                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
101                         "  <request-info>" + EOL +
102                         "    <action>DELETE_VF_MODULE</action>" + EOL +
103                         "    <source>PORTAL</source>" + EOL +
104                         "  </request-info>" + EOL +
105                         "  <vnf-inputs>" + EOL +
106                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c721</vnf-id>" + EOL +
107                         "    <vnf-name>STMTN5MMSC21</vnf-name>" + EOL +
108                         "    <vnf-type>asc_heat-int</vnf-type>" + EOL +
109                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a73</vf-module-id>" + EOL +
110                         "    <vf-module-name>STMTN5MMSC21-MMSC::module-0-0</vf-module-name>" + EOL +
111                         "    <service-id>00000000-0000-0000-0000-000000000000</service-id>" + EOL +
112                         "    <service-type>SDN-ETHERNET-INTERNET</service-type>" + EOL +
113                         "    <tenant-id>fba1bd1e195a404cacb9ce17a9b2b421</tenant-id>" + EOL +
114                         "    <orchestration-status>pending-delete</orchestration-status>" + EOL +
115                         "    <aic-cloud-region>RDM2WAGPLCP</aic-cloud-region>" + EOL +
116                         "  </vnf-inputs>" + EOL +
117                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
118                         "</vnf-request>" + EOL;
119                 logStart();
120                 MockDoDeleteVfModule_SDNCSuccess();
121                 MockDoDeleteVfModule_DeleteVNFSuccess();
122                 MockAAIGenericVnfSearch();
123                 MockAAIVfModulePUT(false);
124                 MockAAIDeleteGenericVnf();
125                 MockAAIDeleteVfModule();
126                 String businessKey = UUID.randomUUID().toString();
127                 Map<String, Object> variables = new HashMap<String, Object>();          
128                 variables.put("isDebugLogEnabled","true");
129                 variables.put("mso-request-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
130                 variables.put("mso-service-instance-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
131                 variables.put("DoDeleteVfModuleRequest",request);
132                 variables.put("isVidRequest", "true");
133                 invokeSubProcess("DoDeleteVfModule", businessKey, variables);
134
135                 // "changedelete" operation not required for deleting a Vf Module
136 //              injectSDNCCallbacks(callbacks, "sdncChangeDelete");
137                 injectVNFRestCallbacks(callbacks, "vnfDelete");
138                 waitForRunningProcessCount("vnfAdapterDeleteV1", 0, 120000);
139                 injectSDNCCallbacks(callbacks, "sdncDelete");
140
141                 waitForProcessEnd(businessKey, 10000);
142                 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, wfeString);
143                 checkVariable(businessKey, wfeString, null);
144                 if (wfe != null) {
145                         System.out.println("TestDoDeleteVfModuleSuccess: ErrorCode=" + wfe.getErrorCode() +
146                                         ", ErrorMessage=" + wfe.getErrorMessage());
147                 }
148                 logEnd();
149         }
150
151         @Test
152         @Deployment(resources = {
153                         "subprocess/DoDeleteVfModule.bpmn",
154                         "subprocess/PrepareUpdateAAIVfModule.bpmn",
155                         "subprocess/UpdateAAIVfModule.bpmn",
156                         "subprocess/UpdateAAIGenericVnf.bpmn",
157                         "subprocess/DeleteAAIVfModule.bpmn",
158                         "subprocess/SDNCAdapterV1.bpmn",
159                         "subprocess/VnfAdapterRestV1.bpmn"
160                 })
161         public void  TestDoDeleteVfModule_Building_Block_Success() {
162                 logStart();
163                 MockDoDeleteVfModule_SDNCSuccess();
164                 MockDoDeleteVfModule_DeleteVNFSuccess();
165                 MockAAIGenericVnfSearch();
166                 MockAAIVfModulePUT(false);
167                 MockAAIDeleteGenericVnf();
168                 MockAAIDeleteVfModule();
169                 String businessKey = UUID.randomUUID().toString();
170                 Map<String, Object> variables = new HashMap<String, Object>();          
171                 
172                 variables.put("mso-request-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");        
173                 variables.put("requestId", "a27ce5a9-29c4-4c22-a017-6615ac73c721");             
174                 variables.put("isDebugLogEnabled","true");
175                 variables.put("vnfId", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
176                 variables.put("vfModuleId", "973ed047-d251-4fb9-bf1a-65b8949e0a73");
177                 variables.put("serviceInstanceId", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
178                 variables.put("vfModuleName", "STMTN5MMSC21-MMSC::module-0-0");
179                 variables.put("sdncVersion", "1610");
180                 variables.put("isVidRequest", "true");
181                 String vfModuleModelInfo = "{" + "\"modelType\": \"vnf\"," +
182                                 "\"modelInvariantId\": \"ff5256d2-5a33-55df-13ab-12abad84e7ff\"," + 
183                                 "\"modelNameVersionId\": \"fe6478e5-ea33-3346-ac12-ab121484a3fe\"," +
184                                 "\"modelName\": \"vSAMP12\"," +
185                                 "\"modelVersion\": \"1.0\"," + 
186                                 "\"modelCustomizationId\": \"MODEL-ID-1234\"," + 
187                                 "}";
188                 variables.put("vfModuleModelInfo", vfModuleModelInfo);
189                         
190                 String cloudConfiguration = "{" + 
191                                 "\"lcpCloudRegionId\": \"RDM2WAGPLCP\"," +              
192                                 "\"tenantId\": \"fba1bd1e195a404cacb9ce17a9b2b421\"" + "}";
193                 variables.put("cloudConfiguration", cloudConfiguration);
194         
195                 
196                 invokeSubProcess("DoDeleteVfModule", businessKey, variables);
197
198                 // "changedelete" operation not required for deleting a Vf Module
199 //              injectSDNCCallbacks(callbacks, "sdncChangeDelete");
200                 injectVNFRestCallbacks(callbacks, "vnfDelete");
201                 waitForRunningProcessCount("vnfAdapterDeleteV1", 0, 120000);
202                 injectSDNCCallbacks(callbacks, "sdncDelete");
203
204                 waitForProcessEnd(businessKey, 10000);
205                 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, wfeString);
206                 checkVariable(businessKey, wfeString, null);
207                 if (wfe != null) {
208                         System.out.println("TestDoDeleteVfModule_Building_Block_Success: ErrorCode=" + wfe.getErrorCode() +
209                                         ", ErrorMessage=" + wfe.getErrorMessage());
210                 }
211                 logEnd();
212         }
213
214         
215         @Test
216         @Deployment(resources = {
217                         "subprocess/DoDeleteVfModule.bpmn",
218                         "subprocess/PrepareUpdateAAIVfModule.bpmn",
219                         "subprocess/UpdateAAIVfModule.bpmn",
220                         "subprocess/UpdateAAIGenericVnf.bpmn",
221                         "subprocess/DeleteAAIVfModule.bpmn",
222                         "subprocess/SDNCAdapterV1.bpmn",
223                         "subprocess/VnfAdapterRestV1.bpmn"
224                 })
225         public void  TestDoDeleteVfModuleSDNCFailure() {
226                 // delete the Base Module and Generic Vnf - SDNCAdapter failure
227                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c721, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a73
228                 String request =
229                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
230                         "  <request-info>" + EOL +
231                         "    <action>DELETE_VF_MODULE</action>" + EOL +
232                         "    <source>PORTAL</source>" + EOL +
233                         "  </request-info>" + EOL +
234                         "  <vnf-inputs>" + EOL +
235                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c721</vnf-id>" + EOL +
236                         "    <vnf-name>STMTN5MMSC21</vnf-name>" + EOL +
237                         "    <vnf-type>asc_heat-int</vnf-type>" + EOL +
238                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a73</vf-module-id>" + EOL +
239                         "    <vf-module-name>STMTN5MMSC21-MMSC::module-0-0</vf-module-name>" + EOL +
240                         "    <service-id>00000000-0000-0000-0000-000000000000</service-id>" + EOL +
241                         "    <service-type>SDN-ETHERNET-INTERNET</service-type>" + EOL +
242                         "    <tenant-id>fba1bd1e195a404cacb9ce17a9b2b421</tenant-id>" + EOL +
243                         "    <orchestration-status>pending-delete</orchestration-status>" + EOL +
244                         "    <aic-cloud-region>RDM2WAGPLCP</aic-cloud-region>" + EOL +
245                         "  </vnf-inputs>" + EOL +
246                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
247                         "</vnf-request>" + EOL;
248
249                 logStart();
250                 MockDoDeleteVfModule_SDNCFailure();
251                 MockDoDeleteVfModule_DeleteVNFSuccess();
252                 MockAAIGenericVnfSearch();
253                 MockAAIVfModulePUT(false);
254                 MockAAIDeleteGenericVnf();
255                 MockAAIDeleteVfModule();
256                 String businessKey = UUID.randomUUID().toString();
257                 Map<String, Object> variables = new HashMap<String, Object>();          
258                 variables.put("isDebugLogEnabled","true");
259                 variables.put("mso-request-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
260                 variables.put("mso-service-instance-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
261                 variables.put("DoDeleteVfModuleRequest", request);
262                 variables.put("isVidRequest", "true");
263                 invokeSubProcess("DoDeleteVfModule", businessKey, variables);
264
265                 // "changedelete" operation not required for deleting a Vf Module
266 //              injectSDNCCallbacks(callbacks, "sdncChangeDelete");
267                 injectVNFRestCallbacks(callbacks, "vnfDelete");
268                 waitForRunningProcessCount("vnfAdapterDeleteV1", 0, 120000);
269                 // cause a failure by not injecting a callback
270 //              injectSDNCCallbacks(callbacks, "sdncDelete");
271
272                 waitForProcessEnd(businessKey, 10000);
273                 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, wfeString);
274                 Assert.assertNotNull(wfe);
275                 if (wfe != null) {
276                         System.out.println("TestDoDeleteVfModuleSDNCFailure: ErrorCode=" + wfe.getErrorCode() +
277                                         ", ErrorMessage=" + wfe.getErrorMessage());
278                         Assert.assertTrue(wfe.getErrorCode() == 7000);
279                         Assert.assertTrue(wfe.getErrorMessage().startsWith("Could not communicate"));
280                 }
281                 logEnd();
282         }
283
284         @Test
285         @Deployment(resources = {
286                         "subprocess/DoDeleteVfModule.bpmn",
287                         "subprocess/PrepareUpdateAAIVfModule.bpmn",
288                         "subprocess/UpdateAAIVfModule.bpmn",
289                         "subprocess/UpdateAAIGenericVnf.bpmn",
290                         "subprocess/DeleteAAIVfModule.bpmn",
291                         "subprocess/SDNCAdapterV1.bpmn",
292                         "subprocess/VnfAdapterRestV1.bpmn"
293                 })
294         public void  TestDoDeleteVfModuleSDNCCallbackFailure() {
295                 // delete the Base Module and Generic Vnf - SDNCAdapter Callback failure
296                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c721, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a73
297                 String request =
298                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
299                         "  <request-info>" + EOL +
300                         "    <action>DELETE_VF_MODULE</action>" + EOL +
301                         "    <source>PORTAL</source>" + EOL +
302                         "  </request-info>" + EOL +
303                         "  <vnf-inputs>" + EOL +
304                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c721</vnf-id>" + EOL +
305                         "    <vnf-name>STMTN5MMSC21</vnf-name>" + EOL +
306                         "    <vnf-type>asc_heat-int</vnf-type>" + EOL +
307                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a73</vf-module-id>" + EOL +
308                         "    <vf-module-name>STMTN5MMSC21-MMSC::module-0-0</vf-module-name>" + EOL +
309                         "    <service-id>00000000-0000-0000-0000-000000000000</service-id>" + EOL +
310                         "    <service-type>SDN-ETHERNET-INTERNET</service-type>" + EOL +
311                         "    <tenant-id>fba1bd1e195a404cacb9ce17a9b2b421</tenant-id>" + EOL +
312                         "    <orchestration-status>pending-delete</orchestration-status>" + EOL +
313                         "    <aic-cloud-region>RDM2WAGPLCP</aic-cloud-region>" + EOL +
314                         "  </vnf-inputs>" + EOL +
315                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
316                         "</vnf-request>" + EOL;
317
318                 logStart();
319                 MockDoDeleteVfModule_SDNCSuccess();
320                 MockDoDeleteVfModule_DeleteVNFSuccess();
321                 MockAAIGenericVnfSearch();
322                 MockAAIVfModulePUT(false);
323                 MockAAIDeleteGenericVnf();
324                 MockAAIDeleteVfModule();
325                 String businessKey = UUID.randomUUID().toString();
326                 Map<String, Object> variables = new HashMap<String, Object>();          
327                 variables.put("isDebugLogEnabled","true");
328                 variables.put("mso-request-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
329                 variables.put("mso-service-instance-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
330                 variables.put("DoDeleteVfModuleRequest",request);
331                 variables.put("isVidRequest", "true");
332                 invokeSubProcess("DoDeleteVfModule", businessKey, variables);
333
334                 // "changedelete" operation not required for deleting a Vf Module
335 //              injectSDNCCallbacks(callbacks, "sdncChangeDelete:ERR");
336                 injectVNFRestCallbacks(callbacks, "vnfDelete");
337                 waitForRunningProcessCount("vnfAdapterDeleteV1", 0, 120000);
338                 // return a failure in the callback
339                 injectSDNCCallbacks(callbacks, "sdncDelete:ERR");
340
341                 waitForProcessEnd(businessKey, 10000);
342                 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, wfeString);
343                 Assert.assertNotNull(wfe);
344                 if (wfe != null) {
345                         System.out.println("TestDoDeleteVfModuleSDNCCallbackFailure: ErrorCode=" + wfe.getErrorCode() +
346                                         ", ErrorMessage=" + wfe.getErrorMessage());
347                         Assert.assertTrue(wfe.getErrorCode() == 5310);
348                         Assert.assertTrue(wfe.getErrorMessage().startsWith("Received error from SDN-C"));
349                 }
350                 logEnd();
351         }
352
353         @Test
354         @Deployment(resources = {
355                         "subprocess/DoDeleteVfModule.bpmn",
356                         "subprocess/PrepareUpdateAAIVfModule.bpmn",
357                         "subprocess/UpdateAAIVfModule.bpmn",
358                         "subprocess/UpdateAAIGenericVnf.bpmn",
359                         "subprocess/DeleteAAIVfModule.bpmn",
360                         "subprocess/SDNCAdapterV1.bpmn",
361                         "subprocess/VnfAdapterRestV1.bpmn"
362                 })
363         public void  TestDoDeleteVfModuleVNFFailure() {
364                 // delete the Base Module and Generic Vnf - VNFAdapter failure
365                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c721, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a73
366                 String request =
367                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
368                         "  <request-info>" + EOL +
369                         "    <action>DELETE_VF_MODULE</action>" + EOL +
370                         "    <source>PORTAL</source>" + EOL +
371                         "  </request-info>" + EOL +
372                         "  <vnf-inputs>" + EOL +
373                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c721</vnf-id>" + EOL +
374                         "    <vnf-name>STMTN5MMSC21</vnf-name>" + EOL +
375                         "    <vnf-type>asc_heat-int</vnf-type>" + EOL +
376                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a73</vf-module-id>" + EOL +
377                         "    <vf-module-name>STMTN5MMSC21-MMSC::module-0-0</vf-module-name>" + EOL +
378                         "    <service-id>00000000-0000-0000-0000-000000000000</service-id>" + EOL +
379                         "    <service-type>SDN-ETHERNET-INTERNET</service-type>" + EOL +
380                         "    <tenant-id>fba1bd1e195a404cacb9ce17a9b2b421</tenant-id>" + EOL +
381                         "    <orchestration-status>pending-delete</orchestration-status>" + EOL +
382                         "    <aic-cloud-region>RDM2WAGPLCP</aic-cloud-region>" + EOL +
383                         "  </vnf-inputs>" + EOL +
384                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
385                         "</vnf-request>" + EOL;
386
387                 logStart();
388                 MockDoDeleteVfModule_SDNCSuccess();
389                 MockDoDeleteVfModule_DeleteVNFFailure();
390                 MockAAIGenericVnfSearch();
391                 MockAAIVfModulePUT(false);
392                 MockAAIDeleteGenericVnf();
393                 MockAAIDeleteVfModule();
394                 String businessKey = UUID.randomUUID().toString();
395                 Map<String, Object> variables = new HashMap<String, Object>();          
396                 variables.put("isDebugLogEnabled","true");
397                 variables.put("mso-request-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
398                 variables.put("mso-service-instance-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
399                 variables.put("DoDeleteVfModuleRequest",request);
400                 invokeSubProcess("DoDeleteVfModule", businessKey, variables);
401
402                 // "changedelete" operation not required for deleting a Vf Module
403 //              injectSDNCCallbacks(callbacks, "sdncChangeDelete");
404                 // cause a failure by not injecting a callback
405 //              injectVNFRestCallbacks(callbacks, "vnfDelete");
406 //              waitForRunningProcessCount("vnfAdapterDeleteV1", 0, 120000);
407 //              injectSDNCCallbacks(callbacks, "sdncDelete");
408
409                 waitForProcessEnd(businessKey, 10000);
410                 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, wfeString);
411                 Assert.assertNotNull(wfe);
412                 if (wfe != null) {
413                         System.out.println("TestDoDeleteVfModuleVNFFailure: ErrorCode=" + wfe.getErrorCode() +
414                                         ", ErrorMessage=" + wfe.getErrorMessage());
415                         Assert.assertTrue(wfe.getErrorCode() == 7020);
416                         Assert.assertTrue(wfe.getErrorMessage().startsWith("Received error from VnfAdapter"));
417                 }
418                 logEnd();
419         }
420
421         @Test
422         @Deployment(resources = {
423                         "subprocess/DoDeleteVfModule.bpmn",
424                         "subprocess/PrepareUpdateAAIVfModule.bpmn",
425                         "subprocess/UpdateAAIVfModule.bpmn",
426                         "subprocess/UpdateAAIGenericVnf.bpmn",
427                         "subprocess/DeleteAAIVfModule.bpmn",
428                         "subprocess/SDNCAdapterV1.bpmn",
429                         "subprocess/VnfAdapterRestV1.bpmn"
430                 })
431         public void  TestDoDeleteVfModuleVNFCallbackFailure() {
432                 // delete the Base Module and Generic Vnf - VNFAdapter Callback failure
433                 // vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c721, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a73
434                 String request =
435                         "<vnf-request xmlns=\"http://openecomp.org/mso/infra/vnf-request/v1\">" + EOL +
436                         "  <request-info>" + EOL +
437                         "    <action>DELETE_VF_MODULE</action>" + EOL +
438                         "    <source>PORTAL</source>" + EOL +
439                         "  </request-info>" + EOL +
440                         "  <vnf-inputs>" + EOL +
441                         "    <vnf-id>a27ce5a9-29c4-4c22-a017-6615ac73c721</vnf-id>" + EOL +
442                         "    <vnf-name>STMTN5MMSC21</vnf-name>" + EOL +
443                         "    <vnf-type>asc_heat-int</vnf-type>" + EOL +
444                         "    <vf-module-id>973ed047-d251-4fb9-bf1a-65b8949e0a73</vf-module-id>" + EOL +
445                         "    <vf-module-name>STMTN5MMSC21-MMSC::module-0-0</vf-module-name>" + EOL +
446                         "    <service-id>00000000-0000-0000-0000-000000000000</service-id>" + EOL +
447                         "    <service-type>SDN-ETHERNET-INTERNET</service-type>" + EOL +
448                         "    <tenant-id>fba1bd1e195a404cacb9ce17a9b2b421</tenant-id>" + EOL +
449                         "    <orchestration-status>pending-delete</orchestration-status>" + EOL +
450                         "    <aic-cloud-region>RDM2WAGPLCP</aic-cloud-region>" + EOL +
451                         "  </vnf-inputs>" + EOL +
452                         "  <vnf-params xmlns:tns=\"http://openecomp.org/mso/infra/vnf-request/v1\"/>" + EOL +
453                         "</vnf-request>" + EOL;
454
455                 logStart();
456                 MockDoDeleteVfModule_SDNCSuccess();
457                 MockDoDeleteVfModule_DeleteVNFSuccess();
458                 MockAAIGenericVnfSearch();
459                 MockAAIVfModulePUT(false);
460                 MockAAIDeleteGenericVnf();
461                 MockAAIDeleteVfModule();
462                 String businessKey = UUID.randomUUID().toString();
463                 Map<String, Object> variables = new HashMap<String, Object>();          
464                 variables.put("isDebugLogEnabled","true");
465                 variables.put("mso-request-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
466                 variables.put("mso-service-instance-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
467                 variables.put("DoDeleteVfModuleRequest",request);
468                 invokeSubProcess("DoDeleteVfModule", businessKey, variables);
469
470                 // "changedelete" operation not required for deleting a Vf Module
471 //              injectSDNCCallbacks(callbacks, "sdncChangeDelete");
472                 injectVNFRestCallbacks(callbacks, "vnfDeleteFail");
473                 waitForRunningProcessCount("vnfAdapterDeleteV1", 0, 120000);
474 //              injectSDNCCallbacks(callbacks, "sdncDelete");
475
476                 waitForProcessEnd(businessKey, 10000);
477                 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, wfeString);
478                 Assert.assertNotNull(wfe);
479                 if (wfe != null) {
480                         System.out.println("TestDoDeleteVfModuleVNFCallbackFailure: ErrorCode=" + wfe.getErrorCode() +
481                                         ", ErrorMessage=" + wfe.getErrorMessage());
482                         Assert.assertTrue(wfe.getErrorCode() == 7020);
483                         Assert.assertTrue(wfe.getErrorMessage().startsWith("Received vfModuleException from VnfAdapter"));
484                 }
485                 logEnd();
486         }
487
488         // start of mocks used locally and by other VF Module unit tests
489         public static void MockAAIVfModulePUT(boolean isCreate){
490                 stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*/vf-modules/vf-module/.*"))
491                                 .withRequestBody(containing("MMSC"))
492                                 .willReturn(aResponse()
493                                                 .withStatus(isCreate ? 201 : 200)));
494                 stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*/vf-modules/vf-module/.*"))
495                                 .withRequestBody(containing("PCRF"))
496                                 .willReturn(aResponse()
497                                                 .withStatus(500)
498                                                 .withHeader("Content-Type", "text/xml")
499                                                 .withBodyFile("aaiFault.xml")));
500                 stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/a27ce5a9-29c4-4c22-a017-6615ac73c721"))                          
501                                 .willReturn(aResponse()
502                                         .withStatus(200)));
503         }
504
505         public static void MockDoDeleteVfModule_SDNCSuccess() {
506                 stubFor(post(urlEqualTo("/SDNCAdapter"))
507                                   .withRequestBody(containing("SvcAction>changedelete"))
508                                   .willReturn(aResponse()
509                                   .withStatus(200)
510                                   .withHeader("Content-Type", "text/xml")
511                                   .withBodyFile("DeleteGenericVNFV1/sdncAdapterResponse.xml")));
512                 stubFor(post(urlEqualTo("/SDNCAdapter"))
513                                   .withRequestBody(containing("SvcAction>delete"))
514                                   .willReturn(aResponse()
515                                   .withStatus(200)
516                                   .withHeader("Content-Type", "text/xml")
517                                   .withBodyFile("DeleteGenericVNFV1/sdncAdapterResponse.xml")));
518         }
519
520         public static void MockDoDeleteVfModule_SDNCFailure() {
521                 stubFor(post(urlEqualTo("/SDNCAdapter"))
522                                   .withRequestBody(containing("SvcAction>changedelete"))
523                                   .willReturn(aResponse()
524                                   .withStatus(500)));
525                 stubFor(post(urlEqualTo("/SDNCAdapter"))
526                                   .withRequestBody(containing("SvcAction>delete"))
527                                   .willReturn(aResponse()
528                                   .withStatus(500)));
529         }
530
531         public static void MockDoDeleteVfModule_DeleteVNFSuccess() {
532                 stubFor(delete(urlMatching("/vnfs/v1/vnfs/.*/vf-modules/.*"))
533                                 .willReturn(aResponse()
534                                 .withStatus(202)
535                                 .withHeader("Content-Type", "application/xml")));
536                 stubFor(delete(urlMatching("/vnfs/v1/volume-groups/78987"))
537                                 .willReturn(aResponse()
538                                 .withStatus(202)
539                                 .withHeader("Content-Type", "application/xml")));
540         }
541
542         public static void MockDoDeleteVfModule_DeleteVNFFailure() {
543                 stubFor(delete(urlMatching("/vnfs/v1/vnfs/.*/vf-modules/.*"))
544                                 .willReturn(aResponse()
545                                 .withStatus(500)
546                                 .withHeader("Content-Type", "application/xml")));
547         }
548 }
549