Search in sources :

Example 81 with PrepareForTest

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);
}
Also used : SR(com.xensource.xenapi.SR) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 82 with PrepareForTest

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);
}
Also used : DomainVO(com.cloud.domain.DomainVO) Domain(com.cloud.domain.Domain) CallContext(org.apache.cloudstack.context.CallContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 83 with PrepareForTest

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);
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) CallContext(org.apache.cloudstack.context.CallContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 84 with PrepareForTest

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())));
}
Also used : Account(com.cloud.user.Account) HandleConfigDriveIsoAnswer(com.cloud.agent.api.HandleConfigDriveIsoAnswer) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) Ip(com.cloud.utils.net.Ip) HandleConfigDriveIsoCommand(com.cloud.agent.api.HandleConfigDriveIsoCommand) Method(java.lang.reflect.Method) Matchers.anyString(org.mockito.Matchers.anyString) UserVmDetailVO(com.cloud.vm.UserVmDetailVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 85 with PrepareForTest

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);
}
Also used : Account(com.cloud.user.Account) InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AccessType(org.apache.cloudstack.acl.SecurityChecker.AccessType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)196 Test (org.junit.Test)194 HttpServletRequest (javax.servlet.http.HttpServletRequest)30 HttpServletResponse (javax.servlet.http.HttpServletResponse)30 StringWriter (java.io.StringWriter)28 PrintWriter (java.io.PrintWriter)27 File (java.io.File)24 ArrayList (java.util.ArrayList)16 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)14 Method (java.lang.reflect.Method)13 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)12 Config (com.twitter.heron.spi.common.Config)12 Matchers.anyString (org.mockito.Matchers.anyString)12 DialogInterface (android.content.DialogInterface)11 Intent (android.content.Intent)11 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)11 Job (hudson.model.Job)11 IOException (java.io.IOException)11 Date (java.util.Date)10 HashMap (java.util.HashMap)10