2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
23 import static org.junit.Assert.*
24 import static org.mockito.Mockito.*
26 import org.apache.commons.lang3.*
27 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
28 import org.junit.Before
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
37 @RunWith(MockitoJUnitRunner.class)
38 class DeleteVfModuleVolumeInfraV1Test extends MsoGroovyTest {
40 def deleteVnfAdapterRequestXml = """<deleteVolumeGroupRequest>
41 <cloudSiteId>RDM2WAGPLCP</cloudSiteId>
42 <tenantId>fba1bd1e195a404cacb9ce17a9b2b421</tenantId>
43 <volumeGroupId>78987</volumeGroupId>
45 <skipAAI>true</skipAAI>
47 <requestId>TEST-REQUEST-ID-0123</requestId>
48 <serviceInstanceId>1234</serviceInstanceId>
50 <messageId>ebb9ef7b-a6a5-40e6-953e-f868f1767677</messageId>
51 <notificationUrl>http://localhost:28080/mso/WorkflowMessage/VNFAResponse/ebb9ef7b-a6a5-40e6-953e-f868f1767677</notificationUrl>
52 </deleteVolumeGroupRequest>"""
54 def dbRequestXml = """<soapenv:Envelope xmlns:req="http://org.openecomp.mso/requestsdb"
55 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
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>
65 </req:updateInfraRequest>
67 </soapenv:Envelope>"""
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">
73 <request-id>TEST-REQUEST-ID-0123</request-id>
74 <action>DELETE</action>
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>"""
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">
85 <request-id>TEST-REQUEST-ID-0123</request-id>
86 <action>DELETE</action>
89 <aetgt:WorkflowException>
90 <aetgt:ErrorMessage>Unexpected Error</aetgt:ErrorMessage>
91 <aetgt:ErrorCode>5000</aetgt:ErrorCode>
92 </aetgt:WorkflowException>
93 </aetgt:FalloutHandlerRequest>"""
98 MockitoAnnotations.initMocks(this)
103 public void testPrepareVnfAdapterDeleteRequest() {
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('')
116 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
117 myproc.prepareVnfAdapterDeleteRequest(mockExecution, 'true')
119 verify(mockExecution).setVariable("DELVfModVol_deleteVnfARequest", deleteVnfAdapterRequestXml)
124 public void testPrepareDbRequest() {
126 ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1')
127 when(mockExecution.getVariable("DELVfModVol_requestId")).thenReturn('TEST-REQUEST-ID-0123')
128 when(mockExecution.getVariable("DELVfModVol_volumeOutputs")).thenReturn('')
130 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
131 myproc.prepareDBRequest(mockExecution, 'true')
133 verify(mockExecution).setVariable("DELVfModVol_updateInfraRequest", dbRequestXml)
137 public void testPrepareCompletionHandlerRequest() {
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')
143 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
144 myproc.prepareCompletionHandlerRequest(mockExecution, 'true')
146 verify(mockExecution).setVariable("DELVfModVol_CompleteMsoProcessRequest", completionRequestXml)
150 public void testPrepareFalloutHandler() {
152 WorkflowException workflowException = new WorkflowException('DeleteVfModuleVolumeInfraV1', 5000, 'Unexpected Error')
154 ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1')
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')
160 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
161 myproc.prepareFalloutHandler(mockExecution, 'true')
163 verify(mockExecution).setVariable("DELVfModVol_Success", false)
164 verify(mockExecution).setVariable("DELVfModVol_FalloutHandlerRequest", falloutHandlerRequestXml)