Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 25226200C4C for ; Tue, 4 Apr 2017 18:06:34 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 23BB0160B90; Tue, 4 Apr 2017 16:06:34 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6A225160B81 for ; Tue, 4 Apr 2017 18:06:33 +0200 (CEST) Received: (qmail 73218 invoked by uid 500); 4 Apr 2017 16:06:32 -0000 Mailing-List: contact dev-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list dev@cloudstack.apache.org Received: (qmail 73207 invoked by uid 99); 4 Apr 2017 16:06:32 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Apr 2017 16:06:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0BDCADFCB3; Tue, 4 Apr 2017 16:06:32 +0000 (UTC) From: rafaelweingartner To: dev@cloudstack.apache.org Reply-To: dev@cloudstack.apache.org References: In-Reply-To: Subject: [GitHub] cloudstack pull request #1935: CLOUDSTACK-9764: Delete domain failure due to... Content-Type: text/plain Message-Id: <20170404160632.0BDCADFCB3@git1-us-west.apache.org> Date: Tue, 4 Apr 2017 16:06:32 +0000 (UTC) archived-at: Tue, 04 Apr 2017 16:06:34 -0000 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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---