fac156e86d2af740265f69407de8450faf0ba2f3
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DeleteVfModuleVolumeInfraV1Test.groovy
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.scripts;
22
23 import static org.junit.Assert.*
24 import static org.mockito.Mockito.*
25
26 import org.apache.commons.lang3.*
27 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
28 import org.junit.Before
29 import org.junit.Ignore
30 import org.junit.Test
31 import org.junit.runner.RunWith
32 import org.mockito.MockitoAnnotations
33 import org.mockito.runners.MockitoJUnitRunner
34 import org.openecomp.mso.bpmn.common.scripts.MsoGroovyTest
35 import org.openecomp.mso.bpmn.core.WorkflowException
36
37
38 @RunWith(MockitoJUnitRunner.class)
39 class DeleteVfModuleVolumeInfraV1Test extends MsoGroovyTest {
40
41         def deleteVnfAdapterRequestXml = """<deleteVolumeGroupRequest>
42    <cloudSiteId>RDM2WAGPLCP</cloudSiteId>
43    <tenantId>fba1bd1e195a404cacb9ce17a9b2b421</tenantId>
44    <volumeGroupId>78987</volumeGroupId>
45    <volumeGroupStackId/>
46    <skipAAI>true</skipAAI>
47    <msoRequest>
48       <requestId>TEST-REQUEST-ID-0123</requestId>
49       <serviceInstanceId>1234</serviceInstanceId>
50    </msoRequest>
51    <messageId>ebb9ef7b-a6a5-40e6-953e-f868f1767677</messageId>
52    <notificationUrl>http://localhost:28080/mso/WorkflowMessage/VNFAResponse/ebb9ef7b-a6a5-40e6-953e-f868f1767677</notificationUrl>
53 </deleteVolumeGroupRequest>"""
54         
55         def dbRequestXml = """<soapenv:Envelope xmlns:req="http://org.openecomp.mso/requestsdb"
56                   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
57    <soapenv:Header/>
58    <soapenv:Body>
59       <req:updateInfraRequest>
60          <requestId>TEST-REQUEST-ID-0123</requestId>
61          <lastModifiedBy>BPMN</lastModifiedBy>
62          <statusMessage>VolumeGroup successfully deleted</statusMessage>
63          <requestStatus>COMPLETE</requestStatus>
64          <progress>100</progress>
65          <vnfOutputs/>
66       </req:updateInfraRequest>
67    </soapenv:Body>
68 </soapenv:Envelope>"""
69         
70         def completionRequestXml = """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
71                             xmlns:ns="http://org.openecomp/mso/request/types/v1"
72                             xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
73    <request-info>
74       <request-id>TEST-REQUEST-ID-0123</request-id>
75       <action>DELETE</action>
76       <source>VID</source>
77    </request-info>
78    <aetgt:status-message>Volume Group has been deleted successfully.</aetgt:status-message>
79    <aetgt:mso-bpel-name>BPMN VF Module Volume action: DELETE</aetgt:mso-bpel-name>
80 </aetgt:MsoCompletionRequest>"""
81         
82         def falloutHandlerRequestXml = """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
83                              xmlns:ns="http://org.openecomp/mso/request/types/v1"
84                              xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
85    <request-info>
86       <request-id>TEST-REQUEST-ID-0123</request-id>
87       <action>DELETE</action>
88       <source>VID</source>
89    </request-info>
90    <aetgt:WorkflowException>
91       <aetgt:ErrorMessage>Unexpected Error</aetgt:ErrorMessage>
92       <aetgt:ErrorCode>5000</aetgt:ErrorCode>
93    </aetgt:WorkflowException>
94 </aetgt:FalloutHandlerRequest>"""
95         
96         @Before
97         public void init()
98         {
99                 MockitoAnnotations.initMocks(this)
100         }
101         
102         
103         @Test
104         public void testPrepareVnfAdapterDeleteRequest() {
105                 
106                 ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1')
107                 when(mockExecution.getVariable("DELVfModVol_cloudRegion")).thenReturn('RDM2WAGPLCP')
108                 when(mockExecution.getVariable("DELVfModVol_tenantId")).thenReturn('fba1bd1e195a404cacb9ce17a9b2b421')
109                 when(mockExecution.getVariable("DELVfModVol_volumeGroupId")).thenReturn('78987')
110                 when(mockExecution.getVariable("DELVfModVol_volumeGroupHeatStackId")).thenReturn('')
111                 when(mockExecution.getVariable("DELVfModVol_requestId")).thenReturn('TEST-REQUEST-ID-0123')
112                 when(mockExecution.getVariable("DELVfModVol_serviceId")).thenReturn('1234')
113                 when(mockExecution.getVariable("DELVfModVol_messageId")).thenReturn('ebb9ef7b-a6a5-40e6-953e-f868f1767677')
114                 when(mockExecution.getVariable("URN_mso_workflow_message_endpoint")).thenReturn('http://localhost:28080/mso/WorkflowMessage')
115                 when(mockExecution.getVariable("URN_mso_use_qualified_host")).thenReturn('')
116
117                 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
118                 myproc.prepareVnfAdapterDeleteRequest(mockExecution, 'true')
119                 
120                 verify(mockExecution).setVariable("DELVfModVol_deleteVnfARequest", deleteVnfAdapterRequestXml)
121
122         }
123         
124         @Test
125         //@Ignore
126         public void testPrepareDbRequest() {
127                 
128                 ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1')
129                 when(mockExecution.getVariable("DELVfModVol_requestId")).thenReturn('TEST-REQUEST-ID-0123')
130                 when(mockExecution.getVariable("DELVfModVol_volumeOutputs")).thenReturn('')
131                 when(mockExecution.getVariable("URN_mso_adapters_db_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
132                 when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
133                 
134                 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
135                 myproc.prepareDBRequest(mockExecution, 'true')
136                 
137                 verify(mockExecution).setVariable("DELVfModVol_updateInfraRequest", dbRequestXml)
138         }
139
140         @Test
141         public void testPrepareCompletionHandlerRequest() {
142                 
143                 ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1')
144                 when(mockExecution.getVariable("mso-request-id")).thenReturn('TEST-REQUEST-ID-0123')
145                 when(mockExecution.getVariable("DELVfModVol_source")).thenReturn('VID')
146                 
147                 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
148                 myproc.prepareCompletionHandlerRequest(mockExecution, 'true')
149                 
150                 verify(mockExecution).setVariable("DELVfModVol_CompleteMsoProcessRequest", completionRequestXml)
151         }
152         
153         @Test
154         public void testPrepareFalloutHandler() {
155                 
156                 WorkflowException workflowException = new WorkflowException('DeleteVfModuleVolumeInfraV1', 5000, 'Unexpected Error')
157                 
158                 ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1')
159                 
160                 when(mockExecution.getVariable("DELVfModVol_requestId")).thenReturn('TEST-REQUEST-ID-0123')
161                 when(mockExecution.getVariable("WorkflowException")).thenReturn(workflowException)
162                 when(mockExecution.getVariable("DELVfModVol_source")).thenReturn('VID')
163                 
164                 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
165                 myproc.prepareFalloutHandler(mockExecution, 'true')
166                 
167                 verify(mockExecution).setVariable("DELVfModVol_Success", false)
168                 verify(mockExecution).setVariable("DELVfModVol_FalloutHandlerRequest", falloutHandlerRequestXml)
169         }
170 }