You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2023/08/04 08:26:04 UTC
[cloudstack] branch main updated: Remove powermock from xenserver hypervisor plugin (#7806)
This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new 90443cdd431 Remove powermock from xenserver hypervisor plugin (#7806)
90443cdd431 is described below
commit 90443cdd431940ab7fcdd1b74871a62f4d369998
Author: Vishesh <vi...@gmail.com>
AuthorDate: Fri Aug 4 13:55:58 2023 +0530
Remove powermock from xenserver hypervisor plugin (#7806)
---
.../xenserver/resource/CitrixResourceBaseTest.java | 60 ++++----
.../resource/Xenserver625StorageProcessorTest.java | 157 ++++++++++-----------
.../wrapper/xenbase/CitrixRequestWrapperTest.java | 68 ++-------
.../wrapper/xenbase/XcpServerWrapperTest.java | 6 +-
.../wrapper/xenbase/XenServer56FP1WrapperTest.java | 4 +-
.../wrapper/xenbase/XenServer56WrapperTest.java | 8 +-
.../wrapper/xenbase/XenServer610WrapperTest.java | 50 +------
.../xenbase/XenServer620SP1WrapperTest.java | 4 +-
.../wrapper/xenbase/XenServer620WrapperTest.java | 4 +-
.../org.mockito.plugins.MockMaker | 1 +
10 files changed, 133 insertions(+), 229 deletions(-)
diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java
index 661200f3ffe..27a108779e0 100644
--- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java
+++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java
@@ -24,6 +24,7 @@ import java.util.Map;
import java.util.Set;
import org.apache.xmlrpc.XmlRpcException;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -31,11 +32,9 @@ import org.junit.runner.RunWith;
import org.mockito.BDDMockito;
import org.mockito.InOrder;
import org.mockito.Mock;
+import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.Spy;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.agent.api.StoragePoolInfo;
@@ -52,13 +51,13 @@ import com.xensource.xenapi.Host.Record;
import com.xensource.xenapi.PBD;
import com.xensource.xenapi.SR;
import com.xensource.xenapi.Types.XenAPIException;
+import org.mockito.junit.MockitoJUnitRunner;
import static com.cloud.hypervisor.xenserver.resource.CitrixResourceBase.PLATFORM_CORES_PER_SOCKET_KEY;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({Host.class, Script.class, SR.class})
+@RunWith(MockitoJUnitRunner.class)
public class CitrixResourceBaseTest {
@Spy
@@ -87,12 +86,14 @@ public class CitrixResourceBaseTest {
final static String publicIp = "10.10.10.10";
final static Integer port = 8080;
+ MockedStatic<Host> hostMocked;
+
@Before
public void beforeTest() throws XenAPIException, XmlRpcException {
citrixResourceBase._host.setUuid(hostUuidMock);
- PowerMockito.mockStatic(Host.class);
- PowerMockito.when(Host.getByUuid(connectionMock, hostUuidMock)).thenReturn(hostMock);
+ hostMocked = Mockito.mockStatic(Host.class);
+ hostMocked.when(() -> Host.getByUuid(connectionMock, hostUuidMock)).thenReturn(hostMock);
hostRecordMock.softwareVersion = new HashMap<>();
Mockito.when(hostMock.getRecord(connectionMock)).thenReturn(hostRecordMock);
@@ -102,25 +103,31 @@ public class CitrixResourceBaseTest {
public void testGetPathFilesException() {
String patch = citrixResourceBase.getPatchFilePath();
- PowerMockito.mockStatic(Script.class);
- Mockito.when(Script.findScript("", patch)).thenReturn(null);
-
- citrixResourceBase.getPatchFiles();
+ try (MockedStatic<Script> ignored = Mockito.mockStatic(Script.class)) {
+ Mockito.when(Script.findScript("", patch)).thenReturn(null);
+ citrixResourceBase.getPatchFiles();
+ }
}
public void testGetPathFilesListReturned() {
String patch = citrixResourceBase.getPatchFilePath();
- PowerMockito.mockStatic(Script.class);
- Mockito.when(Script.findScript("", patch)).thenReturn(patch);
+ try (MockedStatic<Script> ignored = Mockito.mockStatic(Script.class)) {
+ Mockito.when(Script.findScript("", patch)).thenReturn(patch);
- File expected = new File(patch);
- String pathExpected = expected.getAbsolutePath();
+ File expected = new File(patch);
+ String pathExpected = expected.getAbsolutePath();
+
+ List<File> files = citrixResourceBase.getPatchFiles();
+ String receivedPath = files.get(0).getAbsolutePath();
+ Assert.assertEquals(receivedPath, pathExpected);
+ }
+ }
- List<File> files = citrixResourceBase.getPatchFiles();
- String receivedPath = files.get(0).getAbsolutePath();
- Assert.assertEquals(receivedPath, pathExpected);
+ @After
+ public void tearDown() throws Exception {
+ hostMocked.close();
}
@Test
@@ -233,14 +240,14 @@ public class CitrixResourceBaseTest {
Map<SR, SR.Record> mapOfSrsRecords = new HashMap<>();
mapOfSrsRecords.put(srExtShared, srExtSharedRecord);
mapOfSrsRecords.put(srExtNonShared, srExtNonSharedRecord);
+ try (MockedStatic<SR> ignored = Mockito.mockStatic(SR.class)) {
+ BDDMockito.given(SR.getAllRecords(connectionMock)).willReturn(mapOfSrsRecords);
- PowerMockito.mockStatic(SR.class);
- BDDMockito.given(SR.getAllRecords(connectionMock)).willReturn(mapOfSrsRecords);
-
- List<SR> allLocalSrForType = citrixResourceBase.getAllLocalSrForType(connectionMock, SRType.EXT);
+ List<SR> allLocalSrForType = citrixResourceBase.getAllLocalSrForType(connectionMock, SRType.EXT);
- Assert.assertEquals(expectedListOfSrs.size(), allLocalSrForType.size());
- Assert.assertEquals(expectedListOfSrs.get(0), allLocalSrForType.get(0));
+ Assert.assertEquals(expectedListOfSrs.size(), allLocalSrForType.size());
+ Assert.assertEquals(expectedListOfSrs.get(0), allLocalSrForType.get(0));
+ }
}
@Test
@@ -287,9 +294,7 @@ public class CitrixResourceBaseTest {
String hostUuid = "hostUuid";
citrixResourceBase._host.setUuid(hostUuid);
- PowerMockito.mockStatic(Host.class);
- PowerMockito.when(Host.getByUuid(connectionMock, hostUuid)).thenReturn(hostMock);
-
+ Mockito.when(Host.getByUuid(connectionMock, hostUuid)).thenReturn(hostMock);
String srType = "ext";
String srUuid = "srUuid";
long srPhysicalSize = 100l;
@@ -432,7 +437,6 @@ public class CitrixResourceBaseTest {
CitrixResourceBase citrixResourceBaseSpy = Mockito.spy(CitrixResourceBase.class);
Connection connection = Mockito.mock(Connection.class);
- String args = "-g -l " + publicIp;
doReturn(networkStats[0] + ":" + networkStats[1]).when(citrixResourceBaseSpy).networkUsage(Mockito.any(Connection.class),
Mockito.eq(privateIp), Mockito.eq("get"), Mockito.any(), Mockito.eq(publicIp));
diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessorTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessorTest.java
index 070519452b8..5f2ae88faa7 100644
--- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessorTest.java
+++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessorTest.java
@@ -37,10 +37,9 @@ import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.MockedStatic;
import org.mockito.Mockito;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import com.cloud.utils.exception.CloudRuntimeException;
import com.xensource.xenapi.Connection;
@@ -51,7 +50,7 @@ import com.xensource.xenapi.SR;
import com.xensource.xenapi.Types.InternalError;
import com.xensource.xenapi.Types.XenAPIException;
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class Xenserver625StorageProcessorTest {
@InjectMocks
@@ -109,10 +108,8 @@ public class Xenserver625StorageProcessorTest {
@Test
public void createFileSRTestSrAlreadyConfigured() {
SR srMockRetrievedMethod = Mockito.mock(SR.class);
- SR srMockCreateMethod = Mockito.mock(SR.class);
Mockito.doReturn(srMockRetrievedMethod).when(xenserver625StorageProcessor).retrieveAlreadyConfiguredSrWithoutException(connectionMock, pathMock);
- Mockito.doReturn(srMockCreateMethod).when(xenserver625StorageProcessor).createNewFileSr(connectionMock, pathMock);
SR methodCreateFileSrResult = xenserver625StorageProcessor.createFileSR(connectionMock, pathMock);
@@ -172,47 +169,39 @@ public class Xenserver625StorageProcessorTest {
}
@Test
- @PrepareForTest(SR.class)
public void retrieveAlreadyConfiguredSrTestNoSrFound() throws XenAPIException, XmlRpcException {
- prepareToReturnSrs(null);
-
- SR sr = xenserver625StorageProcessor.retrieveAlreadyConfiguredSr(connectionMock, pathMock);
-
- PowerMockito.verifyStatic(SR.class);
- SR.getByNameLabel(connectionMock, pathMock);
- Assert.assertNull(sr);
- }
+ try (MockedStatic<SR> srMocked = Mockito.mockStatic(SR.class)) {
+ Mockito.when(SR.getByNameLabel(connectionMock, pathMock)).thenReturn(null);
+ SR sr = xenserver625StorageProcessor.retrieveAlreadyConfiguredSr(connectionMock, pathMock);
- private void prepareToReturnSrs(Set<SR> srs) throws XenAPIException, XmlRpcException {
- PowerMockito.mockStatic(SR.class);
- PowerMockito.when(SR.getByNameLabel(connectionMock, pathMock)).thenReturn(srs);
+ srMocked.verify(() -> SR.getByNameLabel(connectionMock, pathMock), times(1));
+ Assert.assertNull(sr);
+ }
}
- @PrepareForTest(SR.class)
@Test(expected = CloudRuntimeException.class)
public void retrieveAlreadyConfiguredSrTestMultipleSrsFound() throws XenAPIException, XmlRpcException {
HashSet<SR> srs = new HashSet<>();
srs.add(Mockito.mock(SR.class));
srs.add(Mockito.mock(SR.class));
- prepareToReturnSrs(srs);
+ try (MockedStatic<SR> ignored = Mockito.mockStatic(SR.class)) {
+ Mockito.when(SR.getByNameLabel(connectionMock, pathMock)).thenReturn(srs);
- xenserver625StorageProcessor.retrieveAlreadyConfiguredSr(connectionMock, pathMock);
+ xenserver625StorageProcessor.retrieveAlreadyConfiguredSr(connectionMock, pathMock);
+ }
}
@Test
- @PrepareForTest(SR.class)
public void retrieveAlreadyConfiguredSrTestSrFailsSanityCheckWithXenAPIException() throws XenAPIException, XmlRpcException {
configureAndExecuteMethodRetrieveAlreadyConfiguredSrTestSrFailsSanityCheckForException(XenAPIException.class);
}
@Test
- @PrepareForTest(SR.class)
public void retrieveAlreadyConfiguredSrTestSrFailsSanityCheckWithXmlRpcException() throws XenAPIException, XmlRpcException {
configureAndExecuteMethodRetrieveAlreadyConfiguredSrTestSrFailsSanityCheckForException(XmlRpcException.class);
}
- @PrepareForTest(SR.class)
@Test(expected = RuntimeException.class)
public void retrieveAlreadyConfiguredSrTestSrFailsSanityCheckWithRuntimeException() throws XenAPIException, XmlRpcException {
configureAndExecuteMethodRetrieveAlreadyConfiguredSrTestSrFailsSanityCheckForException(RuntimeException.class);
@@ -225,17 +214,18 @@ public class Xenserver625StorageProcessorTest {
HashSet<SR> srs = new HashSet<>();
srs.add(srMock);
- prepareToReturnSrs(srs);
- Mockito.doNothing().when(xenserver625StorageProcessor).forgetSr(connectionMock, srMock);
+ try (MockedStatic<SR> ignored = Mockito.mockStatic(SR.class)) {
+ Mockito.when(SR.getByNameLabel(connectionMock, pathMock)).thenReturn(srs);
+ Mockito.doNothing().when(xenserver625StorageProcessor).forgetSr(connectionMock, srMock);
- SR sr = xenserver625StorageProcessor.retrieveAlreadyConfiguredSr(connectionMock, pathMock);
+ SR sr = xenserver625StorageProcessor.retrieveAlreadyConfiguredSr(connectionMock, pathMock);
- Assert.assertNull(sr);
- Mockito.verify(xenserver625StorageProcessor).forgetSr(connectionMock, srMock);
+ Assert.assertNull(sr);
+ Mockito.verify(xenserver625StorageProcessor).forgetSr(connectionMock, srMock);
+ }
}
@Test
- @PrepareForTest(SR.class)
public void methodRetrieveAlreadyConfiguredSrTestSrScanSucceeds() throws XenAPIException, XmlRpcException {
SR srMock = Mockito.mock(SR.class);
Mockito.doNothing().when(srMock).scan(connectionMock);
@@ -243,13 +233,14 @@ public class Xenserver625StorageProcessorTest {
HashSet<SR> srs = new HashSet<>();
srs.add(srMock);
- prepareToReturnSrs(srs);
- Mockito.doNothing().when(xenserver625StorageProcessor).forgetSr(connectionMock, srMock);
+ try (MockedStatic<SR> ignored = Mockito.mockStatic(SR.class)) {
+ Mockito.when(SR.getByNameLabel(connectionMock, pathMock)).thenReturn(srs);
- SR sr = xenserver625StorageProcessor.retrieveAlreadyConfiguredSr(connectionMock, pathMock);
+ SR sr = xenserver625StorageProcessor.retrieveAlreadyConfiguredSr(connectionMock, pathMock);
- Assert.assertEquals(srMock, sr);
- Mockito.verify(xenserver625StorageProcessor, times(0)).forgetSr(connectionMock, srMock);
+ Assert.assertEquals(srMock, sr);
+ Mockito.verify(xenserver625StorageProcessor, times(0)).forgetSr(connectionMock, srMock);
+ }
}
@Test
@@ -301,19 +292,16 @@ public class Xenserver625StorageProcessorTest {
}
@Test
- @PrepareForTest({Host.class, SR.class})
public void createNewFileSrTestThrowingXenAPIException() throws XenAPIException, XmlRpcException {
prepareAndExecuteTestcreateNewFileSrTestThrowingException(XenAPIException.class);
}
@Test
- @PrepareForTest({Host.class, SR.class})
public void createNewFileSrTestThrowingXmlRpcException() throws XenAPIException, XmlRpcException {
prepareAndExecuteTestcreateNewFileSrTestThrowingException(XmlRpcException.class);
}
@Test(expected = RuntimeException.class)
- @PrepareForTest({Host.class, SR.class})
public void createNewFileSrTestThrowingRuntimeException() throws XenAPIException, XmlRpcException {
prepareAndExecuteTestcreateNewFileSrTestThrowingException(RuntimeException.class);
}
@@ -326,23 +314,23 @@ public class Xenserver625StorageProcessorTest {
Host hostMock = Mockito.mock(Host.class);
- PowerMockito.mockStatic(Host.class);
- PowerMockito.when(Host.getByUuid(connectionMock, uuid)).thenReturn(hostMock);
+ try (MockedStatic<Host> ignored = Mockito.mockStatic(
+ Host.class); MockedStatic<SR> ignored1 = Mockito.mockStatic(SR.class)) {
+ Mockito.when(Host.getByUuid(connectionMock, uuid)).thenReturn(hostMock);
+ Mockito.when(SR.introduce(Mockito.eq(connectionMock), Mockito.eq(srUuid), Mockito.eq(pathMock),
+ Mockito.eq(pathMock), Mockito.eq("file"), Mockito.eq("file"), Mockito.eq(false),
+ Mockito.anyMap())).thenThrow(Mockito.mock(exceptionClass));
- PowerMockito.mockStatic(SR.class);
- PowerMockito.when(SR.introduce(Mockito.eq(connectionMock), Mockito.eq(srUuid), Mockito.eq(pathMock), Mockito.eq(pathMock), Mockito.eq("file"), Mockito.eq("file"), Mockito.eq(false),
- Mockito.anyMapOf(String.class, String.class))).thenThrow(Mockito.mock(exceptionClass));
- Mockito.doNothing().when(xenserver625StorageProcessor).removeSrAndPbdIfPossible(Mockito.eq(connectionMock), Mockito.any(SR.class), Mockito.any(PBD.class));
+ SR sr = xenserver625StorageProcessor.createNewFileSr(connectionMock, pathMock);
- SR sr = xenserver625StorageProcessor.createNewFileSr(connectionMock, pathMock);
-
- assertNull(sr);
- Mockito.verify(xenserver625StorageProcessor).removeSrAndPbdIfPossible(Mockito.eq(connectionMock), nullable(SR.class), nullable(PBD.class));
+ assertNull(sr);
+ Mockito.verify(xenserver625StorageProcessor).removeSrAndPbdIfPossible(Mockito.eq(connectionMock),
+ nullable(SR.class), nullable(PBD.class));
+ }
}
@Test
- @PrepareForTest({Host.class, SR.class})
public void createNewFileSrTestThrowingDbUniqueException() throws XenAPIException, XmlRpcException {
String uuid = "hostUuid";
Mockito.when(citrixResourceBase._host.getUuid()).thenReturn(uuid);
@@ -353,61 +341,66 @@ public class Xenserver625StorageProcessorTest {
Host hostMock = Mockito.mock(Host.class);
- PowerMockito.mockStatic(Host.class);
- PowerMockito.when(Host.getByUuid(connectionMock, uuid)).thenReturn(hostMock);
-
- PowerMockito.mockStatic(SR.class);
- InternalError dbUniquenessException = new InternalError("message: Db_exn.Uniqueness_constraint_violation(\"SR\", \"uuid\", \"fd3edbcf-f142-83d1-3fcb-029ca2446b68\")");
+ try (MockedStatic<Host> ignored = Mockito.mockStatic(Host.class);MockedStatic<SR> ignored1 =
+ Mockito.mockStatic(SR.class) ) {
+ Mockito.when(Host.getByUuid(connectionMock, uuid)).thenReturn(hostMock);
- PowerMockito.when(SR.introduce(Mockito.eq(connectionMock), Mockito.eq(srUuid), Mockito.eq(pathMock), Mockito.eq(pathMock), Mockito.eq("file"), Mockito.eq("file"), Mockito.eq(false),
- Mockito.anyMapOf(String.class, String.class))).thenThrow(dbUniquenessException);
+ InternalError dbUniquenessException = new InternalError(
+ "message: Db_exn.Uniqueness_constraint_violation(\"SR\", \"uuid\", \"fd3edbcf-f142-83d1-3fcb-029ca2446b68\")");
- Mockito.doNothing().when(xenserver625StorageProcessor).removeSrAndPbdIfPossible(Mockito.eq(connectionMock), Mockito.any(SR.class), Mockito.any(PBD.class));
+ Mockito.when(SR.introduce(Mockito.eq(connectionMock), Mockito.eq(srUuid), Mockito.eq(pathMock),
+ Mockito.eq(pathMock), Mockito.eq("file"), Mockito.eq("file"), Mockito.eq(false),
+ Mockito.anyMap())).thenThrow(dbUniquenessException);
- SR sr = xenserver625StorageProcessor.createNewFileSr(connectionMock, pathMock);
+ SR sr = xenserver625StorageProcessor.createNewFileSr(connectionMock, pathMock);
- Assert.assertEquals(srMock, sr);
- Mockito.verify(xenserver625StorageProcessor, times(0)).removeSrAndPbdIfPossible(Mockito.eq(connectionMock), Mockito.any(SR.class), Mockito.any(PBD.class));
- Mockito.verify(xenserver625StorageProcessor).retrieveAlreadyConfiguredSrWithoutException(connectionMock, pathMock);
+ Assert.assertEquals(srMock, sr);
+ Mockito.verify(xenserver625StorageProcessor, times(0)).removeSrAndPbdIfPossible(Mockito.eq(connectionMock),
+ Mockito.any(SR.class), Mockito.any(PBD.class));
+ Mockito.verify(xenserver625StorageProcessor).retrieveAlreadyConfiguredSrWithoutException(connectionMock,
+ pathMock);
+ }
}
@Test
- @PrepareForTest({Host.class, SR.class, PBD.class})
public void createNewFileSrTest() throws XenAPIException, XmlRpcException {
String uuid = "hostUuid";
Mockito.when(citrixResourceBase._host.getUuid()).thenReturn(uuid);
SR srMock = Mockito.mock(SR.class);
- Mockito.doReturn(srMock).when(xenserver625StorageProcessor).retrieveAlreadyConfiguredSrWithoutException(connectionMock, pathMock);
String srUuid = UUID.nameUUIDFromBytes(pathMock.getBytes()).toString();
Host hostMock = Mockito.mock(Host.class);
- PowerMockito.mockStatic(Host.class);
- PowerMockito.when(Host.getByUuid(connectionMock, uuid)).thenReturn(hostMock);
+ try (MockedStatic<Host> ignored = Mockito.mockStatic(Host.class);MockedStatic<SR> ignored1 =
+ Mockito.mockStatic(SR.class);MockedStatic<PBD> pbdMockedStatic = Mockito.mockStatic(PBD.class)) {
+ Mockito.when(Host.getByUuid(connectionMock, uuid)).thenReturn(hostMock);
- PowerMockito.mockStatic(SR.class);
- PowerMockito.when(SR.introduce(Mockito.eq(connectionMock), Mockito.eq(srUuid), Mockito.eq(pathMock), Mockito.eq(pathMock), Mockito.eq("file"), Mockito.eq("file"), Mockito.eq(false),
- Mockito.anyMapOf(String.class, String.class))).thenReturn(srMock);
- PowerMockito.mockStatic(PBD.class);
- PBD pbdMock = Mockito.mock(PBD.class);
- PowerMockito.when(PBD.create(Mockito.eq(connectionMock), Mockito.any(Record.class))).thenReturn(pbdMock);
+ Mockito.when(SR.introduce(Mockito.eq(connectionMock), Mockito.eq(srUuid), Mockito.eq(pathMock),
+ Mockito.eq(pathMock), Mockito.eq("file"), Mockito.eq("file"), Mockito.eq(false),
+ Mockito.anyMap())).thenReturn(srMock);
- Mockito.doNothing().when(xenserver625StorageProcessor).removeSrAndPbdIfPossible(Mockito.eq(connectionMock), Mockito.any(SR.class), Mockito.any(PBD.class));
- SR sr = xenserver625StorageProcessor.createNewFileSr(connectionMock, pathMock);
+ PBD pbdMock = Mockito.mock(PBD.class);
+ Mockito.when(PBD.create(Mockito.eq(connectionMock), Mockito.any(Record.class))).thenReturn(pbdMock);
- Assert.assertEquals(srMock, sr);
- Mockito.verify(xenserver625StorageProcessor, times(0)).removeSrAndPbdIfPossible(Mockito.eq(connectionMock), Mockito.any(SR.class), Mockito.any(PBD.class));
- Mockito.verify(xenserver625StorageProcessor, times(0)).retrieveAlreadyConfiguredSrWithoutException(connectionMock, pathMock);
+ SR sr = xenserver625StorageProcessor.createNewFileSr(connectionMock, pathMock);
+
+ Assert.assertEquals(srMock, sr);
+ Mockito.verify(xenserver625StorageProcessor, times(0)).removeSrAndPbdIfPossible(Mockito.eq(connectionMock),
+ Mockito.any(SR.class), Mockito.any(PBD.class));
+ Mockito.verify(xenserver625StorageProcessor, times(0)).retrieveAlreadyConfiguredSrWithoutException(
+ connectionMock, pathMock);
+
+ Mockito.verify(srMock).scan(connectionMock);
+ Mockito.verify(pbdMock).plug(connectionMock);
- Mockito.verify(srMock).scan(connectionMock);
- Mockito.verify(pbdMock).plug(connectionMock);
+ SR.introduce(Mockito.eq(connectionMock), Mockito.eq(srUuid), Mockito.eq(pathMock), Mockito.eq(pathMock),
+ Mockito.eq("file"), Mockito.eq("file"), Mockito.eq(false),
+ Mockito.anyMap());
- PowerMockito.verifyStatic(PBD.class);
- SR.introduce(Mockito.eq(connectionMock), Mockito.eq(srUuid), Mockito.eq(pathMock), Mockito.eq(pathMock), Mockito.eq("file"), Mockito.eq("file"), Mockito.eq(false),
- Mockito.anyMapOf(String.class, String.class));
- PBD.create(Mockito.eq(connectionMock), Mockito.any(Record.class));
+ pbdMockedStatic.verify(() -> PBD.create(Mockito.eq(connectionMock), Mockito.any(Record.class)));
+ }
}
@Test
diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java
index 9d18e73afb4..9ecb14d841f 100755
--- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java
+++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java
@@ -40,14 +40,12 @@ import org.apache.cloudstack.storage.command.AttachCommand;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.client.XmlRpcClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.MockedStatic;
import org.mockito.Mockito;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.AttachIsoCommand;
@@ -144,9 +142,9 @@ import com.xensource.xenapi.Types.BadServerResponse;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VM;
import com.xensource.xenapi.VMGuestMetrics;
+import org.springframework.test.util.ReflectionTestUtils;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(value = {Pool.Record.class})
+@RunWith(MockitoJUnitRunner.class)
public class CitrixRequestWrapperTest {
@Mock
@@ -411,15 +409,12 @@ public class CitrixRequestWrapperTest {
@Test
public void testDeleteStoragePoolCommand() {
final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
- final XsHost xsHost = Mockito.mock(XsHost.class);
final DeleteStoragePoolCommand deleteStorageCommand = new DeleteStoragePoolCommand(poolVO);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
- when(citrixResourceBase.getHost()).thenReturn(xsHost);
-
final Answer answer = wrapper.execute(deleteStorageCommand, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
@@ -536,7 +531,6 @@ public class CitrixRequestWrapperTest {
@Test
public void testSetupCommand() {
- final XsHost xsHost = Mockito.mock(XsHost.class);
final HostEnvironment env = Mockito.mock(HostEnvironment.class);
final SetupCommand setupCommand = new SetupCommand(env);
@@ -544,8 +538,6 @@ public class CitrixRequestWrapperTest {
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
- when(citrixResourceBase.getHost()).thenReturn(xsHost);
-
final Answer answer = wrapper.execute(setupCommand, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
@@ -560,10 +552,6 @@ public class CitrixRequestWrapperTest {
final Connection conn = Mockito.mock(Connection.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
- final XmlRpcClient client = Mockito.mock(XmlRpcClient.class);
-
- // final Host.Record hr = PowerMockito.mock(Host.Record.class);
- // final Host host = PowerMockito.mock(Host.class);
final MaintainCommand maintainCommand = new MaintainCommand();
@@ -582,8 +570,8 @@ public class CitrixRequestWrapperTest {
try {
final Object[] params = { Marshalling.toXMLRPC("befc4dcd"), Marshalling.toXMLRPC(uuid) };
- when(client.execute("host.get_by_uuid", new Object[] { "befc4dcd", uuid })).thenReturn(spiedMap);
- PowerMockito.when(conn, "dispatch", "host.get_by_uuid", params).thenReturn(spiedMap);
+
+ when(ReflectionTestUtils.invokeMethod(conn, "dispatch", "host.get_by_uuid", params)).thenReturn(spiedMap);
} catch (final Exception e) {
fail(e.getMessage());
}
@@ -936,11 +924,6 @@ public class CitrixRequestWrapperTest {
when(citrixResourceBase.findOrCreateTunnelNetwork(conn, physicalTopology.getBridgeName())).thenReturn(network);
when(network.getBridge(conn)).thenReturn(bridge);
- when(
- citrixResourceBase.callHostPlugin(conn, "ovstunnel", "configure_ovs_bridge_for_network_topology", "bridge", bridge, "config",
- physicalTopology.getVpcConfigInJson(), "host-id", ((Long) physicalTopology.getHostId()).toString(), "seq-no", Long.toString(1))).thenReturn(
- "SUCCESS");
-
} catch (final BadServerResponse e) {
fail(e.getMessage());
} catch (final XenAPIException e) {
@@ -975,11 +958,6 @@ public class CitrixRequestWrapperTest {
when(citrixResourceBase.findOrCreateTunnelNetwork(conn, routingPolicy.getBridgeName())).thenReturn(network);
when(network.getBridge(conn)).thenReturn(bridge);
- when(
- citrixResourceBase.callHostPlugin(conn, "ovstunnel", "configure_ovs_bridge_for_routing_policies", "bridge", bridge, "host-id",
- ((Long) routingPolicy.getHostId()).toString(), "config", routingPolicy.getVpcConfigInJson(), "seq-no", Long.toString(1))).thenReturn(
- "SUCCESS");
-
} catch (final BadServerResponse e) {
fail(e.getMessage());
} catch (final XenAPIException e) {
@@ -1468,7 +1446,7 @@ public class CitrixRequestWrapperTest {
final Connection conn = Mockito.mock(Connection.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
- final Pool pool = PowerMockito.mock(Pool.class);
+ final Pool pool = Mockito.mock(Pool.class);
final Pool.Record poolr = Mockito.mock(Pool.Record.class);
final Host.Record hostr = Mockito.mock(Host.Record.class);
final Host master = Mockito.mock(Host.class);
@@ -1479,30 +1457,16 @@ public class CitrixRequestWrapperTest {
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
- try {
+ try (MockedStatic<Pool.Record> ignored = Mockito.mockStatic(Pool.Record.class)){
when(citrixResourceBase.getHost()).thenReturn(xsHost);
- when(citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
-
- PowerMockito.mockStatic(Pool.Record.class);
-
- when(pool.getRecord(conn)).thenReturn(poolr);
poolr.master = master;
- when(poolr.master.getRecord(conn)).thenReturn(hostr);
- hostr.uuid = uuid;
- } catch (final BadServerResponse e) {
- fail(e.getMessage());
- } catch (final XenAPIException e) {
- fail(e.getMessage());
- } catch (final XmlRpcException e) {
- fail(e.getMessage());
- }
-
- final Answer answer = wrapper.execute(vmDataSync, citrixResourceBase);
+ final Answer answer = wrapper.execute(vmDataSync, citrixResourceBase);
- verify(citrixResourceBase, times(1)).getConnection();
+ verify(citrixResourceBase, times(1)).getConnection();
- assertTrue(answer.getResult());
+ assertTrue(answer.getResult());
+ }
}
@Test
@@ -1695,14 +1659,6 @@ public class CitrixRequestWrapperTest {
when(citrixResourceBase.getHost()).thenReturn(xsHost);
when(citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
- try {
- when(citrixResourceBase.isDmcEnabled(conn, host)).thenReturn(true);
- } catch (final XenAPIException e) {
- fail(e.getMessage());
- } catch (final XmlRpcException e) {
- fail(e.getMessage());
- }
-
final Answer answer = wrapper.execute(scaleVm, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XcpServerWrapperTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XcpServerWrapperTest.java
index 6b9990516cd..98a6f2b7a58 100644
--- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XcpServerWrapperTest.java
+++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XcpServerWrapperTest.java
@@ -31,18 +31,17 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.NetworkUsageCommand;
import com.cloud.hypervisor.xenserver.resource.XcpServerResource;
-import com.cloud.utils.exception.CloudRuntimeException;
import com.xensource.xenapi.Connection;
import java.util.ArrayList;
import java.util.List;
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class XcpServerWrapperTest {
@Mock
@@ -116,7 +115,6 @@ public class XcpServerWrapperTest {
assertNotNull(wrapper);
when(XcpServerResource.getConnection()).thenReturn(conn);
- when(XcpServerResource.networkUsage(conn, usageCommand.getPrivateIP(), "create", null)).thenThrow(new CloudRuntimeException("FAILED"));
final Answer answer = wrapper.execute(usageCommand, XcpServerResource);
diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer56FP1WrapperTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer56FP1WrapperTest.java
index 77be68ba7aa..3b8525db962 100644
--- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer56FP1WrapperTest.java
+++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer56FP1WrapperTest.java
@@ -26,7 +26,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.FenceCommand;
@@ -35,7 +35,7 @@ import com.cloud.hypervisor.xenserver.resource.XenServer56FP1Resource;
import com.cloud.vm.VMInstanceVO;
import com.xensource.xenapi.Connection;
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class XenServer56FP1WrapperTest {
@Mock
diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer56WrapperTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer56WrapperTest.java
index 21d6c53fb7c..a0c3e45618d 100644
--- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer56WrapperTest.java
+++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer56WrapperTest.java
@@ -28,7 +28,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckOnHostCommand;
@@ -40,7 +40,6 @@ import com.cloud.agent.api.routing.GetAutoScaleMetricsCommand;
import com.cloud.host.Host;
import com.cloud.host.HostEnvironment;
import com.cloud.hypervisor.xenserver.resource.XenServer56Resource;
-import com.cloud.hypervisor.xenserver.resource.XsHost;
import com.cloud.network.router.VirtualRouterAutoScale;
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetrics;
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetricsValue;
@@ -52,7 +51,7 @@ import com.xensource.xenapi.Connection;
import java.util.ArrayList;
import java.util.List;
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class XenServer56WrapperTest {
@Mock
@@ -260,7 +259,6 @@ public class XenServer56WrapperTest {
@Test
public void testSetupCommand() {
- final XsHost xsHost = Mockito.mock(XsHost.class);
final HostEnvironment env = Mockito.mock(HostEnvironment.class);
final SetupCommand setupCommand = new SetupCommand(env);
@@ -268,8 +266,6 @@ public class XenServer56WrapperTest {
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
- when(xenServer56Resource.getHost()).thenReturn(xsHost);
-
final Answer answer = wrapper.execute(setupCommand, xenServer56Resource);
verify(xenServer56Resource, times(1)).getConnection();
diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer610WrapperTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer610WrapperTest.java
index fdb09f1c973..73d2ca6d333 100644
--- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer610WrapperTest.java
+++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer610WrapperTest.java
@@ -29,13 +29,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import com.google.gson.Gson;
import org.apache.xmlrpc.XmlRpcException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckNetworkCommand;
@@ -60,13 +59,12 @@ import com.cloud.utils.Pair;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Network;
import com.xensource.xenapi.SR;
-import com.xensource.xenapi.Task;
-import com.xensource.xenapi.Types.BadServerResponse;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VDI;
import com.xensource.xenapi.VIF;
-@RunWith(PowerMockRunner.class)
+
+@RunWith(MockitoJUnitRunner.class)
public class XenServer610WrapperTest {
@Mock
@@ -105,7 +103,6 @@ public class XenServer610WrapperTest {
public void testMigrateWithStorageCommand() {
final String vmName = "small";
final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
- final String path = "/";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
@@ -128,12 +125,6 @@ public class XenServer610WrapperTest {
final Network networkForSm = Mockito.mock(Network.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
- final SR sr1 = Mockito.mock(SR.class);
- final SR sr2 = Mockito.mock(SR.class);
-
- final VDI vdi1 = Mockito.mock(VDI.class);
- final VDI vdi2 = Mockito.mock(VDI.class);
-
final MigrateWithStorageCommand migrateStorageCommand = new MigrateWithStorageCommand(vmSpec, volumeToFiler);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
@@ -143,17 +134,7 @@ public class XenServer610WrapperTest {
when(vmSpec.getName()).thenReturn(vmName);
when(vmSpec.getNics()).thenReturn(nicTOs);
- when(storage1.getUuid()).thenReturn(uuid);
- when(storage2.getUuid()).thenReturn(uuid);
-
- when(vol1.getPath()).thenReturn(path);
- when(vol2.getPath()).thenReturn(path);
- when(xenServer610Resource.getStorageRepository(conn, storage1.getUuid())).thenReturn(sr1);
- when(xenServer610Resource.getStorageRepository(conn, storage2.getUuid())).thenReturn(sr2);
-
- when(xenServer610Resource.getVDIbyUuid(conn, storage1.getPath())).thenReturn(vdi1);
- when(xenServer610Resource.getVDIbyUuid(conn, storage2.getPath())).thenReturn(vdi2);
try {
when(xenServer610Resource.getNativeNetworkForTraffic(conn, TrafficType.Storage, null)).thenReturn(nativeNetworkForTraffic);
@@ -221,9 +202,6 @@ public class XenServer610WrapperTest {
final Network nw2 = Mockito.mock(Network.class);
final Network nw3 = Mockito.mock(Network.class);
- final SR sr1 = Mockito.mock(SR.class);
- final SR sr2 = Mockito.mock(SR.class);
-
final MigrateWithStorageReceiveCommand migrateStorageCommand = new MigrateWithStorageReceiveCommand(vmSpec, volumeToFiler);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
@@ -233,14 +211,7 @@ public class XenServer610WrapperTest {
when(vmSpec.getName()).thenReturn(vmName);
when(vmSpec.getNics()).thenReturn(nicTOs);
- when(storage1.getUuid()).thenReturn(uuid);
- when(storage2.getUuid()).thenReturn(uuid);
-
- when(xenServer610Resource.getStorageRepository(conn, storage1.getUuid())).thenReturn(sr1);
- when(xenServer610Resource.getStorageRepository(conn, storage2.getUuid())).thenReturn(sr2);
-
try {
-
when(xenServer610Resource.getNetwork(conn, nicTO1)).thenReturn(nw1);
when(xenServer610Resource.getNetwork(conn, nicTO2)).thenReturn(nw2);
when(xenServer610Resource.getNetwork(conn, nicTO3)).thenReturn(nw3);
@@ -410,7 +381,6 @@ public class XenServer610WrapperTest {
final NicTO nic1 = Mockito.mock(NicTO.class);
final NicTO nic2 = Mockito.mock(NicTO.class);
- Gson gson = new Gson();
final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<Pair<VolumeTO, Object>>();
volumeToSr.add(new Pair<VolumeTO, Object>(volume1, sr1));
volumeToSr.add(new Pair<VolumeTO, Object>(volume2, sr2));
@@ -471,12 +441,9 @@ public class XenServer610WrapperTest {
@Test
public void testXenServer610MigrateVolumeCommandWrapper() {
- final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
final Connection conn = Mockito.mock(Connection.class);
- final SR destinationPool = Mockito.mock(SR.class);
final VDI srcVolume = Mockito.mock(VDI.class);
- final Task task = Mockito.mock(Task.class);
final long volumeId = 1l;
final String volumePath = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
@@ -492,19 +459,8 @@ public class XenServer610WrapperTest {
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
- when(pool.getUuid()).thenReturn(uuid);
- when(xenServer610Resource.getStorageRepository(conn, uuid)).thenReturn(destinationPool);
when(xenServer610Resource.getVDIbyUuid(conn, volumePath)).thenReturn(srcVolume);
- try {
- when(srcVolume.poolMigrateAsync(conn, destinationPool, other)).thenReturn(task);
- } catch (final BadServerResponse e) {
- fail(e.getMessage());
- } catch (final XenAPIException e) {
- fail(e.getMessage());
- } catch (final XmlRpcException e) {
- fail(e.getMessage());
- }
when(xenServer610Resource.getMigrateWait()).thenReturn(120);
diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer620SP1WrapperTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer620SP1WrapperTest.java
index 2645229ace4..495370d1cb2 100644
--- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer620SP1WrapperTest.java
+++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer620SP1WrapperTest.java
@@ -31,7 +31,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.GetGPUStatsCommand;
@@ -41,7 +41,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Types.XenAPIException;
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class XenServer620SP1WrapperTest {
@Mock
diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer620WrapperTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer620WrapperTest.java
index fc3d0039eb7..fe694a6e273 100644
--- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer620WrapperTest.java
+++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/XenServer620WrapperTest.java
@@ -23,14 +23,14 @@ import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckNetworkCommand;
import com.cloud.hypervisor.xenserver.resource.XenServer620Resource;
import com.cloud.network.PhysicalNetworkSetupInfo;
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class XenServer620WrapperTest {
@Test
diff --git a/plugins/hypervisors/xenserver/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/hypervisors/xenserver/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 00000000000..1f0955d450f
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline