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));
}
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();
}
}
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()));
}
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/"));
}
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);
}
Aggregations