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 C89CB200CA4 for ; Wed, 24 May 2017 00:07:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C7247160BD6; Tue, 23 May 2017 22:07:08 +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 71AE6160BC3 for ; Wed, 24 May 2017 00:07:07 +0200 (CEST) Received: (qmail 52887 invoked by uid 500); 23 May 2017 22:07:06 -0000 Mailing-List: contact commits-help@atlas.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@atlas.incubator.apache.org Delivered-To: mailing list commits@atlas.incubator.apache.org Received: (qmail 52779 invoked by uid 99); 23 May 2017 22:07:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 May 2017 22:07:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 355A91AFCC0 for ; Tue, 23 May 2017 22:07:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.221 X-Spam-Level: X-Spam-Status: No, score=-4.221 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id EHReCohFT0NU for ; Tue, 23 May 2017 22:07:02 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 517D65FCB9 for ; Tue, 23 May 2017 22:07:00 +0000 (UTC) Received: (qmail 52719 invoked by uid 99); 23 May 2017 22:06:59 -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, 23 May 2017 22:06:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 111DCDFD70; Tue, 23 May 2017 22:06:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: apoorvnaik@apache.org To: commits@atlas.incubator.apache.org Date: Tue, 23 May 2017 22:06:59 -0000 Message-Id: <74cf728c4f474011b1f52cf5c20b1579@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4 with Spring security) over Guice archived-at: Tue, 23 May 2017 22:07:09 -0000 Repository: incubator-atlas Updated Branches: refs/heads/master 35c776448 -> 35e5828fb http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/service/ActiveInstanceElectorServiceTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/service/ActiveInstanceElectorServiceTest.java b/webapp/src/test/java/org/apache/atlas/web/service/ActiveInstanceElectorServiceTest.java index d1b0318..dd2df70 100644 --- a/webapp/src/test/java/org/apache/atlas/web/service/ActiveInstanceElectorServiceTest.java +++ b/webapp/src/test/java/org/apache/atlas/web/service/ActiveInstanceElectorServiceTest.java @@ -18,9 +18,9 @@ package org.apache.atlas.web.service; -import com.google.inject.Provider; import org.apache.atlas.AtlasConstants; import org.apache.atlas.AtlasException; +import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.ha.HAConfiguration; import org.apache.atlas.listener.ActiveStateChangeHandler; import org.apache.commons.configuration.Configuration; @@ -32,15 +32,10 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import org.apache.atlas.exception.AtlasBaseException; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; +import java.util.HashSet; +import java.util.Set; + +import static org.mockito.Mockito.*; public class ActiveInstanceElectorServiceTest { @@ -75,7 +70,7 @@ public class ActiveInstanceElectorServiceTest { when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch); ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory, + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.start(); @@ -96,7 +91,7 @@ public class ActiveInstanceElectorServiceTest { when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch); ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory, + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.start(); @@ -108,7 +103,7 @@ public class ActiveInstanceElectorServiceTest { when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY, false)).thenReturn(false); ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory, + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.start(); @@ -129,7 +124,7 @@ public class ActiveInstanceElectorServiceTest { when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch); ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory, + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.start(); activeInstanceElectorService.stop(); @@ -151,7 +146,7 @@ public class ActiveInstanceElectorServiceTest { when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch); ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory, + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.start(); activeInstanceElectorService.stop(); @@ -165,7 +160,7 @@ public class ActiveInstanceElectorServiceTest { when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY, false)).thenReturn(false); ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory, + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.stop(); @@ -185,23 +180,12 @@ public class ActiveInstanceElectorServiceTest { LeaderLatch leaderLatch = mock(LeaderLatch.class); when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch); - Collection> changeHandlers = new ArrayList(); + Set changeHandlers = new HashSet<>(); final ActiveStateChangeHandler handler1 = mock(ActiveStateChangeHandler.class); final ActiveStateChangeHandler handler2 = mock(ActiveStateChangeHandler.class); - changeHandlers.add(new Provider() { - @Override - public ActiveStateChangeHandler get() { - return handler1; - } - }); - - changeHandlers.add(new Provider() { - @Override - public ActiveStateChangeHandler get() { - return handler2; - } - }); + changeHandlers.add(handler1); + changeHandlers.add(handler2); ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, changeHandlers, curatorFactory, @@ -227,7 +211,7 @@ public class ActiveInstanceElectorServiceTest { when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch); ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory, + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.start(); @@ -250,23 +234,12 @@ public class ActiveInstanceElectorServiceTest { LeaderLatch leaderLatch = mock(LeaderLatch.class); when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch); - Collection> changeHandlers = new ArrayList(); + Set changeHandlers = new HashSet<>(); final ActiveStateChangeHandler handler1 = mock(ActiveStateChangeHandler.class); final ActiveStateChangeHandler handler2 = mock(ActiveStateChangeHandler.class); - changeHandlers.add(new Provider() { - @Override - public ActiveStateChangeHandler get() { - return handler1; - } - }); - - changeHandlers.add(new Provider() { - @Override - public ActiveStateChangeHandler get() { - return handler2; - } - }); + changeHandlers.add(handler1); + changeHandlers.add(handler2); doThrow(new AtlasBaseException()).when(activeInstanceState).update("id1"); @@ -297,7 +270,7 @@ public class ActiveInstanceElectorServiceTest { doThrow(new AtlasBaseException()).when(activeInstanceState).update("id1"); ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory, + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.start(); @@ -324,23 +297,12 @@ public class ActiveInstanceElectorServiceTest { LeaderLatch leaderLatch = mock(LeaderLatch.class); when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch); - Collection> changeHandlers = new ArrayList(); + Set changeHandlers = new HashSet<>(); final ActiveStateChangeHandler handler1 = mock(ActiveStateChangeHandler.class); final ActiveStateChangeHandler handler2 = mock(ActiveStateChangeHandler.class); - changeHandlers.add(new Provider() { - @Override - public ActiveStateChangeHandler get() { - return handler1; - } - }); - - changeHandlers.add(new Provider() { - @Override - public ActiveStateChangeHandler get() { - return handler2; - } - }); + changeHandlers.add(handler1); + changeHandlers.add(handler2); ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, changeHandlers, curatorFactory, @@ -355,7 +317,7 @@ public class ActiveInstanceElectorServiceTest { @Test public void testActiveStateSetOnBecomingLeader() { ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.isLeader(); @@ -368,7 +330,7 @@ public class ActiveInstanceElectorServiceTest { @Test public void testPassiveStateSetOnLoosingLeadership() { ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.notLeader(); @@ -395,7 +357,7 @@ public class ActiveInstanceElectorServiceTest { doThrow(new AtlasBaseException()).when(activeInstanceState).update("id1"); ActiveInstanceElectorService activeInstanceElectorService = - new ActiveInstanceElectorService(configuration, new ArrayList(), + new ActiveInstanceElectorService(configuration, new HashSet(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.start(); activeInstanceElectorService.isLeader(); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java b/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java index 5d4ca97..41c3cb1 100755 --- a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java +++ b/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java @@ -23,10 +23,10 @@ import org.apache.atlas.ApplicationProperties; import org.apache.atlas.Atlas; import org.apache.atlas.AtlasException; import org.apache.atlas.web.TestUtils; -import org.apache.atlas.web.resources.AdminJerseyResourceIT; -import org.apache.atlas.web.resources.EntityJerseyResourceIT; -import org.apache.atlas.web.resources.MetadataDiscoveryJerseyResourceIT; -import org.apache.atlas.web.resources.TypesJerseyResourceIT; +import org.apache.atlas.web.integration.AdminJerseyResourceIT; +import org.apache.atlas.web.integration.EntityJerseyResourceIT; +import org.apache.atlas.web.integration.MetadataDiscoveryJerseyResourceIT; +import org.apache.atlas.web.integration.TypesJerseyResourceIT; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/setup/SetupStepsTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/setup/SetupStepsTest.java b/webapp/src/test/java/org/apache/atlas/web/setup/SetupStepsTest.java index 82abc1b..7365fae 100644 --- a/webapp/src/test/java/org/apache/atlas/web/setup/SetupStepsTest.java +++ b/webapp/src/test/java/org/apache/atlas/web/setup/SetupStepsTest.java @@ -47,12 +47,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import static org.testng.AssertJUnit.assertTrue; public class SetupStepsTest { @@ -94,8 +89,8 @@ public class SetupStepsTest { InterProcessMutex lock = mock(InterProcessMutex.class); when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)). thenReturn(lock); - SetupSteps setupSteps = new SetupSteps(steps, curatorFactory); - setupSteps.runSetup(configuration); + SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration); + setupSteps.runSetup(); verify(setupStep1).run(); verify(setupStep2).run(); @@ -147,8 +142,8 @@ public class SetupStepsTest { thenReturn(lock); InOrder inOrder = inOrder(lock, setupStep1, setupStep2); - SetupSteps setupSteps = new SetupSteps(steps, curatorFactory); - setupSteps.runSetup(configuration); + SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration); + setupSteps.runSetup(); inOrder.verify(lock).acquire(); inOrder.verify(setupStep1).run(); @@ -175,9 +170,9 @@ public class SetupStepsTest { thenReturn(lock); InOrder inOrder = inOrder(lock, setupStep1); - SetupSteps setupSteps = new SetupSteps(steps, curatorFactory); + SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration); try { - setupSteps.runSetup(configuration); + setupSteps.runSetup(); } catch (Exception e) { assertTrue(e instanceof SetupException); } @@ -205,8 +200,8 @@ public class SetupStepsTest { InterProcessMutex lock = mock(InterProcessMutex.class); when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)). thenReturn(lock); - SetupSteps setupSteps = new SetupSteps(steps, curatorFactory); - setupSteps.runSetup(configuration); + SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration); + setupSteps.runSetup(); verify(createBuilder).withACL(aclList); verify(createBuilder).forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT+SetupSteps.SETUP_IN_PROGRESS_NODE, @@ -231,8 +226,8 @@ public class SetupStepsTest { InterProcessMutex lock = mock(InterProcessMutex.class); when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)). thenReturn(lock); - SetupSteps setupSteps = new SetupSteps(steps, curatorFactory); - setupSteps.runSetup(configuration); + SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration); + setupSteps.runSetup(); verify(deleteBuilder).forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT+SetupSteps.SETUP_IN_PROGRESS_NODE); } @@ -252,10 +247,10 @@ public class SetupStepsTest { InterProcessMutex lock = mock(InterProcessMutex.class); when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)). thenReturn(lock); - SetupSteps setupSteps = new SetupSteps(steps, curatorFactory); + SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration); try { - setupSteps.runSetup(configuration); + setupSteps.runSetup(); } catch (Exception e) { assertTrue(e instanceof SetupException); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/resources/test-spring-security.xml ---------------------------------------------------------------------- diff --git a/webapp/src/test/resources/test-spring-security.xml b/webapp/src/test/resources/test-spring-security.xml new file mode 100644 index 0000000..0ef15d7 --- /dev/null +++ b/webapp/src/test/resources/test-spring-security.xml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/webapp/src/test/webapp/WEB-INF/web.xml b/webapp/src/test/webapp/WEB-INF/web.xml index 011bf37..2388fbf 100755 --- a/webapp/src/test/webapp/WEB-INF/web.xml +++ b/webapp/src/test/webapp/WEB-INF/web.xml @@ -24,51 +24,52 @@ Apache Atlas Metadata Management and Data Governance Platform over Hadoop - - guice.packages - - org.apache.atlas.web.resources,org.apache.atlas.web.params,org.apache.atlas.web.rest,org.apache.atlas.web.errors - - - - - com.sun.jersey.api.json.POJOMappingFeature - true - - + + jersey-servlet + + com.sun.jersey.spi.spring.container.servlet.SpringServlet + + + com.sun.jersey.api.json.POJOMappingFeature + true + + 1 + + + + jersey-servlet + /api/atlas/* + + springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy - - - guiceFilter - com.google.inject.servlet.GuiceFilter - - + springSecurityFilterChain /* - + + + AuditFilter + org.apache.atlas.web.filters.AuditFilter + + - guiceFilter + AuditFilter /* org.springframework.web.util.Log4jConfigListener - - - org.apache.atlas.web.listeners.TestGuiceServletConfig - org.springframework.web.context.request.RequestContextListener @@ -88,5 +89,5 @@ - +