Search in sources :

Example 6 with VirtualMachineEntity

use of org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity in project cloudstack by apache.

the class AccountManagerImplVolumeDeleteEventTest method defineMocksBehavior.

protected void defineMocksBehavior() throws AgentUnavailableException, ConcurrentOperationException, CloudException {
    AccountVO account = new AccountVO();
    account.setId(ACCOUNT_ID);
    when(_accountDao.remove(ACCOUNT_ID)).thenReturn(true);
    when(_accountDao.findById(ACCOUNT_ID)).thenReturn(account);
    DomainVO domain = new DomainVO();
    VirtualMachineEntity vmEntity = mock(VirtualMachineEntity.class);
    when(_orchSrvc.getVirtualMachine(nullable(String.class))).thenReturn(vmEntity);
    when(vmEntity.destroy(nullable(String.class), nullable(Boolean.class))).thenReturn(true);
    Mockito.lenient().doReturn(vm).when(_vmDao).findById(nullable(Long.class));
    VolumeVO vol = new VolumeVO(VOLUME_UUID, 1l, 1l, 1l, 1l, 1l, "folder", "path", null, 50, Type.ROOT);
    vol.setDisplayVolume(true);
    List<VolumeVO> volumes = new ArrayList<>();
    volumes.add(vol);
    lenient().when(securityChecker.checkAccess(Mockito.eq(account), nullable(ControlledEntity.class), nullable(AccessType.class), nullable(String.class))).thenReturn(true);
    when(_userVmDao.findById(nullable(Long.class))).thenReturn(vm);
    lenient().when(_userVmDao.listByAccountId(ACCOUNT_ID)).thenReturn(Arrays.asList(vm));
    lenient().when(_userVmDao.findByUuid(nullable(String.class))).thenReturn(vm);
    when(_volumeDao.findByInstance(nullable(Long.class))).thenReturn(volumes);
    ServiceOfferingVO offering = mock(ServiceOfferingVO.class);
    lenient().when(offering.getCpu()).thenReturn(500);
    lenient().when(offering.getId()).thenReturn(1l);
    when(offering.getCpu()).thenReturn(500);
    when(offering.getRamSize()).thenReturn(500);
    when(_serviceOfferingDao.findByIdIncludingRemoved(nullable(Long.class), nullable(Long.class))).thenReturn(offering);
    lenient().when(_domainMgr.getDomain(nullable(Long.class))).thenReturn(domain);
    Mockito.lenient().doReturn(true).when(_vmMgr).expunge(any(UserVmVO.class), anyLong(), any(Account.class));
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) VirtualMachineEntity(org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity) ArrayList(java.util.ArrayList) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) DomainVO(com.cloud.domain.DomainVO) VolumeVO(com.cloud.storage.VolumeVO) ControlledEntity(org.apache.cloudstack.acl.ControlledEntity) Matchers.anyLong(org.mockito.Matchers.anyLong) AccessType(org.apache.cloudstack.acl.SecurityChecker.AccessType)

Aggregations

VirtualMachineEntity (org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 CloudException (com.cloud.exception.CloudException)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)3 Account (com.cloud.user.Account)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ArrayList (java.util.ArrayList)3 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)2 DeploymentPlanner (com.cloud.deploy.DeploymentPlanner)2 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 Host (com.cloud.host.Host)2 SecurityGroup (com.cloud.network.security.SecurityGroup)2 VMTemplateVO (com.cloud.storage.VMTemplateVO)2 VolumeVO (com.cloud.storage.VolumeVO)2 SSHKeyPair (com.cloud.user.SSHKeyPair)2 UserVO (com.cloud.user.UserVO)2 Pair (com.cloud.utils.Pair)2 HashMap (java.util.HashMap)2