You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ps...@apache.org on 2004/02/09 00:16:28 UTC
svn commit: rev 6598 - incubator/directory/naming/trunk/core/src/test/org/apache/naming
Author: psteitz
Date: Sun Feb 8 15:16:26 2004
New Revision: 6598
Added:
incubator/directory/naming/trunk/core/src/test/org/apache/naming/AbstractContextTest.java
incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java
incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java
Modified:
incubator/directory/naming/trunk/core/src/test/org/apache/naming/BasicContextTest.java
Log:
Add initial cut at AbstractContextTest, tests for SelectorContext, NamingContext.
Added: incubator/directory/naming/trunk/core/src/test/org/apache/naming/AbstractContextTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/naming/trunk/core/src/test/org/apache/naming/AbstractContextTest.java Sun Feb 8 15:16:26 2004
@@ -0,0 +1,239 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 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 apache@apache.org.
+ *
+ * 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.naming;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.naming.Binding;
+import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Unit tests for basic ops on a {@link Context}.
+ *
+ *
+ * @version $Revision: 1.2 $ $Date: 2003/11/30 05:36:07 $
+ */
+public abstract class AbstractContextTest extends TestCase {
+ protected HashMap envBinding;
+ protected Context initialContext;
+ protected Context compContext;
+ protected Context envContext;
+
+ public AbstractContextTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Does this context support getNameInNamespace()?
+ * Defaults to true -- override if not supported
+ */
+ protected boolean isGetNameInNamespaceSupported() {
+ return true;
+ }
+
+ /**
+ * Create an initial context to be used in tests
+ */
+ protected abstract Context makeInitialContext();
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ Hashtable env = new Hashtable();
+ envBinding = new HashMap();
+ initialContext = makeInitialContext();
+ 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");
+ }
+
+ protected void tearDown() throws Exception {
+ 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.lookup("hello"),
+ ((Context) envContext.lookup("")).lookup("hello"));
+ }
+
+ 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")));
+ assertEquals("World",
+ ((Context) initialContext.lookup("java:comp")).lookup("env/world"));
+ }
+
+
+ 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
+ }
+ }
+
+ /**
+ * Default implementation just tests to make sure non-null names are returned
+ * or correct exception is thrown.
+ *
+ * @throws Exception
+ */
+ public void testGetNameInNamespace() throws Exception {
+ if (isGetNameInNamespaceSupported()) {
+ String name = initialContext.getNameInNamespace();
+ if (name == null) {
+ fail("Null NameInNamespace for initial context");
+ }
+ } else {
+ try {
+ String name = compContext.getNameInNamespace();
+ fail("Expecting OperationNotSupportedException");
+ } catch(OperationNotSupportedException ex) {
+ // expected
+ }
+ }
+ }
+}
Modified: incubator/directory/naming/trunk/core/src/test/org/apache/naming/BasicContextTest.java
==============================================================================
--- incubator/directory/naming/trunk/core/src/test/org/apache/naming/BasicContextTest.java (original)
+++ incubator/directory/naming/trunk/core/src/test/org/apache/naming/BasicContextTest.java Sun Feb 8 15:16:26 2004
@@ -1,7 +1,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2003 The Apache Software Foundation. All rights
+ * Copyright (c) 2003-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,20 +58,16 @@
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;
Added: incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java Sun Feb 8 15:16:26 2004
@@ -0,0 +1,100 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 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 apache@apache.org.
+ *
+ * 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.naming;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+
+/**
+ * Unit tests for basic ops on a {@link NamingContext}.
+ *
+ * @version $Revision: 1.2 $ $Date: 2003/11/30 05:36:07 $
+ */
+public class NamingContextTest extends AbstractContextTest {
+
+ public NamingContextTest(String name) {
+ super(name);
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(NamingContextTest.class);
+ suite.setName("Selector Context Tests");
+ return suite;
+ }
+
+ protected Context makeInitialContext() {
+ try {
+ return new NamingContext(new Hashtable(), "root");
+ } catch (Exception ex) {
+ fail("Failed to create NamingContext");
+ }
+ return null;
+ }
+
+ protected boolean isGetNameInNamespaceSupported() {
+ return false;
+ }
+}
Added: incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java Sun Feb 8 15:16:26 2004
@@ -0,0 +1,91 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 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 apache@apache.org.
+ *
+ * 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.naming;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+
+/**
+ * Unit tests for basic ops on an {@link SelectorContext}.
+ *
+ * @version $Revision: 1.2 $ $Date: 2003/11/30 05:36:07 $
+ */
+public class SelectorContextTest extends AbstractContextTest {
+
+ public SelectorContextTest(String name) {
+ super(name);
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(SelectorContextTest.class);
+ suite.setName("Selector Context Tests");
+ return suite;
+ }
+
+ protected Context makeInitialContext() {
+ return new SelectorContext(new Hashtable(), true);
+ }
+}