@@ -191,6 +191,7 @@ void testCreateAsync_VolumeWithISCSI_Success() {
191191
192192 when (storagePoolDao .findById (1L )).thenReturn (storagePool );
193193 when (storagePool .getId ()).thenReturn (1L );
194+ when (storagePool .getName ()).thenReturn ("vol1" );
194195 when (storagePool .getPoolType ()).thenReturn (Storage .StoragePoolType .Iscsi );
195196 when (storagePool .getHypervisor ()).thenReturn (Hypervisor .HypervisorType .KVM );
196197
@@ -251,8 +252,6 @@ void testCreateAsync_VolumeWithNFS_Success() {
251252 try (MockedStatic <OntapStorageUtils > utilityMock = mockStatic (OntapStorageUtils .class , CALLS_REAL_METHODS )) {
252253 utilityMock .when (() -> OntapStorageUtils .getStrategyByStoragePoolDetails (storagePoolDetails ))
253254 .thenReturn (nasStrategy );
254- utilityMock .when (() -> OntapStorageUtils .createCloudStackVolumeRequestByProtocol (
255- any (), any (), any ())).thenReturn (mockCloudStackVolume );
256255
257256 when (nasStrategy .createCloudStackVolume (any ())).thenReturn (mockCloudStackVolume );
258257
@@ -273,7 +272,9 @@ void testCreateAsync_VolumeWithNFS_Success() {
273272
274273 @ Test
275274 void testCreateAsync_UnsupportedHypervisor_FailsWithError () {
276- storagePoolDetails .put (OntapStorageConstants .PROTOCOL , ProtocolType .ISCSI .name ());
275+ // Use NFS so createVolumeRequest does not fail earlier in getOSTypeFromHypervisor;
276+ // the failure under test is image-format resolution for non-KVM hypervisors.
277+ storagePoolDetails .put (OntapStorageConstants .PROTOCOL , ProtocolType .NFS3 .name ());
277278
278279 when (dataStore .getId ()).thenReturn (1L );
279280 when (dataStore .getName ()).thenReturn ("ontap-pool" );
@@ -283,12 +284,16 @@ void testCreateAsync_UnsupportedHypervisor_FailsWithError() {
283284
284285 when (storagePoolDao .findById (1L )).thenReturn (storagePool );
285286 when (storagePool .getId ()).thenReturn (1L );
287+ when (storagePool .getPoolType ()).thenReturn (Storage .StoragePoolType .NetworkFilesystem );
286288 when (storagePool .getHypervisor ()).thenReturn (Hypervisor .HypervisorType .VMware );
287289 when (storagePoolDetailsDao .listDetailsKeyPairs (1L )).thenReturn (storagePoolDetails );
288290 when (volumeDao .findById (100L )).thenReturn (volumeVO );
289291
290- try (MockedStatic <OntapStorageUtils > utilityMock = mockStatic (OntapStorageUtils .class )) {
291- utilityMock .when (() -> OntapStorageUtils .getStrategyByStoragePoolDetails (any ())).thenReturn (sanStrategy );
292+ CloudStackVolume mockCloudStackVolume = new CloudStackVolume ();
293+
294+ try (MockedStatic <OntapStorageUtils > utilityMock = mockStatic (OntapStorageUtils .class , CALLS_REAL_METHODS )) {
295+ utilityMock .when (() -> OntapStorageUtils .getStrategyByStoragePoolDetails (any ())).thenReturn (nasStrategy );
296+ when (nasStrategy .createCloudStackVolume (any ())).thenReturn (mockCloudStackVolume );
292297
293298 driver .createAsync (dataStore , volumeInfo , createCallback );
294299
@@ -310,20 +315,18 @@ void testCreateAsync_KvmUnsupportedProtocol_FailsWithError() {
310315 when (volumeInfo .getName ()).thenReturn ("test-volume" );
311316
312317 when (storagePoolDao .findById (1L )).thenReturn (storagePool );
313- when (storagePool .getId ()).thenReturn (1L );
314- when (storagePool .getHypervisor ()).thenReturn (Hypervisor .HypervisorType .KVM );
315318 when (storagePoolDetailsDao .listDetailsKeyPairs (1L )).thenReturn (storagePoolDetails );
316319 when (volumeDao .findById (100L )).thenReturn (volumeVO );
317320
318- try (MockedStatic <OntapStorageUtils > utilityMock = mockStatic (OntapStorageUtils .class )) {
321+ try (MockedStatic <OntapStorageUtils > utilityMock = mockStatic (OntapStorageUtils .class , CALLS_REAL_METHODS )) {
319322 utilityMock .when (() -> OntapStorageUtils .getStrategyByStoragePoolDetails (any ())).thenReturn (sanStrategy );
320323
321324 driver .createAsync (dataStore , volumeInfo , createCallback );
322325
323326 ArgumentCaptor <CreateCmdResult > resultCaptor = ArgumentCaptor .forClass (CreateCmdResult .class );
324327 verify (createCallback ).complete (resultCaptor .capture ());
325328 assertFalse (resultCaptor .getValue ().isSuccess ());
326- assertTrue (resultCaptor .getValue ().getResult ().contains ("No enum constant " ));
329+ assertTrue (resultCaptor .getValue ().getResult ().contains ("Unsupported protocol FC " ));
327330 }
328331 }
329332
@@ -704,7 +707,6 @@ void testGetBytesRequiredForTemplate_SpoolRefNotDownloaded_ReturnsVirtualSize()
704707 when (storagePoolDetailsDao .listDetailsKeyPairs (1L )).thenReturn (storagePoolDetails );
705708 when (vmTemplatePoolDao .findByPoolTemplate (1L , 50L , null )).thenReturn (templatePoolRef );
706709 when (templatePoolRef .getDownloadState ()).thenReturn (VMTemplateStorageResourceAssoc .Status .NOT_DOWNLOADED );
707- when (templatePoolRef .getState ()).thenReturn (ObjectInDataStoreStateMachine .State .Allocated );
708710
709711 assertEquals (5368709120L , driver .getBytesRequiredForTemplate (templateInfo , storagePool ));
710712 }
0 commit comments