1717package com .cloud .storage ;
1818
1919import static org .junit .Assert .assertEquals ;
20- import static org .junit .Assert .assertNull ;
2120import static org .mockito .Mockito .mock ;
2221import static org .mockito .Mockito .when ;
2322
2423import java .util .HashMap ;
2524import java .util .Map ;
2625
26+ import org .apache .cloudstack .framework .config .dao .ConfigurationDao ;
27+ import org .apache .cloudstack .framework .config .impl .ConfigurationVO ;
2728import org .apache .cloudstack .storage .datastore .db .ImageStoreDao ;
2829import org .apache .cloudstack .storage .datastore .db .ImageStoreDetailsDao ;
2930import org .apache .cloudstack .storage .datastore .db .ImageStoreVO ;
@@ -37,11 +38,13 @@ public class ImageStoreDetailsUtilTest {
3738 private final static long STORE_ID = 1l ;
3839 private final static String STORE_UUID = "aaaa-aaaa-aaaa-aaaa" ;
3940 private final static Integer NFS_VERSION = 3 ;
41+ private final static Integer NFS_VERSION_DEFAULT = 2 ;
4042
4143 ImageStoreDetailsUtil imageStoreDetailsUtil = new ImageStoreDetailsUtil ();
4244
4345 ImageStoreDao imgStoreDao = mock (ImageStoreDao .class );
4446 ImageStoreDetailsDao imgStoreDetailsDao = mock (ImageStoreDetailsDao .class );
47+ ConfigurationDao configurationDao = mock (ConfigurationDao .class );
4548
4649 @ Before
4750 public void setup () throws Exception {
@@ -54,8 +57,14 @@ public void setup() throws Exception {
5457 when (imgStoreVO .getId ()).thenReturn (Long .valueOf (STORE_ID ));
5558 when (imgStoreDao .findByUuid (STORE_UUID )).thenReturn (imgStoreVO );
5659
60+ ConfigurationVO confVO = mock (ConfigurationVO .class );
61+ String defaultValue = (NFS_VERSION_DEFAULT == null ? null : String .valueOf (NFS_VERSION_DEFAULT ));
62+ when (confVO .getValue ()).thenReturn (defaultValue );
63+ when (configurationDao .findByName (nfsVersionKey )).thenReturn (confVO );
64+
5765 imageStoreDetailsUtil .imageStoreDao = imgStoreDao ;
5866 imageStoreDetailsUtil .imageStoreDetailsDao = imgStoreDetailsDao ;
67+ imageStoreDetailsUtil .configurationDao = configurationDao ;
5968 }
6069
6170 @ Test
@@ -71,7 +80,7 @@ public void testGetNfsVersionNotFound(){
7180 when (imgStoreDetailsDao .getDetails (STORE_ID )).thenReturn (imgStoreDetails );
7281
7382 Integer nfsVersion = imageStoreDetailsUtil .getNfsVersion (STORE_ID );
74- assertNull ( nfsVersion );
83+ assertEquals ( NFS_VERSION_DEFAULT , nfsVersion );
7584 }
7685
7786 @ Test
@@ -80,7 +89,7 @@ public void testGetNfsVersionNoDetails(){
8089 when (imgStoreDetailsDao .getDetails (STORE_ID )).thenReturn (imgStoreDetails );
8190
8291 Integer nfsVersion = imageStoreDetailsUtil .getNfsVersion (STORE_ID );
83- assertNull ( nfsVersion );
92+ assertEquals ( NFS_VERSION_DEFAULT , nfsVersion );
8493 }
8594
8695 @ Test
@@ -93,6 +102,13 @@ public void testGetNfsVersionByUuid(){
93102 public void testGetNfsVersionByUuidNoImgStore (){
94103 when (imgStoreDao .findByUuid (STORE_UUID )).thenReturn (null );
95104 Integer nfsVersion = imageStoreDetailsUtil .getNfsVersionByUuid (STORE_UUID );
96- assertNull ( nfsVersion );
105+ assertEquals ( NFS_VERSION_DEFAULT , nfsVersion );
97106 }
98- }
107+
108+ @ Test
109+ public void testGetGlobalDefaultNfsVersion (){
110+ Integer globalDefaultNfsVersion = imageStoreDetailsUtil .getGlobalDefaultNfsVersion ();
111+ assertEquals (NFS_VERSION_DEFAULT , globalDefaultNfsVersion );
112+ }
113+
114+ }
0 commit comments