2020package org .apache .cloudstack .storage .service ;
2121
2222import com .cloud .agent .api .Answer ;
23+ import com .cloud .agent .api .to .DataTO ;
2324import com .cloud .host .HostVO ;
2425import com .cloud .storage .VolumeVO ;
2526import com .cloud .storage .dao .VolumeDao ;
2829import org .apache .cloudstack .engine .subsystem .api .storage .EndPointSelector ;
2930import org .apache .cloudstack .engine .subsystem .api .storage .VolumeInfo ;
3031import org .apache .cloudstack .storage .command .CreateObjectCommand ;
32+ import org .apache .cloudstack .storage .command .DeleteCommand ;
3133import org .apache .cloudstack .storage .datastore .db .StoragePoolDetailsDao ;
3234import org .apache .cloudstack .storage .feign .client .JobFeignClient ;
3335import org .apache .cloudstack .storage .feign .client .NASFeignClient ;
@@ -181,7 +183,8 @@ public void testCreateCloudStackVolume_Success() throws Exception {
181183 when (cloudStackVolume .getVolumeInfo ()).thenReturn (volumeObject );
182184 when (volumeObject .getId ()).thenReturn (100L );
183185 when (volumeObject .getUuid ()).thenReturn ("volume-uuid-123" );
184- when (volumeDao .findById (100L )).thenReturn (volumeVO );
186+ when (volumeObject .getTO ()).thenReturn (mock (DataTO .class ));
187+ when (volumeDao .findById (anyLong ())).thenReturn (volumeVO );
185188 when (volumeDao .update (anyLong (), any (VolumeVO .class ))).thenReturn (true );
186189 when (epSelector .select (volumeObject )).thenReturn (endPoint );
187190 when (endPoint .sendMessage (any (CreateObjectCommand .class ))).thenReturn (answer );
@@ -205,7 +208,8 @@ public void testCreateCloudStackVolume_VolumeNotFound() {
205208 when (cloudStackVolume .getDatastoreId ()).thenReturn ("1" );
206209 when (cloudStackVolume .getVolumeInfo ()).thenReturn (volumeObject );
207210 when (volumeObject .getId ()).thenReturn (100L );
208- when (volumeDao .findById (100L )).thenReturn (null );
211+ when (volumeObject .getTO ()).thenReturn (mock (DataTO .class ));
212+ when (volumeDao .findById (anyLong ())).thenReturn (null );
209213
210214 assertThrows (CloudRuntimeException .class , () -> {
211215 strategy .createCloudStackVolume (cloudStackVolume );
@@ -225,7 +229,8 @@ public void testCreateCloudStackVolume_KVMHostFailed() {
225229 when (cloudStackVolume .getVolumeInfo ()).thenReturn (volumeObject );
226230 when (volumeObject .getId ()).thenReturn (100L );
227231 when (volumeObject .getUuid ()).thenReturn ("volume-uuid-123" );
228- when (volumeDao .findById (100L )).thenReturn (volumeVO );
232+ when (volumeObject .getTO ()).thenReturn (mock (DataTO .class ));
233+ when (volumeDao .findById (anyLong ())).thenReturn (volumeVO );
229234 when (volumeDao .update (anyLong (), any (VolumeVO .class ))).thenReturn (true );
230235 when (epSelector .select (volumeObject )).thenReturn (endPoint );
231236 when (endPoint .sendMessage (any (CreateObjectCommand .class ))).thenReturn (answer );
@@ -246,7 +251,8 @@ public void testCreateCloudStackVolume_NoEndpoint() {
246251 when (cloudStackVolume .getVolumeInfo ()).thenReturn (volumeObject );
247252 when (volumeObject .getId ()).thenReturn (100L );
248253 when (volumeObject .getUuid ()).thenReturn ("volume-uuid-123" );
249- when (volumeDao .findById (100L )).thenReturn (volumeVO );
254+ when (volumeObject .getTO ()).thenReturn (mock (DataTO .class ));
255+ when (volumeDao .findById (anyLong ())).thenReturn (volumeVO );
250256 when (volumeDao .update (anyLong (), any (VolumeVO .class ))).thenReturn (true );
251257 when (epSelector .select (volumeObject )).thenReturn (null );
252258
@@ -519,19 +525,19 @@ public void testDeleteCloudStackVolume_Success() throws Exception {
519525 CloudStackVolume cloudStackVolume = mock (CloudStackVolume .class );
520526 VolumeInfo volumeInfo = mock (VolumeInfo .class );
521527 EndPoint endpoint = mock (EndPoint .class );
522- Answer answer = mock ( Answer . class );
528+ Answer answer = new Answer ( null , true , "Success" );
523529
524530 when (cloudStackVolume .getVolumeInfo ()).thenReturn (volumeInfo );
531+ when (volumeInfo .getTO ()).thenReturn (mock (DataTO .class ));
525532 when (epSelector .select (volumeInfo )).thenReturn (endpoint );
526- when (endpoint .sendMessage (any ())).thenReturn (answer );
527- when (answer .getResult ()).thenReturn (true );
533+ when (endpoint .sendMessage (any (DeleteCommand .class ))).thenReturn (answer );
528534
529535 // Execute - should not throw exception
530536 strategy .deleteCloudStackVolume (cloudStackVolume );
531537
532538 // Verify endpoint was selected and message sent
533539 verify (epSelector ).select (volumeInfo );
534- verify (endpoint ).sendMessage (any ());
540+ verify (endpoint ).sendMessage (any (DeleteCommand . class ));
535541 }
536542
537543 // Test deleteCloudStackVolume - Endpoint Not Found
@@ -541,6 +547,7 @@ public void testDeleteCloudStackVolume_EndpointNotFound() {
541547 VolumeInfo volumeInfo = mock (VolumeInfo .class );
542548
543549 when (cloudStackVolume .getVolumeInfo ()).thenReturn (volumeInfo );
550+ when (volumeInfo .getTO ()).thenReturn (mock (DataTO .class ));
544551 when (epSelector .select (volumeInfo )).thenReturn (null );
545552
546553 assertThrows (CloudRuntimeException .class , () -> {
@@ -554,13 +561,12 @@ public void testDeleteCloudStackVolume_AnswerResultFalse() throws Exception {
554561 CloudStackVolume cloudStackVolume = mock (CloudStackVolume .class );
555562 VolumeInfo volumeInfo = mock (VolumeInfo .class );
556563 EndPoint endpoint = mock (EndPoint .class );
557- Answer answer = mock ( Answer . class );
564+ Answer answer = new Answer ( null , false , "Failed to delete volume file" );
558565
559566 when (cloudStackVolume .getVolumeInfo ()).thenReturn (volumeInfo );
567+ when (volumeInfo .getTO ()).thenReturn (mock (DataTO .class ));
560568 when (epSelector .select (volumeInfo )).thenReturn (endpoint );
561- when (endpoint .sendMessage (any ())).thenReturn (answer );
562- when (answer .getResult ()).thenReturn (false );
563- when (answer .getDetails ()).thenReturn ("Failed to delete volume file" );
569+ when (endpoint .sendMessage (any (DeleteCommand .class ))).thenReturn (answer );
564570
565571 assertThrows (CloudRuntimeException .class , () -> {
566572 strategy .deleteCloudStackVolume (cloudStackVolume );
@@ -575,8 +581,9 @@ public void testDeleteCloudStackVolume_AnswerNull() throws Exception {
575581 EndPoint endpoint = mock (EndPoint .class );
576582
577583 when (cloudStackVolume .getVolumeInfo ()).thenReturn (volumeInfo );
584+ when (volumeInfo .getTO ()).thenReturn (mock (DataTO .class ));
578585 when (epSelector .select (volumeInfo )).thenReturn (endpoint );
579- when (endpoint .sendMessage (any ())).thenReturn (null );
586+ when (endpoint .sendMessage (any (DeleteCommand . class ))).thenReturn (null );
580587
581588 assertThrows (CloudRuntimeException .class , () -> {
582589 strategy .deleteCloudStackVolume (cloudStackVolume );
0 commit comments