Github user rafaelweingartner commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1935#discussion_r103529869
  
    --- Diff: server/test/com/cloud/user/DomainManagerImplTest.java ---
    @@ -134,4 +164,69 @@ 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);
    +    }
    +
    +    @Test
    +    public void testDeleteDomainNoCleanup() {
    +        domainManager.deleteDomain(DOMAIN_ID, testDomainCleanup);
    +        Mockito.verify(domainManager).deleteDomain(domain, 
testDomainCleanup);
    +        
Mockito.verify(domainManager).removeDomainWithNoAccountsForCleanupNetworksOrDedicatedResources(domain);
    +        Mockito.verify(domainManager).cleanupDomainOfferings(DOMAIN_ID);
    +        Mockito.verify(lock).unlock();
    +    }
    +
    +    @Test
    +    public void 
testRemoveDomainWithNoAccountsForCleanupNetworksOrDedicatedResourcesRemoveDomain()
 {
    +        
domainManager.removeDomainWithNoAccountsForCleanupNetworksOrDedicatedResources(domain);
    +        
Mockito.verify(domainManager).publishRemoveEventsAndRemoveDomain(domain);
    +    }
    +
    +    @Test(expected=CloudRuntimeException.class)
    +    public void 
testRemoveDomainWithNoAccountsForCleanupNetworksOrDedicatedResourcesDontRemoveDomain()
 {
    +        domainNetworkIds.add(2l);
    +        
domainManager.removeDomainWithNoAccountsForCleanupNetworksOrDedicatedResources(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
    +    public void testFailRemoveOperation() {
    +        try {
    +            domainManager.failRemoveOperation(domain, 
domainAccountsForCleanup, domainNetworkIds, true);
    --- End diff --
    
    Now that you removed the use of `rollBackState`, made the method last 
problematic to test. Therefore, you can use the `@Test(expected=...)`, instead 
of this very unusual construction here.


---
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.
---

Reply via email to