1- /*
1+ /*
22 * Licensed to the Apache Software Foundation (ASF) under one
33 * or more contributor license agreements. See the NOTICE file
44 * distributed with this work for additional information
2020
2121import com .cloud .utils .exception .CloudRuntimeException ;
2222import feign .FeignException ;
23- import org .apache .cloudstack .storage .feign .FeignClientFactory ;
2423import org .apache .cloudstack .storage .feign .client .AggregateFeignClient ;
2524import org .apache .cloudstack .storage .feign .client .JobFeignClient ;
2625import org .apache .cloudstack .storage .feign .client .NetworkFeignClient ;
3635import org .apache .cloudstack .storage .feign .model .Volume ;
3736import org .apache .cloudstack .storage .feign .model .response .JobResponse ;
3837import org .apache .cloudstack .storage .feign .model .response .OntapResponse ;
38+ import org .apache .cloudstack .storage .service .model .AccessGroup ;
39+ import org .apache .cloudstack .storage .service .model .CloudStackVolume ;
3940import org .apache .cloudstack .storage .service .model .ProtocolType ;
4041import org .apache .cloudstack .storage .utils .Constants ;
4142import org .junit .jupiter .api .BeforeEach ;
5253import java .util .Map ;
5354
5455import static org .junit .jupiter .api .Assertions .assertEquals ;
56+ import static org .junit .jupiter .api .Assertions .assertFalse ;
5557import static org .junit .jupiter .api .Assertions .assertNotNull ;
5658import static org .junit .jupiter .api .Assertions .assertThrows ;
5759import static org .junit .jupiter .api .Assertions .assertTrue ;
6971@ MockitoSettings (strictness = Strictness .LENIENT )
7072public class StorageStrategyTest {
7173
72- @ Mock
73- private FeignClientFactory feignClientFactory ;
74-
7574 @ Mock
7675 private AggregateFeignClient aggregateFeignClient ;
7776
@@ -134,17 +133,21 @@ org.apache.cloudstack.storage.service.model.CloudStackVolume updateCloudStackVol
134133 }
135134
136135 @ Override
137- void deleteCloudStackVolume (org .apache .cloudstack .storage .service .model .CloudStackVolume cloudstackVolume ) {
136+ public void deleteCloudStackVolume (org .apache .cloudstack .storage .service .model .CloudStackVolume cloudstackVolume ) {
138137 }
139138
140139 @ Override
141- org .apache .cloudstack .storage .service .model .CloudStackVolume getCloudStackVolume (
142- org .apache .cloudstack .storage .service .model .CloudStackVolume cloudstackVolume ) {
140+ public void copyCloudStackVolume (org .apache .cloudstack .storage .service .model .CloudStackVolume cloudstackVolume ) {
141+ }
142+
143+ @ Override
144+ public CloudStackVolume getCloudStackVolume (
145+ Map <String , String > cloudStackVolumeMap ) {
143146 return null ;
144147 }
145148
146149 @ Override
147- public org . apache . cloudstack . storage . service . model . AccessGroup createAccessGroup (
150+ public AccessGroup createAccessGroup (
148151 org .apache .cloudstack .storage .service .model .AccessGroup accessGroup ) {
149152 return null ;
150153 }
@@ -154,23 +157,29 @@ public void deleteAccessGroup(org.apache.cloudstack.storage.service.model.Access
154157 }
155158
156159 @ Override
157- org . apache . cloudstack . storage . service . model . AccessGroup updateAccessGroup (
160+ AccessGroup updateAccessGroup (
158161 org .apache .cloudstack .storage .service .model .AccessGroup accessGroup ) {
159162 return null ;
160163 }
161164
162165 @ Override
163- org .apache .cloudstack .storage .service .model .AccessGroup getAccessGroup (
164- org .apache .cloudstack .storage .service .model .AccessGroup accessGroup ) {
166+ public AccessGroup getAccessGroup (
167+ Map <String , String > values ) {
168+ return null ;
169+ }
170+
171+ @ Override
172+ public Map <String , String > enableLogicalAccess (Map <String , String > values ) {
165173 return null ;
166174 }
167175
168176 @ Override
169- void enableLogicalAccess (Map <String , String > values ) {
177+ public void disableLogicalAccess (Map <String , String > values ) {
170178 }
171179
172180 @ Override
173- void disableLogicalAccess (Map <String , String > values ) {
181+ public Map <String , String > getLogicalAccess (Map <String , String > values ) {
182+ return null ;
174183 }
175184 }
176185
@@ -223,9 +232,11 @@ public void testConnect_svmNotFound() {
223232
224233 when (svmFeignClient .getSvmResponse (anyMap (), anyString ())).thenReturn (svmResponse );
225234
226- // Execute & Verify
227- Exception ex = assertThrows (CloudRuntimeException .class , () -> storageStrategy .connect ());
228- assertTrue (ex .getMessage ().contains ("No SVM found" ));
235+ // Execute
236+ boolean result = storageStrategy .connect ();
237+
238+ // Verify
239+ assertFalse (result , "connect() should return false when SVM is not found" );
229240 }
230241
231242 @ Test
@@ -241,9 +252,11 @@ public void testConnect_svmNotRunning() {
241252
242253 when (svmFeignClient .getSvmResponse (anyMap (), anyString ())).thenReturn (svmResponse );
243254
244- // Execute & Verify
245- Exception ex = assertThrows (CloudRuntimeException .class , () -> storageStrategy .connect ());
246- assertTrue (ex .getMessage ().contains ("not in running state" ));
255+ // Execute
256+ boolean result = storageStrategy .connect ();
257+
258+ // Verify
259+ assertFalse (result , "connect() should return false when SVM is not running" );
247260 }
248261
249262 @ Test
@@ -316,25 +329,29 @@ public void testConnect_noAggregates() {
316329
317330 when (svmFeignClient .getSvmResponse (anyMap (), anyString ())).thenReturn (svmResponse );
318331
319- // Execute & Verify
320- Exception ex = assertThrows (CloudRuntimeException .class , () -> storageStrategy .connect ());
321- assertTrue (ex .getMessage ().contains ("No aggregates are assigned" ));
332+ // Execute
333+ boolean result = storageStrategy .connect ();
334+
335+ // Verify
336+ assertFalse (result , "connect() should return false when no aggregates are assigned" );
322337 }
323338
324339 @ Test
325340 public void testConnect_nullSvmResponse () {
326341 // Setup
327342 when (svmFeignClient .getSvmResponse (anyMap (), anyString ())).thenReturn (null );
328343
329- // Execute & Verify
330- Exception ex = assertThrows (CloudRuntimeException .class , () -> storageStrategy .connect ());
331- assertTrue (ex .getMessage ().contains ("No SVM found" ));
344+ // Execute
345+ boolean result = storageStrategy .connect ();
346+
347+ // Verify
348+ assertFalse (result , "connect() should return false when SVM response is null" );
332349 }
333350
334351 // ========== createStorageVolume() Tests ==========
335352
336353 @ Test
337- public void testCreateStorageVolume_positive () throws Exception {
354+ public void testCreateStorageVolume_positive () {
338355 // Setup - First connect to populate aggregates
339356 setupSuccessfulConnect ();
340357 storageStrategy .connect ();
@@ -422,7 +439,7 @@ public void testCreateStorageVolume_noAggregates() {
422439 }
423440
424441 @ Test
425- public void testCreateStorageVolume_aggregateNotOnline () throws Exception {
442+ public void testCreateStorageVolume_aggregateNotOnline () {
426443 // Setup
427444 setupSuccessfulConnect ();
428445 storageStrategy .connect ();
@@ -442,7 +459,7 @@ public void testCreateStorageVolume_aggregateNotOnline() throws Exception {
442459 }
443460
444461 @ Test
445- public void testCreateStorageVolume_insufficientSpace () throws Exception {
462+ public void testCreateStorageVolume_insufficientSpace () {
446463 // Setup
447464 setupSuccessfulConnect ();
448465 storageStrategy .connect ();
@@ -463,7 +480,7 @@ public void testCreateStorageVolume_insufficientSpace() throws Exception {
463480 }
464481
465482 @ Test
466- public void testCreateStorageVolume_jobFailed () throws Exception {
483+ public void testCreateStorageVolume_jobFailed () {
467484 // Setup
468485 setupSuccessfulConnect ();
469486 storageStrategy .connect ();
@@ -493,7 +510,7 @@ public void testCreateStorageVolume_jobFailed() throws Exception {
493510 }
494511
495512 @ Test
496- public void testCreateStorageVolume_volumeNotFoundAfterCreation () throws Exception {
513+ public void testCreateStorageVolume_volumeNotFoundAfterCreation () {
497514 // Setup
498515 setupSuccessfulConnect ();
499516 storageStrategy .connect ();
@@ -516,7 +533,7 @@ public void testCreateStorageVolume_volumeNotFoundAfterCreation() throws Excepti
516533 // ========== deleteStorageVolume() Tests ==========
517534
518535 @ Test
519- public void testDeleteStorageVolume_positive () throws Exception {
536+ public void testDeleteStorageVolume_positive () {
520537 // Setup
521538 Volume volume = new Volume ();
522539 volume .setName ("test-volume" );
@@ -545,7 +562,7 @@ public void testDeleteStorageVolume_positive() throws Exception {
545562 }
546563
547564 @ Test
548- public void testDeleteStorageVolume_jobFailed () throws Exception {
565+ public void testDeleteStorageVolume_jobFailed () {
549566 // Setup
550567 Volume volume = new Volume ();
551568 volume .setName ("test-volume" );
@@ -778,7 +795,7 @@ private void setupAggregateForVolumeCreation() {
778795 .thenReturn (aggregateDetail );
779796 }
780797
781- private void setupSuccessfulJobCreation () throws InterruptedException {
798+ private void setupSuccessfulJobCreation () {
782799 Job job = new Job ();
783800 job .setUuid ("job-uuid-1" );
784801 JobResponse jobResponse = new JobResponse ();
0 commit comments