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/11 07:26:10 UTC

svn commit: rev 6614 - incubator/directory/naming/trunk/core/src/test/org/apache/naming/resources

Author: psteitz
Date: Tue Feb 10 22:26:10 2004
New Revision: 6614

Added:
   incubator/directory/naming/trunk/core/src/test/org/apache/naming/resources/
   incubator/directory/naming/trunk/core/src/test/org/apache/naming/resources/AbstractDirContextTest.java
   incubator/directory/naming/trunk/core/src/test/org/apache/naming/resources/FileDirContextTest.java
Log:
Initial version of DirContext tests.

Added: incubator/directory/naming/trunk/core/src/test/org/apache/naming/resources/AbstractDirContextTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/naming/trunk/core/src/test/org/apache/naming/resources/AbstractDirContextTest.java	Tue Feb 10 22:26:10 2004
@@ -0,0 +1,127 @@
+/* ====================================================================
+ * 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.resources;
+
+import java.io.ByteArrayInputStream;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.naming.AbstractContextTest;
+
+
+/**
+ * Unit tests for basic ops on a {@link DirContext}.
+ *  
+ * @version $Revision: 1.2 $ $Date: 2003/11/30 05:36:07 $
+ */
+public abstract class AbstractDirContextTest extends AbstractContextTest {
+    public AbstractDirContextTest(String name) {
+        super(name);
+    }
+    
+    /** A few bytes to write to temp files created */
+    protected byte[] bytes = {'a', 'b', 'c'}; 
+    
+    /** firstContext name -- relative to InitialContext  */
+    protected String firstContextName() {
+        return "firstDir";
+    }
+    
+    /** secondContext name -- relative to first context  */
+    protected String secondContextName() {
+        return "secondDir";
+    }
+    
+    /** First name to bind */
+    protected String firstBoundName() {
+        return "test1";
+    }
+    
+    /** First bound object */
+    protected Object firstBoundObject() {
+        return new Resource(new ByteArrayInputStream(bytes));
+    }
+    
+    /** Second name to bind */
+    protected String secondBoundName() {
+        return "test2";
+    }
+    
+    /** Second bound object */
+    protected Object secondBoundObject() {
+        return new Resource(new ByteArrayInputStream(bytes));
+    }
+    
+    protected void verifyLookup(Object boundObject, Object returnedObject) {
+        assertTrue(returnedObject instanceof Resource);
+    }
+    
+    protected void verifyList(Map expected, Map returned) {
+        assertEquals(expected.keySet(), returned.keySet());
+        Iterator iterator = returned.values().iterator();
+        while (iterator.hasNext()) {
+            assertTrue(((String) iterator.next()).length() > 0);
+        }
+    }
+    
+    protected void verifyListBindings(Map expected, Map returned) {
+        assertEquals(expected.keySet(), returned.keySet());
+        Iterator iterator = returned.values().iterator();
+        while (iterator.hasNext()) {
+            assertTrue(iterator.next() instanceof Resource);
+        }
+    }
+}

Added: incubator/directory/naming/trunk/core/src/test/org/apache/naming/resources/FileDirContextTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/naming/trunk/core/src/test/org/apache/naming/resources/FileDirContextTest.java	Tue Feb 10 22:26:10 2004
@@ -0,0 +1,124 @@
+/* ====================================================================
+ * 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.resources;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.naming.Context;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+
+/**
+ * Unit tests for basic ops on a {@link FileDirContext}.
+ *  
+ * @version $Revision: 1.2 $ $Date: 2003/11/30 05:36:07 $
+ */
+public class FileDirContextTest extends AbstractDirContextTest {
+    
+    public FileDirContextTest(String name) {
+        super(name);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+
+    public static Test suite() {
+    	TestSuite suite = new TestSuite(FileDirContextTest.class);
+    	suite.setName("FileDirContext Tests");
+        return suite;
+    }
+    
+    protected Context makeInitialContext() {
+    	try {
+    	    FileDirContext fdc = new FileDirContext();
+    	    fdc.setDocBase(".");
+    		return fdc;
+    	} catch (Exception ex) {
+    		fail("Failed to create Initial Context");
+    	}
+    	return null;
+    }
+    
+    /**
+     * Just verify that the bound object is a resource 
+     */
+    protected void verifyLookup(Object boundObject, Object returnedObject) {
+        assertTrue(returnedObject instanceof Resource);
+    }
+    
+    /**
+     * Verify that the listed bound names match expectation and
+     * that the bound objects are Resources
+     */
+    protected void verifyListBindings(Map expected, Map returned) {
+       super.verifyListBindings(expected, returned);
+        Iterator iterator = returned.values().iterator();
+        while (iterator.hasNext()) {
+            assertTrue(iterator.next() instanceof Resource);
+        }
+    }
+    
+    protected boolean isGetNameInNamespaceSupported() {
+    	return true;
+    }
+    
+    // todo:  Add better lookup / binding tests for files, directories
+}