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