Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
gzhao9 committed Oct 19, 2023
1 parent 8530432 commit 8b0675a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5067,7 +5067,6 @@ public void testStartCommandFailedConnect() {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final LibvirtVMDef vmDef = Mockito.mock(LibvirtVMDef.class);

final NicTO nic = Mockito.mock(NicTO.class);
final NicTO[] nics = new NicTO[]{nic};
Expand Down Expand Up @@ -5120,7 +5119,6 @@ public void testStartCommandLibvirtException() {

final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final LibvirtVMDef vmDef = Mockito.mock(LibvirtVMDef.class);

final NicTO nic = Mockito.mock(NicTO.class);
final NicTO[] nics = new NicTO[]{nic};
Expand Down Expand Up @@ -5164,7 +5162,6 @@ public void testStartCommandInternalError() {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final LibvirtVMDef vmDef = Mockito.mock(LibvirtVMDef.class);

final NicTO nic = Mockito.mock(NicTO.class);
final NicTO[] nics = new NicTO[]{nic};
Expand Down Expand Up @@ -5215,7 +5212,6 @@ public void testStartCommandUriException() {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final LibvirtVMDef vmDef = Mockito.mock(LibvirtVMDef.class);

final NicTO nic = Mockito.mock(NicTO.class);
final NicTO[] nics = new NicTO[]{nic};
Expand Down Expand Up @@ -5266,7 +5262,6 @@ public void testStartCommand() throws Exception {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final LibvirtVMDef vmDef = Mockito.mock(LibvirtVMDef.class);
final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);

final NicTO nic = Mockito.mock(NicTO.class);
Expand Down Expand Up @@ -5345,7 +5340,6 @@ public void testStartCommandIsolationEc2() throws Exception {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final LibvirtVMDef vmDef = Mockito.mock(LibvirtVMDef.class);
final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);

final NicTO nic = Mockito.mock(NicTO.class);
Expand Down Expand Up @@ -5425,7 +5419,6 @@ public void testStartCommandHostMemory() {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final LibvirtVMDef vmDef = Mockito.mock(LibvirtVMDef.class);

final NicTO nic = Mockito.mock(NicTO.class);
final NicTO[] nics = new NicTO[]{nic};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class Xenserver625StorageProcessorTest {

@Mock
private Connection connectionMock;
@Mock
PBD pbdMock;

private String pathMock = "pathMock";

Expand Down Expand Up @@ -245,7 +247,7 @@ public void methodRetrieveAlreadyConfiguredSrTestSrScanSucceeds() throws XenAPIE

@Test
public void forgetSrTest() throws XenAPIException, XmlRpcException {
PBD pbdMock = Mockito.mock(PBD.class);

Set<PBD> pbds = new HashSet<>();
pbds.add(pbdMock);

Expand All @@ -262,7 +264,7 @@ public void forgetSrTest() throws XenAPIException, XmlRpcException {

@Test
public void unplugPbdTest() throws XenAPIException, XmlRpcException {
PBD pbdMock = Mockito.mock(PBD.class);


xenserver625StorageProcessor.unplugPbd(connectionMock, pbdMock);

Expand All @@ -286,7 +288,7 @@ public void unplugPbdTestThrowRuntimeException() throws XenAPIException, XmlRpcE
}

private void prepareAndExecuteUnplugMethodForException(Class<? extends Throwable> exceptionClass) throws XenAPIException, XmlRpcException {
PBD pbdMock = Mockito.mock(PBD.class);

Mockito.doThrow(exceptionClass).when(pbdMock).unplug(connectionMock);
xenserver625StorageProcessor.unplugPbd(connectionMock, pbdMock);
}
Expand Down Expand Up @@ -381,7 +383,7 @@ public void createNewFileSrTest() throws XenAPIException, XmlRpcException {
Mockito.eq(pathMock), Mockito.eq("file"), Mockito.eq("file"), Mockito.eq(false),
Mockito.anyMap())).thenReturn(srMock);

PBD pbdMock = Mockito.mock(PBD.class);

Mockito.when(PBD.create(Mockito.eq(connectionMock), Mockito.any(Record.class))).thenReturn(pbdMock);

SR sr = xenserver625StorageProcessor.createNewFileSr(connectionMock, pathMock);
Expand All @@ -408,7 +410,7 @@ public void removeSrAndPbdIfPossibleBothPbdAndSrNotNull() {
SR srMock = Mockito.mock(SR.class);
Mockito.doNothing().when(xenserver625StorageProcessor).forgetSr(connectionMock, srMock);

PBD pbdMock = Mockito.mock(PBD.class);

Mockito.doNothing().when(xenserver625StorageProcessor).unplugPbd(connectionMock, pbdMock);

xenserver625StorageProcessor.removeSrAndPbdIfPossible(connectionMock, srMock, pbdMock);
Expand All @@ -432,7 +434,7 @@ public void removeSrAndPbdIfPossiblePbdNullAndSrNotNull() {

@Test
public void removeSrAndPbdIfPossiblePbdNotNullButSrNull() {
PBD pbdMock = Mockito.mock(PBD.class);

Mockito.doNothing().when(xenserver625StorageProcessor).unplugPbd(connectionMock, pbdMock);

xenserver625StorageProcessor.removeSrAndPbdIfPossible(connectionMock, null, pbdMock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ public void testImplement() throws InsufficientVirtualNetworkCapacityException,

when(netmodel.findPhysicalNetworkId(anyLong(), (String)any(), (TrafficType)any())).thenReturn(NETWORK_ID);

final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice =CreateMockBrocadeVcsDeviceVO();

List<BrocadeVcsDeviceVO> devices = new ArrayList();
devices.add(brocadeDevice);
Expand Down Expand Up @@ -310,8 +309,7 @@ public void testImplementFail() throws InsufficientVirtualNetworkCapacityExcepti

when(netmodel.findPhysicalNetworkId(anyLong(), (String)any(), (TrafficType)any())).thenReturn(NETWORK_ID);

final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice =CreateMockBrocadeVcsDeviceVO();

final List<BrocadeVcsDeviceVO> devices = mock(List.class);
when(devices.isEmpty()).thenReturn(true);
Expand Down Expand Up @@ -364,8 +362,7 @@ public void testReserve() throws InsufficientVirtualNetworkCapacityException, UR

when(netmodel.findPhysicalNetworkId(anyLong(), (String)any(), (TrafficType)any())).thenReturn(NETWORK_ID);

final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice =CreateMockBrocadeVcsDeviceVO();

List<BrocadeVcsDeviceVO> devices = new ArrayList();
devices.add(brocadeDevice);
Expand Down Expand Up @@ -416,8 +413,7 @@ public void testReserveFail() throws InsufficientVirtualNetworkCapacityException

when(netmodel.findPhysicalNetworkId(anyLong(), (String)any(), (TrafficType)any())).thenReturn(NETWORK_ID);

final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice =CreateMockBrocadeVcsDeviceVO();

final List<BrocadeVcsDeviceVO> devices = mock(List.class);
when(devices.isEmpty()).thenReturn(true);
Expand Down Expand Up @@ -461,8 +457,7 @@ public void testDeallocate() {

when(netmodel.findPhysicalNetworkId(anyLong(), (String)any(), (TrafficType)any())).thenReturn(NETWORK_ID);

final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice =CreateMockBrocadeVcsDeviceVO();

final List<BrocadeVcsDeviceVO> devices = new ArrayList();
devices.add(brocadeDevice);
Expand Down Expand Up @@ -497,8 +492,7 @@ public void testDeallocateFail() {

when(netmodel.findPhysicalNetworkId(anyLong(), (String)any(), (TrafficType)any())).thenReturn(NETWORK_ID);

final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice =CreateMockBrocadeVcsDeviceVO();

final List<BrocadeVcsDeviceVO> devices = mock(List.class);
when(devices.isEmpty()).thenReturn(true);
Expand Down Expand Up @@ -536,8 +530,7 @@ public void testTrash() {
when(mapping.getVlanId()).thenReturn(14);
when(vcsmapdao.findByNetworkId(anyLong())).thenReturn(mapping);

final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice =CreateMockBrocadeVcsDeviceVO();

final List<BrocadeVcsDeviceVO> devices = new ArrayList();
devices.add(brocadeDevice);
Expand Down Expand Up @@ -579,8 +572,7 @@ public void testTrashFail() {
when(vcsmapdao.findByNetworkId(anyLong())).thenReturn(mapping);
when(vcsmapdao.remove(anyLong())).thenReturn(true);

final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice =CreateMockBrocadeVcsDeviceVO();

final List<BrocadeVcsDeviceVO> devices = mock(List.class);
when(devices.isEmpty()).thenReturn(true);
Expand All @@ -590,4 +582,9 @@ public void testTrashFail() {
assertTrue(result == false);
verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command)any());
}
BrocadeVcsDeviceVO CreateMockBrocadeVcsDeviceVO() {
BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);//
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
return brocadeDevice;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ public class TungstenServiceImplTest {
@Mock
IpAddressManager ipAddressManager;

@Mock
TungstenSecurityGroupRuleVO tungstenSecurityGroupRuleVO;


TungstenServiceImpl tungstenService;

AutoCloseable closeable;
Expand Down Expand Up @@ -727,7 +731,7 @@ public void createTungstenSecurityGroupTest() {
ProjectVO projectVO = mock(ProjectVO.class);
TungstenProviderVO tungstenProviderVO = mock(TungstenProviderVO.class);
DomainVO domainVO = mock(DomainVO.class);
TungstenSecurityGroupRuleVO tungstenSecurityGroupRuleVO = mock(TungstenSecurityGroupRuleVO.class);

TungstenAnswer createTungstenSecurityGroupAnswer = mock(TungstenAnswer.class);
TungstenAnswer addTungstenSecurityGroupRuleAnswer = mock(TungstenAnswer.class);

Expand Down Expand Up @@ -767,7 +771,7 @@ public void addTungstenSecurityGroupEgressRuleTest() {
TungstenAnswer addTungstenSecurityGroupRuleAnswer = mock(TungstenAnswer.class);
TungstenProviderVO tungstenProviderVO = mock(TungstenProviderVO.class);
net.juniper.tungsten.api.types.SecurityGroup securityGroup = mock(net.juniper.tungsten.api.types.SecurityGroup.class);
TungstenSecurityGroupRuleVO tungstenSecurityGroupRuleVO = mock(TungstenSecurityGroupRuleVO.class);

NicVO nicVO = mock(NicVO.class);

when(tungstenProviderDao.findAll()).thenReturn(List.of(tungstenProviderVO));
Expand Down Expand Up @@ -822,7 +826,7 @@ public void removeTungstenSecurityGroupEgressRuleTest() {
SecurityRule securityRule = mock(SecurityRule.class);
SecurityGroupVO securityGroupVO = mock(SecurityGroupVO.class);
TungstenProviderVO tungstenProviderVO = mock(TungstenProviderVO.class);
TungstenSecurityGroupRuleVO tungstenSecurityGroupRuleVO = mock(TungstenSecurityGroupRuleVO.class);

TungstenAnswer addTungstenSecurityGroupRuleAnswer = mock(TungstenAnswer.class);
TungstenAnswer removeTungstenSecurityGroupRuleAnswer = mock(TungstenAnswer.class);
NicVO nicVO = mock(NicVO.class);
Expand Down Expand Up @@ -874,7 +878,7 @@ public void addTungstenNicSecondaryIpAddressTest() {
Nic nic = mock(Nic.class);
SecurityGroupVO securityGroupVO = mock(SecurityGroupVO.class);
SecurityGroupRuleVO securityGroupRuleVO = mock(SecurityGroupRuleVO.class);
TungstenSecurityGroupRuleVO tungstenSecurityGroupRuleVO = mock(TungstenSecurityGroupRuleVO.class);

TungstenProviderVO tungstenProviderVO = mock(TungstenProviderVO.class);
TungstenAnswer addTungstenSecondaryIpAddressAnswer = mock(TungstenAnswer.class);
TungstenAnswer addTungstenSecurityGroupRuleAnswer = mock(TungstenAnswer.class);
Expand Down Expand Up @@ -905,7 +909,7 @@ public void removeTungstenNicSecondaryIpAddressTest() {
Network network = mock(Network.class);
DataCenter dataCenter = mock(DataCenter.class);
TungstenAnswer removeTungstenSecondaryIpAddressAnswer = mock(TungstenAnswer.class);
TungstenSecurityGroupRuleVO tungstenSecurityGroupRuleVO = mock(TungstenSecurityGroupRuleVO.class);

SecurityGroupVO securityGroupVO = mock(SecurityGroupVO.class);
TungstenAnswer removeTungstenSecurityGroupRuleAnswer = mock(TungstenAnswer.class);

Expand Down Expand Up @@ -1635,7 +1639,7 @@ public void addTungstenVmSecurityGroupTest() {
net.juniper.tungsten.api.types.SecurityGroup securityGroup = mock(net.juniper.tungsten.api.types.SecurityGroup.class);
NicVO nicVO = mock(NicVO.class);
SecurityGroupRuleVO securityGroupRuleVO = mock(SecurityGroupRuleVO.class);
TungstenSecurityGroupRuleVO tungstenSecurityGroupRuleVO = mock(TungstenSecurityGroupRuleVO.class);

TungstenAnswer addTungstenSecurityGroupRuleAnswer = mock(TungstenAnswer.class);

when(dataCenterDao.findById(anyLong())).thenReturn(dataCenterVO);
Expand Down Expand Up @@ -1670,7 +1674,7 @@ public void removeTungstenVmSecurityGroupTest() {
NicVO nicVO = mock(NicVO.class);
SecurityGroupRuleVO securityGroupRuleVO = mock(SecurityGroupRuleVO.class);
TungstenAnswer removeTungstenSecurityGroupRuleAnswer = mock(TungstenAnswer.class);
TungstenSecurityGroupRuleVO tungstenSecurityGroupRuleVO = mock(TungstenSecurityGroupRuleVO.class);


when(dataCenterDao.findById(anyLong())).thenReturn(dataCenterVO);
when(dataCenterVO.isSecurityGroupEnabled()).thenReturn(true);
Expand Down

0 comments on commit 8b0675a

Please sign in to comment.