geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [1/3] incubator-geode git commit: GEODE-1993: refactor tests to use rules rather than abstract classes
Date Fri, 14 Oct 2016 22:00:28 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop b06599353 -> de6215978


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/de621597/geode-cq/src/test/java/org/apache/geode/security/CQClientAuthDunitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/org/apache/geode/security/CQClientAuthDunitTest.java b/geode-cq/src/test/java/org/apache/geode/security/CQClientAuthDunitTest.java
index 2386af1..cc0a191 100644
--- a/geode-cq/src/test/java/org/apache/geode/security/CQClientAuthDunitTest.java
+++ b/geode-cq/src/test/java/org/apache/geode/security/CQClientAuthDunitTest.java
@@ -43,8 +43,10 @@ import org.apache.geode.test.junit.categories.SecurityTest;
 @Category({ DistributedTest.class, SecurityTest.class })
 public class CQClientAuthDunitTest extends AbstractSecureServerDUnitTest {
 
-  public CQClientAuthDunitTest(){
-    this.postProcessor = SamplePostProcessor.class;
+  public Properties getProperties(){
+    Properties  properties = super.getProperties();
+    properties.setProperty(SECURITY_POST_PROCESSOR, SamplePostProcessor.class.getName());
+    return properties;
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/de621597/geode-cq/src/test/java/org/apache/geode/security/CQPDXPostProcessorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/org/apache/geode/security/CQPDXPostProcessorDUnitTest.java
b/geode-cq/src/test/java/org/apache/geode/security/CQPDXPostProcessorDUnitTest.java
index 12f08ec..470b722 100644
--- a/geode-cq/src/test/java/org/apache/geode/security/CQPDXPostProcessorDUnitTest.java
+++ b/geode-cq/src/test/java/org/apache/geode/security/CQPDXPostProcessorDUnitTest.java
@@ -17,11 +17,14 @@
 
 package org.apache.geode.security;
 
+import static org.apache.geode.distributed.ConfigurationProperties.*;
 import static org.junit.Assert.*;
 
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
 import com.jayway.awaitility.Awaitility;
@@ -53,6 +56,7 @@ import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactor
 @Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class CQPDXPostProcessorDUnitTest extends AbstractSecureServerDUnitTest {
   private static byte[] BYTES = {1,0};
+  private static int jmxPort = AvailablePortHelper.getRandomAvailableTCPPort();
 
   @Parameterized.Parameters
   public static Collection<Object[]> parameters(){
@@ -60,11 +64,20 @@ public class CQPDXPostProcessorDUnitTest extends AbstractSecureServerDUnitTest
{
     return Arrays.asList(params);
   }
 
+  public Properties getProperties(){
+    Properties  properties = super.getProperties();
+    properties.setProperty(SECURITY_POST_PROCESSOR, PDXPostProcessor.class.getName());
+    properties.setProperty("security-pdx", pdxPersistent+"");
+    properties.setProperty(JMX_MANAGER_PORT, jmxPort+"");
+    return properties;
+  }
+
+  public Map<String, String> getData(){
+    return new HashMap();
+  }
+
   public CQPDXPostProcessorDUnitTest(boolean pdxPersistent){
-    this.postProcessor = PDXPostProcessor.class;
     this.pdxPersistent = pdxPersistent;
-    this.jmxPort = AvailablePortHelper.getRandomAvailableTCPPort();
-    values = new HashMap();
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/de621597/geode-cq/src/test/java/org/apache/geode/security/CQPostProcessorDunitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/org/apache/geode/security/CQPostProcessorDunitTest.java
b/geode-cq/src/test/java/org/apache/geode/security/CQPostProcessorDunitTest.java
index e2b555a..32632ef 100644
--- a/geode-cq/src/test/java/org/apache/geode/security/CQPostProcessorDunitTest.java
+++ b/geode-cq/src/test/java/org/apache/geode/security/CQPostProcessorDunitTest.java
@@ -17,8 +17,11 @@
 
 package org.apache.geode.security;
 
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_POST_PROCESSOR;
 import static org.junit.Assert.*;
 
+import java.util.Properties;
+
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -40,10 +43,13 @@ import org.apache.geode.test.junit.categories.SecurityTest;
 @Category({ DistributedTest.class, SecurityTest.class })
 public class CQPostProcessorDunitTest extends AbstractSecureServerDUnitTest {
 
-  public CQPostProcessorDunitTest(){
-    this.postProcessor = SamplePostProcessor.class;
+  public Properties getProperties(){
+    Properties  properties = super.getProperties();
+    properties.setProperty(SECURITY_POST_PROCESSOR, SamplePostProcessor.class.getName());
+    return properties;
   }
 
+
   @Test
   public void testPostProcess(){
     String query = "select * from /AuthRegion";

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/de621597/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
index 30532b9..bcc5ab3 100755
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
@@ -47,7 +47,7 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.rules.LocatorServerConfigurationRule;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.junit.categories.DistributedTest;
 
 
@@ -57,8 +57,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
   private String groupName = "Lucene";
 
   @Rule
-  public LocatorServerConfigurationRule ls = new LocatorServerConfigurationRule(
-      this);
+  public LocatorServerStartupRule ls = new LocatorServerStartupRule();
 
   @Test
   public void indexGetsCreatedUsingClusterConfiguration()
@@ -78,7 +77,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
     // configuration.
     VM vm2 = startNodeUsingClusterConfiguration(2, false);
     vm2.invoke(() -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      LuceneService luceneService = LuceneServiceProvider.get(ls.serverStarter.cache);
       final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
       assertNotNull(index);
       validateIndexFields(new String[] { "field1", "field2", "field3" }, index);
@@ -104,7 +103,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
     // configuration.
     VM vm2 = startNodeUsingClusterConfiguration(2, false);
     vm2.invoke(() -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      LuceneService luceneService = LuceneServiceProvider.get(ls.serverStarter.cache);
       final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
       assertNotNull(index);
       String[] fields = new String[] { "field1", "field2", "field3" };
@@ -139,7 +138,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
 
     // VM2 should have lucene index created using gfsh execution.
     vm2.invoke(() -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      LuceneService luceneService = LuceneServiceProvider.get(ls.serverStarter.cache);
       final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
       assertNotNull(index);
       validateIndexFields(new String[] { "field1", "field2", "field3" }, index);
@@ -147,7 +146,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
 
     // The Lucene index is present in vm3.
     vm3.invoke(() -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      LuceneService luceneService = LuceneServiceProvider.get(ls.serverStarter.cache);
       final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
       assertNotNull(index);
     });
@@ -176,7 +175,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
 
     // VM2 should have lucene index created using gfsh execution
     vm2.invoke(() -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      LuceneService luceneService = LuceneServiceProvider.get(ls.serverStarter.cache);
       final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
       assertNotNull(index);
       validateIndexFields(new String[] { "field1", "field2", "field3" }, index);
@@ -184,7 +183,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
 
     // The Lucene index should not be present in vm3.
     vm3.invoke(() -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      LuceneService luceneService = LuceneServiceProvider.get(ls.serverStarter.cache);
       final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
       assertNull(index);
     });
@@ -213,7 +212,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
 
     // VM2 should have lucene index created using gfsh execution
     vm2.invoke(() -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      LuceneService luceneService = LuceneServiceProvider.get(ls.serverStarter.cache);
       final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
       assertNotNull(index);
       validateIndexFields(new String[] { "field1", "field2", "field3" }, index);
@@ -221,7 +220,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
 
     // The Lucene index should not be present in vm3.
     vm3.invoke(() -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      LuceneService luceneService = LuceneServiceProvider.get(ls.serverStarter.cache);
       final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
       assertNull(index);
     });
@@ -242,7 +241,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
     if (addGroup) {
       nodeProperties.setProperty(GROUPS, groupName);
     }
-    return ls.getServerVM(vmIndex, nodeProperties);
+    return ls.getServerVM(vmIndex, nodeProperties, ls.getLocatorPort(0));
   }
 
   private VM startLocatorWithClusterConfigurationEnabled() throws Exception {
@@ -268,7 +267,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
     locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
     locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR,
  dir.getCanonicalPath());
-    return ls.getLocatorVM(locatorProps);
+    return ls.getLocatorVM(0, locatorProps);
   }
 
   private void createLuceneIndexUsingGfsh(boolean addGroup) throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/de621597/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/CommonCrudController.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/CommonCrudController.java
b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/CommonCrudController.java
index 35d8fb4..2bcb31b 100644
--- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/CommonCrudController.java
+++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/CommonCrudController.java
@@ -140,7 +140,7 @@ public abstract class CommonCrudController extends AbstractBaseController
{
     @ApiResponse( code = 404, message = "Region or key(s) does not exist" ),
     @ApiResponse( code = 500, message = "GemFire throws an error or exception" )      
   } )
-  @PreAuthorize("@securityService.authorizeKeys('WRITE', #region, #keys)")
+  @PreAuthorize("@securityService.authorize('WRITE', #region, #keys)")
   public ResponseEntity<?> delete(@PathVariable("region") String region,
                                   @PathVariable("keys") final String[] keys){
     logger.debug("Delete data for key {} on region {}", ArrayUtils.toString((Object[])keys),
region);
@@ -169,7 +169,7 @@ public abstract class CommonCrudController extends AbstractBaseController
{
     @ApiResponse( code = 404, message = "Region does not exist" ),
     @ApiResponse( code = 500, message = "if GemFire throws an error or exception" )   
   } )
-  @PreAuthorize("@securityService.authorize('DATA', 'WRITE', #regon)")
+  @PreAuthorize("@securityService.authorize('DATA', 'WRITE', #region)")
   public ResponseEntity<?> delete(@PathVariable("region") String region) {
     logger.debug("Deleting all data in Region ({})...", region);
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/de621597/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/PdxBasedCrudController.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/PdxBasedCrudController.java
b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/PdxBasedCrudController.java
index 3003b3d..ebb8ccc 100644
--- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/PdxBasedCrudController.java
+++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/PdxBasedCrudController.java
@@ -227,7 +227,7 @@ public class PdxBasedCrudController extends CommonCrudController {
     @ApiResponse( code = 404, message = "Region does not exist." ),
     @ApiResponse( code = 500, message = "GemFire throws an error or exception.")  
   } )
-  @PreAuthorize("@securityService.authorizeKeys('READ', #region, #keys)")
+  @PreAuthorize("@securityService.authorize('READ', #region, #keys)")
   public ResponseEntity<?> read(
       @PathVariable("region") String region,
       @PathVariable("keys") final String[] keys,
@@ -311,7 +311,7 @@ public class PdxBasedCrudController extends CommonCrudController {
     @ApiResponse( code = 409, message = "For CAS, @old value does not match to the current
value in region" ),
     @ApiResponse( code = 500, message = "GemFire throws an error or exception.")
   } )
-  @PreAuthorize("@securityService.authorizeKeys('WRITE', #region, #keys)")
+  @PreAuthorize("@securityService.authorize('WRITE', #region, #keys)")
   public ResponseEntity<?> update(@PathVariable("region") String region,
       @PathVariable("keys") final String[] keys,
       @RequestParam(value = "op", defaultValue = "PUT") final String opValue,

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/de621597/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/security/RestSecurityService.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/security/RestSecurityService.java
b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/security/RestSecurityService.java
index 3d09f09..2247de0 100644
--- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/security/RestSecurityService.java
+++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/security/RestSecurityService.java
@@ -44,7 +44,7 @@ public class RestSecurityService {
     }
   }
 
-  public boolean authorizeKeys(String operation, String region, String[] keys) {
+  public boolean authorize(String operation, String region, String[] keys) {
     boolean authorized = false;
     for(String key:keys){
       authorized = authorize("DATA", operation, region, key);


Mime
View raw message