directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szoer...@apache.org
Subject svn commit: r307188 [1/2] - in /directory/testsuite/trunk/ldaptests: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/ldap/ src/main/java/org/apache/ldap/testsuite/ src/main/java/org/apache/ldap/tes...
Date Fri, 07 Oct 2005 20:27:30 GMT
Author: szoerner
Date: Fri Oct  7 13:27:08 2005
New Revision: 307188

URL: http://svn.apache.org/viewcvs?rev=307188&view=rev
Log:
Initial version for a refactored test suite with basic LDAP operations.
The initial version was basically a proof of concept. Package names did  not adhere to conventions, etc.

Added:
    directory/testsuite/trunk/ldaptests/
    directory/testsuite/trunk/ldaptests/src/
    directory/testsuite/trunk/ldaptests/src/main/
    directory/testsuite/trunk/ldaptests/src/main/java/
    directory/testsuite/trunk/ldaptests/src/main/java/jndi.properties
    directory/testsuite/trunk/ldaptests/src/main/java/org/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/BaseProtocolTest.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/AllTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/AllTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/AllTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/BasicCompareTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/CompareOperationalAttributesTest.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/MatchingRuleCompareTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/AllTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/BasicDeleteTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/TreeDeleteControlTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/AllTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/UnknownExtendedOperationTest.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/AllTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyAddTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyRemoveTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyReplaceTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/MixedModifyFailureTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/AllTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/BasicModifyDnTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/ModifyDnSameAttributeTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/AllTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/IllegalSearchFilterTest.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchScopeTest.java
    directory/testsuite/trunk/ldaptests/src/test/

Added: directory/testsuite/trunk/ldaptests/src/main/java/jndi.properties
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/jndi.properties?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/jndi.properties (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/jndi.properties Fri Oct  7 13:27:08 2005
@@ -0,0 +1,12 @@
+java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
+
+# Connection Pooling
+com.sun.jndi.ldap.connect.pool=true
+com.sun.jndi.ldap.connect.pool.debug=true
+
+# Apache Directory Server
+#
+java.naming.provider.url=ldap://localhost:10389/dc=apache,dc=org
+java.naming.security.principal=uid=admin,ou=system
+java.naming.security.credentials=secret
+java.naming.security.authentication=simple
\ No newline at end of file

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/BaseProtocolTest.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/BaseProtocolTest.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/BaseProtocolTest.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/BaseProtocolTest.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,109 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi;
+
+import javax.naming.Binding;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class BaseProtocolTest extends TestCase
+{
+
+    public void setUp() throws NamingException
+    {
+
+        // Check whether test container entry exists
+        // If yes: delete it
+        DirContext ctx = this.createContext();
+        try {
+            LdapContext entry = (LdapContext) ctx.lookup(getTestContainerRdn());
+            this.deleteSubtree(entry);
+        } catch (NameNotFoundException ignored) {
+        }
+
+        // Create an entry
+        Attributes attributes = new BasicAttributes();
+        Attribute attribute = new BasicAttribute("objectClass");
+        attribute.add("top");
+        attribute.add("organizationalUnit");
+        attributes.put(attribute);
+        attributes.put("ou", "playground");
+
+        DirContext pg = ctx.createSubcontext(getTestContainerRdn(), attributes);
+        assertNotNull(pg);
+
+        pg = (DirContext) ctx.lookup(getTestContainerRdn());
+        assertNotNull(pg);
+
+        ctx.close();
+        ctx = null;
+    }
+
+    public void tearDown() throws NamingException
+    {
+        LdapContext ctx = this.createContext();
+
+        LdapContext pg = (LdapContext) ctx.lookup(getTestContainerRdn());
+        this.deleteSubtree(pg);
+
+        try {
+            ctx.lookup(getTestContainerRdn());
+            fail("test entry not deleted");
+        } catch (NameNotFoundException ignored) {
+        }
+
+        ctx.close();
+        ctx = null;
+    }
+
+    private void deleteSubtree(LdapContext entry) throws NamingException
+    {
+
+        NamingEnumeration enumeration = entry.listBindings("");
+        while (enumeration.hasMore()) {
+            Binding b = (Binding) enumeration.next();
+            if (b.getObject() instanceof LdapContext) {
+                deleteSubtree((LdapContext) b.getObject());
+            }
+        }
+        entry.unbind("");
+    }
+
+    protected LdapContext createContext() throws NamingException
+    {
+        return new InitialLdapContext();
+    }
+
+    protected String getTestContainerRdn()
+    {
+        return "ou=playground";
+    }
+}
\ No newline at end of file

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/AllTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/AllTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/AllTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/AllTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,62 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops;
+
+import junit.framework.TestSuite;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class AllTests extends TestSuite
+{
+
+    public static TestSuite suite()
+    {
+
+        TestSuite suite = new TestSuite("JNDI Operations");
+
+        // Bind
+
+        // Unbind
+
+        // Search
+        suite.addTest(org.apache.ldap.testsuite.ldaptests.jndi.ops.search.AllTests.suite());
+
+        // Modify
+        suite.addTest(org.apache.ldap.testsuite.ldaptests.jndi.ops.modify.AllTests.suite());
+
+        // Add
+        suite.addTest(org.apache.ldap.testsuite.ldaptests.jndi.ops.add.AllTests.suite());
+
+        // Delete
+        suite.addTest(org.apache.ldap.testsuite.ldaptests.jndi.ops.delete.AllTests.suite());
+
+        // Mofify DN
+        suite.addTest(org.apache.ldap.testsuite.ldaptests.jndi.ops.modifydn.AllTests.suite());
+
+        // Compare
+        suite.addTest(org.apache.ldap.testsuite.ldaptests.jndi.ops.compare.AllTests.suite());
+
+        // Abandon
+
+        // Extended
+        suite.addTest(org.apache.ldap.testsuite.ldaptests.jndi.ops.extended.AllTests.suite());
+
+        return suite;
+    }
+}

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/AllTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/AllTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/AllTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/AllTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,37 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.add;
+
+import junit.framework.TestSuite;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class AllTests extends TestSuite
+{
+
+    public static TestSuite suite()
+    {
+        TestSuite suite = new TestSuite("Add");
+
+        suite.addTestSuite(BasicAddTests.class);
+        suite.addTestSuite(SpecialCharacterAddTests.class);
+
+        return suite;
+    }
+}

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,148 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.add;
+
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class BasicAddTests extends org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest
+{
+
+    private static String PERSON_SN_VALUE = "Amos";
+
+    private static String PERSON_CN_VALUE = "Tori Amos";
+
+    private static String PERSON_CN_ALTERNATE = "Myra Ellen Amos";
+
+    private static String PERSON_RDN = "cn=" + PERSON_CN_VALUE;
+
+    private Attributes createPersonAttributes(String cn, String sn)
+    {
+        Attributes person = new BasicAttributes();
+
+        Attribute ocls = new BasicAttribute("objectClass");
+        ocls.add("top");
+        ocls.add("person");
+        person.put(ocls);
+
+        person.put("cn", cn);
+        person.put("sn", sn);
+
+        return person;
+    }
+
+    /**
+     * Just checks whether creation of a simple entry succeeds.
+     * 
+     * @throws NamingException
+     */
+    public void testAddEntry() throws NamingException
+    {
+
+        DirContext ctx = this.createContext();
+        DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+        // Add a person
+        Attributes attributes = createPersonAttributes(PERSON_CN_VALUE, PERSON_SN_VALUE);
+        DirContext person = target.createSubcontext(PERSON_RDN, attributes);
+
+        // Check wether person looks fine
+        person = (DirContext) target.lookup(PERSON_RDN);
+        assertNotNull(person);
+        attributes = person.getAttributes("");
+
+        // objectclasses
+        Attribute ocls = attributes.get("objectClass");
+        String[] expectedOcls = { "top", "person" };
+        for (int i = 0; i < expectedOcls.length; i++) {
+            boolean found = false;
+            String name = expectedOcls[i].toLowerCase();
+            for (int j = 0; j < ocls.size(); j++) {
+                if (name.equalsIgnoreCase(ocls.get(j).toString())) {
+                    found = true;
+                }
+            }
+            assertTrue("object class " + name + " is present", found);
+        }
+
+        // Other attributes
+        Attribute cn = attributes.get("cn");
+        assertTrue(cn.contains(PERSON_CN_VALUE));
+        Attribute sn = attributes.get("sn");
+        assertTrue(sn.contains(PERSON_SN_VALUE));
+
+        ctx.close();
+    }
+
+    /**
+     * Checks whether a duplicate entry causes a NameAlreadyBoundException.
+     * 
+     * @throws NamingException
+     */
+    public void testAddDuplicateEntry() throws NamingException
+    {
+
+        DirContext ctx = this.createContext();
+        DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+        Attributes attributes = createPersonAttributes(PERSON_CN_VALUE, PERSON_SN_VALUE);
+        target.createSubcontext(PERSON_RDN, attributes);
+
+        try {
+            target.createSubcontext(PERSON_RDN, attributes);
+            fail("duplicate entry should fail");
+        } catch (NameAlreadyBoundException e) {
+            // Excepted behaviour;
+            assertTrue(true);
+        }
+        ctx.close();
+    }
+
+    public void testAddEntryWithMultipleValues() throws NamingException
+    {
+
+        DirContext ctx = this.createContext();
+        DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+        // Create a person, description has multiple attributes
+        Attributes attributes = createPersonAttributes(PERSON_CN_VALUE, PERSON_SN_VALUE);
+        Attribute descr = new BasicAttribute("description");
+        descr.add("a description for the person");
+        descr.add("another description for this person");
+        attributes.put(descr);
+        int two = descr.size();
+
+        target.createSubcontext(PERSON_RDN, attributes);
+
+        DirContext tori = (DirContext) target.lookup(PERSON_RDN);
+        attributes = tori.getAttributes("");
+        descr = attributes.get("description");
+
+        assertEquals(two, descr.size());
+
+        ctx.close();
+    }
+}
\ No newline at end of file

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,102 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.add;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class SpecialCharacterAddTests extends BaseProtocolTest
+{
+
+    DirContext ctx;
+
+    public void setUp() throws NamingException
+    {
+        super.setUp();
+
+        ctx = this.createContext();
+        ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
+    }
+
+    public void tearDown() throws NamingException
+    {
+        ctx.close();
+        ctx = null;
+
+        super.tearDown();
+    }
+
+    private Attributes createPersonAttributes(String cn, String sn)
+    {
+        Attributes person = new BasicAttributes();
+
+        Attribute ocls = new BasicAttribute("objectClass");
+        ocls.add("top");
+        ocls.add("person");
+        person.put(ocls);
+
+        person.put("cn", cn);
+        person.put("sn", sn);
+
+        return person;
+    }
+
+    public void testAddEntryWithGermanUmlauts() throws NamingException
+    {
+
+        // Create a person with german "umlaut"
+        String cnValue = "Stefan Zörner";
+        String snValue = "Zörner";
+        String rdn = "cn=" + cnValue;
+        String allUmlauts = "äöüÄÖÜß";
+        Attributes attributes = createPersonAttributes(cnValue, snValue);
+        attributes.put("description", allUmlauts);
+
+        // add entry
+        ctx.createSubcontext(rdn, attributes);
+
+        // lookup and verify entry
+        DirContext stefan = (DirContext) ctx.lookup(rdn);
+        attributes = stefan.getAttributes("");
+        // cn
+        Attribute cn = attributes.get("cn");
+        assertNotNull(cn);
+        assertEquals("number of cn values", 1, cn.size());
+        assertTrue(cn.contains(cnValue));
+        // sn
+        Attribute sn = attributes.get("sn");
+        assertNotNull(sn);
+        assertEquals("number of sn values", 1, sn.size());
+        assertTrue(sn.contains(snValue));
+        // description
+        Attribute description = attributes.get("description");
+        assertNotNull(description);
+        assertEquals("number of description values", 1, description.size());
+        assertTrue(description.contains(allUmlauts));
+
+    }
+}
\ No newline at end of file

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/AllTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/AllTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/AllTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/AllTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,36 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.compare;
+
+import junit.framework.TestSuite;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class AllTests extends TestSuite
+{
+
+    public static TestSuite suite()
+    {
+        TestSuite suite = new TestSuite("Compare");
+
+        suite.addTestSuite(BasicCompareTests.class);
+
+        return suite;
+    }
+}

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/BasicCompareTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/BasicCompareTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/BasicCompareTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/BasicCompareTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,159 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.compare;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.NoSuchAttributeException;
+import javax.naming.directory.SearchControls;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $ 
+ */
+public class BasicCompareTests extends BaseProtocolTest {
+
+	DirContext ctx;
+	DirContext target;
+
+	public static final String RDN = "cn=Tori Amos";
+
+	protected Attributes getPersonAttributes(String sn, String cn) {
+		Attributes attributes = new BasicAttributes();
+		Attribute attribute = new BasicAttribute("objectClass");
+		attribute.add("top");
+		attribute.add("person");
+		attributes.put(attribute);
+		attributes.put("cn", cn);
+		attributes.put("sn", sn);
+
+		return attributes;
+	}
+
+	public void setUp() throws NamingException {
+		super.setUp();
+		
+		ctx    = this.createContext();
+		target = (DirContext) ctx.lookup(this.getTestContainerRdn()); 
+
+		// Create a person
+		Attributes attributes = this.getPersonAttributes("Amos", "Tori Amos");
+		target.createSubcontext(RDN, attributes);
+	}
+
+	public void tearDown() throws NamingException {
+		target.unbind(RDN);
+		target.close();
+		
+		ctx.close();
+		ctx = null;
+		
+		super.tearDown();
+	}
+
+	/**
+	 * Compare an existing attribute.
+	 * 
+	 * @throws NamingException
+	 */
+	public void testCompareExisting() throws NamingException {
+
+		// Setting up search controls
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[0]); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		// search operation, which leads to a compare
+		// value is correct
+		NamingEnumeration enumeration = target.search(RDN, "sn={0}",
+				new String[] { "Amos" }, ctls);
+
+		// Check, that result contains exactly one entry
+		boolean result = enumeration.hasMore();
+		assertTrue(result);
+		if (result) {
+			enumeration.next();
+			assertFalse(enumeration.hasMore());
+		}
+
+		// search operation, which leads to a compare.
+		// value is wrong
+		enumeration = target.search(RDN, "sn={0}", new String[] { "Bush" }, ctls);
+
+		// Check, that result contains no entry
+		assertFalse(enumeration.hasMore());
+	}
+
+	/**
+	 * Compare an attribute which does not exist in the entry.
+	 * 
+	 * @throws NamingException
+	 */
+	public void testCompareNonExisting() throws NamingException {
+
+		// Setting up search controls
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[0]); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		// search operation, which leads to a compare.
+		// the entry does not have a value for the attribute
+		try {
+			target.search(RDN, "description={0}",
+					new String[] { "a description" }, ctls);
+			fail("operation should cause an error");
+		} catch (NoSuchAttributeException nsae) {
+			// expected behaviour
+		}
+	}
+
+	/**
+	 * Compare an invalid attribute.
+	 * 
+	 * @throws NamingException
+	 */
+	public void testCompareInvalidAttribute() throws NamingException {
+
+		// Setting up search controls
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[0]); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		// search operation, which leads to a compare
+		// attribute does not exist
+		try {
+			target.search(RDN, "XXX={0}", new String[] { "a value" }, ctls);
+			fail("operation should cause an error");
+		} catch (NamingException iaie) {
+			// expected behaviour
+			
+			// TODO: add
+
+			// I am uncertain, whether Return code 16 or 17 is appropriate here.
+			// both values occur, depending on the server you use
+			// 16: noSuchAttribute
+			// 17: undefinedAttributeType
+		}
+	}
+}
\ No newline at end of file

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/CompareOperationalAttributesTest.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/CompareOperationalAttributesTest.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/CompareOperationalAttributesTest.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/CompareOperationalAttributesTest.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,247 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.compare;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * Tests with compare operations on the operational attributes createTimestamp,
+ * modifyTimestamp, creatorsName, modifiersName.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $ 
+ */
+public class CompareOperationalAttributesTest extends BaseProtocolTest {
+
+	private LdapContext ctx = null;
+
+	public static final String RDN = "ou=Peoples Front of Judea";
+
+	/**
+	 * Creation of required attributes of an organizationalUnit entry.
+	 */
+	protected Attributes getOrganizationalUnitAttributes(String ou) {
+		Attributes attributes = new BasicAttributes();
+		Attribute attribute = new BasicAttribute("objectClass");
+		attribute.add("top");
+		attribute.add("organizationalUnit");
+		attributes.put(attribute);
+		attributes.put("ou", ou);
+
+		return attributes;
+	}
+
+	public void setUp() throws NamingException {
+		super.setUp();
+
+		ctx = this.createContext();
+		ctx = (LdapContext) ctx.lookup(this.getTestContainerRdn());
+
+		// Create an organizationalUnit
+		Attributes attributes = this.getOrganizationalUnitAttributes("Amos");
+		ctx.createSubcontext(RDN, attributes);
+	}
+
+	public void tearDown() throws NamingException {
+		ctx.unbind(RDN);
+		ctx.close();
+		ctx = null;
+
+		super.tearDown();
+	}
+
+	/**
+	 * Determine an attribute value with a search op.
+	 * 
+	 * @param attributeName
+	 *            name of attribute
+	 * @return attribute value
+	 * @throws NamingException
+	 */
+	protected Object getAttributeValues(String attributeName)
+			throws NamingException {
+
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[] { attributeName });
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		NamingEnumeration enumeration = ctx
+				.search(RDN, "(objectClass=*)", ctls);
+		assertTrue(enumeration.hasMore());
+		SearchResult rs = (SearchResult) enumeration.next();
+		Attribute attr = rs.getAttributes().get(attributeName);
+		assertNotNull(attr);
+		Object value = (String) attr.get();
+		enumeration.close();
+
+		return value;
+	}
+
+	/**
+	 * Execute compare operations on the operational attribute createTimestamp.
+	 * 
+	 * @throws NamingException
+	 */
+	public void testCreateTimestamp() throws NamingException {
+		// Determine createTimestamp of entry
+		String createTimestamp = (String) this
+				.getAttributeValues("createTimestamp");
+		assertNotNull(createTimestamp);
+		
+		System.err.println(createTimestamp);
+
+		// Setting up search controls for compare op
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[] {}); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		// Compare values and expected results
+		String[] values = { createTimestamp, "19710401000000Z" };
+		boolean[] expected = { false, true, false };
+
+		for (int i = 0; i < values.length; i++) {
+			String value = values[i];
+			NamingEnumeration enumeration = ctx.search(RDN,
+					"createTimestamp={0}", new Object[] { value }, ctls);
+			boolean result = enumeration.hasMore();
+			assertEquals("compare 'createTimestamp' with '" + value + "'",
+					expected[i], result);
+			enumeration.close();
+		}
+	}
+
+	/**
+	 * Execute compare operations on the operational attribute creatorsName.
+	 * 
+	 * @throws NamingException
+	 */
+	public void testCreatorsName() throws NamingException {
+		// Determine creatorsName of entry
+		String creatorsName = (String) this.getAttributeValues("creatorsName");
+		assertNotNull(creatorsName);
+
+		// Setting up search controls for compare op
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[] {}); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		// Compare values and expected results
+		String[] values = { "", creatorsName, "cn=Not the right value" };
+		boolean[] expected = { false, true, false };
+
+		for (int i = 0; i < values.length; i++) {
+			String value = values[i];
+			NamingEnumeration enumeration = ctx.search(RDN, "creatorsName={0}",
+					new Object[] { value }, ctls);
+			boolean result = enumeration.hasMore();
+			assertEquals("compare 'creatorsName' with '" + value + "'",
+					expected[i], result);
+			enumeration.close();
+		}
+	}
+
+	/**
+	 * Execute compare operations on the operational attribute modifiersName.
+	 * 
+	 * @throws NamingException
+	 */
+	public void testModifiersName() throws NamingException {
+		// modify entry
+		ctx.modifyAttributes(RDN, DirContext.ADD_ATTRIBUTE,
+				new BasicAttributes("description", "Change this"));
+
+		String modifiersName = (String) this
+				.getAttributeValues("modifiersName");
+
+		// Setting up search controls for compare op
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[] {}); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		// Compare values and expected results
+		String[] values = { "", modifiersName, "cn=Not the right value" };
+		boolean[] expected = { false, true, false };
+
+		for (int i = 0; i < values.length; i++) {
+			String value = values[i];
+
+			NamingEnumeration enumeration = ctx.search(RDN,
+					"modifiersName={0}", new Object[] { value }, ctls);
+			boolean result = enumeration.hasMore();
+			assertEquals("compare 'modifiersName' with '" + value + "'",
+					expected[i], result);
+			enumeration.close();
+		}
+	}
+
+	/**
+	 * Execute compare operations on the operational attribute modifyTimestamp.
+	 * 
+	 * @throws NamingException
+	 */
+	public void testModifyTimestamp() throws NamingException {
+		// wait 2s
+		try {
+			Thread.sleep(2000);
+		} catch (InterruptedException ignored) {
+		}
+
+		// modify entry
+		ctx.modifyAttributes(RDN, DirContext.ADD_ATTRIBUTE,
+				new BasicAttributes("description", "Change this"));
+
+		// Determine timestamps of entry
+		String modifyTimestamp = (String) this
+				.getAttributeValues("modifyTimestamp");
+		String createTimestamp = (String) this
+				.getAttributeValues("createTimestamp");
+
+		assertNotNull(modifyTimestamp);
+		assertNotNull(createTimestamp);
+
+		// Setting up search controls for compare op
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[] {}); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		// Compare values and expected results
+		String[] values = { modifyTimestamp, createTimestamp,
+				"19710401000000Z" };
+		boolean[] expected = { false, true, false, false };
+
+		for (int i = 0; i < values.length; i++) {
+			String value = values[i];
+			NamingEnumeration enumeration = ctx.search(RDN,
+					"modifyTimestamp={0}", new Object[] { value }, ctls);
+			boolean result = enumeration.hasMore();
+			assertEquals("compare 'modifyTimestamp' with '" + value + "'",
+					expected[i], result);
+			enumeration.close();
+		}
+	}
+}
\ No newline at end of file

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/MatchingRuleCompareTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/MatchingRuleCompareTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/MatchingRuleCompareTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/compare/MatchingRuleCompareTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,226 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.compare;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * Tests for the Compare operation with JNDI.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $ 
+ */
+
+public class MatchingRuleCompareTests extends BaseProtocolTest {
+
+	DirContext ctx;
+
+	public static final String PERSON_CN = "Tori Amos";
+	
+	public static final String PERSON_SN = "Amos";
+	
+	public static final String PERSON_RDN = "cn="+PERSON_CN;
+
+	public static final String PERSON_TELEPHONE = "1234567890abc";
+
+	public static final String PERSON_PWD = "Secret1!";
+
+	public static final String GROUP_CN = "Artists";
+	
+	public static final String GROUP_RDN = "cn=Artists";
+
+	protected Attributes getPersonAttributes(String sn, String cn) {
+		Attributes attributes = new BasicAttributes();
+		Attribute attribute = new BasicAttribute("objectClass");
+		attribute.add("top");
+		attribute.add("person");
+		attributes.put(attribute);
+		attributes.put("cn", cn);
+		attributes.put("sn", sn);
+
+		return attributes;
+	}
+
+	protected Attributes getGroupOfNamesAttributes(String cn, String member) {
+		Attributes attributes = new BasicAttributes();
+		Attribute attribute = new BasicAttribute("objectClass");
+		attribute.add("top");
+		attribute.add("groupOfNames");
+		attributes.put(attribute);
+		attributes.put("cn", cn);
+		attributes.put("member", member);
+
+		return attributes;
+	}
+
+	public void setUp() throws NamingException {
+		super.setUp();
+
+		ctx = this.createContext();
+		ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+		// Create a person
+		Attributes attributes = this.getPersonAttributes(PERSON_SN, PERSON_CN);
+		attributes.put("telephoneNumber", PERSON_TELEPHONE);
+		attributes.put("userPassword", PERSON_PWD);
+		ctx.createSubcontext(PERSON_RDN, attributes);
+
+		// Create a group
+		DirContext member = (DirContext) ctx.lookup(PERSON_RDN);
+		attributes = this.getGroupOfNamesAttributes(GROUP_CN, member
+				.getNameInNamespace());
+		ctx.createSubcontext(GROUP_RDN, attributes);
+
+	}
+
+	public void tearDown() throws NamingException {
+
+		ctx.unbind(PERSON_RDN);
+		ctx.unbind(GROUP_RDN);
+
+		ctx.close();
+		ctx = null;
+
+		super.tearDown();
+	}
+
+	/**
+	 * Compare with caseIgnoreMatch matching rule.
+	 * 
+	 * @throws NamingException
+	 */
+	public void testCaseIgnoreMatch() throws NamingException {
+		// Setting up search controls
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[] {}); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		String[] values = { PERSON_SN, PERSON_SN.toUpperCase(), PERSON_SN.toLowerCase(), PERSON_SN+"X" };
+		boolean[] expected = { true, true, true, false };
+
+		for (int i = 0; i < values.length; i++) {
+			String value = values[i];
+
+			NamingEnumeration enumeration = ctx.search(PERSON_RDN, "sn={0}",
+					new String[] { value }, ctls);
+			// Check, that result contains exactly one entry
+			boolean result = enumeration.hasMore();
+
+			assertEquals("compare sn value '" + PERSON_SN + "' with '" + value + "'", expected[i],
+					result);
+
+			enumeration.close();
+		}
+	}
+
+	//
+
+	/**
+	 * Compare with telephoneNumberMatch matching rule.
+	 * 
+	 * @throws NamingException
+	 */
+	public void testTelephoneNumberMatch() throws NamingException {
+		// Setting up search controls
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[] {}); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		String[] values = { "", "1234567890abc", "   1234567890 A B C",
+				"123 456 7890 abc", "123-456-7890 abC", "123456-7890 A bc" };
+		boolean[] expected = { false, true, true, true, true, true };
+
+		for (int i = 0; i < values.length; i++) {
+			String value = values[i];
+
+			NamingEnumeration enumeration = ctx.search(PERSON_RDN,
+					"telephoneNumber={0}", new String[] { value }, ctls);
+			boolean result = enumeration.hasMore();
+
+			assertEquals("compare '1234567890' with '" + value + "'",
+					expected[i], result);
+
+			enumeration.close();
+		}
+	}
+
+	/**
+	 * Compare with octetStringMatch matching rule.
+	 * 
+	 * @throws NamingException
+	 */
+	public void testOctetStringMatch() throws NamingException {
+		// Setting up search controls
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[] {}); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		String[] values = { "", PERSON_PWD, PERSON_PWD.toUpperCase(), PERSON_PWD.toLowerCase(), PERSON_PWD+"X" };
+		boolean[] expected = { false, true, false, false, false };
+
+		for (int i = 0; i < values.length; i++) {
+			String value = values[i];
+
+			NamingEnumeration enumeration = ctx.search(PERSON_RDN,
+					"userPassword={0}", new String[] { value }, ctls);
+			boolean result = enumeration.hasMore();
+
+			assertEquals("compare 'Secret1!' with '" + value + "'",
+					expected[i], result);
+
+			enumeration.close();
+		}
+	}
+
+	public void testDistinguishedNameMatch() throws NamingException {
+
+		// determine member DN
+		DirContext member = (DirContext) ctx.lookup(PERSON_RDN);
+		String memberDN = member.getNameInNamespace();
+
+		// Setting up search controls for compare op
+		SearchControls ctls = new SearchControls();
+		ctls.setReturningAttributes(new String[] {}); // no attributes
+		ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+
+		String[] values = { "", memberDN, "cn=nobody", memberDN.toLowerCase(),
+				PERSON_RDN + " , " + ctx.getNameInNamespace() };
+		boolean[] expected = { false, true, false, true, true };
+
+		for (int i = 0; i < values.length; i++) {
+			String value = values[i];
+
+			NamingEnumeration enumeration = ctx.search(GROUP_RDN, "member={0}",
+					new Object[] { value }, ctls);
+			boolean result = enumeration.hasMore();
+
+			assertEquals("compare 'member' with '" + value + "'", expected[i],
+					result);
+
+			enumeration.close();
+		}
+	}
+}
\ No newline at end of file

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/AllTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/AllTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/AllTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/AllTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,37 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.delete;
+
+import junit.framework.TestSuite;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class AllTests extends TestSuite
+{
+
+    public static TestSuite suite()
+    {
+        TestSuite suite = new TestSuite("Delete");
+
+        suite.addTestSuite(BasicDeleteTests.class);
+        suite.addTestSuite(TreeDeleteControlTests.class);
+
+        return suite;
+    }
+}

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/BasicDeleteTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/BasicDeleteTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/BasicDeleteTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/BasicDeleteTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,129 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.delete;
+
+import javax.naming.ContextNotEmptyException;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class BasicDeleteTests extends BaseProtocolTest
+{
+
+    protected Attributes getOrganizationalUnitAttributes(String ou)
+    {
+        Attributes attributes = new BasicAttributes();
+
+        Attribute ocls = new BasicAttribute("objectClass");
+        ocls.add("top");
+        ocls.add("organizationalUnit");
+        attributes.put(ocls);
+
+        attributes.put("ou", ou);
+
+        return attributes;
+    }
+
+    /**
+     * Basic deletion test. Creates an entry, delete it, and check whether it is
+     * gone.
+     * 
+     * @throws NamingException
+     */
+    public void testDeleteEntry() throws NamingException
+    {
+
+        final String ou = "myUnit";
+        final String rdn = "ou=myUnit";
+
+        DirContext ctx = this.createContext();
+        DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+        // Add an entry
+        Attributes attributes = this.getOrganizationalUnitAttributes(ou);
+        DirContext orgUnit = target.createSubcontext(rdn, attributes);
+
+        // Check wether entry is created
+        orgUnit = (DirContext) target.lookup(rdn);
+        assertNotNull(orgUnit);
+
+        // Delete Entry
+        target.unbind(rdn);
+
+        // Check whether it is gone
+        try {
+            orgUnit = (DirContext) target.lookup(rdn);
+            fail("Deletion of entry failed");
+        } catch (NameNotFoundException nnfe) {
+            // expected behaviour
+            assertTrue(true);
+        }
+
+        ctx.close();
+    }
+
+    /**
+     * Deletion of an entry which is not a leaf.
+     * 
+     * @throws NamingException
+     */
+    public void testDeleteNonEmptyEntry() throws NamingException
+    {
+        DirContext ctx = this.createContext();
+        DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+        // Add an entry
+        final String ou = "nonLeaf";
+        final String rdn = "ou=" + ou;
+        Attributes attributes = this.getOrganizationalUnitAttributes(ou);
+        target.createSubcontext(rdn, attributes);
+
+        // Check wether entry is created
+        DirContext nonLeafRdn = (DirContext) target.lookup(rdn);
+        assertNotNull(nonLeafRdn);
+
+        // Add an entry below this
+        final String ouLeaf = "leaf";
+        final String rdnLeaf = "ou=" + ouLeaf;
+        attributes = this.getOrganizationalUnitAttributes(ouLeaf);
+        nonLeafRdn.createSubcontext(rdnLeaf, attributes);
+
+        // Try to delete subtree Entry
+        try {
+            target.unbind(rdn);
+            fail("deletion of entry should fail.");
+        } catch (ContextNotEmptyException e) {
+            // expected;
+        }
+
+        // Verify that entry soes exist
+        nonLeafRdn = (DirContext) target.lookup(rdn);
+        assertNotNull(nonLeafRdn);
+
+        ctx.close();
+    }
+}

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/TreeDeleteControlTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/TreeDeleteControlTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/TreeDeleteControlTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/delete/TreeDeleteControlTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,130 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.delete;
+
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class TreeDeleteControlTests extends BaseProtocolTest
+{
+    class TreeDeleteControl implements Control
+    {
+        private static final long serialVersionUID = 1L;
+
+        private boolean critical;
+
+        TreeDeleteControl() {
+            this(Control.CRITICAL);
+        }
+
+        TreeDeleteControl(boolean criticalValue) {
+            this.critical = criticalValue;
+        }
+
+        public String getID()
+        {
+            return "1.2.840.113556.1.4.805";
+        }
+
+        public boolean isCritical()
+        {
+            return this.critical;
+        }
+
+        public byte[] getEncodedValue()
+        {
+            return null;
+        }
+    }
+
+    protected Attributes getOrganizationalUnitAttributes(String ou)
+    {
+        Attributes attributes = new BasicAttributes();
+
+        Attribute ocls = new BasicAttribute("objectClass");
+        ocls.add("top");
+        ocls.add("organizationalUnit");
+        attributes.put(ocls);
+
+        attributes.put("ou", ou);
+        attributes.put("description", ou + "is an organizationalUnit");
+
+        return attributes;
+    }
+
+    public void testDeleteSubtreeWithControl() throws NamingException
+    {
+        LdapContext ctx = this.createContext();
+        LdapContext target = (LdapContext) ctx.lookup(this.getTestContainerRdn());
+
+        // Add an entry
+        final String ou = "nonLeaf";
+        final String rdn = "ou=" + ou;
+        Attributes attributes = this.getOrganizationalUnitAttributes(ou);
+        target.createSubcontext(rdn, attributes);
+
+        // Check wether entry is created
+        DirContext nonLeafRdn = (DirContext) target.lookup(rdn);
+        assertNotNull(nonLeafRdn);
+
+        // Add an entry below this
+        final String ouLeaf = "leaf";
+        final String rdnLeaf = "ou=" + ouLeaf;
+        attributes = this.getOrganizationalUnitAttributes(ouLeaf);
+        nonLeafRdn.createSubcontext(rdnLeaf, attributes);
+
+        // Try to delete subtree Entry
+        boolean supported = true;
+        try {
+            target.setRequestControls(new Control[] { new TreeDeleteControl(Control.CRITICAL) });
+            target.unbind(rdn);
+        } catch (OperationNotSupportedException e) {
+            // expected;
+            supported = false;
+        }
+        target.setRequestControls(null);
+
+        // Check, whether entry is deleted
+        boolean deleted = false;
+        try {
+            target.lookup(rdn);
+        } catch (NameNotFoundException e) {
+            deleted = true;
+        }
+
+        // Two option are valid here:
+        // 1. The control is not supported and the entry still exists
+        // 2. The control is supported and te entry is deleted
+        assertTrue((!supported & !deleted) || (supported & deleted));
+
+        ctx.close();
+    }
+}

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/AllTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/AllTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/AllTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/AllTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,36 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.extended;
+
+import junit.framework.TestSuite;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class AllTests extends TestSuite
+{
+
+    public static TestSuite suite()
+    {
+        TestSuite suite = new TestSuite("Extended");
+
+        suite.addTestSuite(UnknownExtendedOperationTest.class);
+
+        return suite;
+    }
+}

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/UnknownExtendedOperationTest.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/UnknownExtendedOperationTest.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/UnknownExtendedOperationTest.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/extended/UnknownExtendedOperationTest.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,76 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.extended;
+
+import javax.naming.CommunicationException;
+import javax.naming.NamingException;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.ExtendedResponse;
+import javax.naming.ldap.LdapContext;
+
+/**
+ * Check the behaviour of the server for an unknown extended operation.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class UnknownExtendedOperationTest extends org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest
+{
+
+    /**
+     * Calls an extended exception, which does not exist. Expected behaviour is
+     * a CommunicationException.
+     * 
+     * @throws NamingException
+     */
+    public void testUnknownExtendedOperation() throws NamingException
+    {
+        LdapContext ctx = this.createContext();
+
+        try {
+            ctx.extendedOperation(new UnknownExtendedOperationRequest());
+            fail("Calling an unknown extended operation should fail.");
+        } catch (CommunicationException ce) {
+            // expected behaviour
+        }
+    }
+
+    /**
+     * Class for the request of an extended operation which does not exist.
+     */
+    private class UnknownExtendedOperationRequest implements ExtendedRequest
+    {
+
+        private static final long serialVersionUID = 1L;
+
+        public String getID()
+        {
+            return "1.1";
+        }
+
+        public byte[] getEncodedValue()
+        {
+            return null;
+        }
+
+        public ExtendedResponse createExtendedResponse(String id, byte[] berValue, int offset, int length)
+                throws NamingException
+        {
+            return null;
+        }
+    }
+}
\ No newline at end of file

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/AllTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/AllTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/AllTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/AllTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,39 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.modify;
+
+import junit.framework.TestSuite;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class AllTests extends TestSuite
+{
+
+    public static TestSuite suite()
+    {
+        TestSuite suite = new TestSuite("Modify");
+
+        suite.addTestSuite(BasicModifyAddTests.class);
+        suite.addTestSuite(BasicModifyRemoveTests.class);
+        suite.addTestSuite(BasicModifyReplaceTests.class);
+        suite.addTestSuite(MixedModifyFailureTests.class);
+
+        return suite;
+    }
+}
\ No newline at end of file

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyAddTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyAddTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyAddTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyAddTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,181 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.modify;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.AttributeInUseException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * Tests for the modify operations with JNDI, which only include replace
+ * modifications.
+ * 
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class BasicModifyAddTests extends BaseProtocolTest
+{
+
+    DirContext start;
+
+    DirContext ctx;
+
+    public static final String RDN = "cn=Tori Amos";
+
+    public static final String PERSON_DESCRIPTION = "an American singer-songwriter";
+
+    protected Attributes getPersonAttributes(String sn, String cn)
+    {
+        Attributes attributes = new BasicAttributes();
+        Attribute attribute = new BasicAttribute("objectClass");
+        attribute.add("top");
+        attribute.add("person");
+        attributes.put(attribute);
+        attributes.put("cn", cn);
+        attributes.put("sn", sn);
+
+        return attributes;
+    }
+
+    public void setUp() throws NamingException
+    {
+        super.setUp();
+
+        start = this.createContext();
+        ctx = (DirContext) start.lookup(this.getTestContainerRdn());
+
+        // Create a person with description
+        Attributes attributes = this.getPersonAttributes("Amos", "Tori Amos");
+        attributes.put("description", PERSON_DESCRIPTION);
+
+        ctx.createSubcontext(RDN, attributes);
+    }
+
+    public void tearDown() throws NamingException
+    {
+        ctx.unbind(RDN);
+        ctx.close();
+
+        start.close();
+        start = null;
+
+        super.tearDown();
+    }
+
+    /**
+     * @throws NamingException
+     */
+    public void testAddNewAttributeValue() throws NamingException
+    {
+
+        // Change description attribute
+        String newValue = "1234567890";
+        Attributes attrs = new BasicAttributes("telephoneNumber", newValue);
+        ctx.modifyAttributes(RDN, DirContext.ADD_ATTRIBUTE, attrs);
+
+        // Verify, that attribute value changed
+        attrs = ctx.getAttributes(RDN);
+        Attribute attr = attrs.get("telephoneNumber");
+        assertNotNull(attr);
+        assertTrue(attr.contains(newValue));
+        assertEquals(1, attr.size());
+    }
+
+    /**
+     * @throws NamingException
+     */
+    public void testAddNewAttributeValues() throws NamingException
+    {
+
+        // Change description attribute
+        String[] newValues = { "1234567890", "999999999" };
+        Attribute attr = new BasicAttribute("telephoneNumber");
+        attr.add(newValues[0]);
+        attr.add(newValues[1]);
+        Attributes attrs = new BasicAttributes();
+        attrs.put(attr);
+        ctx.modifyAttributes(RDN, DirContext.ADD_ATTRIBUTE, attrs);
+
+        // Verify, that attribute values are present
+        attrs = ctx.getAttributes(RDN);
+        attr = attrs.get("telephoneNumber");
+        assertNotNull(attr);
+        assertTrue(attr.contains(newValues[0]));
+        assertTrue(attr.contains(newValues[1]));
+        assertEquals(newValues.length, attr.size());
+    }
+
+    /**
+     * @throws NamingException
+     */
+    public void testAddAdditionalAttributeValue() throws NamingException
+    {
+
+        // A new description attribute value
+        String newValue = "A new description for this person";
+        assertFalse(newValue.equals(PERSON_DESCRIPTION));
+        Attributes attrs = new BasicAttributes("description", newValue);
+
+        ctx.modifyAttributes(RDN, DirContext.ADD_ATTRIBUTE, attrs);
+
+        // Verify, that attribute value is added
+        attrs = ctx.getAttributes(RDN);
+        Attribute attr = attrs.get("description");
+        assertNotNull(attr);
+        assertTrue(attr.contains(newValue));
+        assertTrue(attr.contains(PERSON_DESCRIPTION));
+        assertEquals(2, attr.size());
+    }
+
+    /**
+     * Try to add an already existing attribute value.
+     * 
+     * Expected behaviour: Modify operation fails with an
+     * AttributeInUseException. Original LDAP Error code: 20 (Indicates that the
+     * attribute value specified in a modify or add operation already exists as
+     * a value for that attribute).
+     * 
+     * @throws NamingException
+     */
+    public void testAddExistingAttributeValue() throws NamingException
+    {
+
+        // Change description attribute
+        Attributes attrs = new BasicAttributes("description", PERSON_DESCRIPTION);
+        try {
+            ctx.modifyAttributes(RDN, DirContext.ADD_ATTRIBUTE, attrs);
+            fail("Adding an already existing atribute value should fail.");
+        } catch (AttributeInUseException e) {
+            // expected behaviour
+        }
+
+        // Verify, that attribute is still there, and is the only one
+        attrs = ctx.getAttributes(RDN);
+        Attribute attr = attrs.get("description");
+        assertNotNull(attr);
+        assertTrue(attr.contains(PERSON_DESCRIPTION));
+        assertEquals(1, attr.size());
+    }
+
+}
\ No newline at end of file

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyRemoveTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyRemoveTests.java?rev=307188&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyRemoveTests.java (added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modify/BasicModifyRemoveTests.java Fri Oct  7 13:27:08 2005
@@ -0,0 +1,273 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.modify;
+
+import javax.naming.InvalidNameException;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InvalidAttributeIdentifierException;
+import javax.naming.directory.NoSuchAttributeException;
+import javax.naming.directory.SchemaViolationException;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * Tests for the modify operations with JNDI, which only include simple remove
+ * modifications.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class BasicModifyRemoveTests extends BaseProtocolTest
+{
+
+    DirContext ctx;
+
+    DirContext target;
+
+    public static final String RDN = "cn=Tori Amos";
+
+    protected Attributes getInetOrgPersonAttributes(String sn, String cn)
+    {
+        Attributes attributes = new BasicAttributes();
+        Attribute attribute = new BasicAttribute("objectClass");
+        attribute.add("top");
+        attribute.add("person");
+        attribute.add("organizationalPerson");
+        attribute.add("inetOrgPerson");
+
+        attributes.put(attribute);
+        attributes.put("cn", cn);
+        attributes.put("sn", sn);
+
+        return attributes;
+    }
+
+    public void setUp() throws NamingException
+    {
+        super.setUp();
+
+        ctx = this.createContext();
+        target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+        // Create a person with description
+        Attributes attributes = this.getInetOrgPersonAttributes("Amos", "Tori Amos");
+        attributes.put("description", "an American singer-songwriter");
+
+        target.createSubcontext(RDN, attributes);
+    }
+
+    public void tearDown() throws NamingException
+    {
+        target.unbind(RDN);
+        target.close();
+
+        ctx.close();
+        ctx = null;
+
+        super.tearDown();
+    }
+
+    /**
+     * Remove an attribute, which is not required.
+     * 
+     * Expected result: After successful deletion, attribute is not present in
+     * entry.
+     * 
+     * @throws NamingException
+     */
+    public void testRemoveNotRequiredAttribute() throws NamingException
+    {
+
+        // Remove description Attribute
+        Attribute attr = new BasicAttribute("description");
+        Attributes attrs = new BasicAttributes();
+        attrs.put(attr);
+        target.modifyAttributes(RDN, DirContext.REMOVE_ATTRIBUTE, attrs);
+
+        // Verify, that attribute is deleted
+        attrs = target.getAttributes(RDN);
+        attr = attrs.get("description");
+        assertNull(attr);
+    }
+
+    /**
+     * Remove two not required attributes.
+     * 
+     * Expected result: After successful deletion, both attributes ar not
+     * present in entry.
+     * 
+     * @throws NamingException
+     */
+    public void testRemoveTwoNotRequiredAttributes() throws NamingException
+    {
+
+        // add telephoneNumber to entry
+        Attributes tn = new BasicAttributes("telephoneNumber", "12345678");
+        target.modifyAttributes(RDN, DirContext.ADD_ATTRIBUTE, tn);
+
+        // Remove description and telephoneNumber to Attribute
+        Attributes attrs = new BasicAttributes();
+        attrs.put(new BasicAttribute("description"));
+        attrs.put(new BasicAttribute("telephoneNumber"));
+        target.modifyAttributes(RDN, DirContext.REMOVE_ATTRIBUTE, attrs);
+
+        // Verify, that attributes are deleted
+        attrs = target.getAttributes(RDN);
+        assertNull(attrs.get("description"));
+        assertNull(attrs.get("telephoneNumber"));
+        assertNotNull(attrs.get("cn"));
+        assertNotNull(attrs.get("sn"));
+    }
+
+    /**
+     * Remove a required attribute.
+     * 
+     * Expected Result: Deletion fails with NamingException (Schema Violation).
+     * 
+     * @throws NamingException
+     */
+    public void testRemoveRequiredAttribute() throws NamingException
+    {
+
+        // Remove sn attribute
+        Attribute attr = new BasicAttribute("sn");
+        Attributes attrs = new BasicAttributes();
+        attrs.put(attr);
+
+        try {
+            target.modifyAttributes(RDN, DirContext.REMOVE_ATTRIBUTE, attrs);
+            fail("Deletion of required attribute should fail.");
+        } catch (SchemaViolationException e) {
+            // expected behaviour
+        }
+    }
+
+    /**
+     * Remove a required attribute from RDN.
+     * 
+     * Expected Result: Deletion fails with SchemaViolationException.
+     * 
+     * @throws NamingException
+     */
+    public void testRemovePartOfRdn() throws NamingException
+    {
+
+        // Remove sn attribute
+        Attribute attr = new BasicAttribute("cn");
+        Attributes attrs = new BasicAttributes();
+        attrs.put(attr);
+
+        try {
+            target.modifyAttributes(RDN, DirContext.REMOVE_ATTRIBUTE, attrs);
+            fail("Deletion of RDN attribute should fail.");
+        } catch (NamingException e) {
+            // expected behaviour
+        }
+    }
+
+    /**
+     * Remove a not required attribute from RDN.
+     * 
+     * Expected Result: Deletion fails with SchemaViolationException.
+     * 
+     * @throws NamingException
+     */
+    public void testRemovePartOfRdnNotRequired() throws NamingException
+    {
+
+        // add uid attribute
+        Attributes uid = new BasicAttributes("uid", "tamos");
+        target.modifyAttributes(RDN, DirContext.ADD_ATTRIBUTE, uid);
+
+        // Change RDN to another attribute (uid)
+        String newRdn = "uid=tamos";
+        target.addToEnvironment("java.naming.ldap.deleteRDN", "false");
+        target.rename(RDN, newRdn);
+
+        // Remove uid, which is now RDN attribute
+        Attribute attr = new BasicAttribute("uid");
+        Attributes attrs = new BasicAttributes();
+        attrs.put(attr);
+
+        try {
+            target.modifyAttributes(newRdn, DirContext.REMOVE_ATTRIBUTE, attrs);
+            fail("Deletion of RDN attribute should fail.");
+        } catch (SchemaViolationException e) {
+            // expected behaviour
+        } catch (InvalidNameException e) {
+            // Expected behaviour
+        }
+
+        // Change RDN back to original
+        target.addToEnvironment("java.naming.ldap.deleteRDN", "false");
+        target.rename(newRdn, RDN);
+    }
+
+    /**
+     * Remove a an attribute which is not present on the entry, but in the
+     * schema.
+     * 
+     * Expected result: Deletion fails with NoSuchAttributeException
+     * 
+     * @throws NamingException
+     */
+    public void testRemoveAttributeNotPresent() throws NamingException
+    {
+
+        // Remove telephoneNumber Attribute
+        Attribute attr = new BasicAttribute("telephoneNumber");
+        Attributes attrs = new BasicAttributes();
+        attrs.put(attr);
+
+        try {
+            target.modifyAttributes(RDN, DirContext.REMOVE_ATTRIBUTE, attrs);
+            fail("Deletion of attribute, which is not present in the entry, should fail.");
+        } catch (NoSuchAttributeException e) {
+            // expected behaviour
+        }
+    }
+
+    /**
+     * Remove a an attribute which is not present in the schema.
+     * 
+     * Expected result: Deletion fails with NoSuchAttributeException
+     * 
+     * @throws NamingException
+     */
+    public void testRemoveAttributeNotValid() throws NamingException
+    {
+
+        // Remove phantasy attribute
+        Attribute attr = new BasicAttribute("XXX");
+        Attributes attrs = new BasicAttributes();
+        attrs.put(attr);
+
+        try {
+            target.modifyAttributes(RDN, DirContext.REMOVE_ATTRIBUTE, attrs);
+            fail("Deletion of an invalid attribute should fail.");
+        } catch (NoSuchAttributeException e) {
+            // expected behaviour
+        } catch (InvalidAttributeIdentifierException e) {
+            // expected behaviour
+        }
+    }
+}
\ No newline at end of file



Mime
View raw message