Github user rafaelweingartner commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1935#discussion_r102534985 --- Diff: server/test/com/cloud/user/DomainManagerImplTest.java --- @@ -134,4 +164,67 @@ public void testFindDomainByIdOrPathValidId() { Assert.assertEquals(domain, domainManager.findDomainByIdOrPath(1L, "/validDomain/")); } + @Test(expected=InvalidParameterValueException.class) + public void testDeleteDomainNullDomain() { + Mockito.when(_domainDao.findById(DOMAIN_ID)).thenReturn(null); + domainManager.deleteDomain(DOMAIN_ID, testDomainCleanup); + } + + @Test(expected=PermissionDeniedException.class) + public void testDeleteDomainRootDomain() { + Mockito.when(_domainDao.findById(Domain.ROOT_DOMAIN)).thenReturn(domain); + domainManager.deleteDomain(Domain.ROOT_DOMAIN, testDomainCleanup); + } + + //TODO testDeleteDomainCleanup + + @Test + public void testDeleteDomainNoCleanup() { + domainManager.deleteDomain(DOMAIN_ID, testDomainCleanup); + Mockito.verify(domainManager).deleteDomain(domain, testDomainCleanup); + Mockito.verify(domainManager).checkDomainAccountsNetworksAndResourcesBeforeRemoving(domain); + Mockito.verify(domainManager).cleanupDomainOfferings(DOMAIN_ID); + Mockito.verify(lock).unlock(); + Assert.assertEquals(false, domainManager.getRollBackState()); + } + + @Test + public void testCheckDomainAccountsNetworksAndResourcesBeforeRemovingRemoveDomain() { + domainManager.checkDomainAccountsNetworksAndResourcesBeforeRemoving(domain); + Mockito.verify(domainManager).publishRemoveEventsAndRemoveDomain(domain); + } + + @Test(expected=CloudRuntimeException.class) + public void testCheckDomainAccountsNetworksAndResourcesBeforeRemovingDontRemoveDomain() { + domainNetworkIds.add(2l); + domainManager.checkDomainAccountsNetworksAndResourcesBeforeRemoving(domain); + Mockito.verify(domainManager).failRemoveOperation(domain, domainAccountsForCleanup, domainNetworkIds, false); + } + + @Test + public void testPublishRemoveEventsAndRemoveDomainSuccessfulDelete() { + domainManager.publishRemoveEventsAndRemoveDomain(domain); + Mockito.verify(_messageBus).publish(Mockito.anyString(), Matchers.eq(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT), + Matchers.eq(PublishScope.LOCAL), Matchers.eq(domain)); + Mockito.verify(_messageBus).publish(Mockito.anyString(), Matchers.eq(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT), + Matchers.eq(PublishScope.LOCAL), Matchers.eq(domain)); + Mockito.verify(_domainDao).remove(DOMAIN_ID); + } + + @Test(expected=CloudRuntimeException.class) + public void testPublishRemoveEventsAndRemoveDomainExceptionDelete() { + Mockito.when(_domainDao.remove(DOMAIN_ID)).thenReturn(false); + domainManager.publishRemoveEventsAndRemoveDomain(domain); + Mockito.verify(_messageBus).publish(Mockito.anyString(), Matchers.eq(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT), + Matchers.eq(PublishScope.LOCAL), Matchers.eq(domain)); + Mockito.verify(_messageBus, Mockito.never()).publish(Mockito.anyString(), Matchers.eq(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT), + Matchers.eq(PublishScope.LOCAL), Matchers.eq(domain)); + Mockito.verify(_domainDao).remove(DOMAIN_ID); + } + + @Test(expected=CloudRuntimeException.class) + public void testFailRemoveOperation() { --- End diff -- Here we still have a problem. the exception is thrown at line 227 and the code at line 228 is never executed. That is why I called nasty to write a test here. It is very tricky
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---