[jboss-cvs] JBossAS SVN: r64673 - in branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming: test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 17 18:57:41 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-08-17 18:57:41 -0400 (Fri, 17 Aug 2007)
New Revision: 64673

Modified:
   branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
   branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java
Log:
[JBAS-4574] Test other Context methods as well

Modified: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
===================================================================
--- branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java	2007-08-17 22:55:04 UTC (rev 64672)
+++ branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java	2007-08-17 22:57:41 UTC (rev 64673)
@@ -44,6 +44,7 @@
    
    public static final String NAME = "NamingRestartBinding";
    public static final String VALUE = "VALUE";
+   public static final String SUBCONTEXT_NAME = "LocalSubcontext";
    private String providerURL;  
    private NamingParser parser = new NamingParser();
    private RestartNamingServiceMBean naming;
@@ -81,8 +82,10 @@
       
       naming.getNamingInstance().bind(parser.parse(NAME), 
                                       new MarshalledValuePair(VALUE), 
-                                      VALUE.getClass().getName());
-      log.info("Bound " + VALUE + " to " + naming.getNamingInstance() + " under " + NAME);
+                                      VALUE.getClass().getName());log.info("Bound " + VALUE + " to " + naming.getNamingInstance() + " under " + NAME);
+      Context sub = naming.getNamingInstance().createSubcontext(parser.parse(SUBCONTEXT_NAME));
+      sub.bind(parser.parse(NAME), VALUE);
+      
    }
    
    /* (non-Javadoc)

Modified: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java
===================================================================
--- branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java	2007-08-17 22:55:04 UTC (rev 64672)
+++ branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java	2007-08-17 22:57:41 UTC (rev 64673)
@@ -24,14 +24,18 @@
 
 import java.util.Properties;
 
+import javax.naming.Binding;
 import javax.naming.Context;
 import javax.naming.InitialContext;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 
 import junit.framework.Test;
 
 import org.jboss.test.JBossTestCase;
 import org.jboss.test.naming.restart.ObjectBinder;
+import org.jnp.interfaces.MarshalledValuePair;
 
 /**
  * A NamingRestartUnitTestCase.
@@ -44,6 +48,11 @@
    private static final String namingPort = "19099";
    private static final String haNamingPort = "19100";
  
+   private static final String BIND_NAME = "BindName";
+   private static final String BIND_VALUE = "BindValue";
+   
+   private static final String SUBCONTEXT_NAME = "RemoteSubcontext";
+   
    private static boolean deployed = true;
    
    public NamingRestartUnitTestCase(String name)
@@ -64,26 +73,81 @@
          deploy("naming-restart.sar");
    }
    
+   public void testBind() throws Exception
+   {
+      log.info("Running testBind()");
+      
+      Properties env = createNamingEnvironment(namingPort);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         ctx2.bind(BIND_NAME, BIND_VALUE);
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+      
+      assertEquals(BIND_VALUE, ctx2.lookup(BIND_NAME));
+   }
+   
+   public void testCreateSubcontext() throws Exception
+   {
+      log.info("Running testCreateSubcontext()");
+      
+      Properties env = createNamingEnvironment(namingPort);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         Context sub = ctx2.createSubcontext(SUBCONTEXT_NAME);
+         sub.bind(BIND_NAME, BIND_VALUE);
+         assertEquals("Proper bind to " + SUBCONTEXT_NAME, BIND_VALUE, sub.lookup(BIND_NAME));
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+   }
+   
    public void testLookupAfterHANamingRestart() throws Exception
    {
       log.info("Running testLookupAfterHANamingRestart");
       
-      namingRestartTest(haNamingPort);
+      lookupTest(haNamingPort);
    }
 
    public void testLookupAfterNamingRestart() throws Exception
    {
       log.info("Running testLookupAfterNamingRestart");
       
-      namingRestartTest(namingPort);
+      lookupTest(namingPort);
    }
    
-   private void namingRestartTest(String port) throws Exception
+   private void lookupTest(String port) throws Exception
    {
-      String namingURL = getServerHost() + ":" + port;
-      Properties env = new Properties();
-      env.setProperty("java.naming.provider.url", namingURL);
-      env.setProperty("jnp.disableDiscovery", "true");
+      Properties env = createNamingEnvironment(port);
       
       Context ctx1 = new InitialContext(env);
       assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
@@ -92,9 +156,7 @@
       // static map in org.jnp.interfaces.NamingContext.
       
       // Redeploy the naming service
-      deployed = false;
-      redeploy("naming-restart.sar");
-      deployed = true;
+      redeployNaming();
       
       Context ctx2 = new InitialContext(env);
       NamingException ne = null;
@@ -124,8 +186,168 @@
          // Now fail due to the earlier failure
          fail(ne.getMessage());         
       }
+   }
+   
+   public void testList() throws Exception
+   {
+      log.info("Running testList()");
       
+      Properties env = createNamingEnvironment(namingPort);
       
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         NamingEnumeration list = ctx2.list(ObjectBinder.SUBCONTEXT_NAME);
+         assertNotNull("NamingEnumeration returned", list);
+         assertTrue("NamingEnumeration has entry", list.hasMoreElements());
+         NameClassPair pair = (NameClassPair) list.next();
+         assertEquals(ObjectBinder.NAME, pair.getName());
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
    }
+   
+   public void testListBindings() throws Exception
+   {
+      log.info("Running testListBindings()");
+      
+      Properties env = createNamingEnvironment(namingPort);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         NamingEnumeration list = ctx2.listBindings(ObjectBinder.SUBCONTEXT_NAME);
+         assertNotNull("NamingEnumeration returned", list);
+         assertTrue("NamingEnumeration has entry", list.hasMoreElements());
+         Binding binding = (Binding) list.next();
+         assertEquals(ObjectBinder.NAME, binding.getName());
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+   }
+   
+   public void testLookupLink() throws Exception
+   {
+      log.info("Running testLookupLink()");
+      
+      Properties env = createNamingEnvironment(namingPort);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         Object obj = ctx2.lookupLink(ObjectBinder.NAME);
+         if (obj instanceof MarshalledValuePair)
+            obj = ((MarshalledValuePair) obj).get();
+         assertEquals(ObjectBinder.VALUE, obj);
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+   }
+   
+   public void testRebind() throws Exception
+   {
+      log.info("Running testRebind()");
+      
+      Properties env = createNamingEnvironment(namingPort);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         ctx2.rebind(ObjectBinder.NAME, ObjectBinder.VALUE);
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+   }
+   
+   public void testUnbind() throws Exception
+   {
+      log.info("Running testUnbind()");
+      
+      Properties env = createNamingEnvironment(namingPort);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         ctx2.unbind(ObjectBinder.NAME);
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+   }
 
+   private Properties createNamingEnvironment(String port)
+   {
+      String namingURL = getServerHost() + ":" + port;
+      Properties env = new Properties();
+      env.setProperty("java.naming.provider.url", namingURL);
+      env.setProperty("jnp.disableDiscovery", "true");
+      return env;
+   }
+
+   private void redeployNaming() throws Exception
+   {
+      deployed = false;
+      redeploy("naming-restart.sar");
+      deployed = true;
+   }
+
 }




More information about the jboss-cvs-commits mailing list