2727import com .cloud .host .HostVO ;
2828import com .cloud .host .Status ;
2929import com .cloud .host .dao .HostDao ;
30+ import com .cloud .network .dao .NetworkDao ;
3031import com .cloud .resource .ResourceManager ;
3132import com .cloud .resource .ResourceState ;
3233import com .cloud .storage .DataStoreRole ;
3334import com .cloud .storage .Storage ;
3435import com .cloud .storage .StorageManager ;
3536import com .cloud .storage .StorageManagerImpl ;
3637import com .cloud .storage .StoragePoolHostVO ;
38+ import com .cloud .storage .StorageService ;
3739import com .cloud .storage .dao .StoragePoolHostDao ;
3840import junit .framework .TestCase ;
3941import org .apache .cloudstack .engine .subsystem .api .storage .ClusterScope ;
5759import org .mockito .MockitoAnnotations ;
5860import org .mockito .Spy ;
5961import org .mockito .runners .MockitoJUnitRunner ;
62+ import org .springframework .test .util .ReflectionTestUtils ;
6063
6164import java .util .ArrayList ;
6265import java .util .List ;
@@ -79,8 +82,8 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
7982 @ InjectMocks
8083 PrimaryDataStoreLifeCycle _cloudStackPrimaryDataStoreLifeCycle = new CloudStackPrimaryDataStoreLifeCycleImpl ();
8184
82- @ Mock
83- StorageManager storageMgr ;
85+ @ InjectMocks
86+ StorageManager storageMgr = new StorageManagerImpl () ;
8487
8588 @ Mock
8689 ResourceManager _resourceMgr ;
@@ -127,10 +130,14 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
127130
128131 @ Before
129132 public void initMocks () {
130-
131133 MockitoAnnotations .initMocks (this );
132134
133- List <HostVO > hostList = new ArrayList <HostVO >();
135+ ReflectionTestUtils .setField (storageMgr , "_storagePoolDao" , primaryStoreDao );
136+ ReflectionTestUtils .setField (storageMgr , "_dataStoreProviderMgr" , _dataStoreProviderMgr );
137+ ReflectionTestUtils .setField (storageMgr , "_dataStoreMgr" , _dataStoreMgr );
138+ ReflectionTestUtils .setField (_cloudStackPrimaryDataStoreLifeCycle , "storageMgr" , storageMgr );
139+
140+ List <HostVO > hostList = new ArrayList <>();
134141 HostVO host1 = new HostVO (1L , "aa01" , Host .Type .Routing , "192.168.1.1" , "255.255.255.0" , null , null , null , null , null , null , null , null , null , null ,
135142 UUID .randomUUID ().toString (), Status .Up , "1.0" , null , null , 1L , null , 0 , 0 , "aa" , 0 , Storage .StoragePoolType .NetworkFilesystem );
136143 HostVO host2 = new HostVO (2L , "aa02" , Host .Type .Routing , "192.168.1.1" , "255.255.255.0" , null , null , null , null , null , null , null , null , null , null ,
@@ -145,10 +152,15 @@ public void initMocks() {
145152 when (store .getPoolType ()).thenReturn (Storage .StoragePoolType .NetworkFilesystem );
146153 when (store .isShared ()).thenReturn (true );
147154 when (store .getName ()).thenReturn ("newPool" );
155+ when (store .getStorageProviderName ()).thenReturn ("default" );
148156
149157 when (_dataStoreProviderMgr .getDataStoreProvider (anyString ())).thenReturn (dataStoreProvider );
150158 when (dataStoreProvider .getName ()).thenReturn ("default" );
151- ((StorageManagerImpl )storageMgr ).registerHostListener ("default" , hostListener );
159+
160+ ReflectionTestUtils .setField (hostListener , "storageService" , Mockito .mock (StorageService .class ));
161+ ReflectionTestUtils .setField (hostListener , "networkDao" , Mockito .mock (NetworkDao .class ));
162+
163+ storageMgr .registerHostListener ("default" , hostListener );
152164
153165 when (hostDao .listIdsForUpRouting (anyLong (), anyLong (), anyLong ()))
154166 .thenReturn (hostList .stream ().map (HostVO ::getId ).collect (Collectors .toList ()));
0 commit comments