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