You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/01/11 21:28:34 UTC

[1/2] incubator-geode git commit: GEODE-766: Ignore gemfire.properties file and convert to JUnit 4

Repository: incubator-geode
Updated Branches:
  refs/heads/develop 5dffe257c -> 0b5b30af8


GEODE-766: Ignore gemfire.properties file and convert to JUnit 4


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/678451ab
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/678451ab
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/678451ab

Branch: refs/heads/develop
Commit: 678451abf954aaaa2c138ff486d2ea256a63a23f
Parents: 5dffe25
Author: Kirk Lund <kl...@pivotal.io>
Authored: Mon Jan 11 12:10:17 2016 -0800
Committer: Kirk Lund <kl...@pivotal.io>
Committed: Mon Jan 11 12:10:17 2016 -0800

----------------------------------------------------------------------
 .../internal/security/JSONAuthCodeTest.java     | 183 +++++++------------
 1 file changed, 63 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/678451ab/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthCodeTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthCodeTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthCodeTest.java
index 3898fc3..c408116 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthCodeTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthCodeTest.java
@@ -16,7 +16,8 @@
  */
 package com.gemstone.gemfire.management.internal.security;
 
-import java.io.IOException;
+import static org.junit.Assert.*;
+
 import java.lang.management.ManagementFactory;
 import java.util.Properties;
 import java.util.Set;
@@ -25,9 +26,12 @@ import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.management.remote.JMXPrincipal;
 
-import junit.framework.TestCase;
-
-import org.json.JSONException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
 import org.junit.experimental.categories.Category;
 
 import com.gemstone.gemfire.cache.CacheFactory;
@@ -40,114 +44,64 @@ import com.gemstone.gemfire.util.test.TestUtil;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 
 @Category(IntegrationTest.class)
-public class JSONAuthCodeTest extends TestCase {
+public class JSONAuthCodeTest {
   
-  /*private String readFile(String name) throws IOException, JSONException {
-    File file = new File(name);
-    FileReader reader = new FileReader(file);
-    char[] buffer = new char[(int) file.length()];
-    reader.read(buffer);
-    String json = new String(buffer);
-    reader.close();
-    return json;
-  }*/
+  private GemFireCacheImpl cache;
+  private DistributedSystem ds;
+
+  @Rule
+  public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
   
-  public void testSimpleUserAndRole() throws IOException, JSONException {    
-    System.setProperty("resource.secDescriptor", TestUtil.getResourcePath(getClass(), "auth1.json")); 
-    JSONAuthorization authorization = JSONAuthorization.create();        
-    authorization.init(new JMXPrincipal("tushark"), null, null);
-    
-    try {
-      JMXOperationContext context = new JMXOperationContext(MBeanJMXAdapter.getDistributedSystemName(), "queryData");
-      boolean result = authorization.authorizeOperation(null, context);
-      //assertTrue(result);
-      
-      context = new JMXOperationContext(MBeanJMXAdapter.getDistributedSystemName(), "changeAlertLevel");
-      result = authorization.authorizeOperation(null,context);
-      assertFalse(result);
-      
-    } catch (Exception e) {
-      e.printStackTrace();
-      fail(e.getMessage());
-    } finally{
-      System.clearProperty("resource.secDescriptor");
-    }
-        
+  @Before
+  public void setUp() {
+    System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, getClass().getSimpleName() + ".properties");
   }
-  
-  public void testInheritRole() {
-    
+
+  @After
+  public void tearDown() {
+    if (cache != null) {
+      cache.close();
+      cache = null;
+    }
+    if (ds != null) {
+      ds.disconnect();
+      ds = null;
+    }
   }
   
-  /*
-  public void testUserMultipleRole() throws IOException, JSONException {
-    System.setProperty("resource.secDescriptor", JSONAuthorizationTest.filePathPrefix + "auth2.json"); 
-    JSONAuthorization authorization = JSONAuthorization.create();    
-    //AccessControl acc = (AccessControl)authorization;
-    
-    //check authentication
-    Properties props = new Properties();
-    props.setProperty(ManagementInterceptor.USER_NAME, "tushark");
-    props.setProperty(ManagementInterceptor.PASSWORD, "1234567");
-    try{
-      Principal pl = authorization.authenticate(props, null);
-      assertNotNull(pl);
-    }catch(AuthenticationFailedException fe) {
-      fail(fe.getMessage());
-    }
-    
+  @Test
+  public void testSimpleUserAndRole() throws Exception {    
+    System.setProperty("resource.secDescriptor", TestUtil.getResourcePath(getClass(), "auth1.json")); 
+    JSONAuthorization authorization = JSONAuthorization.create();        
     authorization.init(new JMXPrincipal("tushark"), null, null);
+    
     JMXOperationContext context = new JMXOperationContext(MBeanJMXAdapter.getDistributedSystemName(), "queryData");
-    boolean result = authorization.authorizeOperation(null,context);
+    boolean result = authorization.authorizeOperation(null, context);
     //assertTrue(result);
     
-    System.setProperty("resource-auth-accessor", JSONAuthorization.class.getCanonicalName());
-    System.setProperty("resource-authenticator", JSONAuthorization.class.getCanonicalName());
-    GemFireCacheImpl cache = null;
-    DistributedSystem ds = null;
-    Properties pr = new Properties();
-    pr.put("name", "testJMXOperationContext");
-    pr.put(DistributionConfig.JMX_MANAGER_NAME, "true");
-    pr.put(DistributionConfig.JMX_MANAGER_START_NAME, "true");
-    int port = AvailablePortHelper.getRandomAvailableTCPPort();
-    pr.put(DistributionConfig.JMX_MANAGER_PORT_NAME, String.valueOf(port));
-    pr.put(DistributionConfig.HTTP_SERVICE_PORT_NAME, "0");
-    ds = DistributedSystem.connect(pr);
-    cache = (GemFireCacheImpl) CacheFactory.create(ds);
-    
-    try {
-      CLIOperationContext cliContext = new CLIOperationContext("put --key=k1 --value=v1 --region=/region1");
-      authorization.init(new JMXPrincipal("tushark"), null, null);
-      result = authorization.authorizeOperation(null, cliContext);
-      assertTrue(result);
-
-      cliContext = new CLIOperationContext("locate entry --key=k1 --region=/region1");
-      result = authorization.authorizeOperation(null, cliContext);
-      assertTrue(result);
+    context = new JMXOperationContext(MBeanJMXAdapter.getDistributedSystemName(), "changeAlertLevel");
+    result = authorization.authorizeOperation(null,context);
+    assertFalse(result);
+  }
 
-      context = new JMXOperationContext(MBeanJMXAdapter.getDistributedSystemName(), "changeAlertLevel");
-      result = authorization.authorizeOperation(null, context);
-      assertFalse(result);
-    } catch (Exception e) {
-      e.printStackTrace();
-      fail(e.getMessage());
-    } finally {
-      System.clearProperty("resource.secDescriptor");
-      cache.close();
-      ds.disconnect();
-    }
-    
-  }*/
+  @Ignore("Test was never implemented")
+  @Test
+  public void testInheritRole() {
+  }
   
-  public void testCLIAuthForRegion() throws IOException, JSONException {
+  @Ignore("Test was dead-coded")
+  @Test
+  public void testUserMultipleRole() throws Exception {
+  }
+  
+  @Test
+  public void testCLIAuthForRegion() throws Exception {
     System.setProperty("resource.secDescriptor", TestUtil.getResourcePath(getClass(), "auth3.json")); 
     JSONAuthorization authorization = JSONAuthorization.create();       
     authorization.init(new JMXPrincipal("tushark"), null, null);
     
     System.setProperty("resource-auth-accessor", JSONAuthorization.class.getCanonicalName());
     System.setProperty("resource-authenticator", JSONAuthorization.class.getCanonicalName());
-    GemFireCacheImpl cache = null;
-    DistributedSystem ds = null;
     Properties pr = new Properties();
     pr.put("name", "testJMXOperationContext");
     pr.put(DistributionConfig.JMX_MANAGER_NAME, "true");
@@ -158,34 +112,23 @@ public class JSONAuthCodeTest extends TestCase {
     ds = DistributedSystem.connect(pr);
     cache = (GemFireCacheImpl) CacheFactory.create(ds);
     
-    try {
-      checkAccessControlMBean();
-      CLIOperationContext cliContext = new CLIOperationContext("locate entry --key=k1 --region=region1");
-      boolean result = authorization.authorizeOperation(null, cliContext);
-      assertTrue(result);
+    checkAccessControlMBean();
+    CLIOperationContext cliContext = new CLIOperationContext("locate entry --key=k1 --region=region1");
+    boolean result = authorization.authorizeOperation(null, cliContext);
+    assertTrue(result);
 
-      cliContext = new CLIOperationContext("locate entry --key=k1 --region=secureRegion");
-      result = authorization.authorizeOperation(null, cliContext);
-      System.out.println("Result for secureRegion=" + result);
-      //assertFalse(result); //this is failing due to logic issue
+    cliContext = new CLIOperationContext("locate entry --key=k1 --region=secureRegion");
+    result = authorization.authorizeOperation(null, cliContext);
+    System.out.println("Result for secureRegion=" + result);
+    //assertFalse(result); //this is failing due to logic issue
 
-      authorization.init(new JMXPrincipal("avinash"), null, null);
-      result = authorization.authorizeOperation(null, cliContext);
-      assertTrue(result);
+    authorization.init(new JMXPrincipal("avinash"), null, null);
+    result = authorization.authorizeOperation(null, cliContext);
+    assertTrue(result);
 
-      cliContext = new CLIOperationContext("locate entry --key=k1 --region=region1");
-      result = authorization.authorizeOperation(null, cliContext);
-      assertTrue(result);
-      
-    } catch (Exception e) {
-      e.printStackTrace();
-      fail(e.getMessage());
-    } finally {
-      System.clearProperty("resource.secDescriptor");  
-      cache.close();
-      ds.disconnect();
-    }      
-    
+    cliContext = new CLIOperationContext("locate entry --key=k1 --region=region1");
+    result = authorization.authorizeOperation(null, cliContext);
+    assertTrue(result);
   }
 
   private void checkAccessControlMBean() throws Exception {


[2/2] incubator-geode git commit: GEODE-765: Ignore gemfire.properties file and convert to JUnit 4

Posted by kl...@apache.org.
GEODE-765: Ignore gemfire.properties file and convert to JUnit 4


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/0b5b30af
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/0b5b30af
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/0b5b30af

Branch: refs/heads/develop
Commit: 0b5b30af80f24a903dc21542e13b799036a41606
Parents: 678451a
Author: Kirk Lund <kl...@pivotal.io>
Authored: Mon Jan 11 12:17:29 2016 -0800
Committer: Kirk Lund <kl...@pivotal.io>
Committed: Mon Jan 11 12:17:29 2016 -0800

----------------------------------------------------------------------
 .../gemfire/redis/ConcurrentStartTest.java      | 34 +++++++++++++++++---
 1 file changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0b5b30af/gemfire-core/src/test/java/com/gemstone/gemfire/redis/ConcurrentStartTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/redis/ConcurrentStartTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/redis/ConcurrentStartTest.java
index b5954b8..6c11c96 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/redis/ConcurrentStartTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/redis/ConcurrentStartTest.java
@@ -18,11 +18,16 @@ package com.gemstone.gemfire.redis;
 
 import static org.junit.Assert.assertFalse;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
 import org.junit.experimental.categories.Category;
 
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.distributed.DistributedSystem;
 import com.gemstone.gemfire.internal.AvailablePortHelper;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
@@ -30,20 +35,39 @@ import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 @Category(IntegrationTest.class)
 public class ConcurrentStartTest {
 
-  int numServers = 10;
+  private Cache cache;
+  private int numServers = 10;
+  
+  @Rule
+  public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+  
+  @Before
+  public void setUp() {
+    System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, getClass().getSimpleName() + ".properties");
+  }
+
+  @After
+  public void tearDown() {
+    if (this.cache != null) {
+      this.cache.close();
+      this.cache = null;
+    }
+  }
+  
   @Test
   public void testCachelessStart() throws InterruptedException {
     runNServers(numServers);
     GemFireCacheImpl.getInstance().close();
   }
+  
   @Test
   public void testCachefulStart() throws InterruptedException {
     CacheFactory cf = new CacheFactory();
     cf.set("mcast-port", "0");
     cf.set("locators", "");
-    Cache c = cf.create();
+    this.cache = cf.create();
+    
     runNServers(numServers);
-    c.close();
   }
   
   private void runNServers(int n) throws InterruptedException {
@@ -68,7 +92,7 @@ public class ConcurrentStartTest {
     }
     for (Thread t : threads)
       t.join();
-    Cache c = GemFireCacheImpl.getInstance();
-    assertFalse(c.isClosed());
+    this.cache = GemFireCacheImpl.getInstance();
+    assertFalse(this.cache.isClosed());
   }
 }