|
66 | 66 | import org.mockito.InOrder; |
67 | 67 | import org.mockito.InjectMocks; |
68 | 68 | import org.mockito.Mock; |
| 69 | +import org.mockito.MockedStatic; |
69 | 70 | import org.mockito.Mockito; |
70 | 71 | import org.mockito.Spy; |
| 72 | +import org.mockito.junit.MockitoJUnitRunner; |
71 | 73 | import org.mockito.stubbing.Answer; |
72 | 74 |
|
73 | 75 | import com.cloud.agent.AgentManager; |
|
107 | 109 | import com.cloud.vm.VirtualMachine.State; |
108 | 110 | import com.cloud.vm.dao.UserVmDao; |
109 | 111 | import com.cloud.vm.dao.VMInstanceDao; |
110 | | -import org.powermock.api.mockito.PowerMockito; |
111 | | -import org.powermock.core.classloader.annotations.PowerMockIgnore; |
112 | | -import org.powermock.core.classloader.annotations.PrepareForTest; |
113 | | -import org.powermock.modules.junit4.PowerMockRunner; |
114 | 112 | import org.springframework.test.util.ReflectionTestUtils; |
115 | 113 |
|
116 | | -@RunWith(PowerMockRunner.class) |
117 | | -@PrepareForTest(CallContext.class) |
118 | | -@PowerMockIgnore({"javax.xml.*", "org.w3c.dom.*", "org.apache.xerces.*", "org.xml.*"}) |
| 114 | +@RunWith(MockitoJUnitRunner.class) |
119 | 115 | public class VirtualMachineManagerImplTest { |
120 | 116 |
|
121 | 117 | @Spy |
@@ -1014,15 +1010,16 @@ public void testOrchestrateStartNonNullPodId() throws Exception { |
1014 | 1010 | doReturn(false).when(virtualMachineManagerImpl).areAllVolumesAllocated(Mockito.anyLong()); |
1015 | 1011 |
|
1016 | 1012 | CallContext callContext = mock(CallContext.class); |
1017 | | - Mockito.when(callContext.getCallingAccount()).thenReturn(account); |
1018 | | - Mockito.when(callContext.getCallingUser()).thenReturn(user); |
1019 | | - PowerMockito.mockStatic(CallContext.class); |
1020 | | - PowerMockito.when(CallContext.current()).thenReturn(callContext); |
1021 | | - |
1022 | | - try { |
1023 | | - virtualMachineManagerImpl.orchestrateStart("vm-uuid", params, plan, planner); |
1024 | | - } catch (CloudRuntimeException e) { |
1025 | | - assertEquals(e.getMessage(), "Error while transitioning"); |
| 1013 | + when(callContext.getCallingAccount()).thenReturn(account); |
| 1014 | + when(callContext.getCallingUser()).thenReturn(user); |
| 1015 | + try (MockedStatic<CallContext> ignored = Mockito.mockStatic(CallContext.class)) { |
| 1016 | + when(CallContext.current()).thenReturn(callContext); |
| 1017 | + |
| 1018 | + try { |
| 1019 | + virtualMachineManagerImpl.orchestrateStart("vm-uuid", params, plan, planner); |
| 1020 | + } catch (CloudRuntimeException e) { |
| 1021 | + assertEquals(e.getMessage(), "Error while transitioning"); |
| 1022 | + } |
1026 | 1023 | } |
1027 | 1024 |
|
1028 | 1025 | assertEquals(vmInstance.getPodIdToDeployIn(), (Long) destPod.getId()); |
@@ -1106,15 +1103,16 @@ public void testOrchestrateStartNullPodId() throws Exception { |
1106 | 1103 | doReturn(true).when(virtualMachineManagerImpl).areAllVolumesAllocated(Mockito.anyLong()); |
1107 | 1104 |
|
1108 | 1105 | CallContext callContext = mock(CallContext.class); |
1109 | | - Mockito.when(callContext.getCallingAccount()).thenReturn(account); |
1110 | | - Mockito.when(callContext.getCallingUser()).thenReturn(user); |
1111 | | - PowerMockito.mockStatic(CallContext.class); |
1112 | | - PowerMockito.when(CallContext.current()).thenReturn(callContext); |
1113 | | - |
1114 | | - try { |
1115 | | - virtualMachineManagerImpl.orchestrateStart("vm-uuid", params, plan, planner); |
1116 | | - } catch (CloudRuntimeException e) { |
1117 | | - assertEquals(e.getMessage(), "Error while transitioning"); |
| 1106 | + when(callContext.getCallingAccount()).thenReturn(account); |
| 1107 | + when(callContext.getCallingUser()).thenReturn(user); |
| 1108 | + try (MockedStatic<CallContext> ignored = Mockito.mockStatic(CallContext.class)) { |
| 1109 | + when(CallContext.current()).thenReturn(callContext); |
| 1110 | + |
| 1111 | + try { |
| 1112 | + virtualMachineManagerImpl.orchestrateStart("vm-uuid", params, plan, planner); |
| 1113 | + } catch (CloudRuntimeException e) { |
| 1114 | + assertEquals(e.getMessage(), "Error while transitioning"); |
| 1115 | + } |
1118 | 1116 | } |
1119 | 1117 |
|
1120 | 1118 | assertNull(vmInstance.getPodIdToDeployIn()); |
|
0 commit comments