Search in sources :

Example 46 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class AccountManagerImplTest method deleteUserAccount.

@Test
public void deleteUserAccount() {
    AccountVO account = new AccountVO();
    account.setId(42l);
    DomainVO domain = new DomainVO();
    Mockito.when(_accountDao.findById(42l)).thenReturn(account);
    Mockito.doNothing().when(accountManagerImpl).checkAccess(Mockito.any(Account.class), Mockito.isNull(), Mockito.anyBoolean(), Mockito.any(Account.class));
    Mockito.when(_accountDao.remove(42l)).thenReturn(true);
    Mockito.when(_configMgr.releaseAccountSpecificVirtualRanges(42l)).thenReturn(true);
    Mockito.lenient().when(_domainMgr.getDomain(Mockito.anyLong())).thenReturn(domain);
    Mockito.lenient().when(securityChecker.checkAccess(Mockito.any(Account.class), Mockito.any(Domain.class))).thenReturn(true);
    Mockito.when(_vmSnapshotDao.listByAccountId(Mockito.anyLong())).thenReturn(new ArrayList<VMSnapshotVO>());
    List<SSHKeyPairVO> sshkeyList = new ArrayList<SSHKeyPairVO>();
    SSHKeyPairVO sshkey = new SSHKeyPairVO();
    sshkey.setId(1l);
    sshkeyList.add(sshkey);
    Mockito.when(_sshKeyPairDao.listKeyPairs(Mockito.anyLong(), Mockito.anyLong())).thenReturn(sshkeyList);
    Mockito.when(_sshKeyPairDao.remove(Mockito.anyLong())).thenReturn(true);
    Assert.assertTrue(accountManagerImpl.deleteUserAccount(42l));
    // assert that this was a clean delete
    Mockito.verify(_accountDao, Mockito.never()).markForCleanup(Mockito.eq(42l));
}
Also used : DomainVO(com.cloud.domain.DomainVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain) ProjectAccountVO(com.cloud.projects.ProjectAccountVO) Test(org.junit.Test)

Example 47 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImplTest method deleteDomain.

@Test
public void deleteDomain() {
    DomainVO domain = new DomainVO();
    domain.setId(20l);
    domain.setAccountId(30l);
    Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    Mockito.when(domainDaoMock.findById(20l)).thenReturn(domain);
    Mockito.doNothing().when(_accountMgr).checkAccess(Mockito.any(Account.class), Mockito.any(Domain.class));
    Mockito.when(domainDaoMock.update(Mockito.eq(20l), Mockito.any(DomainVO.class))).thenReturn(true);
    Mockito.lenient().when(_accountDao.search(Mockito.any(SearchCriteria.class), (Filter) org.mockito.Matchers.isNull())).thenReturn(new ArrayList<AccountVO>());
    Mockito.when(_networkDomainDao.listNetworkIdsByDomain(Mockito.anyLong())).thenReturn(new ArrayList<Long>());
    Mockito.when(_accountDao.findCleanupsForRemovedAccounts(Mockito.anyLong())).thenReturn(new ArrayList<AccountVO>());
    Mockito.when(_dedicatedDao.listByDomainId(Mockito.anyLong())).thenReturn(new ArrayList<DedicatedResourceVO>());
    Mockito.when(domainDaoMock.remove(Mockito.anyLong())).thenReturn(true);
    Mockito.when(_configMgr.releaseDomainSpecificVirtualRanges(Mockito.anyLong())).thenReturn(true);
    Mockito.when(_diskOfferingDao.findByDomainId(Mockito.anyLong())).thenReturn(Collections.emptyList());
    Mockito.when(_offeringsDao.findByDomainId(Mockito.anyLong())).thenReturn(Collections.emptyList());
    try {
        Assert.assertTrue(domainManager.deleteDomain(20l, false));
    } finally {
        CallContext.unregister();
    }
}
Also used : DomainVO(com.cloud.domain.DomainVO) Domain(com.cloud.domain.Domain) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) SearchCriteria(com.cloud.utils.db.SearchCriteria) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 48 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImplTest method createDomainVoTestCreateValidUuidIfEmptyString.

@Test
public void createDomainVoTestCreateValidUuidIfEmptyString() {
    DomainVO domainVo = domainManager.createDomainVo("test", 1L, 2L, "NetworkTest", "");
    Assert.assertTrue(UuidUtils.validateUUID(domainVo.getUuid()));
}
Also used : DomainVO(com.cloud.domain.DomainVO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 49 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImplTest method testFindDomainByIdOrPathValidId.

@Test
public void testFindDomainByIdOrPathValidId() {
    final DomainVO domain = new DomainVO("someDomain", 123, 1L, "network.domain");
    Mockito.when(domainDaoMock.findById(1L)).thenReturn(domain);
    Mockito.lenient().when(domainDaoMock.findDomainByPath(Mockito.eq("/validDomain/"))).thenReturn(new DomainVO());
    Assert.assertEquals(domain, domainManager.findDomainByIdOrPath(1L, null));
    Assert.assertEquals(domain, domainManager.findDomainByIdOrPath(1L, ""));
    Assert.assertEquals(domain, domainManager.findDomainByIdOrPath(1L, " "));
    Assert.assertEquals(domain, domainManager.findDomainByIdOrPath(1L, "       "));
    Assert.assertEquals(domain, domainManager.findDomainByIdOrPath(1L, "/validDomain/"));
}
Also used : DomainVO(com.cloud.domain.DomainVO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 50 with DomainVO

use of com.cloud.domain.DomainVO 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)

Aggregations

DomainVO (com.cloud.domain.DomainVO)196 Account (com.cloud.user.Account)85 AccountVO (com.cloud.user.AccountVO)64 Test (org.junit.Test)56 ArrayList (java.util.ArrayList)53 DomainDao (com.cloud.domain.dao.DomainDao)30 Field (java.lang.reflect.Field)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)29 SslCertDao (com.cloud.network.dao.SslCertDao)29 AccountManager (com.cloud.user.AccountManager)29 SslCertVO (com.cloud.network.dao.SslCertVO)27 List (java.util.List)26 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)24 Pair (com.cloud.utils.Pair)24 Domain (com.cloud.domain.Domain)23 Filter (com.cloud.utils.db.Filter)23 File (java.io.File)23 IOException (java.io.IOException)23 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)23 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22