psteitz 2003/09/01 21:43:37 Added: naming/core/src/test/org/apache/commons/naming BasicContextTest.java LocalStrings.properties LocalStrings_es.properties LocalStrings_fr.properties LocalStrings_ja.properties Log: added simple test for NamingContext Revision Changes Path 1.1 jakarta-commons-sandbox/naming/core/src/test/org/apache/commons/naming/BasicContextTest.java Index: BasicContextTest.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Geronimo" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Geronimo", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ package org.apache.commons.naming; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Enumeration; import java.util.Map; import java.util.Properties; import java.util.NoSuchElementException; import javax.naming.Binding; import javax.naming.CompositeName; import javax.naming.CompoundName; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NameClassPair; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.naming.Name; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.textui.TestRunner; /** * Unit tests for basic ops on an [EMAIL PROTECTED] NamingContext}. * Adapted from o.a.geronimo.naming test of the same name * * @version $Revision: 1.1 $ $Date: 2003/09/02 04:43:37 $ */ public class BasicContextTest extends TestCase { private HashMap envBinding; private Context initialContext; private Context compContext; private Context envContext; public BasicContextTest(String name) { super(name); } public static void main(String[] args) { TestRunner.run(suite()); } public static Test suite() { TestSuite suite = new TestSuite(BasicContextTest.class); suite.setName("Basic Context Tests"); return suite; } protected void setUp() throws Exception { super.setUp(); Hashtable env = new Hashtable(); envBinding = new HashMap(); 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); 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"); } protected void tearDown() throws Exception { ContextAccessController.setWritable("root","x"); compContext.destroySubcontext("env"); initialContext.destroySubcontext("java:comp"); initialContext = null; } 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 } public void testLookup() throws NamingException { assertEquals("Hello", envContext.lookup("hello")); assertEquals("Hello", compContext.lookup("env/hello")); try { envContext.lookup("foo"); fail("expecting NamingException"); } catch (NamingException e) { // OK } assertEquals("Hello", envContext.lookup(new CompositeName("hello"))); assertEquals("Hello", compContext.lookup(new CompositeName("env/hello"))); } /* 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"))); } public void testList() throws NamingException { NamingEnumeration enum; Map expected; Map result; expected = new HashMap(); for (Iterator i = envBinding.entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); expected.put(entry.getKey(), entry.getValue().getClass().getName()); } enum = envContext.list(""); result = new HashMap(); while (enum.hasMore()) { NameClassPair pair = (NameClassPair) enum.next(); result.put(pair.getName(), pair.getClassName()); } assertEquals(expected, result); try { enum.next(); fail(); } catch (NoSuchElementException e) { // ok } try { enum.nextElement(); fail(); } catch (NoSuchElementException e) { // ok } } public void testListBindings() throws NamingException { NamingEnumeration enum; Map result; enum = envContext.listBindings(""); result = new HashMap(); while (enum.hasMore()) { Binding pair = (Binding) enum.next(); result.put(pair.getName(), pair.getObject()); } assertEquals(envBinding, result); try { enum.next(); fail(); } catch (NoSuchElementException e) { // ok } try { enum.nextElement(); fail(); } catch (NoSuchElementException e) { // 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"); envContext.bind("goodbye", "Goodbye"); // Unlocked now } } 1.1 jakarta-commons-sandbox/naming/core/src/test/org/apache/commons/naming/LocalStrings.properties Index: LocalStrings.properties =================================================================== contextBindings.unknownContext=Unknown context name : {0} contextBindings.noContextBoundToThread=No naming context bound to this thread contextBindings.noContextBoundToCL=No naming context bound to this class loader selectorContext.noJavaUrl=This context must be accessed throught a java: URL namingContext.contextExpected=Name is not bound to a Context namingContext.nameNotBound=Name {0} is not bound in this Context namingContext.readOnly=Context is read only namingContext.invalidName=Name is not valid namingContext.alreadyBound=Name {0} is already bound in this Context namingContext.noAbsoluteName=Can't generate an absolute name for this namespace 1.1 jakarta-commons-sandbox/naming/core/src/test/org/apache/commons/naming/LocalStrings_es.properties Index: LocalStrings_es.properties =================================================================== # $Id: LocalStrings_es.properties,v 1.1 2003/09/02 04:43:37 psteitz Exp $ # language es # package org.apache.naming contextBindings.unknownContext=Contexto {0} desconocido contextBindings.noContextBoundToThread=No hay contexto de nombres asociado a este hilo selectorContext.noJavaUrl=Este contexto debe de ser accedido a traves de una URL de tipo java: namingContext.contextExpected=El nombre no esta asociado a ningun Contexto namingContext.nameNotBound=El nombre {0} no este asociado a este contexto namingContext.readOnly=El contexto es de solo lectura namingContext.invalidName=Nombre no valido namingContext.noAbsoluteName=No se puede generar un nombre absoluto para este espacio de nombres namingContext.alreadyBound=El nombre {0} este ya asociado en este Contexto 1.1 jakarta-commons-sandbox/naming/core/src/test/org/apache/commons/naming/LocalStrings_fr.properties Index: LocalStrings_fr.properties =================================================================== contextBindings.unknownContext=Nom de Contexte inconnu : {0} contextBindings.noContextBoundToThread=Aucun Contexte de nommage lié à ce thread contextBindings.noContextBoundToCL=Aucun Contexte de nommage lié à ce chargeur de classes selectorContext.noJavaUrl=Ce Contexte doit être accédé par une java: URL namingContext.contextExpected=Le Nom n''est pas lié à un Contexte namingContext.nameNotBound=Le Nom {0} n''est pas lié à ce Contexte namingContext.readOnly=Le Contexte est en lecture seule namingContext.invalidName=Le Nom est invalide namingContext.alreadyBound=Le Nom {0} est déjà lié à ce Contexte namingContext.noAbsoluteName=Impossible de générer un nom absolu pour cet espace de nommage (namespace) 1.1 jakarta-commons-sandbox/naming/core/src/test/org/apache/commons/naming/LocalStrings_ja.properties Index: LocalStrings_ja.properties =================================================================== contextBindings.unknownContext=\u672a\u77e5\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u540d\u3067\u3059: {0} contextBindings.noContextBoundToThread=\u540d\u524d\u4ed8\u3051\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306f\u3053\u306e\u30b9\u30ec\u30c3\u30c9\u306b\u306f\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u307e\u305b\u3093 contextBindings.noContextBoundToCL=\u540d\u524d\u4ed8\u3051\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306f\u3053\u306e\u30af\u30e9\u30b9\u30ed\u30fc\u30c0\u306b\u306f\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u307e\u305b\u3093 selectorContext.noJavaUrl=\u3053\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306b\u306fjava: URL\u3092\u7528\u3044\u3066\u30a2\u30af\u30bb\u30b9\u3055\u308c\u306d\u3070\u3044\u3051\u307e\u305b\u3093 namingContext.contextExpected=\u540d\u524d\u304c\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306b\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u307e\u305b\u3093 namingContext.nameNotBound=\u540d\u524d {0} \u306f\u3053\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306b\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u307e\u305b\u3093 namingContext.readOnly=\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306f\u30ea\u30fc\u30c9\u30aa\u30f3\u30ea\u30fc\u3067\u3059 namingContext.invalidName=\u540d\u524d\u306f\u7121\u52b9\u3067\u3059 namingContext.alreadyBound=\u540d\u524d {0} \u306f\u3059\u3067\u306b\u3053\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306b\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u307e\u3059 namingContext.noAbsoluteName=\u3053\u306e\u540d\u524d\u7a7a\u9593\u306b\u7d76\u5bfe\u540d\u3092\u751f\u6210\u3067\u304d\u307e\u305b\u3093
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]