commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons-sandbox/naming/core/src/test/org/apache/commons/naming BasicContextTest.java
Date Sun, 30 Nov 2003 05:36:07 GMT
psteitz     2003/11/29 21:36:07

  Modified:    naming/core/src/test/org/apache/commons/naming
                        BasicContextTest.java
  Log:
  Added composeName tests, prepared to break out.
  
  Revision  Changes    Path
  1.2       +24 -39    jakarta-commons-sandbox/naming/core/src/test/org/apache/commons/naming/BasicContextTest.java
  
  Index: BasicContextTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/naming/core/src/test/org/apache/commons/naming/BasicContextTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicContextTest.java	2 Sep 2003 04:43:37 -0000	1.1
  +++ BasicContextTest.java	30 Nov 2003 05:36:07 -0000	1.2
  @@ -78,8 +78,10 @@
   import junit.framework.TestSuite;
   import junit.textui.TestRunner;
   
  +import org.apache.commons.naming.java.javaURLContextFactory;
  +
   /**
  -* Unit tests for basic ops on an {@link NamingContext}.
  + * Unit tests for basic ops on an {@link NamingContext}.
    * Adapted from o.a.geronimo.naming test of the same name
    *  
    * @version $Revision$ $Date$
  @@ -111,20 +113,19 @@
           env.put(Context.INITIAL_CONTEXT_FACTORY,
               "org.apache.commons.naming.java.javaURLContextFactory");
           env.put(Context.URL_PKG_PREFIXES,"org.apache.commons.naming");
  -        initialContext = new NamingContext(env,"root");
  -        //initialContext = new SelectorContext(env,true);
  +        initialContext = new InitialContext(env);
           compContext = initialContext.createSubcontext("java:comp");
           envContext =  compContext.createSubcontext("env");
           envContext.bind("hello", "Hello");
           envContext.bind("world", "World");
           envBinding.put("hello", "Hello");
           envBinding.put("world", "World");
  -        ContextAccessController.setReadOnly("root");
  -        ContextAccessController.setSecurityToken("root","x");
  +        ContextAccessController.setReadOnly(javaURLContextFactory.MAIN);
  +        ContextAccessController.setSecurityToken(javaURLContextFactory.MAIN,"x");
       }
       
       protected void tearDown() throws Exception {
  -        ContextAccessController.setWritable("root","x");
  +        ContextAccessController.setWritable(javaURLContextFactory.MAIN,"x");
           compContext.destroySubcontext("env");
           initialContext.destroySubcontext("java:comp");
           initialContext = null;
  @@ -133,7 +134,8 @@
       public void testInitialContext() throws NamingException {
           assertEquals("Hello", initialContext.lookup("java:comp/env/hello"));
           assertEquals("World", initialContext.lookup(new CompositeName("java:comp/env/world")));
  -        //assertEquals(envContext, envContext.lookup("")); <-- this impl returns a new
context
  +        assertEquals(envContext.lookup("hello"), 
  +            ((Context) envContext.lookup("")).lookup("hello"));  
       }
   
       public void testLookup() throws NamingException {
  @@ -147,26 +149,22 @@
           }
           assertEquals("Hello", envContext.lookup(new CompositeName("hello")));
           assertEquals("Hello", compContext.lookup(new CompositeName("env/hello")));
  +        assertEquals("World", 
  +            ((Context) initialContext.lookup("java:comp")).lookup("env/world"));
       }
       
  -   /* 
  -    public void testSchemeLookup() throws NamingException {
  -        envContext.lookup("dns:apache.org");
  -        assertEquals("Hello", envContext.lookup("java:comp/env/hello"));
  -        assertEquals("Hello", compContext.lookup("java:comp/env/hello"));
  -    }
  -    */
  -     
  -
  -    public void testLookupLink() throws NamingException {
  -        assertEquals("Hello", envContext.lookup("hello"));
  -    }
   
       public void testComposeName() throws NamingException {
  -        assertEquals("org/research/user/jane", envContext.composeName("user/jane", "org/research"));
  -        assertEquals("research/user/jane", envContext.composeName("user/jane", "research"));
  -        //assertEquals(new CompositeName("org/research/user/jane"), envContext.composeName(new
CompositeName("user/jane"), new CompositeName("org/research")));
  -        //assertEquals(new CompositeName("research/user/jane"), envContext.composeName(new
CompositeName("user/jane"), new CompositeName("research")));
  +        assertEquals("org/research/user/jane", 
  +            envContext.composeName("user/jane", "org/research"));
  +        assertEquals("research/user/jane", 
  +            envContext.composeName("user/jane", "research"));
  +        assertEquals(new CompositeName("org/research/user/jane"), 
  +            envContext.composeName(new CompositeName("user/jane"), 
  +                new CompositeName("org/research")));
  +        assertEquals(new CompositeName("research/user/jane"), 
  +            envContext.composeName(new CompositeName("user/jane"), 
  +                new CompositeName("research")));
       }
   
       public void testList() throws NamingException {
  @@ -225,26 +223,13 @@
               // ok
           }
       }
  -  
  -    public void testSpeed() throws NamingException {
  -        long startTime = System.currentTimeMillis();
  -        Context comp = (Context) initialContext.lookup("java:comp");    
  -        for (int i=0; i < 1000000; i++) {
  -            //initialContext.lookup("java:comp/env/hello"); 
  -            // this is sloooow due to scheme resolution
  -            //envContext.lookup("hello");
  -            comp.lookup("env/hello");
  -        }       
  -        System.out.println("lookup(String): " + (System.currentTimeMillis() - startTime));
  -    }
       
       public void testAccess() throws NamingException {
           try {
               envContext.bind("goodbye", "Goodbye");
               fail("expecting NamingException"); // Context is read only
           } catch (NamingException ex) {}   
  -        ContextAccessController.setWritable("root","x");
  +        ContextAccessController.setWritable(javaURLContextFactory.MAIN,"x");
           envContext.bind("goodbye", "Goodbye"); // Unlocked now
  -    }
  -    
  +    }  
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message