geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [04/22] incubator-geode git commit: GEODE-766: Ignore gemfire.properties file and convert to JUnit 4
Date Tue, 19 Jan 2016 21:46:02 GMT
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/feature/GEODE-217
Commit: 678451abf954aaaa2c138ff486d2ea256a63a23f
Parents: 5dffe25
Author: Kirk Lund <klund@pivotal.io>
Authored: Mon Jan 11 12:10:17 2016 -0800
Committer: Kirk Lund <klund@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 {


Mime
View raw message