|
38 | 38 | import org.mockito.Mock; |
39 | 39 | import org.mockito.Mockito; |
40 | 40 | import org.mockito.MockitoAnnotations; |
| 41 | +import org.powermock.core.classloader.annotations.PrepareForTest; |
| 42 | +import org.springframework.context.ApplicationContext; |
41 | 43 | import org.springframework.context.annotation.Bean; |
42 | 44 | import org.springframework.context.annotation.ComponentScan; |
43 | 45 | import org.springframework.context.annotation.ComponentScan.Filter; |
|
54 | 56 | import org.apache.cloudstack.context.CallContext; |
55 | 57 | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; |
56 | 58 | import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
57 | | -import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; |
58 | | -import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao; |
59 | 59 | import org.apache.cloudstack.test.utils.SpringUtils; |
60 | 60 |
|
61 | 61 | import com.cloud.agent.AgentManager; |
|
101 | 101 |
|
102 | 102 | @RunWith(SpringJUnit4ClassRunner.class) |
103 | 103 | @ContextConfiguration(loader = AnnotationConfigContextLoader.class) |
| 104 | +@PrepareForTest({ComponentContext.class, ApplicationContext.class}) |
104 | 105 | public class VmwareDatacenterApiUnitTest { |
105 | 106 |
|
106 | 107 | @Inject |
@@ -133,9 +134,6 @@ public class VmwareDatacenterApiUnitTest { |
133 | 134 | @Inject |
134 | 135 | AccountManager _acctMgr; |
135 | 136 |
|
136 | | - @Inject |
137 | | - ImageStoreDetailsUtil imageStoreDetailsUtil; |
138 | | - |
139 | 137 | long zoneId; |
140 | 138 | long podId; |
141 | 139 | long clusterId; |
@@ -163,6 +161,13 @@ public class VmwareDatacenterApiUnitTest { |
163 | 161 |
|
164 | 162 | @BeforeClass |
165 | 163 | public static void setUp() throws ConfigurationException { |
| 164 | + ComponentContext ctx = new ComponentContext(); |
| 165 | + ImageStoreDetailsUtil imgSDUtil = Mockito.mock(ImageStoreDetailsUtil.class); |
| 166 | + Mockito.when(imgSDUtil.getNfsVersion(Mockito.anyLong())).thenReturn("3"); |
| 167 | + Mockito.when(imgSDUtil.getNfsVersionByUuid(Mockito.anyString())).thenReturn("3"); |
| 168 | + ApplicationContext appCtx = Mockito.mock(ApplicationContext.class); |
| 169 | + Mockito.when(appCtx.getBean(Mockito.anyString(), Mockito.any(ImageStoreDetailsUtil.class))).thenReturn(imgSDUtil); |
| 170 | + ctx.setApplicationContext(appCtx); |
166 | 171 | } |
167 | 172 |
|
168 | 173 | @Before |
@@ -230,8 +235,6 @@ public void testSetUp() { |
230 | 235 | Mockito.when(addCmd.getPassword()).thenReturn(password); |
231 | 236 | Mockito.when(addCmd.getName()).thenReturn(vmwareDcName); |
232 | 237 | Mockito.when(removeCmd.getZoneId()).thenReturn(1L); |
233 | | - Mockito.when(imageStoreDetailsUtil.getNfsVersion(Mockito.anyLong())).thenReturn(null); |
234 | | - Mockito.when(imageStoreDetailsUtil.getNfsVersionByUuid(Mockito.anyString())).thenReturn(null); |
235 | 238 | } |
236 | 239 |
|
237 | 240 | @After |
@@ -439,21 +442,6 @@ public DataStoreManager dataStoreManager() { |
439 | 442 | return Mockito.mock(DataStoreManager.class); |
440 | 443 | } |
441 | 444 |
|
442 | | - @Bean |
443 | | - public ImageStoreDetailsUtil imageStoreDetailsUtil() { |
444 | | - return Mockito.mock(ImageStoreDetailsUtil.class); |
445 | | - } |
446 | | - |
447 | | - @Bean |
448 | | - public ImageStoreDao imageStoreDao() { |
449 | | - return Mockito.mock(ImageStoreDao.class); |
450 | | - } |
451 | | - |
452 | | - @Bean |
453 | | - public ImageStoreDetailsDao imageStoreDetailsDao() { |
454 | | - return Mockito.mock(ImageStoreDetailsDao.class); |
455 | | - } |
456 | | - |
457 | 445 | public static class Library implements TypeFilter { |
458 | 446 |
|
459 | 447 | @Override |
|
0 commit comments