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.onap.so.bpmn.infrastructure.scripts
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
25 import org.junit.Before
28 import org.junit.rules.ExpectedException
29 import org.junit.runner.RunWith
30 import org.mockito.ArgumentCaptor
31 import org.mockito.Captor
32 import org.mockito.Mockito
33 import org.mockito.MockitoAnnotations
34 import org.mockito.runners.MockitoJUnitRunner
35 import org.onap.aai.domain.yang.GenericVnf
36 import org.onap.aai.domain.yang.Volume
37 import org.onap.aai.domain.yang.VolumeGroup
38 import org.onap.aai.domain.yang.VolumeGroups
39 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
40 import org.onap.so.bpmn.core.RollbackData
41 import org.onap.aaiclient.client.aai.AAIObjectPlurals
42 import org.onap.aaiclient.client.aai.AAIObjectType
43 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
44 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
45 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
46 import org.onap.so.constants.Defaults
48 import static org.junit.Assert.assertEquals
49 import static org.junit.Assert.assertNotNull
50 import static org.mockito.ArgumentMatchers.anyObject
51 import static org.mockito.Mockito.spy
52 import static org.mockito.Mockito.times
53 import static org.mockito.Mockito.verify
54 import static org.mockito.Mockito.when
57 class DoCreateVfModuleVolumeV2Test extends MsoGroovyTest {
59 private DoCreateVfModuleVolumeV2 doCreateVfModuleVolumeV2;
62 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
64 String volumeRollbackRequest = """
65 <rollbackVolumeGroupRequest>
67 <volumeGroupId>171907d6-cdf0-4e08-953d-81ee104005a7</volumeGroupId>
68 <volumeGroupStackId>{{VOLUMEGROUPSTACKID}}</volumeGroupStackId>
69 <tenantId>c2141e3fcae940fcb4797ec9115e5a7a</tenantId>
70 <cloudSiteId>mtwnj1a</cloudSiteId>
71 <volumeGroupCreated>true</volumeGroupCreated>
73 <requestId>230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5</requestId>
74 <serviceInstanceId>88c871d6-be09-4982-8490-96b1d243fb34</serviceInstanceId>
76 <messageId>9a5a91e8-3b79-463c-81c3-874a78f5b567</messageId>
77 </volumeGroupRollback>
78 <skipAAI>true</skipAAI>
79 <notificationUrl>http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567</notificationUrl>
80 </rollbackVolumeGroupRequest>
83 String volumeRollbackRequestWithStackId = """
84 <rollbackVolumeGroupRequest>
86 <volumeGroupId>171907d6-cdf0-4e08-953d-81ee104005a7</volumeGroupId>
87 <volumeGroupStackId>mdt22avrr_volume01/0f1aaae8-efe3-45ce-83e1-bfad01db58d8</volumeGroupStackId>
88 <tenantId>c2141e3fcae940fcb4797ec9115e5a7a</tenantId>
89 <cloudSiteId>mtwnj1a</cloudSiteId>
90 <volumeGroupCreated>true</volumeGroupCreated>
92 <requestId>230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5</requestId>
93 <serviceInstanceId>88c871d6-be09-4982-8490-96b1d243fb34</serviceInstanceId>
95 <messageId>9a5a91e8-3b79-463c-81c3-874a78f5b567</messageId>
96 </volumeGroupRollback>
97 <skipAAI>true</skipAAI>
98 <notificationUrl>http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567</notificationUrl>
99 </rollbackVolumeGroupRequest>
107 super.init("DoCreateVfModuleVolumeV2")
108 doCreateVfModuleVolumeV2 = spy(DoCreateVfModuleVolumeV2.class)
109 when(doCreateVfModuleVolumeV2.getAAIClient()).thenReturn(client)
110 MockitoAnnotations.initMocks(this)
114 public void testBuildRollbackVolumeGroupRequestXml() {
115 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
116 String xml = process.buildRollbackVolumeGroupRequestXml(
117 "171907d6-cdf0-4e08-953d-81ee104005a7", // volumeGroupId
118 "mtwnj1a", // cloudSiteId
119 "c2141e3fcae940fcb4797ec9115e5a7a", // tenantId
120 "230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5", // requestId
121 "88c871d6-be09-4982-8490-96b1d243fb34", // serviceInstanceId
122 "9a5a91e8-3b79-463c-81c3-874a78f5b567", // messageId
123 "http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567") // notificationUrl
125 assertEquals(volumeRollbackRequest.replaceAll("\\s", ""), xml.replaceAll("\\s", ""))
130 public void testUpdateRollbackVolumeGroupRequestXml() {
131 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
132 String updatedXml = process.updateRollbackVolumeGroupRequestXml(volumeRollbackRequest, "mdt22avrr_volume01/0f1aaae8-efe3-45ce-83e1-bfad01db58d8")
133 assertEquals(volumeRollbackRequestWithStackId.replaceAll("\\s", ""), updatedXml.replaceAll("\\s", ""))
137 public void testPrepareVnfAdapterCreateRequest (){
138 ExecutionEntity mockExecution = setupMock('DoCreateVfModuleVolumeV2')
140 when(mockExecution.getVariable("prefix")).thenReturn('DCVFMODVOLV2_')
141 when(mockExecution.getVariable("DCVFMODVOLV2_AAIQueryGenericVfnResponse")).thenReturn(new GenericVnf())
142 when(mockExecution.getVariable("serviceInstanceId")).thenReturn('')
143 when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id')
144 when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
145 when(mockExecution.getVariable("volumeGroupId")).thenReturn('1234')
146 when(mockExecution.getVariable("mso.use.qualified.host")).thenReturn("true")
147 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn("http://localhost:28080/mso/WorkflowMesssage")
148 Map vfModuleInputParams = new HashMap()
149 vfModuleInputParams.put("param1","value1")
150 when(mockExecution.getVariable("vfModuleInputParams")).thenReturn(vfModuleInputParams)
151 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
152 process.prepareVnfAdapterCreateRequest(mockExecution,"true");
153 Mockito.verify(mockExecution,times(2)).setVariable(captor.capture(), captor.capture())
154 String DCVFMODVOLV2_createVnfARequest = captor.getValue();
155 assertNotNull(DCVFMODVOLV2_createVnfARequest)
159 void testcallRESTQueryAAIVolGrpName(){
160 String volumeGroupName = "volumeGroupName"
161 String lcpCloudRegionId = "lcpCloudRegionId"
162 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
163 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
164 AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), lcpCloudRegionId).queryParam("volume-group-name", volumeGroupName)
165 VolumeGroups volumeGroups = new VolumeGroups();
166 VolumeGroup volumeGroup = new VolumeGroup()
167 volumeGroup.setVolumeGroupId("volumeGroupId")
168 volumeGroups.getVolumeGroup().add(volumeGroup);
169 when(client.get(VolumeGroups.class,uri)).thenReturn(Optional.of(volumeGroups))
170 doCreateVfModuleVolumeV2.callRESTQueryAAIVolGrpName(mockExecution,null)
171 verify(mockExecution).setVariable("DCVFMODVOLV2_AaiReturnCode",200)
175 void testcallRESTQueryAAIVolGrpName_NoData(){
176 String volumeGroupName = "volumeGroupName"
177 String lcpCloudRegionId = "lcpCloudRegionId"
178 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
179 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
180 AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), lcpCloudRegionId).queryParam("volume-group-name", volumeGroupName)
181 when(client.get(VolumeGroup.class,uri)).thenReturn(Optional.empty())
182 thrown.expect(BpmnError.class)
183 doCreateVfModuleVolumeV2.callRESTQueryAAIVolGrpName(mockExecution,null)
187 void testcallRESTUpdateCreatedVolGrpName(){
188 String queriedVolumeGroupId = "queriedVolumeGroupId"
189 String modelCustomizationId = "modelCustomizationId"
190 String lcpCloudRegionId = "lcpCloudRegionId"
191 when(mockExecution.getVariable(queriedVolumeGroupId)).thenReturn(queriedVolumeGroupId)
192 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
193 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
194 when(mockExecution.getVariable("DCVFMODVOLV2_createVnfAResponse")).thenReturn("<createVnfAResponse><volumeGroupStackId>volumeGroupStackId</volumeGroupStackId></createVnfAResponse>")
195 doCreateVfModuleVolumeV2.callRESTUpdateCreatedVolGrpName(mockExecution,null)
196 verify(mockExecution).setVariable("DCVFMODVOLV2_heatStackId","volumeGroupStackId")
200 void testcallRESTUpdateCreatedVolGrpNameException(){
201 String queriedVolumeGroupId = "queriedVolumeGroupId"
202 String modelCustomizationId = "modelCustomizationId"
203 String lcpCloudRegionId = "lcpCloudRegionId"
204 when(mockExecution.getVariable(queriedVolumeGroupId)).thenReturn(queriedVolumeGroupId)
205 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
206 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
207 when(mockExecution.getVariable("DCVFMODVOLV2_createVnfAResponse")).thenReturn("<createVnfAResponse><volumeGroupStackId>volumeGroupStackId</volumeGroupStackId></createVnfAResponse>")
208 when(client.update(anyObject(),anyObject())).thenThrow(Exception.class)
209 thrown.expect(BpmnError.class)
210 doCreateVfModuleVolumeV2.callRESTUpdateCreatedVolGrpName(mockExecution,null)
211 verify(mockExecution).setVariable("DCVFMODVOLV2_heatStackId","volumeGroupStackId")
215 void testcallRESTQueryAAIGenericVnf(){
216 String vnfId = "vnfId"
217 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
218 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
219 GenericVnf genericVnf = new GenericVnf()
220 genericVnf.setVnfId(vnfId)
221 when(client.get(GenericVnf.class,uri)).thenReturn(Optional.of(genericVnf))
222 doCreateVfModuleVolumeV2.callRESTQueryAAIGenericVnf(mockExecution,null)
223 verify(mockExecution).setVariable("DCVFMODVOLV2_AAIQueryGenericVfnResponse",genericVnf)
227 void testcallRESTQueryAAIGenericVnf_NotFound(){
228 String vnfId = "vnfId"
229 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
230 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
231 when(client.get(GenericVnf.class,uri)).thenReturn(Optional.empty())
232 thrown.expect(BpmnError.class)
233 doCreateVfModuleVolumeV2.callRESTQueryAAIGenericVnf(mockExecution,null)
237 void testcallRESTCreateAAIVolGrpName(){
238 String vnfId = "vnfId"
239 String volumeGroupId = "volumeGroupId"
240 String volumeGroupName = "volumeGroupName"
241 String modelCustomizationId = "modelCustomizationId"
242 String vnfType= "vnfType"
243 String tenantId = "tenantId"
244 String lcpCloudRegionId= "lcpCloudRegionId"
245 String cloudOwner = "cloudOwner"
247 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
248 when(mockExecution.getVariable(volumeGroupId)).thenReturn(volumeGroupId)
249 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
250 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
251 when(mockExecution.getVariable(vnfType)).thenReturn(vnfType)
252 when(mockExecution.getVariable(tenantId)).thenReturn(tenantId)
253 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
254 when(mockExecution.getVariable(cloudOwner)).thenReturn(cloudOwner)
255 when(mockExecution.getVariable("rollbackData")).thenReturn(new RollbackData())
256 doCreateVfModuleVolumeV2.callRESTCreateAAIVolGrpName(mockExecution,null)
257 verify(mockExecution).setVariable("queriedVolumeGroupId", "volumeGroupId")
261 void testcallRESTCreateAAIVolGrpNameException(){
262 String vnfId = "vnfId"
263 String volumeGroupId = "volumeGroupId"
264 String volumeGroupName = "volumeGroupName"
265 String modelCustomizationId = "modelCustomizationId"
266 String vnfType= "vnfType"
267 String tenantId = "tenantId"
268 String lcpCloudRegionId= "lcpCloudRegionId"
269 String cloudOwner = "cloudOwner"
271 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
272 when(mockExecution.getVariable(volumeGroupId)).thenReturn(volumeGroupId)
273 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
274 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
275 when(mockExecution.getVariable(vnfType)).thenReturn(vnfType)
276 when(mockExecution.getVariable(tenantId)).thenReturn(tenantId)
277 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
278 when(mockExecution.getVariable(cloudOwner)).thenReturn(cloudOwner)
279 thrown.expect(BpmnError.class)
280 doCreateVfModuleVolumeV2.callRESTCreateAAIVolGrpName(mockExecution,null)