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
29 import org.junit.Ignore
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
38 @RunWith(MockitoJUnitRunner.class)
39 class DeleteVfModuleVolumeInfraV1Test extends MsoGroovyTest {
41 def deleteVnfAdapterRequestXml = """<deleteVolumeGroupRequest>
42 <cloudSiteId>RDM2WAGPLCP</cloudSiteId>
43 <tenantId>fba1bd1e195a404cacb9ce17a9b2b421</tenantId>
44 <volumeGroupId>78987</volumeGroupId>
46 <skipAAI>true</skipAAI>
48 <requestId>TEST-REQUEST-ID-0123</requestId>
49 <serviceInstanceId>1234</serviceInstanceId>
51 <messageId>ebb9ef7b-a6a5-40e6-953e-f868f1767677</messageId>
52 <notificationUrl>http://localhost:28080/mso/WorkflowMessage/VNFAResponse/ebb9ef7b-a6a5-40e6-953e-f868f1767677</notificationUrl>
53 </deleteVolumeGroupRequest>"""
55 def dbRequestXml = """<soapenv:Envelope xmlns:req="http://org.openecomp.mso/requestsdb"
56 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
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>
66 </req:updateInfraRequest>
68 </soapenv:Envelope>"""
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">
74 <request-id>TEST-REQUEST-ID-0123</request-id>
75 <action>DELETE</action>
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>"""
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">
86 <request-id>TEST-REQUEST-ID-0123</request-id>
87 <action>DELETE</action>
90 <aetgt:WorkflowException>
91 <aetgt:ErrorMessage>Unexpected Error</aetgt:ErrorMessage>
92 <aetgt:ErrorCode>5000</aetgt:ErrorCode>
93 </aetgt:WorkflowException>
94 </aetgt:FalloutHandlerRequest>"""
99 MockitoAnnotations.initMocks(this)
104 public void testPrepareVnfAdapterDeleteRequest() {
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('')
117 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
118 myproc.prepareVnfAdapterDeleteRequest(mockExecution, 'true')
120 verify(mockExecution).setVariable("DELVfModVol_deleteVnfARequest", deleteVnfAdapterRequestXml)
126 public void testPrepareDbRequest() {
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")
134 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
135 myproc.prepareDBRequest(mockExecution, 'true')
137 verify(mockExecution).setVariable("DELVfModVol_updateInfraRequest", dbRequestXml)
141 public void testPrepareCompletionHandlerRequest() {
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')
147 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
148 myproc.prepareCompletionHandlerRequest(mockExecution, 'true')
150 verify(mockExecution).setVariable("DELVfModVol_CompleteMsoProcessRequest", completionRequestXml)
154 public void testPrepareFalloutHandler() {
156 WorkflowException workflowException = new WorkflowException('DeleteVfModuleVolumeInfraV1', 5000, 'Unexpected Error')
158 ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1')
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')
164 DeleteVfModuleVolumeInfraV1 myproc = new DeleteVfModuleVolumeInfraV1()
165 myproc.prepareFalloutHandler(mockExecution, 'true')
167 verify(mockExecution).setVariable("DELVfModVol_Success", false)
168 verify(mockExecution).setVariable("DELVfModVol_FalloutHandlerRequest", falloutHandlerRequestXml)