use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class Xenserver625StorageProcessorTest method retrieveAlreadyConfiguredSrTestNoSrFound.
@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);
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class DomainManagerImplTest method createDomainTest.
@Test
@PrepareForTest(CallContext.class)
public void createDomainTest() {
Mockito.doNothing().when(domainManager).validateDomainNameAndNetworkDomain(Mockito.any(String.class), Mockito.any(Long.class), Mockito.any(String.class));
DomainVO domainVoMock = Mockito.mock(DomainVO.class);
Mockito.doReturn(domainVoMock).when(domainManager).createDomainVo("test", 1L, 2L, "netTest", "uuidTest");
Mockito.doReturn(domainVoMock).when(domainDaoMock).create(domainVoMock);
PowerMockito.mockStatic(CallContext.class);
CallContext callContextMock = Mockito.mock(CallContext.class);
PowerMockito.when(CallContext.current()).thenReturn(callContextMock);
Domain actualDomain = domainManager.createDomain("test", 1L, 2L, "netTest", "uuidTest");
Mockito.verify(domainManager).validateDomainNameAndNetworkDomain("test", 1L, "netTest");
Mockito.verify(domainManager).createDomainVo("test", 1L, 2L, "netTest", "uuidTest");
Mockito.verify(domainDaoMock).create(domainVoMock);
Mockito.verify(_resourceCountDao).createResourceCounts(domainVoMock.getId(), ResourceLimit.ResourceOwnerType.Domain);
PowerMockito.verifyStatic(CallContext.class);
CallContext.current();
Mockito.verify(callContextMock).putContextParameter(Domain.class, domainVoMock.getUuid());
Mockito.verify(_messageBus).publish("DomainManagerImpl", DomainManager.MESSAGE_ADD_DOMAIN_EVENT, PublishScope.LOCAL, domainVoMock.getId());
Assert.assertEquals(domainVoMock, actualDomain);
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class UserVmManagerImplTest method validateInputsAndPermissionForUpdateVirtualMachineCommandTest.
@Test
@PrepareForTest(CallContext.class)
public void validateInputsAndPermissionForUpdateVirtualMachineCommandTest() {
Mockito.doNothing().when(userVmManagerImpl).validateGuestOsIdForUpdateVirtualMachineCommand(updateVmCommand);
CallContext callContextMock = Mockito.mock(CallContext.class);
Mockito.lenient().doReturn(accountMock).when(callContextMock).getCallingAccount();
ServiceOffering offering = getSvcoffering(512);
Mockito.lenient().when(_serviceOfferingDao.findById(Mockito.anyLong(), Mockito.anyLong())).thenReturn((ServiceOfferingVO) offering);
Mockito.lenient().doNothing().when(accountManager).checkAccess(accountMock, null, true, userVmVoMock);
userVmManagerImpl.validateInputsAndPermissionForUpdateVirtualMachineCommand(updateVmCommand);
Mockito.verify(userVmManagerImpl).validateGuestOsIdForUpdateVirtualMachineCommand(updateVmCommand);
Mockito.verify(accountManager).checkAccess(callerAccount, null, true, userVmVoMock);
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class ConfigDriveNetworkElementTest method testAddPasswordAndUserData.
@Test
@SuppressWarnings("unchecked")
@PrepareForTest({ ConfigDriveBuilder.class, CallContext.class })
public void testAddPasswordAndUserData() throws Exception {
PowerMockito.mockStatic(ConfigDriveBuilder.class);
PowerMockito.mockStatic(CallContext.class);
PowerMockito.when(CallContext.current()).thenReturn(callContextMock);
Mockito.doReturn(Mockito.mock(Account.class)).when(callContextMock).getCallingAccount();
Method method = ReflectionUtils.getMethods(ConfigDriveBuilder.class, ReflectionUtils.withName("buildConfigDrive")).iterator().next();
PowerMockito.when(ConfigDriveBuilder.class, method).withArguments(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.anyString()).thenReturn("content");
final HandleConfigDriveIsoAnswer answer = mock(HandleConfigDriveIsoAnswer.class);
final UserVmDetailVO userVmDetailVO = mock(UserVmDetailVO.class);
when(agentManager.easySend(anyLong(), any(HandleConfigDriveIsoCommand.class))).thenReturn(answer);
when(answer.getResult()).thenReturn(true);
when(answer.getConfigDriveLocation()).thenReturn(NetworkElement.Location.PRIMARY);
when(network.getTrafficType()).thenReturn(Networks.TrafficType.Guest);
when(virtualMachine.getState()).thenReturn(VirtualMachine.State.Stopped);
when(virtualMachine.getUuid()).thenReturn("vm-uuid");
when(userVmDetailVO.getValue()).thenReturn(PUBLIC_KEY);
when(nicp.getIPv4Address()).thenReturn("192.168.111.111");
when(_userVmDetailsDao.findDetail(anyLong(), anyString())).thenReturn(userVmDetailVO);
when(_ipAddressDao.findByAssociatedVmId(VMID)).thenReturn(publicIp);
when(publicIp.getAddress()).thenReturn(new Ip("7.7.7.7"));
when(_hostDao.findById(virtualMachine.getHostId())).thenReturn(hostVO);
when(_hostDao.findById(virtualMachine.getHostId()).getName()).thenReturn("dest-hyp-host-name");
Map<VirtualMachineProfile.Param, Object> parms = Maps.newHashMap();
parms.put(VirtualMachineProfile.Param.VmPassword, PASSWORD);
parms.put(VirtualMachineProfile.Param.VmSshPubKey, PUBLIC_KEY);
VirtualMachineProfile profile = new VirtualMachineProfileImpl(virtualMachine, null, serviceOfferingVO, null, parms);
profile.setConfigDriveLabel("testlabel");
assertTrue(_configDrivesNetworkElement.addPasswordAndUserdata(network, nicp, profile, deployDestination, null));
ArgumentCaptor<HandleConfigDriveIsoCommand> commandCaptor = ArgumentCaptor.forClass(HandleConfigDriveIsoCommand.class);
verify(agentManager, times(1)).easySend(anyLong(), commandCaptor.capture());
HandleConfigDriveIsoCommand createCommand = commandCaptor.getValue();
assertTrue(createCommand.isCreate());
assertTrue(createCommand.getIsoData().length() > 0);
assertTrue(createCommand.getIsoFile().equals(ConfigDrive.createConfigDrivePath(profile.getInstanceName())));
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class NetworkACLServiceImplTest method updateNetworkACLTestParametersNotNull.
@Test
@PrepareForTest(CallContext.class)
public void updateNetworkACLTestParametersNotNull() {
String name = "name";
String description = "desc";
String customId = "customId";
Mockito.when(updateNetworkACLListCmdMock.getName()).thenReturn(name);
Mockito.when(updateNetworkACLListCmdMock.getDescription()).thenReturn(description);
Mockito.when(updateNetworkACLListCmdMock.getCustomId()).thenReturn(customId);
Mockito.when(updateNetworkACLListCmdMock.getId()).thenReturn(networkAclListId);
Mockito.when(updateNetworkACLListCmdMock.getDisplay()).thenReturn(false);
networkAclServiceImpl.updateNetworkACL(updateNetworkACLListCmdMock);
InOrder inOrder = Mockito.inOrder(networkAclDaoMock, entityManagerMock, entityManagerMock, accountManagerMock, networkACLVOMock);
inOrder.verify(networkAclDaoMock).findById(networkAclListId);
inOrder.verify(entityManagerMock).findById(Mockito.eq(Vpc.class), Mockito.anyLong());
inOrder.verify(accountManagerMock).checkAccess(Mockito.any(Account.class), Mockito.isNull(AccessType.class), Mockito.eq(true), nullable(Vpc.class));
inOrder.verify(networkACLVOMock).setName(name);
inOrder.verify(networkACLVOMock).setDescription(description);
inOrder.verify(networkACLVOMock).setUuid(customId);
inOrder.verify(networkACLVOMock).setDisplay(false);
inOrder.verify(networkAclDaoMock).update(networkAclListId, networkACLVOMock);
inOrder.verify(networkAclDaoMock).findById(networkAclListId);
}
Aggregations