SENTRY-1021: Add PMD to Sentry tests (Colm O hEigeartaigh, Reviewed by: Hao Hao)
Change-Id: Ie7a5b71b30efce23d98e9fb3fc0f951a9fe157ef Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/cfaa570f Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/cfaa570f Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/cfaa570f Branch: refs/heads/master Commit: cfaa570f0e3b802407e690e630ca50572e2ffc3e Parents: 1c32c13 Author: hahao <[email protected]> Authored: Mon Mar 7 00:01:53 2016 -0800 Committer: hahao <[email protected]> Committed: Mon Mar 7 00:01:53 2016 -0800 ---------------------------------------------------------------------- build-tools/sentry-pmd-ruleset.xml | 11 +++- pom.xml | 1 + .../binding/hive/TestHiveAuthzBindings.java | 2 - .../binding/solr/TestSolrAuthzBinding.java | 2 - .../core/model/sqoop/TestSqoopAuthorizable.java | 4 -- .../sentry/hdfs/TestKrbConnectionTimeout.java | 2 +- .../sentry/hdfs/TestUpdateableAuthzPaths.java | 1 - .../hdfs/TestMetastoreCacheInitializer.java | 2 +- .../apache/sentry/hdfs/TestUpdateForwarder.java | 2 - .../policy/db/TestDBWildcardPrivilege.java | 5 +- .../policy/db/TestDatabaseRequiredInRole.java | 2 +- ...ndexerAuthorizationProviderGeneralCases.java | 1 - .../indexer/TestIndexerRequiredInRole.java | 4 +- .../indexer/TestIndexerWildcardPrivilege.java | 4 +- .../search/TestCollectionRequiredInRole.java | 4 +- .../search/TestSearchWildcardPrivilege.java | 4 +- ...tSqoopAuthorizationProviderGeneralCases.java | 10 ++-- .../sqoop/TestSqoopWildcardPrivilege.java | 4 +- .../provider/common/TestGetGroupMapping.java | 3 -- .../persistent/TestSentryGMPrivilege.java | 6 +-- .../service/persistent/TestSentryRole.java | 2 - .../SentryGenericServiceIntegrationBase.java | 1 - .../TestSentryGenericPolicyProcessor.java | 53 +++++++++----------- .../TestSentryGenericServiceIntegration.java | 4 -- .../db/generic/tools/TestSentryShellSolr.java | 8 --- .../TestRollingFileWithoutDeleteAppender.java | 2 - .../db/log/entity/TestJsonLogEntityFactory.java | 24 +++------ .../persistent/TestSentryServiceDiscovery.java | 1 - .../db/service/persistent/TestSentryStore.java | 26 ++++------ .../persistent/TestSentryStoreImportExport.java | 48 ++++++++++++------ .../service/persistent/TestSentryVersion.java | 4 +- .../TestSentryServerForHaWithoutKerberos.java | 12 ++--- .../thrift/TestSentryServerWithoutKerberos.java | 12 ++--- .../provider/db/tools/TestSentryShellHive.java | 6 +-- .../thrift/SentryServiceIntegrationBase.java | 2 +- .../admin/SecureCoreAdminHandlerTest.java | 6 +-- .../QueryDocAuthorizationComponentTest.java | 1 - .../QueryIndexAuthorizationComponentTest.java | 1 - .../SentryIndexAuthorizationSingletonTest.java | 8 ++- .../sentry/SentrySingletonTestInstance.java | 1 - .../org/apache/solr/sentry/SentryTestBase.java | 4 +- .../e2e/solr/AbstractSolrSentryTestBase.java | 26 +++++++--- .../tests/e2e/solr/DocLevelGenerator.java | 4 +- .../ModifiableUserAuthenticationFilter.java | 4 -- .../tests/e2e/solr/TestDocLevelOperations.java | 17 +++---- .../tests/e2e/solr/TestQueryOperations.java | 3 -- .../sentry/tests/e2e/solr/TestRealTimeGet.java | 28 +++++------ .../AbstractSolrSentryTestWithDbProvider.java | 7 ++- .../db/integration/TestSolrAdminOperations.java | 5 +- .../db/integration/TestSolrQueryOperations.java | 5 +- .../integration/TestSolrUpdateOperations.java | 5 +- .../tests/e2e/sqoop/TestConnectorEndToEnd.java | 3 -- .../tests/e2e/sqoop/TestOwnerPrivilege.java | 2 - .../tests/e2e/sqoop/TestShowPrivilege.java | 1 - .../tests/e2e/sqoop/TomcatSqoopRunner.java | 1 - 55 files changed, 180 insertions(+), 231 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/build-tools/sentry-pmd-ruleset.xml ---------------------------------------------------------------------- diff --git a/build-tools/sentry-pmd-ruleset.xml b/build-tools/sentry-pmd-ruleset.xml index 87a761c..8a26446 100644 --- a/build-tools/sentry-pmd-ruleset.xml +++ b/build-tools/sentry-pmd-ruleset.xml @@ -24,14 +24,21 @@ A PMD ruleset for Apache Sentry </description> - <rule ref="rulesets/java/basic.xml"/> + <rule ref="rulesets/java/basic.xml"> + <exclude name="CheckResultSet"/> + <exclude name="AvoidUsingOctalValues"/> + </rule> <rule ref="rulesets/java/unusedcode.xml"/> <rule ref="rulesets/java/imports.xml"/> <rule ref="rulesets/java/braces.xml"/> <rule ref="rulesets/java/empty.xml"> <exclude name="EmptyCatchBlock" /> </rule> - <rule ref="rulesets/java/migrating.xml"/> + <rule ref="rulesets/java/migrating.xml"> + <exclude name="JUnitUseExpected" /> + <exclude name="JUnit4TestShouldUseAfterAnnotation" /> + <exclude name="JUnit4TestShouldUseBeforeAnnotation" /> + </rule> <rule ref="rulesets/java/unnecessary.xml"> <exclude name="UselessParentheses" /> </rule> http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 186a0c6..5c31bf4 100644 --- a/pom.xml +++ b/pom.xml @@ -632,6 +632,7 @@ limitations under the License. <sourceEncoding>UTF-8</sourceEncoding> <failOnViolation>true</failOnViolation> <linkXRef>false</linkXRef> + <includeTests>true</includeTests> <verbose>true</verbose> <targetJdk>${targetJdk}</targetJdk> <excludeRoots> http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestHiveAuthzBindings.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestHiveAuthzBindings.java b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestHiveAuthzBindings.java index 1fac0c7..726e3dc 100644 --- a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestHiveAuthzBindings.java +++ b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestHiveAuthzBindings.java @@ -75,11 +75,9 @@ public class TestHiveAuthzBindings { // Tables private static final String PURCHASES_TAB = "purchases"; - private static final String PAYMENT_TAB = "payments"; // Columns private static final String AGE_COL = "age"; - private static final String NAME_COL = "name"; // Entities private List<List<DBModelAuthorizable>> inputTabHierarcyList = new ArrayList<List<DBModelAuthorizable>>(); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-binding/sentry-binding-solr/src/test/java/org/apache/sentry/binding/solr/TestSolrAuthzBinding.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-solr/src/test/java/org/apache/sentry/binding/solr/TestSolrAuthzBinding.java b/sentry-binding/sentry-binding-solr/src/test/java/org/apache/sentry/binding/solr/TestSolrAuthzBinding.java index c0445ab..bec12d3 100644 --- a/sentry-binding/sentry-binding-solr/src/test/java/org/apache/sentry/binding/solr/TestSolrAuthzBinding.java +++ b/sentry-binding/sentry-binding-solr/src/test/java/org/apache/sentry/binding/solr/TestSolrAuthzBinding.java @@ -179,7 +179,6 @@ public class TestSolrAuthzBinding { new SolrAuthzConf(Resources.getResource("sentry-site.xml")); setUsableAuthzConf(solrAuthzConf); SolrAuthzBinding binding = new SolrAuthzBinding(solrAuthzConf); - Set<String> emptyList = Collections.emptySet(); // check non-existant users try { @@ -385,7 +384,6 @@ public class TestSolrAuthzBinding { + System.currentTimeMillis()).getAbsolutePath()); String resourceOnHDFS = "/hdfs" + File.separator + UUID.randomUUID() + File.separator + "test-authz-provider.ini"; try { - Path src = new Path(baseDir.getPath(), RESOURCE_PATH); // Copy resource to HDFSS dfsCluster.getFileSystem().copyFromLocalFile(false, new Path(baseDir.getPath(), RESOURCE_PATH), http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-core/sentry-core-model-sqoop/src/test/java/org/apache/sentry/core/model/sqoop/TestSqoopAuthorizable.java ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-model-sqoop/src/test/java/org/apache/sentry/core/model/sqoop/TestSqoopAuthorizable.java b/sentry-core/sentry-core-model-sqoop/src/test/java/org/apache/sentry/core/model/sqoop/TestSqoopAuthorizable.java index c346290..17798a1 100644 --- a/sentry-core/sentry-core-model-sqoop/src/test/java/org/apache/sentry/core/model/sqoop/TestSqoopAuthorizable.java +++ b/sentry-core/sentry-core-model-sqoop/src/test/java/org/apache/sentry/core/model/sqoop/TestSqoopAuthorizable.java @@ -19,10 +19,6 @@ package org.apache.sentry.core.model.sqoop; import junit.framework.Assert; -import org.apache.sentry.core.model.sqoop.Connector; -import org.apache.sentry.core.model.sqoop.Job; -import org.apache.sentry.core.model.sqoop.Link; -import org.apache.sentry.core.model.sqoop.Server; import org.apache.sentry.core.model.sqoop.SqoopAuthorizable.AuthorizableType; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestKrbConnectionTimeout.java ---------------------------------------------------------------------- diff --git a/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestKrbConnectionTimeout.java b/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestKrbConnectionTimeout.java index 968d29c..b62a83f 100644 --- a/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestKrbConnectionTimeout.java +++ b/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestKrbConnectionTimeout.java @@ -27,7 +27,7 @@ public class TestKrbConnectionTimeout extends SentryHdfsServiceIntegrationBase { @BeforeClass - public static void testSetup() throws Exception { + public static void setup() throws Exception { Assume.assumeTrue("true".equalsIgnoreCase(System.getProperty( "sentry.hive.test.ticket.timeout", "false"))); kdcConfOverlay.setProperty(MiniKdc.MAX_TICKET_LIFETIME, "300001"); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestUpdateableAuthzPaths.java ---------------------------------------------------------------------- diff --git a/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestUpdateableAuthzPaths.java b/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestUpdateableAuthzPaths.java index 98ab7ba..a5bc313 100644 --- a/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestUpdateableAuthzPaths.java +++ b/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestUpdateableAuthzPaths.java @@ -17,7 +17,6 @@ */ package org.apache.sentry.hdfs; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-hdfs/sentry-hdfs-service/src/test/java/org/apache/sentry/hdfs/TestMetastoreCacheInitializer.java ---------------------------------------------------------------------- diff --git a/sentry-hdfs/sentry-hdfs-service/src/test/java/org/apache/sentry/hdfs/TestMetastoreCacheInitializer.java b/sentry-hdfs/sentry-hdfs-service/src/test/java/org/apache/sentry/hdfs/TestMetastoreCacheInitializer.java index 2c9e19d..9e6072d 100644 --- a/sentry-hdfs/sentry-hdfs-service/src/test/java/org/apache/sentry/hdfs/TestMetastoreCacheInitializer.java +++ b/sentry-hdfs/sentry-hdfs-service/src/test/java/org/apache/sentry/hdfs/TestMetastoreCacheInitializer.java @@ -169,7 +169,7 @@ public class TestMetastoreCacheInitializer { try { MetastoreCacheInitializer cacheInitializer = new MetastoreCacheInitializer(hmsHandler, conf); - UpdateableAuthzPaths update = cacheInitializer.createInitialUpdate(); + cacheInitializer.createInitialUpdate(); Assert.fail("Expected cacheInitializer to fail"); } catch (Exception e) { Assert.assertTrue(e instanceof RuntimeException); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-hdfs/sentry-hdfs-service/src/test/java/org/apache/sentry/hdfs/TestUpdateForwarder.java ---------------------------------------------------------------------- diff --git a/sentry-hdfs/sentry-hdfs-service/src/test/java/org/apache/sentry/hdfs/TestUpdateForwarder.java b/sentry-hdfs/sentry-hdfs-service/src/test/java/org/apache/sentry/hdfs/TestUpdateForwarder.java index 54a83b0..d6975ec 100644 --- a/sentry-hdfs/sentry-hdfs-service/src/test/java/org/apache/sentry/hdfs/TestUpdateForwarder.java +++ b/sentry-hdfs/sentry-hdfs-service/src/test/java/org/apache/sentry/hdfs/TestUpdateForwarder.java @@ -26,8 +26,6 @@ import java.util.concurrent.locks.ReadWriteLock; import junit.framework.Assert; import org.apache.hadoop.conf.Configuration; -import org.apache.sentry.hdfs.UpdateForwarder; -import org.apache.sentry.hdfs.Updateable; import org.apache.sentry.hdfs.UpdateForwarder.ExternalImageRetriever; import org.apache.sentry.hdfs.Updateable.Update; import org.apache.sentry.service.thrift.ServiceConstants.ServerConfig; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDBWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDBWildcardPrivilege.java b/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDBWildcardPrivilege.java index 9fcf853..8504a7a 100644 --- a/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDBWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDBWildcardPrivilege.java @@ -17,9 +17,6 @@ * under the License. */ package org.apache.sentry.policy.db; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; import static org.apache.sentry.policy.common.PolicyConstants.KV_SEPARATOR; @@ -29,7 +26,7 @@ import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.KeyValue; import org.junit.Test; -public class TestDBWildcardPrivilege { +public class TestDBWildcardPrivilege extends junit.framework.Assert { private static final String ALL = AccessConstants.ALL; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDatabaseRequiredInRole.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDatabaseRequiredInRole.java b/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDatabaseRequiredInRole.java index f9b00b4..5d9cb29 100644 --- a/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDatabaseRequiredInRole.java +++ b/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDatabaseRequiredInRole.java @@ -43,7 +43,7 @@ public class TestDatabaseRequiredInRole { "server=server1->db=db1->URI=file:///user/db/warehouse/tab1")); Assert.fail("Expected ConfigurationException"); } catch (ConfigurationException e) { - ; + // expected } } } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerAuthorizationProviderGeneralCases.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerAuthorizationProviderGeneralCases.java b/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerAuthorizationProviderGeneralCases.java index 00c1b6d..428cbd8 100644 --- a/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerAuthorizationProviderGeneralCases.java +++ b/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerAuthorizationProviderGeneralCases.java @@ -66,7 +66,6 @@ public class TestIndexerAuthorizationProviderGeneralCases { private static final Indexer IND_TMP = new Indexer("tmpindexer"); private static final Indexer IND_PURCHASES_PARTIAL = new Indexer("purchases_partial"); - private static final IndexerModelAction ALL = IndexerModelAction.ALL; private static final IndexerModelAction READ = IndexerModelAction.READ; private static final IndexerModelAction WRITE = IndexerModelAction.WRITE; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerRequiredInRole.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerRequiredInRole.java b/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerRequiredInRole.java index 8494a8f..ff13159 100644 --- a/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerRequiredInRole.java +++ b/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerRequiredInRole.java @@ -35,7 +35,7 @@ public class TestIndexerRequiredInRole { indexerRequiredInRole.validate(new PrivilegeValidatorContext("index=index1")); Assert.fail("Expected ConfigurationException"); } catch (ConfigurationException e) { - ; + // expected } // check with db @@ -43,7 +43,7 @@ public class TestIndexerRequiredInRole { indexerRequiredInRole.validate(new PrivilegeValidatorContext("db1","index=index2")); Assert.fail("Expected ConfigurationException"); } catch (ConfigurationException e) { - ; + // expected } } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerWildcardPrivilege.java b/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerWildcardPrivilege.java index b599a84..4329c5c 100644 --- a/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerWildcardPrivilege.java @@ -17,8 +17,6 @@ * under the License. */ package org.apache.sentry.policy.indexer; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; import static org.apache.sentry.policy.common.PolicyConstants.KV_SEPARATOR; @@ -28,7 +26,7 @@ import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.KeyValue; import org.junit.Test; -public class TestIndexerWildcardPrivilege { +public class TestIndexerWildcardPrivilege extends junit.framework.Assert { private static final String ALL = IndexerConstants.ALL; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestCollectionRequiredInRole.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestCollectionRequiredInRole.java b/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestCollectionRequiredInRole.java index b626f1a..f0842b5 100644 --- a/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestCollectionRequiredInRole.java +++ b/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestCollectionRequiredInRole.java @@ -35,7 +35,7 @@ public class TestCollectionRequiredInRole { collRequiredInRole.validate(new PrivilegeValidatorContext("index=index1")); Assert.fail("Expected ConfigurationException"); } catch (ConfigurationException e) { - ; + // expected } // check with db @@ -43,7 +43,7 @@ public class TestCollectionRequiredInRole { collRequiredInRole.validate(new PrivilegeValidatorContext("db1","index=index2")); Assert.fail("Expected ConfigurationException"); } catch (ConfigurationException e) { - ; + // expected } } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestSearchWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestSearchWildcardPrivilege.java b/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestSearchWildcardPrivilege.java index a4c8a2b..ffdbe11 100644 --- a/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestSearchWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestSearchWildcardPrivilege.java @@ -17,8 +17,6 @@ * under the License. */ package org.apache.sentry.policy.search; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; import static org.apache.sentry.policy.common.PolicyConstants.KV_SEPARATOR; @@ -28,7 +26,7 @@ import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.KeyValue; import org.junit.Test; -public class TestSearchWildcardPrivilege { +public class TestSearchWildcardPrivilege extends junit.framework.Assert { private static final String ALL = SearchConstants.ALL; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopAuthorizationProviderGeneralCases.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopAuthorizationProviderGeneralCases.java b/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopAuthorizationProviderGeneralCases.java index e59164d..4c02856 100644 --- a/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopAuthorizationProviderGeneralCases.java +++ b/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopAuthorizationProviderGeneralCases.java @@ -136,8 +136,9 @@ public class TestSqoopAuthorizationProviderGeneralCases { Set<SqoopAction> allActions = Sets.newHashSet(ALL, READ, WRITE); for (SqoopAction action : allActions) { //developer only has the read action on all connectors - for (Connector connector : Sets.newHashSet(jdbc_connector, hdfs_connector, kafka_connector, kite_connector)) - doTestResourceAuthorizationProvider(SUB_DEVELOPER, Arrays.asList(server1, connector), Sets.newHashSet(action), READ.equals(action)); + for (Connector connector : Sets.newHashSet(jdbc_connector, hdfs_connector, kafka_connector, kite_connector)) { + doTestResourceAuthorizationProvider(SUB_DEVELOPER, Arrays.asList(server1, connector), Sets.newHashSet(action), READ.equals(action)); + } } for (Link link : Sets.newHashSet(link1, link2)) { @@ -156,8 +157,9 @@ public class TestSqoopAuthorizationProviderGeneralCases { Set<SqoopAction> allActions = Sets.newHashSet(ALL, READ, WRITE); for (SqoopAction action : allActions) { //analyst has not the any action on all connectors - for (Connector connector : Sets.newHashSet(jdbc_connector, hdfs_connector, kafka_connector, kite_connector)) - doTestResourceAuthorizationProvider(SUB_ANALYST, Arrays.asList(server1, connector), Sets.newHashSet(action), false); + for (Connector connector : Sets.newHashSet(jdbc_connector, hdfs_connector, kafka_connector, kite_connector)) { + doTestResourceAuthorizationProvider(SUB_ANALYST, Arrays.asList(server1, connector), Sets.newHashSet(action), false); + } } for (Link link : Sets.newHashSet(link1, link2)) { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopWildcardPrivilege.java b/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopWildcardPrivilege.java index f19a1f8..cbc61ea 100644 --- a/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopWildcardPrivilege.java @@ -17,8 +17,6 @@ * under the License. */ package org.apache.sentry.policy.sqoop; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; import static org.apache.sentry.policy.common.PolicyConstants.KV_SEPARATOR; @@ -28,7 +26,7 @@ import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.KeyValue; import org.junit.Test; -public class TestSqoopWildcardPrivilege { +public class TestSqoopWildcardPrivilege extends junit.framework.Assert { private static final Privilege SQOOP_SERVER1_ALL = create(new KeyValue("SERVER", "server1"), new KeyValue("action", SqoopActionConstant.ALL)); private static final Privilege SQOOP_SERVER1_READ = http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/TestGetGroupMapping.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/TestGetGroupMapping.java b/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/TestGetGroupMapping.java index dfb5d70..14af2d4 100644 --- a/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/TestGetGroupMapping.java +++ b/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/TestGetGroupMapping.java @@ -25,8 +25,6 @@ import org.apache.sentry.core.common.SentryConfigurationException; import org.apache.sentry.core.common.ActiveRoleSet; import org.apache.sentry.policy.common.PrivilegeFactory; import org.apache.sentry.policy.common.PolicyEngine; -import org.apache.sentry.provider.common.GroupMappingService; -import org.apache.sentry.provider.common.ResourceAuthorizationProvider; import org.junit.Test; import com.google.common.collect.ImmutableSet; @@ -66,7 +64,6 @@ public class TestGetGroupMapping { @Override public void validatePolicy(boolean strictValidation) throws SentryConfigurationException { - return; } @Override http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/persistent/TestSentryGMPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/persistent/TestSentryGMPrivilege.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/persistent/TestSentryGMPrivilege.java index 1411692..0780d0a 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/persistent/TestSentryGMPrivilege.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/persistent/TestSentryGMPrivilege.java @@ -35,21 +35,21 @@ public class TestSentryGMPrivilege { @Test public void testValidateAuthorizables() throws Exception { try { - MSentryGMPrivilege fieldPrivilege = new MSentryGMPrivilege("solr", + new MSentryGMPrivilege("solr", "service1", Arrays.asList(new Collection("c1"), new Field("f1")),SearchConstants.QUERY, false); } catch (IllegalStateException e) { fail("unexpect happend: it is a validated privilege"); } try { - MSentryGMPrivilege collectionPrivilege = new MSentryGMPrivilege("solr", + new MSentryGMPrivilege("solr", "service1", Arrays.asList(new Collection(""), new Field("f1")),SearchConstants.QUERY, false); fail("unexpect happend: it is not a validated privilege, The empty name of authorizable can't be empty"); } catch (IllegalStateException e) { } try { - MSentryGMPrivilege fieldPrivilege = new MSentryGMPrivilege("solr", + new MSentryGMPrivilege("solr", "service1", Arrays.asList(null, new Field("f1")),SearchConstants.QUERY, false); fail("unexpect happend: it is not a validated privilege, The authorizable can't be null"); } catch (IllegalStateException e) { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/persistent/TestSentryRole.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/persistent/TestSentryRole.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/persistent/TestSentryRole.java index f8eecd9..54bd720 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/persistent/TestSentryRole.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/persistent/TestSentryRole.java @@ -39,9 +39,7 @@ import org.apache.sentry.provider.db.service.model.MSentryRole; import org.apache.sentry.provider.db.service.persistent.SentryStore; import org.apache.sentry.service.thrift.ServiceConstants.ServerConfig; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import com.google.common.base.Preconditions; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/SentryGenericServiceIntegrationBase.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/SentryGenericServiceIntegrationBase.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/SentryGenericServiceIntegrationBase.java index e55f711..cec925b 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/SentryGenericServiceIntegrationBase.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/SentryGenericServiceIntegrationBase.java @@ -39,7 +39,6 @@ public class SentryGenericServiceIntegrationBase extends SentryServiceIntegratio public void connectToSentryService() throws Exception { // The client should already be logged in when running in solr // therefore we must manually login in the integration tests - final SentryGenericServiceClientFactory clientFactory; if (kerberos) { this.client = Subject.doAs(clientSubject, new PrivilegedExceptionAction<SentryGenericServiceClient>() { @Override http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/TestSentryGenericPolicyProcessor.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/TestSentryGenericPolicyProcessor.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/TestSentryGenericPolicyProcessor.java index 48c45ce..436073c 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/TestSentryGenericPolicyProcessor.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/TestSentryGenericPolicyProcessor.java @@ -17,17 +17,13 @@ */ package org.apache.sentry.provider.db.generic.service.thrift; -import static junit.framework.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.anySetOf; import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import java.util.*; -import com.google.common.collect.Lists; import org.apache.hadoop.conf.Configuration; import org.apache.sentry.core.common.Authorizable; import org.apache.sentry.core.model.search.Collection; @@ -51,16 +47,17 @@ import org.apache.sentry.service.thrift.Status; import org.apache.sentry.service.thrift.TSentryResponseStatus; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import com.google.common.collect.Sets; -public class TestSentryGenericPolicyProcessor { +public class TestSentryGenericPolicyProcessor extends junit.framework.Assert { private static final String ADMIN_GROUP = "admin_group"; private static final String ADMIN_USER = "admin_user"; private static final UUID SERVER_UUID = UUID.randomUUID(); private static final long SEQ_ID = 10000; - private SentryStoreLayer mockStore = mock(SentryStoreLayer.class); + private SentryStoreLayer mockStore = Mockito.mock(SentryStoreLayer.class); private SentryGenericPolicyProcessor processor; @Before @@ -117,22 +114,22 @@ public class TestSentryGenericPolicyProcessor { @Test public void testAdminOperation() throws Exception { - when(mockStore.createRole(anyString(), anyString(), anyString())) + Mockito.when(mockStore.createRole(anyString(), anyString(), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID)); - when(mockStore.dropRole(anyString(), anyString(), anyString())) + Mockito.when(mockStore.dropRole(anyString(), anyString(), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 1)); - when(mockStore.alterRoleAddGroups(anyString(), anyString(), anySetOf(String.class),anyString())) + Mockito.when(mockStore.alterRoleAddGroups(anyString(), anyString(), anySetOf(String.class),anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 2)); - when(mockStore.alterRoleDeleteGroups(anyString(), anyString(),anySetOf(String.class), anyString())) + Mockito.when(mockStore.alterRoleDeleteGroups(anyString(), anyString(),anySetOf(String.class), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 3)); - when(mockStore.dropPrivilege(anyString(), any(PrivilegeObject.class), anyString())) + Mockito.when(mockStore.dropPrivilege(anyString(), any(PrivilegeObject.class), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 4)); - when(mockStore.renamePrivilege(anyString(), anyString(), anyListOf(Authorizable.class), + Mockito.when(mockStore.renamePrivilege(anyString(), anyString(), anyListOf(Authorizable.class), anyListOf(Authorizable.class), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 5)); testOperation(ADMIN_USER, Status.OK); @@ -140,10 +137,10 @@ public class TestSentryGenericPolicyProcessor { @Test public void testGrantAndRevokePrivilege() throws Exception { - when(mockStore.alterRoleGrantPrivilege(anyString(), anyString(), any(PrivilegeObject.class), anyString())) + Mockito.when(mockStore.alterRoleGrantPrivilege(anyString(), anyString(), any(PrivilegeObject.class), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 6)); - when(mockStore.alterRoleRevokePrivilege(anyString(), anyString(),any(PrivilegeObject.class), anyString())) + Mockito.when(mockStore.alterRoleRevokePrivilege(anyString(), anyString(),any(PrivilegeObject.class), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 7)); setup(); @@ -166,33 +163,33 @@ public class TestSentryGenericPolicyProcessor { @Test public void testOperationWithException() throws Exception { String roleName = anyString(); - when(mockStore.createRole(anyString(), roleName, anyString())) + Mockito.when(mockStore.createRole(anyString(), roleName, anyString())) .thenThrow(new SentryAlreadyExistsException("Role: " + roleName + " already exists")); roleName = anyString(); - when(mockStore.dropRole(anyString(), roleName, anyString())) + Mockito.when(mockStore.dropRole(anyString(), roleName, anyString())) .thenThrow(new SentryNoSuchObjectException("Role: " + roleName + " doesn't exist")); roleName = anyString(); - when(mockStore.alterRoleAddGroups(anyString(), roleName, anySetOf(String.class),anyString())) + Mockito.when(mockStore.alterRoleAddGroups(anyString(), roleName, anySetOf(String.class),anyString())) .thenThrow(new SentryNoSuchObjectException("Role: " + roleName + " doesn't exist")); roleName = anyString(); - when(mockStore.alterRoleDeleteGroups(anyString(), roleName, anySetOf(String.class), anyString())) + Mockito.when(mockStore.alterRoleDeleteGroups(anyString(), roleName, anySetOf(String.class), anyString())) .thenThrow(new SentryNoSuchObjectException("Role: " + roleName + " doesn't exist")); roleName = anyString(); - when(mockStore.alterRoleGrantPrivilege(anyString(), roleName, any(PrivilegeObject.class), anyString())) + Mockito.when(mockStore.alterRoleGrantPrivilege(anyString(), roleName, any(PrivilegeObject.class), anyString())) .thenThrow(new SentryGrantDeniedException("Role: " + roleName + " is not allowed to do grant")); roleName = anyString(); - when(mockStore.alterRoleRevokePrivilege(anyString(), roleName, any(PrivilegeObject.class), anyString())) + Mockito.when(mockStore.alterRoleRevokePrivilege(anyString(), roleName, any(PrivilegeObject.class), anyString())) .thenThrow(new SentryGrantDeniedException("Role: " + roleName + " is not allowed to do grant")); - when(mockStore.dropPrivilege(anyString(), any(PrivilegeObject.class), anyString())) + Mockito.when(mockStore.dropPrivilege(anyString(), any(PrivilegeObject.class), anyString())) .thenThrow(new SentryInvalidInputException("Invalid input privilege object")); - when(mockStore.renamePrivilege(anyString(), anyString(), anyListOf(Authorizable.class), + Mockito.when(mockStore.renamePrivilege(anyString(), anyString(), anyListOf(Authorizable.class), anyListOf(Authorizable.class), anyString())) .thenThrow(new RuntimeException("Unknown error")); @@ -266,20 +263,20 @@ public class TestSentryGenericPolicyProcessor { MSentryRole role = new MSentryRole("r1", 290); mSentryGMPrivilege.setRoles(Sets.newHashSet(role)); - when(mockStore.getRolesByGroups(anyString(), anySetOf(String.class))) + Mockito.when(mockStore.getRolesByGroups(anyString(), anySetOf(String.class))) .thenReturn(Sets.newHashSet(roleName)); - when(mockStore.getPrivilegesByProvider(anyString(), anyString(), anySetOf(String.class), + Mockito.when(mockStore.getPrivilegesByProvider(anyString(), anyString(), anySetOf(String.class), anySetOf(String.class), anyListOf(Authorizable.class))) .thenReturn(Sets.newHashSet(queryPrivilege, updatePrivilege)); - when(mockStore.getGroupsByRoles(anyString(), anySetOf(String.class))) + Mockito.when(mockStore.getGroupsByRoles(anyString(), anySetOf(String.class))) .thenReturn(Sets.newHashSet(groupName)); - when(mockStore.getPrivilegesByAuthorizable(anyString(), anyString(), anySetOf(String.class), anyListOf(Authorizable.class))) + Mockito.when(mockStore.getPrivilegesByAuthorizable(anyString(), anyString(), anySetOf(String.class), anyListOf(Authorizable.class))) .thenReturn(Sets.newHashSet(mSentryGMPrivilege)); - when(mockStore.getAllRoleNames()) + Mockito.when(mockStore.getAllRoleNames()) .thenReturn(Sets.newHashSet(roleName)); TListSentryPrivilegesRequest request1 = new TListSentryPrivilegesRequest(); @@ -331,7 +328,7 @@ public class TestSentryGenericPolicyProcessor { } public static class MockGroupMapping implements GroupMappingService { - public MockGroupMapping(Configuration conf, String resource) { + public MockGroupMapping(Configuration conf, String resource) { //NOPMD } @Override public Set<String> getGroups(String user) { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/TestSentryGenericServiceIntegration.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/TestSentryGenericServiceIntegration.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/TestSentryGenericServiceIntegration.java index 7f8f916..921685a 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/TestSentryGenericServiceIntegration.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/service/thrift/TestSentryGenericServiceIntegration.java @@ -32,16 +32,12 @@ import org.apache.sentry.core.model.search.Collection; import org.apache.sentry.core.model.search.Field; import org.apache.sentry.core.model.search.SearchConstants; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.collect.Lists; import com.google.common.collect.Sets; public class TestSentryGenericServiceIntegration extends SentryGenericServiceIntegrationBase { - private static final Logger LOGGER = LoggerFactory.getLogger(TestSentryGenericServiceIntegration.class); - @Test public void testCreateDropShowRole() throws Exception { runTestAsSubject(new TestOperation(){ http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java index 37cc966..6dbe7c0 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java @@ -29,16 +29,12 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; -import java.security.PrivilegedExceptionAction; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import javax.security.auth.Subject; import org.apache.commons.io.FileUtils; import org.apache.sentry.SentryUserException; -import org.apache.sentry.provider.db.generic.service.thrift.SentryGenericServiceClient; -import org.apache.sentry.provider.db.generic.service.thrift.SentryGenericServiceClientFactory; import org.apache.sentry.provider.db.generic.service.thrift.SentryGenericServiceIntegrationBase; import org.apache.sentry.provider.db.generic.service.thrift.TSentryRole; import org.apache.sentry.provider.db.generic.service.thrift.TSentryPrivilege; @@ -48,11 +44,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase { - private static final Logger LOGGER = LoggerFactory.getLogger(TestSentryShellSolr.class); private File confDir; private File confPath; private static String TEST_ROLE_NAME_1 = "testRole1"; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/log/appender/TestRollingFileWithoutDeleteAppender.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/log/appender/TestRollingFileWithoutDeleteAppender.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/log/appender/TestRollingFileWithoutDeleteAppender.java index e1ebce6..9acd5de 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/log/appender/TestRollingFileWithoutDeleteAppender.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/log/appender/TestRollingFileWithoutDeleteAppender.java @@ -24,8 +24,6 @@ import static org.junit.Assert.assertTrue; import java.io.File; -import junit.framework.ComparisonFailure; - import org.apache.commons.io.FileUtils; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/log/entity/TestJsonLogEntityFactory.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/log/entity/TestJsonLogEntityFactory.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/log/entity/TestJsonLogEntityFactory.java index 4e40038..0432853 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/log/entity/TestJsonLogEntityFactory.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/log/entity/TestJsonLogEntityFactory.java @@ -126,10 +126,8 @@ public class TestJsonLogEntityFactory { Set<JsonLogEntity> amles = JsonLogEntityFactory .getInstance().createJsonLogEntitys(request, response, conf); assertEquals(amles.size(),1); - for (JsonLogEntity amle1 : amles) { - amle = (DBAuditMetadataLogEntity) amle1; - break; - } + amle = (DBAuditMetadataLogEntity) amles.iterator().next(); + assertCommon(amle, Constants.TRUE, Constants.OPERATION_GRANT_PRIVILEGE, "GRANT ALL ON DATABASE testDB TO ROLE testRole", TEST_DATABASE_NAME, null, null, Constants.OBJECT_TYPE_PRINCIPAL); @@ -143,10 +141,8 @@ public class TestJsonLogEntityFactory { amles = JsonLogEntityFactory.getInstance() .createJsonLogEntitys(request, response, conf); assertEquals(amles.size(),1); - for (JsonLogEntity amle1 : amles) { - amle = (DBAuditMetadataLogEntity) amle1; - break; - } + amle = (DBAuditMetadataLogEntity) amles.iterator().next(); + assertCommon(amle, Constants.FALSE, Constants.OPERATION_GRANT_PRIVILEGE, "GRANT ALL ON TABLE testTable TO ROLE testRole", null, TEST_TABLE_NAME, null, Constants.OBJECT_TYPE_PRINCIPAL); @@ -169,10 +165,8 @@ public class TestJsonLogEntityFactory { Set<JsonLogEntity> amles = JsonLogEntityFactory .getInstance().createJsonLogEntitys(request, response, conf); assertEquals(amles.size(),1); - for (JsonLogEntity amle1 : amles) { - amle = (DBAuditMetadataLogEntity) amle1; - break; - } + amle = (DBAuditMetadataLogEntity) amles.iterator().next(); + assertCommon(amle, Constants.TRUE, Constants.OPERATION_REVOKE_PRIVILEGE, "REVOKE ALL ON DATABASE testDB FROM ROLE testRole", TEST_DATABASE_NAME, null, null, Constants.OBJECT_TYPE_PRINCIPAL); @@ -186,10 +180,8 @@ public class TestJsonLogEntityFactory { amles = JsonLogEntityFactory.getInstance() .createJsonLogEntitys(request, response, conf); assertEquals(amles.size(),1); - for (JsonLogEntity amle1 : amles) { - amle = (DBAuditMetadataLogEntity) amle1; - break; - } + amle = (DBAuditMetadataLogEntity) amles.iterator().next(); + assertCommon(amle, Constants.FALSE, Constants.OPERATION_REVOKE_PRIVILEGE, "REVOKE ALL ON TABLE testTable FROM ROLE testRole", null, TEST_TABLE_NAME, null, Constants.OBJECT_TYPE_PRINCIPAL); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryServiceDiscovery.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryServiceDiscovery.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryServiceDiscovery.java index 2773a9e..5fc0b2a 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryServiceDiscovery.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryServiceDiscovery.java @@ -25,7 +25,6 @@ import java.util.Map; import org.apache.hadoop.conf.Configuration; import org.apache.curator.test.TestingServer; -import org.apache.curator.utils.CloseableUtils; import org.apache.curator.x.discovery.ServiceInstance; import org.apache.sentry.service.thrift.ServiceConstants.ServerConfig; import org.junit.After; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java index 56c05c2..f42a3c8 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java @@ -18,16 +18,10 @@ package org.apache.sentry.provider.db.service.persistent; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; - import java.io.File; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Set; import org.apache.commons.io.FileUtils; @@ -60,7 +54,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import com.google.common.io.Files; -public class TestSentryStore { +public class TestSentryStore extends junit.framework.Assert { private static File dataDir; private static SentryStore sentryStore; @@ -535,7 +529,7 @@ public class TestSentryStore { privilegeTable1.setTableName(table1); privilegeTable1.setAction(AccessConstants.ALL); privilegeTable1.setCreateTime(System.currentTimeMillis()); - TSentryPrivilege privilegeTable2 = privilegeTable1.deepCopy();; + TSentryPrivilege privilegeTable2 = privilegeTable1.deepCopy(); privilegeTable2.setTableName(table2); // Grant ALL on table1 and table2 @@ -614,7 +608,7 @@ public class TestSentryStore { privilegeCol1.setColumnName(column1); privilegeCol1.setAction(AccessConstants.ALL); privilegeCol1.setCreateTime(System.currentTimeMillis()); - TSentryPrivilege privilegeCol2 = privilegeCol1.deepCopy();; + TSentryPrivilege privilegeCol2 = privilegeCol1.deepCopy(); privilegeCol2.setColumnName(column2); // Grant ALL on column1 and column2 @@ -1566,17 +1560,17 @@ public class TestSentryStore { String grantor = "g1"; - assertEquals(new Long(0), sentryStore.getPrivilegeCountGauge().getValue()); + assertEquals(Long.valueOf(0), sentryStore.getPrivilegeCountGauge().getValue()); sentryStore.alterSentryRoleGrantPrivilege(grantor, role1, privilege); - assertEquals(new Long(1), sentryStore.getPrivilegeCountGauge().getValue()); + assertEquals(Long.valueOf(1), sentryStore.getPrivilegeCountGauge().getValue()); sentryStore.alterSentryRoleGrantPrivilege(grantor, role2, privilege); - assertEquals(new Long(1), sentryStore.getPrivilegeCountGauge().getValue()); + assertEquals(Long.valueOf(1), sentryStore.getPrivilegeCountGauge().getValue()); privilege.setTableName("tb2"); sentryStore.alterSentryRoleGrantPrivilege(grantor, role2, privilege); - assertEquals(new Long(2), sentryStore.getPrivilegeCountGauge().getValue()); + assertEquals(Long.valueOf(2), sentryStore.getPrivilegeCountGauge().getValue()); } @Test @@ -1595,14 +1589,14 @@ public class TestSentryStore { String grantor = "g1"; sentryStore.alterSentryRoleAddGroups(grantor, role1, groups); - assertEquals(new Long(1), sentryStore.getGroupCountGauge().getValue()); + assertEquals(Long.valueOf(1), sentryStore.getGroupCountGauge().getValue()); sentryStore.alterSentryRoleAddGroups(grantor, role2, groups); - assertEquals(new Long(1), sentryStore.getGroupCountGauge().getValue()); + assertEquals(Long.valueOf(1), sentryStore.getGroupCountGauge().getValue()); groups.add(new TSentryGroup("group2")); sentryStore.alterSentryRoleAddGroups(grantor, role2, groups); - assertEquals(new Long(2), sentryStore.getGroupCountGauge().getValue()); + assertEquals(Long.valueOf(2), sentryStore.getGroupCountGauge().getValue()); } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java index 9350a50..7d46ce4 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java @@ -824,74 +824,90 @@ public class TestSentryStoreImportExport { boolean this_present_privilegeScope = true && tSentryPrivilege1.isSetPrivilegeScope(); boolean that_present_privilegeScope = true && tSentryPrivilege2.isSetPrivilegeScope(); if (this_present_privilegeScope || that_present_privilegeScope) { - if (!(this_present_privilegeScope && that_present_privilegeScope)) + if (!(this_present_privilegeScope && that_present_privilegeScope)) { return false; + } if (!tSentryPrivilege1.getPrivilegeScope().equalsIgnoreCase( - tSentryPrivilege2.getPrivilegeScope())) + tSentryPrivilege2.getPrivilegeScope())) { return false; + } } boolean this_present_serverName = true && tSentryPrivilege1.isSetServerName(); boolean that_present_serverName = true && tSentryPrivilege2.isSetServerName(); if (this_present_serverName || that_present_serverName) { - if (!(this_present_serverName && that_present_serverName)) + if (!(this_present_serverName && that_present_serverName)) { return false; - if (!tSentryPrivilege1.getServerName().equalsIgnoreCase(tSentryPrivilege2.getServerName())) + } + if (!tSentryPrivilege1.getServerName().equalsIgnoreCase(tSentryPrivilege2.getServerName())) { return false; + } } boolean this_present_dbName = true && tSentryPrivilege1.isSetDbName(); boolean that_present_dbName = true && tSentryPrivilege2.isSetDbName(); if (this_present_dbName || that_present_dbName) { - if (!(this_present_dbName && that_present_dbName)) + if (!(this_present_dbName && that_present_dbName)) { return false; - if (!tSentryPrivilege1.getDbName().equalsIgnoreCase(tSentryPrivilege2.getDbName())) + } + if (!tSentryPrivilege1.getDbName().equalsIgnoreCase(tSentryPrivilege2.getDbName())) { return false; + } } boolean this_present_tableName = true && tSentryPrivilege1.isSetTableName(); boolean that_present_tableName = true && tSentryPrivilege2.isSetTableName(); if (this_present_tableName || that_present_tableName) { - if (!(this_present_tableName && that_present_tableName)) + if (!(this_present_tableName && that_present_tableName)) { return false; - if (!tSentryPrivilege1.getTableName().equalsIgnoreCase(tSentryPrivilege2.getTableName())) + } + if (!tSentryPrivilege1.getTableName().equalsIgnoreCase(tSentryPrivilege2.getTableName())) { return false; + } } boolean this_present_URI = true && tSentryPrivilege1.isSetURI(); boolean that_present_URI = true && tSentryPrivilege2.isSetURI(); if (this_present_URI || that_present_URI) { - if (!(this_present_URI && that_present_URI)) + if (!(this_present_URI && that_present_URI)) { return false; - if (!tSentryPrivilege1.getURI().equalsIgnoreCase(tSentryPrivilege2.getURI())) + } + if (!tSentryPrivilege1.getURI().equalsIgnoreCase(tSentryPrivilege2.getURI())) { return false; + } } boolean this_present_action = true && tSentryPrivilege1.isSetAction(); boolean that_present_action = true && tSentryPrivilege2.isSetAction(); if (this_present_action || that_present_action) { - if (!(this_present_action && that_present_action)) + if (!(this_present_action && that_present_action)) { return false; - if (!tSentryPrivilege1.getAction().equalsIgnoreCase(tSentryPrivilege2.getAction())) + } + if (!tSentryPrivilege1.getAction().equalsIgnoreCase(tSentryPrivilege2.getAction())) { return false; + } } boolean this_present_grantOption = true && tSentryPrivilege1.isSetGrantOption(); boolean that_present_grantOption = true && tSentryPrivilege2.isSetGrantOption(); if (this_present_grantOption || that_present_grantOption) { - if (!(this_present_grantOption && that_present_grantOption)) + if (!(this_present_grantOption && that_present_grantOption)) { return false; - if (!tSentryPrivilege1.getGrantOption().equals(tSentryPrivilege2.getGrantOption())) + } + if (!tSentryPrivilege1.getGrantOption().equals(tSentryPrivilege2.getGrantOption())) { return false; + } } boolean this_present_columnName = true && tSentryPrivilege1.isSetColumnName(); boolean that_present_columnName = true && tSentryPrivilege2.isSetColumnName(); if (this_present_columnName || that_present_columnName) { - if (!(this_present_columnName && that_present_columnName)) + if (!(this_present_columnName && that_present_columnName)) { return false; - if (!tSentryPrivilege1.getColumnName().equalsIgnoreCase(tSentryPrivilege2.getColumnName())) + } + if (!tSentryPrivilege1.getColumnName().equalsIgnoreCase(tSentryPrivilege2.getColumnName())) { return false; + } } return true; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryVersion.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryVersion.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryVersion.java index 9c6597b..0d1656a 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryVersion.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryVersion.java @@ -61,12 +61,12 @@ public class TestSentryVersion { /** * Verify that store is not initialized by default without schema pre-created - * + * * @throws Exception */ @Test(expected = SentryNoSuchObjectException.class) public void testNegSentrySchemaDefault() throws Exception { - SentryStore sentryStore = new SentryStore(conf); + new SentryStore(conf); } /** http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServerForHaWithoutKerberos.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServerForHaWithoutKerberos.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServerForHaWithoutKerberos.java index e02e0ba..e069c9a 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServerForHaWithoutKerberos.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServerForHaWithoutKerberos.java @@ -22,8 +22,6 @@ import static junit.framework.Assert.assertEquals; import java.util.HashSet; import java.util.Set; -import junit.framework.Assert; - import org.apache.sentry.core.common.ActiveRoleSet; import org.apache.sentry.core.model.db.AccessConstants; import org.apache.sentry.core.model.db.Database; @@ -107,18 +105,18 @@ public class TestSentryServerForHaWithoutKerberos extends SentryServiceIntegrati assertEquals("Privilege not assigned to role2 !!", 1, listPrivilegesByRoleName.size()); Set<String> listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), ActiveRoleSet.ALL, new Server("server"), new Database("db2")); - Assert.assertEquals("Privilege not correctly assigned to roles !!", + assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=server->db=db2->table=table4->action=all", "server=server->db=db2->table=table3->action=all"), listPrivilegesForProvider); listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), ActiveRoleSet.ALL, new Server("server"), new Database("db3")); - Assert.assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=server->db=db3->table=table5->action=all"), listPrivilegesForProvider); + assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=server->db=db3->table=table5->action=all"), listPrivilegesForProvider); listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), new ActiveRoleSet(Sets.newHashSet(roleName1)), new Server("server"), new Database("db3")); - Assert.assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=+"), listPrivilegesForProvider); + assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=+"), listPrivilegesForProvider); listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), new ActiveRoleSet(Sets.newHashSet(roleName1)), new Server("server1")); - Assert.assertEquals("Privilege not correctly assigned to roles !!", new HashSet<String>(), listPrivilegesForProvider); + assertEquals("Privilege not correctly assigned to roles !!", new HashSet<String>(), listPrivilegesForProvider); } @@ -178,4 +176,4 @@ public class TestSentryServerForHaWithoutKerberos extends SentryServiceIntegrati // We just need to ensure that we are able to correct connect to the server connectToSentryService(); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServerWithoutKerberos.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServerWithoutKerberos.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServerWithoutKerberos.java index 5afc5b6..a1ebdd0 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServerWithoutKerberos.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServerWithoutKerberos.java @@ -23,8 +23,6 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Set; -import junit.framework.Assert; - import org.apache.sentry.core.common.ActiveRoleSet; import org.apache.sentry.core.common.Authorizable; import org.apache.sentry.core.model.db.AccessConstants; @@ -113,18 +111,18 @@ public class TestSentryServerWithoutKerberos extends SentryServiceIntegrationBas assertEquals("Privilege not assigned to role2 !!", 1, listPrivilegesByRoleName.size()); Set<String> listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), ActiveRoleSet.ALL, new Server("server"), new Database("db2")); - Assert.assertEquals("Privilege not correctly assigned to roles !!", + assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=server->db=db2->table=table4->action=all", "server=server->db=db2->table=table3->action=all"), listPrivilegesForProvider); listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), ActiveRoleSet.ALL, new Server("server"), new Database("db3")); - Assert.assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=server->db=db3->table=table5->action=all"), listPrivilegesForProvider); + assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=server->db=db3->table=table5->action=all"), listPrivilegesForProvider); listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), new ActiveRoleSet(Sets.newHashSet(roleName1)), new Server("server"), new Database("db3")); - Assert.assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=+"), listPrivilegesForProvider); + assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=+"), listPrivilegesForProvider); listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), new ActiveRoleSet(Sets.newHashSet(roleName1)), new Server("server1")); - Assert.assertEquals("Privilege not correctly assigned to roles !!", new HashSet<String>(), listPrivilegesForProvider); + assertEquals("Privilege not correctly assigned to roles !!", new HashSet<String>(), listPrivilegesForProvider); } @@ -174,4 +172,4 @@ public class TestSentryServerWithoutKerberos extends SentryServiceIntegrationBas ActiveRoleSet.ALL).size()); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentryShellHive.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentryShellHive.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentryShellHive.java index 6cb1925..ded4b62 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentryShellHive.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentryShellHive.java @@ -30,7 +30,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import junit.framework.Assert; import org.apache.commons.io.FileUtils; import org.apache.sentry.SentryUserException; import org.apache.sentry.provider.db.service.thrift.TSentryPrivilege; @@ -39,15 +38,12 @@ import org.apache.sentry.service.thrift.SentryServiceIntegrationBase; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.collect.Sets; import com.google.common.io.Files; public class TestSentryShellHive extends SentryServiceIntegrationBase { - private static final Logger LOGGER = LoggerFactory.getLogger(TestSentryShellHive.class); private File confDir; private File confPath; private static String TEST_ROLE_NAME_1 = "testRole1"; @@ -585,7 +581,7 @@ public class TestSentryShellHive extends SentryServiceIntegrationBase { private void validateMissingParameterMsg(SentryShellHive sentryShell, String[] args, String exceptedErrorMsg) throws Exception { Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false); - Assert.assertTrue(errorMsgs.contains(exceptedErrorMsg)); + assertTrue(errorMsgs.contains(exceptedErrorMsg)); } private void validateMissingParameterMsgsContains(SentryShellHive sentryShell, String[] args, http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryServiceIntegrationBase.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryServiceIntegrationBase.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryServiceIntegrationBase.java index 124293a..e02bd8a 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryServiceIntegrationBase.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryServiceIntegrationBase.java @@ -355,7 +355,7 @@ public abstract class SentryServiceIntegrationBase extends SentryMiniKdcTestcase } protected interface TestOperation { - public void runTestAsSubject() throws Exception; + void runTestAsSubject() throws Exception; } } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/admin/SecureCoreAdminHandlerTest.java ---------------------------------------------------------------------- diff --git a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/admin/SecureCoreAdminHandlerTest.java b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/admin/SecureCoreAdminHandlerTest.java index a145bc5..f93fb65 100644 --- a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/admin/SecureCoreAdminHandlerTest.java +++ b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/admin/SecureCoreAdminHandlerTest.java @@ -137,7 +137,7 @@ public class SecureCoreAdminHandlerTest extends SentryTestBase { } private void verifyQueryAccess(CoreAdminAction action, boolean checkCollection) throws Exception { - CoreContainer cc = getCleanCoreContainer(action, h.getCoreContainer()); + CoreContainer cc = getCleanCoreContainer(action); CoreAdminHandler handler = new SecureCoreAdminHandler(cc); verifyAuthorized(handler, getCoreAdminRequest("collection1", "junit", action)); verifyAuthorized(handler, getCoreAdminRequest("queryCollection", "junit", action)); @@ -151,7 +151,7 @@ public class SecureCoreAdminHandlerTest extends SentryTestBase { } private void verifyUpdateAccess(CoreAdminAction action, boolean checkCollection) throws Exception { - CoreContainer cc = getCleanCoreContainer(action, h.getCoreContainer()); + CoreContainer cc = getCleanCoreContainer(action); CoreAdminHandler handler = new SecureCoreAdminHandler(cc); verifyAuthorized(handler, getCoreAdminRequest("collection1", "junit", action)); verifyAuthorized(handler, getCoreAdminRequest("updateCollection", "junit", action)); @@ -176,7 +176,7 @@ public class SecureCoreAdminHandlerTest extends SentryTestBase { return (CoreContainer)e.create(); } - private CoreContainer getCleanCoreContainer(CoreAdminAction action, CoreContainer cc) { + private CoreContainer getCleanCoreContainer(CoreAdminAction action) { // Ensure CoreContainer is empty for (String coreName : h.getCoreContainer().getCoreNames()) { h.getCoreContainer().unload(coreName); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/component/QueryDocAuthorizationComponentTest.java ---------------------------------------------------------------------- diff --git a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/component/QueryDocAuthorizationComponentTest.java b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/component/QueryDocAuthorizationComponentTest.java index c94f6fb..1f44628 100644 --- a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/component/QueryDocAuthorizationComponentTest.java +++ b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/component/QueryDocAuthorizationComponentTest.java @@ -25,7 +25,6 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.core.SolrCore; -import org.apache.solr.handler.component.ResponseBuilder; import org.apache.solr.sentry.SentryTestBase; import org.apache.solr.sentry.SentryIndexAuthorizationSingleton; import org.apache.solr.sentry.SentrySingletonTestInstance; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/component/QueryIndexAuthorizationComponentTest.java ---------------------------------------------------------------------- diff --git a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/component/QueryIndexAuthorizationComponentTest.java b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/component/QueryIndexAuthorizationComponentTest.java index b9766e0..a1f3760 100644 --- a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/component/QueryIndexAuthorizationComponentTest.java +++ b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/handler/component/QueryIndexAuthorizationComponentTest.java @@ -19,7 +19,6 @@ package org.apache.solr.handler.component; import org.apache.solr.cloud.CloudDescriptor; import org.apache.solr.common.SolrException; import org.apache.solr.core.SolrCore; -import org.apache.solr.handler.component.ResponseBuilder; import org.apache.solr.sentry.SentryIndexAuthorizationSingleton; import org.apache.solr.sentry.SentryTestBase; import org.apache.solr.sentry.SentrySingletonTestInstance; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentryIndexAuthorizationSingletonTest.java ---------------------------------------------------------------------- diff --git a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentryIndexAuthorizationSingletonTest.java b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentryIndexAuthorizationSingletonTest.java index 694c486..30a849a 100644 --- a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentryIndexAuthorizationSingletonTest.java +++ b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentryIndexAuthorizationSingletonTest.java @@ -195,7 +195,9 @@ public class SentryIndexAuthorizationSingletonTest extends SentryTestBase { String localName = sentryInstance.getUserName(localRequest); assertEquals(superUser, localName); } finally { - if (localRequest != null) localRequest.close(); + if (localRequest != null) { + localRequest.close(); + } } // null userName @@ -210,7 +212,9 @@ public class SentryIndexAuthorizationSingletonTest extends SentryTestBase { String returnedName = sentryInstance.getUserName(sqr); assertEquals(userName, returnedName); } finally { - if (request != null) request.close(); + if (request != null) { + request.close(); + } } } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentrySingletonTestInstance.java ---------------------------------------------------------------------- diff --git a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentrySingletonTestInstance.java b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentrySingletonTestInstance.java index 664719f..579f791 100644 --- a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentrySingletonTestInstance.java +++ b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentrySingletonTestInstance.java @@ -21,7 +21,6 @@ import java.lang.reflect.Constructor; import org.apache.commons.io.FileUtils; import org.apache.solr.SolrTestCaseJ4; -import org.apache.solr.sentry.SecureRequestHandlerUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentryTestBase.java ---------------------------------------------------------------------- diff --git a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentryTestBase.java b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentryTestBase.java index b5548e6..fc13728 100644 --- a/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentryTestBase.java +++ b/sentry-solr/solr-sentry-handlers/src/test/java/org/apache/solr/sentry/SentryTestBase.java @@ -97,7 +97,9 @@ public abstract class SentryTestBase extends SolrTestCaseJ4 { HttpServletRequest httpServletRequest = EasyMock.createMock(HttpServletRequest.class); IExpectationSetters getAttributeExpect = EasyMock.expect(httpServletRequest.getAttribute(USER_NAME)).andReturn(user); - if(!onlyOnce) getAttributeExpect.anyTimes(); + if (!onlyOnce) { + getAttributeExpect.anyTimes(); + } EasyMock.replay(httpServletRequest); request.getContext().put("httpRequest", httpServletRequest); return request; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/AbstractSolrSentryTestBase.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/AbstractSolrSentryTestBase.java b/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/AbstractSolrSentryTestBase.java index 3a2104a..7ddd1e2 100644 --- a/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/AbstractSolrSentryTestBase.java +++ b/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/AbstractSolrSentryTestBase.java @@ -70,7 +70,6 @@ import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.params.CollectionParams.CollectionAction; import org.apache.solr.common.params.CoreAdminParams; import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.common.util.NamedList; import org.apache.solr.servlet.SolrDispatchFilter; import org.junit.After; import org.junit.AfterClass; @@ -139,6 +138,10 @@ public class AbstractSolrSentryTestBase { return 0; } + public int hashCode() { + return 17; + } + public boolean equals(Object obj) { return true; } @@ -442,7 +445,7 @@ public class AbstractSolrSentryTestBase { QueryRequest request = populateCollectionAdminParams(adminOp, collectionName, params); CloudSolrServer solrServer = createNewCloudSolrServer(); try { - NamedList<Object> result = solrServer.request(request); + solrServer.request(request); if (adminOp.compareTo(CollectionAction.CREATE) == 0) { // Wait for collection creation to complete. waitForRecoveriesToFinish(collectionName, solrServer, false); @@ -488,7 +491,7 @@ public class AbstractSolrSentryTestBase { QueryRequest request = populateCollectionAdminParams(adminOp, collectionName, params); CloudSolrServer solrServer = createNewCloudSolrServer(); try { - NamedList<Object> result = solrServer.request(request); + solrServer.request(request); if (adminOp.compareTo(CollectionAction.CREATE) == 0) { // Wait for collection creation to complete. waitForRecoveriesToFinish(collectionName, solrServer, false); @@ -811,7 +814,6 @@ public class AbstractSolrSentryTestBase { String retValue = ""; try { final HttpResponse response = httpClient.execute(method); - int httpStatus = response.getStatusLine().getStatusCode(); httpEntity = response.getEntity(); if (httpEntity != null) { @@ -866,7 +868,9 @@ public class AbstractSolrSentryTestBase { int cnt = 0; while (cont) { - if (verbose) LOG.debug("-"); + if (verbose) { + LOG.debug("-"); + } boolean sawLiveRecovering = false; zkStateReader.updateClusterState(true); ClusterState clusterState = zkStateReader.getClusterState(); @@ -875,9 +879,11 @@ public class AbstractSolrSentryTestBase { for (Map.Entry<String, Slice> entry : slices.entrySet()) { Map<String, Replica> shards = entry.getValue().getReplicasMap(); for (Map.Entry<String, Replica> shard : shards.entrySet()) { - if (verbose) LOG.debug("rstate:" + if (verbose) { + LOG.debug("rstate:" + shard.getValue().getStr(ZkStateReader.STATE_PROP) + " live:" + clusterState.liveNodesContain(shard.getValue().getNodeName())); + } String state = shard.getValue().getStr(ZkStateReader.STATE_PROP); if ((state.equals(ZkStateReader.RECOVERING) || state.equals(ZkStateReader.SYNC) || state @@ -890,9 +896,13 @@ public class AbstractSolrSentryTestBase { } if (!sawLiveRecovering || cnt == timeoutSeconds) { if (!sawLiveRecovering) { - if (verbose) LOG.debug("no one is recovering"); + if (verbose) { + LOG.debug("no one is recovering"); + } } else { - if (verbose) LOG.debug("Gave up waiting for recovery to finish.."); + if (verbose) { + LOG.debug("Gave up waiting for recovery to finish.."); + } if (failOnTimeout) { fail("There are still nodes recovering - waited for " + timeoutSeconds + " seconds"); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/DocLevelGenerator.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/DocLevelGenerator.java b/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/DocLevelGenerator.java index 30afd4c..e50e3f8 100644 --- a/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/DocLevelGenerator.java +++ b/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/DocLevelGenerator.java @@ -22,11 +22,9 @@ import org.apache.solr.client.solrj.impl.CloudSolrServer; import java.util.ArrayList; public class DocLevelGenerator { - private String collection; private String authField; - public DocLevelGenerator(String collection, String authField) { - this.collection = collection; + public DocLevelGenerator(String authField) { this.authField = authField; } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/cfaa570f/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/ModifiableUserAuthenticationFilter.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/ModifiableUserAuthenticationFilter.java b/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/ModifiableUserAuthenticationFilter.java index 533858b..ac676a8 100644 --- a/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/ModifiableUserAuthenticationFilter.java +++ b/sentry-tests/sentry-tests-solr/src/test/java/org/apache/sentry/tests/e2e/solr/ModifiableUserAuthenticationFilter.java @@ -27,15 +27,11 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import org.apache.solr.servlet.SolrRequestParsers; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Authentication Filter that authenticates any request as user "junit" */ public class ModifiableUserAuthenticationFilter implements Filter { - private static final Logger LOG = LoggerFactory - .getLogger(ModifiableUserAuthenticationFilter.class); /** * String that saves the user to be authenticated into Solr
