You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ji...@apache.org on 2006/05/05 14:52:54 UTC
svn commit: r400067 [7/7] - in /directory/trunks:
apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/
clients/ldap/ mina/core/src/main/java/org/apache/mina/filter/
mina/core/src/main/java/org/apache/mina/handler/mult...
Modified: directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/BasicModifyDnTests.java
URL: http://svn.apache.org/viewcvs/directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/BasicModifyDnTests.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/BasicModifyDnTests.java (original)
+++ directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/BasicModifyDnTests.java Fri May 5 05:52:49 2006
@@ -1,188 +1,188 @@
-/*
- * 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.modifydn;
-
-import javax.naming.NameAlreadyBoundException;
-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 javax.naming.directory.SchemaViolationException;
-
-import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
-
-/**
- * Basic Tests for the Modify DN operation.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: $
- */
-public class BasicModifyDnTests extends BaseProtocolTest
-{
-
- /**
- * Creates attributes for a inetOrgPerson with minimum required attributes.
- *
- * @param sn
- * sn value of the person (surname)
- * @param cn
- * cn value of the person (common name)
- * @return attributes object for this person
- */
- 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;
- }
-
- /**
- * Modify DN of an entry, changing RDN from cn to uid.
- *
- * @throws NamingException
- */
- public void testModifyRdnAndKeepOld() throws NamingException
- {
- DirContext ctx = this.createContext();
- DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
- // Create a person, cn value is rdn
- String cnVal = "Tori Amos";
- String snVal = "Amos";
- String uidVal = "tamos";
- String oldRdn = "cn=" + cnVal;
- Attributes attributes = this.getInetOrgPersonAttributes(snVal, cnVal);
- attributes.put("uid", uidVal);
- target.createSubcontext(oldRdn, attributes);
-
- // modify Rdn
- String newRdn = "uid=" + uidVal;
- target.addToEnvironment("java.naming.ldap.deleteRDN", "false");
- target.rename(oldRdn, newRdn);
-
- // Check, whether old Entry does not exists
- try {
- target.lookup(oldRdn);
- fail("Entry must not exist");
- } catch (NameNotFoundException ignored) {
- // expected behaviour
- }
-
- // Check, whether new Entry exists
- DirContext tori = (DirContext) target.lookup(newRdn);
- assertNotNull(tori);
-
- // Check values of cn and uid
- Attribute cn = tori.getAttributes("").get("cn");
- assertTrue(cn.contains(cnVal));
- assertEquals(1, cn.size());
- Attribute uid = tori.getAttributes("").get("uid");
- assertTrue(uid.contains(uidVal));
- assertEquals(1, uid.size());
-
- ctx.close();
- }
-
- /**
- * Modify Rdn of an entry, changing it from cn to uid, but try delete old
- * rdn. This should cause a schema violation.
- *
- * @throws NamingException
- */
- public void testModifyRdnAndTryToDeleteOld() throws NamingException
- {
-
- DirContext ctx = this.createContext();
- DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
- // Create a person, cn value is rdn
- String cnVal = "Tori Amos";
- String snVal = "Amos";
- String uidVal = "tamos";
- String oldRdn = "cn=" + cnVal;
- Attributes attributes = this.getInetOrgPersonAttributes(snVal, cnVal);
- target.createSubcontext(oldRdn, attributes);
-
- // modify Rdn, but try delete old val
- try {
- String newRdn = "uid=" + uidVal;
- target.addToEnvironment("java.naming.ldap.deleteRDN", "true");
- target.rename(oldRdn, newRdn);
- fail("modify DN should cause a schema violation");
- } catch (SchemaViolationException sve) {
- // expected behaviour
- }
-
- // Check that old entry still exists
- DirContext tori = (DirContext) target.lookup(oldRdn);
- assertNotNull(tori);
-
- ctx.close();
- }
-
- /**
- * Modify Rdn of an entry, changing it from cn to uid. But an entry with
- * corresponding RDN already exists. This should cause an exception.
- *
- * @throws NamingException
- */
- public void testModifyRdnToExistingValue() throws NamingException
- {
-
- DirContext ctx = this.createContext();
- DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
- // Create a person, cn value is rdn
- String cnVal = "Tori Amos";
- String snVal = "Amos";
- String oldRdn = "cn=" + cnVal;
- String uidVal = "tamos";
- Attributes attributes = this.getInetOrgPersonAttributes(snVal, cnVal);
- target.createSubcontext(oldRdn, attributes);
-
- // create same person with sn as RDN
- String newRdn = "uid=" + uidVal;
- attributes.put("uid", uidVal);
- target.createSubcontext(newRdn, attributes);
-
- // modify DN, use existing value
- target.addToEnvironment("java.naming.ldap.deleteRDN", "false");
- try {
- target.rename(oldRdn, newRdn);
- fail("modify DN should cause an exception");
- } catch (NameAlreadyBoundException nbe) {
- // expected behaviour
- }
-
- // Check that old entry still exists
- DirContext tori = (DirContext) target.lookup(oldRdn);
- assertNotNull(tori);
-
- ctx.close();
- }
-}
\ No newline at end of file
+/*
+ * 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.modifydn;
+
+import javax.naming.NameAlreadyBoundException;
+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 javax.naming.directory.SchemaViolationException;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * Basic Tests for the Modify DN operation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class BasicModifyDnTests extends BaseProtocolTest
+{
+
+ /**
+ * Creates attributes for a inetOrgPerson with minimum required attributes.
+ *
+ * @param sn
+ * sn value of the person (surname)
+ * @param cn
+ * cn value of the person (common name)
+ * @return attributes object for this person
+ */
+ 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;
+ }
+
+ /**
+ * Modify DN of an entry, changing RDN from cn to uid.
+ *
+ * @throws NamingException
+ */
+ public void testModifyRdnAndKeepOld() throws NamingException
+ {
+ DirContext ctx = this.createContext();
+ DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+ // Create a person, cn value is rdn
+ String cnVal = "Tori Amos";
+ String snVal = "Amos";
+ String uidVal = "tamos";
+ String oldRdn = "cn=" + cnVal;
+ Attributes attributes = this.getInetOrgPersonAttributes(snVal, cnVal);
+ attributes.put("uid", uidVal);
+ target.createSubcontext(oldRdn, attributes);
+
+ // modify Rdn
+ String newRdn = "uid=" + uidVal;
+ target.addToEnvironment("java.naming.ldap.deleteRDN", "false");
+ target.rename(oldRdn, newRdn);
+
+ // Check, whether old Entry does not exists
+ try {
+ target.lookup(oldRdn);
+ fail("Entry must not exist");
+ } catch (NameNotFoundException ignored) {
+ // expected behaviour
+ }
+
+ // Check, whether new Entry exists
+ DirContext tori = (DirContext) target.lookup(newRdn);
+ assertNotNull(tori);
+
+ // Check values of cn and uid
+ Attribute cn = tori.getAttributes("").get("cn");
+ assertTrue(cn.contains(cnVal));
+ assertEquals(1, cn.size());
+ Attribute uid = tori.getAttributes("").get("uid");
+ assertTrue(uid.contains(uidVal));
+ assertEquals(1, uid.size());
+
+ ctx.close();
+ }
+
+ /**
+ * Modify Rdn of an entry, changing it from cn to uid, but try delete old
+ * rdn. This should cause a schema violation.
+ *
+ * @throws NamingException
+ */
+ public void testModifyRdnAndTryToDeleteOld() throws NamingException
+ {
+
+ DirContext ctx = this.createContext();
+ DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+ // Create a person, cn value is rdn
+ String cnVal = "Tori Amos";
+ String snVal = "Amos";
+ String uidVal = "tamos";
+ String oldRdn = "cn=" + cnVal;
+ Attributes attributes = this.getInetOrgPersonAttributes(snVal, cnVal);
+ target.createSubcontext(oldRdn, attributes);
+
+ // modify Rdn, but try delete old val
+ try {
+ String newRdn = "uid=" + uidVal;
+ target.addToEnvironment("java.naming.ldap.deleteRDN", "true");
+ target.rename(oldRdn, newRdn);
+ fail("modify DN should cause a schema violation");
+ } catch (SchemaViolationException sve) {
+ // expected behaviour
+ }
+
+ // Check that old entry still exists
+ DirContext tori = (DirContext) target.lookup(oldRdn);
+ assertNotNull(tori);
+
+ ctx.close();
+ }
+
+ /**
+ * Modify Rdn of an entry, changing it from cn to uid. But an entry with
+ * corresponding RDN already exists. This should cause an exception.
+ *
+ * @throws NamingException
+ */
+ public void testModifyRdnToExistingValue() throws NamingException
+ {
+
+ DirContext ctx = this.createContext();
+ DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+ // Create a person, cn value is rdn
+ String cnVal = "Tori Amos";
+ String snVal = "Amos";
+ String oldRdn = "cn=" + cnVal;
+ String uidVal = "tamos";
+ Attributes attributes = this.getInetOrgPersonAttributes(snVal, cnVal);
+ target.createSubcontext(oldRdn, attributes);
+
+ // create same person with sn as RDN
+ String newRdn = "uid=" + uidVal;
+ attributes.put("uid", uidVal);
+ target.createSubcontext(newRdn, attributes);
+
+ // modify DN, use existing value
+ target.addToEnvironment("java.naming.ldap.deleteRDN", "false");
+ try {
+ target.rename(oldRdn, newRdn);
+ fail("modify DN should cause an exception");
+ } catch (NameAlreadyBoundException nbe) {
+ // expected behaviour
+ }
+
+ // Check that old entry still exists
+ DirContext tori = (DirContext) target.lookup(oldRdn);
+ assertNotNull(tori);
+
+ ctx.close();
+ }
+}
Modified: directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/ModifyDnSameAttributeTests.java
URL: http://svn.apache.org/viewcvs/directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/ModifyDnSameAttributeTests.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/ModifyDnSameAttributeTests.java (original)
+++ directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/modifydn/ModifyDnSameAttributeTests.java Fri May 5 05:52:49 2006
@@ -1,175 +1,175 @@
-/*
- * 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.modifydn;
-
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-
-import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
-import org.apache.ldap.testsuite.ldaptests.jndi.util.AttributesFactory;
-
-/**
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
- */
-public class ModifyDnSameAttributeTests extends BaseProtocolTest
-{
- /**
- * Modify Rdn of an entry, delete its old rdn value.
- *
- * @throws NamingException
- */
- public void testModifyRdnAndDeleteOld() throws NamingException
- {
- DirContext ctx = this.createContext();
- DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
- // Create an organizational unit, ou value is rdn
- String oldOu = "Judean People's Front";
- String oldRdn = "ou=" + oldOu;
- Attributes attributes = AttributesFactory.createOrganizationalUnitAttributes(oldOu);
- target.createSubcontext(oldRdn, attributes);
-
- // modify Rdn
- String newOu = "People's Front of Judea";
- String newRdn = "ou=" + newOu;
- target.addToEnvironment("java.naming.ldap.deleteRDN", "true");
- target.rename(oldRdn, newRdn);
-
- // Check, whether old Entry does not exists
- try {
- target.lookup(oldRdn);
- fail("Entry must not exist");
- } catch (NameNotFoundException ignored) {
- // expected behaviour
- assertTrue(true);
- }
-
- // Check, whether new Entry exists
- DirContext ouEntry = (DirContext) target.lookup(newRdn);
- assertNotNull(ouEntry);
-
- // Check values of ou
- Attribute ou = ouEntry.getAttributes("").get("ou");
- assertTrue(ou.contains(newOu));
- assertTrue(!ou.contains(oldOu)); // old vaue is gone
- assertEquals(1, ou.size());
-
- ctx.close();
- }
-
- /**
- * Modify Rdn of an entry, keep its old rdn value.
- *
- * @throws NamingException
- */
- public void testModifyRdnAndKeepOld() throws NamingException
- {
-
- DirContext ctx = this.createContext();
- DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
- // Create an organizational unit, ou value is rdn
- String oldOu = "Judean People's Front";
- String oldRdn = "ou=" + oldOu;
- Attributes attributes = AttributesFactory.createOrganizationalUnitAttributes(oldOu);
- target.createSubcontext(oldRdn, attributes);
-
- // modify Rdn
- String newOu = "People's Front of Judea";
- String newRdn = "ou=" + newOu;
- target.addToEnvironment("java.naming.ldap.deleteRDN", "false");
- target.rename(oldRdn, newRdn);
-
- // Check, whether old entry does not exist
- try {
- target.lookup(oldRdn);
- fail("Entry must not exist");
- } catch (NameNotFoundException ignored) {
- // expected behaviour
- assertTrue(true);
- }
-
- // Check, whether new entry exists
- DirContext ouEntry = (DirContext) target.lookup(newRdn);
- assertNotNull(ouEntry);
-
- // Check values of cn
- Attribute ou = ouEntry.getAttributes("").get("ou");
- assertTrue(ou.contains(newOu));
- assertTrue(ou.contains(oldOu)); // old value is still present
- assertEquals(2, ou.size());
-
- ouEntry.close();
- target.close();
- ctx.close();
- }
-
- /**
- * Modify Rdn of an entry, delete its old rdn value. Here, the rdn attribute
- * cn has another value as well.
- *
- * @throws NamingException
- */
- public void testModifyRdnAndDeleteOldVariant() throws NamingException
- {
- DirContext ctx = this.createContext();
- DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
- // Create an organizational unit, ou value is rdn
- String oldOu = "Judean People's Front";
- String oldRdn = "ou=" + oldOu;
- Attributes attributes = AttributesFactory.createOrganizationalUnitAttributes(oldOu);
-
- // add a second ou value
- String alternateOu = "J.P.F.";
- Attribute ou = attributes.get("ou");
- ou.add(alternateOu);
- assertEquals(2, ou.size());
-
- target.createSubcontext(oldRdn, attributes);
-
- // modify Rdn
- String newOu = "People's Front of Judea";
- String newRdn = "ou=" + newOu;
- target.addToEnvironment("java.naming.ldap.deleteRDN", "true");
- target.rename(oldRdn, newRdn);
-
- // Check, whether old Entry does not exist anymore
- try {
- target.lookup(oldRdn);
- fail("Entry must not exist");
- } catch (NameNotFoundException ignored) {
- // expected behaviour
- assertTrue(true);
- }
-
- // Check, whether new Entry exists
- DirContext ouEntry = (DirContext) target.lookup(newRdn);
- assertNotNull(ouEntry);
-
- // Check values of cn
- ou = ouEntry.getAttributes("").get("ou");
- assertTrue(ou.contains(newOu));
- assertTrue(!ou.contains(oldOu)); // old value is gone
- assertTrue(ou.contains(alternateOu)); // alternate value is still
- assertEquals(2, ou.size());
- }
-}
+/*
+ * 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.modifydn;
+
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+import org.apache.ldap.testsuite.ldaptests.jndi.util.AttributesFactory;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ModifyDnSameAttributeTests extends BaseProtocolTest
+{
+ /**
+ * Modify Rdn of an entry, delete its old rdn value.
+ *
+ * @throws NamingException
+ */
+ public void testModifyRdnAndDeleteOld() throws NamingException
+ {
+ DirContext ctx = this.createContext();
+ DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+ // Create an organizational unit, ou value is rdn
+ String oldOu = "Judean People's Front";
+ String oldRdn = "ou=" + oldOu;
+ Attributes attributes = AttributesFactory.createOrganizationalUnitAttributes(oldOu);
+ target.createSubcontext(oldRdn, attributes);
+
+ // modify Rdn
+ String newOu = "People's Front of Judea";
+ String newRdn = "ou=" + newOu;
+ target.addToEnvironment("java.naming.ldap.deleteRDN", "true");
+ target.rename(oldRdn, newRdn);
+
+ // Check, whether old Entry does not exists
+ try {
+ target.lookup(oldRdn);
+ fail("Entry must not exist");
+ } catch (NameNotFoundException ignored) {
+ // expected behaviour
+ assertTrue(true);
+ }
+
+ // Check, whether new Entry exists
+ DirContext ouEntry = (DirContext) target.lookup(newRdn);
+ assertNotNull(ouEntry);
+
+ // Check values of ou
+ Attribute ou = ouEntry.getAttributes("").get("ou");
+ assertTrue(ou.contains(newOu));
+ assertTrue(!ou.contains(oldOu)); // old vaue is gone
+ assertEquals(1, ou.size());
+
+ ctx.close();
+ }
+
+ /**
+ * Modify Rdn of an entry, keep its old rdn value.
+ *
+ * @throws NamingException
+ */
+ public void testModifyRdnAndKeepOld() throws NamingException
+ {
+
+ DirContext ctx = this.createContext();
+ DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+ // Create an organizational unit, ou value is rdn
+ String oldOu = "Judean People's Front";
+ String oldRdn = "ou=" + oldOu;
+ Attributes attributes = AttributesFactory.createOrganizationalUnitAttributes(oldOu);
+ target.createSubcontext(oldRdn, attributes);
+
+ // modify Rdn
+ String newOu = "People's Front of Judea";
+ String newRdn = "ou=" + newOu;
+ target.addToEnvironment("java.naming.ldap.deleteRDN", "false");
+ target.rename(oldRdn, newRdn);
+
+ // Check, whether old entry does not exist
+ try {
+ target.lookup(oldRdn);
+ fail("Entry must not exist");
+ } catch (NameNotFoundException ignored) {
+ // expected behaviour
+ assertTrue(true);
+ }
+
+ // Check, whether new entry exists
+ DirContext ouEntry = (DirContext) target.lookup(newRdn);
+ assertNotNull(ouEntry);
+
+ // Check values of cn
+ Attribute ou = ouEntry.getAttributes("").get("ou");
+ assertTrue(ou.contains(newOu));
+ assertTrue(ou.contains(oldOu)); // old value is still present
+ assertEquals(2, ou.size());
+
+ ouEntry.close();
+ target.close();
+ ctx.close();
+ }
+
+ /**
+ * Modify Rdn of an entry, delete its old rdn value. Here, the rdn attribute
+ * cn has another value as well.
+ *
+ * @throws NamingException
+ */
+ public void testModifyRdnAndDeleteOldVariant() throws NamingException
+ {
+ DirContext ctx = this.createContext();
+ DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+ // Create an organizational unit, ou value is rdn
+ String oldOu = "Judean People's Front";
+ String oldRdn = "ou=" + oldOu;
+ Attributes attributes = AttributesFactory.createOrganizationalUnitAttributes(oldOu);
+
+ // add a second ou value
+ String alternateOu = "J.P.F.";
+ Attribute ou = attributes.get("ou");
+ ou.add(alternateOu);
+ assertEquals(2, ou.size());
+
+ target.createSubcontext(oldRdn, attributes);
+
+ // modify Rdn
+ String newOu = "People's Front of Judea";
+ String newRdn = "ou=" + newOu;
+ target.addToEnvironment("java.naming.ldap.deleteRDN", "true");
+ target.rename(oldRdn, newRdn);
+
+ // Check, whether old Entry does not exist anymore
+ try {
+ target.lookup(oldRdn);
+ fail("Entry must not exist");
+ } catch (NameNotFoundException ignored) {
+ // expected behaviour
+ assertTrue(true);
+ }
+
+ // Check, whether new Entry exists
+ DirContext ouEntry = (DirContext) target.lookup(newRdn);
+ assertNotNull(ouEntry);
+
+ // Check values of cn
+ ou = ouEntry.getAttributes("").get("ou");
+ assertTrue(ou.contains(newOu));
+ assertTrue(!ou.contains(oldOu)); // old value is gone
+ assertTrue(ou.contains(alternateOu)); // alternate value is still
+ assertEquals(2, ou.size());
+ }
+}
Modified: directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/AllTests.java
URL: http://svn.apache.org/viewcvs/directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/AllTests.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/AllTests.java (original)
+++ directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/AllTests.java Fri May 5 05:52:49 2006
@@ -1,42 +1,42 @@
-/*
- * 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.search;
-
-import junit.framework.TestSuite;
-
-/**
- * Contains the test classes for the LDAP search operation executed via JNDI. It
- * is used to form the complete suite into a structure.
- *
- * @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("Search");
-
- suite.addTestSuite(SearchFilterSimpleTest.class);
- suite.addTestSuite(SearchScopeTest.class);
- suite.addTestSuite(IllegalSearchFilterTest.class);
- suite.addTestSuite(SearchFilterAttributeNamesTest.class);
-
- return suite;
- }
-}
+/*
+ * 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.search;
+
+import junit.framework.TestSuite;
+
+/**
+ * Contains the test classes for the LDAP search operation executed via JNDI. It
+ * is used to form the complete suite into a structure.
+ *
+ * @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("Search");
+
+ suite.addTestSuite(SearchFilterSimpleTest.class);
+ suite.addTestSuite(SearchScopeTest.class);
+ suite.addTestSuite(IllegalSearchFilterTest.class);
+ suite.addTestSuite(SearchFilterAttributeNamesTest.class);
+
+ return suite;
+ }
+}
Modified: directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/IllegalSearchFilterTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/IllegalSearchFilterTest.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/IllegalSearchFilterTest.java (original)
+++ directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/IllegalSearchFilterTest.java Fri May 5 05:52:49 2006
@@ -1,94 +1,94 @@
-/*
- * 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.search;
-
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InvalidSearchFilterException;
-import javax.naming.directory.SearchControls;
-
-import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
-
-/**
- * Tests for the search operations with JNDI which use illegal search filters.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: $
- */
-public class IllegalSearchFilterTest extends BaseProtocolTest
-{
-
- private 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();
- }
-
- public void testFiltersWithSyntaxErrors() throws NamingException
- {
-
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
-
- String[] filters = { null, "", ",", "&", "1", "This is no filter" };
-
- for (int i = 0; i < filters.length; i++) {
- String filter = filters[i];
-
- // Search
- try {
- ctx.search("", filter, ctls);
- fail("Filter [" + filter + "] has syntax errors and should cause an error.");
- } catch (InvalidSearchFilterException e) {
- // Expected behaviour
- }
- }
- }
-
- public void testFilterWithUnbalancedParenthesis() throws NamingException
- {
-
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
-
- String[] filters = { "((sn=Amos)", "(&(sn=Amos)(cn=Tori Amos)", "(!(sn=Amos)" };
-
- for (int i = 0; i < filters.length; i++) {
- String filter = filters[i];
-
- // Search
- try {
- ctx.search("", filter, ctls);
- fail("Filter [" + filter + "] has unbalanced parenthesis and should cause an error.");
- } catch (InvalidSearchFilterException e) {
- // Expected behaviour
- }
- }
- }
-}
\ No newline at end of file
+/*
+ * 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.search;
+
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InvalidSearchFilterException;
+import javax.naming.directory.SearchControls;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * Tests for the search operations with JNDI which use illegal search filters.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class IllegalSearchFilterTest extends BaseProtocolTest
+{
+
+ private 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();
+ }
+
+ public void testFiltersWithSyntaxErrors() throws NamingException
+ {
+
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+
+ String[] filters = { null, "", ",", "&", "1", "This is no filter" };
+
+ for (int i = 0; i < filters.length; i++) {
+ String filter = filters[i];
+
+ // Search
+ try {
+ ctx.search("", filter, ctls);
+ fail("Filter [" + filter + "] has syntax errors and should cause an error.");
+ } catch (InvalidSearchFilterException e) {
+ // Expected behaviour
+ }
+ }
+ }
+
+ public void testFilterWithUnbalancedParenthesis() throws NamingException
+ {
+
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+
+ String[] filters = { "((sn=Amos)", "(&(sn=Amos)(cn=Tori Amos)", "(!(sn=Amos)" };
+
+ for (int i = 0; i < filters.length; i++) {
+ String filter = filters[i];
+
+ // Search
+ try {
+ ctx.search("", filter, ctls);
+ fail("Filter [" + filter + "] has unbalanced parenthesis and should cause an error.");
+ } catch (InvalidSearchFilterException e) {
+ // Expected behaviour
+ }
+ }
+ }
+}
Modified: directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterAttributeNamesTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterAttributeNamesTest.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterAttributeNamesTest.java (original)
+++ directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterAttributeNamesTest.java Fri May 5 05:52:49 2006
@@ -1,149 +1,149 @@
-/*
- * 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.search;
-
-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 org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
-
-/**
- * Tests for the search operations with concentrating on attribute names.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
- */
-public class SearchFilterAttributeNamesTest extends BaseProtocolTest
-{
-
- private DirContext ctx;
-
- static final String[] firstNames = { "Tori", "Heather", "Alanis", "Kate", "Fiona" };
-
- static final String[] lastNames = { "Amos", "Nova", "Morisette", "Bush", "Apple" };
-
- protected Attributes getPersonAttributes(Person p)
- {
- Attributes attributes = new BasicAttributes();
- Attribute attribute = new BasicAttribute("objectClass");
- attribute.add("top");
- attribute.add("person");
- attributes.put(attribute);
- attributes.put("sn", p.sn);
- attributes.put("cn", p.cn);
-
- return attributes;
- }
-
- public void setUp() throws NamingException
- {
- super.setUp();
-
- ctx = this.createContext();
- ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
- for (int i = 0; i < lastNames.length; ++i) {
- Person p = new Person(firstNames[i], lastNames[i]);
- ctx.createSubcontext("cn=" + p.cn, getPersonAttributes(p));
- }
- }
-
- public void tearDown() throws NamingException
- {
- ctx.close();
- ctx = null;
-
- super.tearDown();
- }
-
- /**
- * Tests presence filter for the objectClass attribute.
- */
- public void testObjectclassPresence() throws NamingException
- {
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
-
- String[] filters = { "(objectClass=*)", "(objectclass=*)", "(OBJECTCLASS=*)", "(Objectclass=*)" };
-
- for (int i = 0; i < filters.length; i++) {
- String filter = filters[i];
-
- NamingEnumeration enm = ctx.search("", filter, ctls);
- assertTrue("Entries found with filter " + filter, enm.hasMore());
- int numberOfEntries = 0;
- while (enm.hasMore()) {
- SearchResult entry = (SearchResult) enm.next();
- Attributes attrs = entry.getAttributes();
- Attribute sn = attrs.get("sn");
- assertEquals(1, sn.size());
-
- numberOfEntries++;
- }
-
- assertEquals("number of entries in result with filter " + filter, lastNames.length, numberOfEntries);
- }
- }
-
- /**
- * Tests equals filter for the objectClass attribute.
- */
- public void testObjectclassEquals() throws NamingException
- {
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-
- String[] filters = { "(objectClass=person)", "(objectclass=person)", "(OBJECTCLASS=person)",
- "(Objectclass=person)" };
-
- for (int i = 0; i < filters.length; i++) {
- String filter = filters[i];
-
- NamingEnumeration enm = ctx.search("", filter, ctls);
- assertTrue("Entries found with filter " + filter, enm.hasMore());
- int numberOfEntries = 0;
- while (enm.hasMore()) {
- SearchResult entry = (SearchResult) enm.next();
- Attributes attrs = entry.getAttributes();
- Attribute sn = attrs.get("sn");
- assertEquals(1, sn.size());
-
- numberOfEntries++;
- }
-
- assertEquals("number of entries in result with filter " + filter, lastNames.length, numberOfEntries);
- }
- }
-
- private class Person
- {
- Person(String firstName, String lastName) {
- this.sn = lastName;
- this.cn = firstName + " " + lastName;
- }
-
- String sn;
- String cn;
- }
-}
\ No newline at end of file
+/*
+ * 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.search;
+
+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 org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+
+/**
+ * Tests for the search operations with concentrating on attribute names.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SearchFilterAttributeNamesTest extends BaseProtocolTest
+{
+
+ private DirContext ctx;
+
+ static final String[] firstNames = { "Tori", "Heather", "Alanis", "Kate", "Fiona" };
+
+ static final String[] lastNames = { "Amos", "Nova", "Morisette", "Bush", "Apple" };
+
+ protected Attributes getPersonAttributes(Person p)
+ {
+ Attributes attributes = new BasicAttributes();
+ Attribute attribute = new BasicAttribute("objectClass");
+ attribute.add("top");
+ attribute.add("person");
+ attributes.put(attribute);
+ attributes.put("sn", p.sn);
+ attributes.put("cn", p.cn);
+
+ return attributes;
+ }
+
+ public void setUp() throws NamingException
+ {
+ super.setUp();
+
+ ctx = this.createContext();
+ ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+ for (int i = 0; i < lastNames.length; ++i) {
+ Person p = new Person(firstNames[i], lastNames[i]);
+ ctx.createSubcontext("cn=" + p.cn, getPersonAttributes(p));
+ }
+ }
+
+ public void tearDown() throws NamingException
+ {
+ ctx.close();
+ ctx = null;
+
+ super.tearDown();
+ }
+
+ /**
+ * Tests presence filter for the objectClass attribute.
+ */
+ public void testObjectclassPresence() throws NamingException
+ {
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+
+ String[] filters = { "(objectClass=*)", "(objectclass=*)", "(OBJECTCLASS=*)", "(Objectclass=*)" };
+
+ for (int i = 0; i < filters.length; i++) {
+ String filter = filters[i];
+
+ NamingEnumeration enm = ctx.search("", filter, ctls);
+ assertTrue("Entries found with filter " + filter, enm.hasMore());
+ int numberOfEntries = 0;
+ while (enm.hasMore()) {
+ SearchResult entry = (SearchResult) enm.next();
+ Attributes attrs = entry.getAttributes();
+ Attribute sn = attrs.get("sn");
+ assertEquals(1, sn.size());
+
+ numberOfEntries++;
+ }
+
+ assertEquals("number of entries in result with filter " + filter, lastNames.length, numberOfEntries);
+ }
+ }
+
+ /**
+ * Tests equals filter for the objectClass attribute.
+ */
+ public void testObjectclassEquals() throws NamingException
+ {
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
+
+ String[] filters = { "(objectClass=person)", "(objectclass=person)", "(OBJECTCLASS=person)",
+ "(Objectclass=person)" };
+
+ for (int i = 0; i < filters.length; i++) {
+ String filter = filters[i];
+
+ NamingEnumeration enm = ctx.search("", filter, ctls);
+ assertTrue("Entries found with filter " + filter, enm.hasMore());
+ int numberOfEntries = 0;
+ while (enm.hasMore()) {
+ SearchResult entry = (SearchResult) enm.next();
+ Attributes attrs = entry.getAttributes();
+ Attribute sn = attrs.get("sn");
+ assertEquals(1, sn.size());
+
+ numberOfEntries++;
+ }
+
+ assertEquals("number of entries in result with filter " + filter, lastNames.length, numberOfEntries);
+ }
+ }
+
+ private class Person
+ {
+ Person(String firstName, String lastName) {
+ this.sn = lastName;
+ this.cn = firstName + " " + lastName;
+ }
+
+ String sn;
+ String cn;
+ }
+}
Modified: directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java (original)
+++ directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java Fri May 5 05:52:49 2006
@@ -1,184 +1,184 @@
-/*
- * 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.search;
-
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
-
-import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
-import org.apache.ldap.testsuite.ldaptests.jndi.util.AttributesFactory;
-
-/**
- * Tests for the search operations with JNDI containing simple filter
- * expressions. All boolean operators are covered.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
- */
-public class SearchFilterSimpleTest extends BaseProtocolTest
-{
-
- private DirContext ctx;
-
- static final String[] firstNames = { "Tori", "Heather", "Alanis", "Kate", "Fiona" };
-
- static final String[] lastNames = { "Amos", "Nova", "Morisette", "Bush", "Apple" };
-
- public void setUp() throws NamingException
- {
- super.setUp();
-
- ctx = this.createContext();
- ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
- // Create person entries
- for (int i = 0; i < lastNames.length; ++i) {
- String cn = firstNames[i] + " " + lastNames[i];
- Attributes person = AttributesFactory.createPersonAttributes(cn, lastNames[i]);
- ctx.createSubcontext("cn=" + cn, person);
- }
-
- // Create an organization Unit
- String ou = "anOrgUnit";
- Attributes orgUnit = AttributesFactory.createOrganizationalUnitAttributes(ou);
- ctx.createSubcontext("ou=" + ou, orgUnit);
- }
-
- public void tearDown() throws NamingException
- {
- ctx.close();
- ctx = null;
-
- super.tearDown();
- }
-
- public void testSimpleFilter() throws NamingException
- {
-
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
-
- NamingEnumeration enm = ctx.search("", "(sn=Amos)", ctls);
- assertTrue(enm.hasMore());
- int numberOfEntries = 0;
- while (enm.hasMore()) {
- SearchResult entry = (SearchResult) enm.next();
- Attributes attrs = entry.getAttributes();
- Attribute sn = attrs.get("sn");
-
- assertEquals(1, sn.size());
- assertTrue(sn.contains("Amos"));
-
- numberOfEntries++;
- }
-
- assertEquals("number of entries in result", 1, numberOfEntries);
- enm.close();
- }
-
- /**
- * Test with a search filter which contains an NOT operator.
- */
- public void testFilterWithNot() throws NamingException
- {
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
-
- // Filter "(!(objectClass=person))"
- //
- NamingEnumeration enm = ctx.search("", "(!(objectClass=person))", ctls);
- assertTrue(enm.hasMore());
- int numberOfEntries = 0;
- while (enm.hasMore()) {
- SearchResult entry = (SearchResult) enm.next();
- Attributes attrs = entry.getAttributes();
- Attribute ocls = attrs.get("objectClass");
-
- assertFalse(ocls.contains("person"));
-
- numberOfEntries++;
- }
- // Check whether number of entries foud is 1 (the org unit)
- assertEquals("number of entries in result", 1, numberOfEntries);
- enm.close();
-
- // Filter "(!(objectClass=*))"
- //
- enm = ctx.search("", "(!(objectClass=*))", ctls);
- assertFalse("entries found", enm.hasMore());
- enm.close();
- }
-
- /**
- * Test with search filters which contain an AND operator.
- */
- public void testFilterWithAnd() throws NamingException
- {
-
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-
- // Filter "(&(objectClass=person)(sn=Amos))"
- //
- NamingEnumeration enm = ctx.search("", "(&(objectClass=person)(sn=Amos))", ctls);
- assertTrue(enm.hasMore());
- int numberOfEntries = 0;
- while (enm.hasMore()) {
- SearchResult entry = (SearchResult) enm.next();
- Attributes attrs = entry.getAttributes();
- Attribute sn = attrs.get("sn");
- assertTrue(sn.contains("Amos"));
- numberOfEntries++;
- }
- assertEquals("number of entries in result", 1, numberOfEntries);
- enm.close();
-
- // Filter "(&(sn=Amos)(sn=Bush))"
- //
- enm = ctx.search("", "(&(sn=Amos)(sn=Bush))", ctls);
- assertFalse("entries found", enm.hasMore());
- enm.close();
- }
-
- /**
- * Test with a search filter which contains an OR operator.
- */
- public void testFilterWithOr() throws NamingException
- {
-
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-
- NamingEnumeration enm = ctx.search("", "(|(cn=Kate Bush)(sn=Amos))", ctls);
- assertTrue(enm.hasMore());
- int numberOfEntries = 0;
- while (enm.hasMore()) {
- SearchResult entry = (SearchResult) enm.next();
- Attributes attrs = entry.getAttributes();
- Attribute sn = attrs.get("sn");
- assertTrue(sn.contains("Amos") || sn.contains("Bush"));
- numberOfEntries++;
- }
- assertEquals("number of entries in result", 2, numberOfEntries);
- enm.close();
- }
-}
\ No newline at end of file
+/*
+ * 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.search;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+import org.apache.ldap.testsuite.ldaptests.jndi.util.AttributesFactory;
+
+/**
+ * Tests for the search operations with JNDI containing simple filter
+ * expressions. All boolean operators are covered.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SearchFilterSimpleTest extends BaseProtocolTest
+{
+
+ private DirContext ctx;
+
+ static final String[] firstNames = { "Tori", "Heather", "Alanis", "Kate", "Fiona" };
+
+ static final String[] lastNames = { "Amos", "Nova", "Morisette", "Bush", "Apple" };
+
+ public void setUp() throws NamingException
+ {
+ super.setUp();
+
+ ctx = this.createContext();
+ ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+ // Create person entries
+ for (int i = 0; i < lastNames.length; ++i) {
+ String cn = firstNames[i] + " " + lastNames[i];
+ Attributes person = AttributesFactory.createPersonAttributes(cn, lastNames[i]);
+ ctx.createSubcontext("cn=" + cn, person);
+ }
+
+ // Create an organization Unit
+ String ou = "anOrgUnit";
+ Attributes orgUnit = AttributesFactory.createOrganizationalUnitAttributes(ou);
+ ctx.createSubcontext("ou=" + ou, orgUnit);
+ }
+
+ public void tearDown() throws NamingException
+ {
+ ctx.close();
+ ctx = null;
+
+ super.tearDown();
+ }
+
+ public void testSimpleFilter() throws NamingException
+ {
+
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+
+ NamingEnumeration enm = ctx.search("", "(sn=Amos)", ctls);
+ assertTrue(enm.hasMore());
+ int numberOfEntries = 0;
+ while (enm.hasMore()) {
+ SearchResult entry = (SearchResult) enm.next();
+ Attributes attrs = entry.getAttributes();
+ Attribute sn = attrs.get("sn");
+
+ assertEquals(1, sn.size());
+ assertTrue(sn.contains("Amos"));
+
+ numberOfEntries++;
+ }
+
+ assertEquals("number of entries in result", 1, numberOfEntries);
+ enm.close();
+ }
+
+ /**
+ * Test with a search filter which contains an NOT operator.
+ */
+ public void testFilterWithNot() throws NamingException
+ {
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+
+ // Filter "(!(objectClass=person))"
+ //
+ NamingEnumeration enm = ctx.search("", "(!(objectClass=person))", ctls);
+ assertTrue(enm.hasMore());
+ int numberOfEntries = 0;
+ while (enm.hasMore()) {
+ SearchResult entry = (SearchResult) enm.next();
+ Attributes attrs = entry.getAttributes();
+ Attribute ocls = attrs.get("objectClass");
+
+ assertFalse(ocls.contains("person"));
+
+ numberOfEntries++;
+ }
+ // Check whether number of entries foud is 1 (the org unit)
+ assertEquals("number of entries in result", 1, numberOfEntries);
+ enm.close();
+
+ // Filter "(!(objectClass=*))"
+ //
+ enm = ctx.search("", "(!(objectClass=*))", ctls);
+ assertFalse("entries found", enm.hasMore());
+ enm.close();
+ }
+
+ /**
+ * Test with search filters which contain an AND operator.
+ */
+ public void testFilterWithAnd() throws NamingException
+ {
+
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
+
+ // Filter "(&(objectClass=person)(sn=Amos))"
+ //
+ NamingEnumeration enm = ctx.search("", "(&(objectClass=person)(sn=Amos))", ctls);
+ assertTrue(enm.hasMore());
+ int numberOfEntries = 0;
+ while (enm.hasMore()) {
+ SearchResult entry = (SearchResult) enm.next();
+ Attributes attrs = entry.getAttributes();
+ Attribute sn = attrs.get("sn");
+ assertTrue(sn.contains("Amos"));
+ numberOfEntries++;
+ }
+ assertEquals("number of entries in result", 1, numberOfEntries);
+ enm.close();
+
+ // Filter "(&(sn=Amos)(sn=Bush))"
+ //
+ enm = ctx.search("", "(&(sn=Amos)(sn=Bush))", ctls);
+ assertFalse("entries found", enm.hasMore());
+ enm.close();
+ }
+
+ /**
+ * Test with a search filter which contains an OR operator.
+ */
+ public void testFilterWithOr() throws NamingException
+ {
+
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
+
+ NamingEnumeration enm = ctx.search("", "(|(cn=Kate Bush)(sn=Amos))", ctls);
+ assertTrue(enm.hasMore());
+ int numberOfEntries = 0;
+ while (enm.hasMore()) {
+ SearchResult entry = (SearchResult) enm.next();
+ Attributes attrs = entry.getAttributes();
+ Attribute sn = attrs.get("sn");
+ assertTrue(sn.contains("Amos") || sn.contains("Bush"));
+ numberOfEntries++;
+ }
+ assertEquals("number of entries in result", 2, numberOfEntries);
+ enm.close();
+ }
+}
Modified: directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchScopeTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchScopeTest.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchScopeTest.java (original)
+++ directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchScopeTest.java Fri May 5 05:52:49 2006
@@ -1,150 +1,150 @@
-/*
- * 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.search;
-
-import java.util.HashSet;
-import java.util.Set;
-
-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.DirContext;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
-
-import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
-import org.apache.ldap.testsuite.ldaptests.jndi.util.AttributesFactory;
-
-/**
- * Tests for the search operations with JNDI.
- *
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
- */
-public class SearchScopeTest extends BaseProtocolTest
-{
-
- private DirContext ctx;
-
- private static final String MATCH_ALL_FILTER = "(objectClass=*)";
-
- private static final String UNITS_NAME = "units";
-
- private static final String UNITS_RDN = "ou=" + UNITS_NAME;
-
- private static final int SUBTREE_LEVEL_DEPTH = 2;
-
- private static final int ENTRIES_PER_LEVEL = 3;
-
- protected void createSubtrees(DirContext target, int depth, int maxDepth, int count) throws NamingException
- {
- if (depth < maxDepth) {
- for (int i = 0; i < count; ++i) {
- String ou = "unit_" + depth + "_" + (i);
- Attributes attr = AttributesFactory.createOrganizationalUnitAttributes(ou);
- DirContext entry = target.createSubcontext("ou=" + ou, attr);
- createSubtrees(entry, depth + 1, maxDepth, count);
- }
- }
-
- }
-
- public void setUp() throws NamingException
- {
- super.setUp();
-
- ctx = this.createContext();
- ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
- DirContext units = ctx.createSubcontext(UNITS_RDN, AttributesFactory.createOrganizationalUnitAttributes(UNITS_NAME));
- createSubtrees(units, 0, SUBTREE_LEVEL_DEPTH, ENTRIES_PER_LEVEL);
-
- }
-
- public void tearDown() throws NamingException
- {
- ctx.close();
- ctx = null;
-
- super.tearDown();
- }
-
- public void testBaseScopeExisting() throws NamingException
- {
-
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
- ctls.setReturningAttributes(new String[] { "ou" });
-
- // Search
- NamingEnumeration enm = ctx.search(UNITS_RDN, MATCH_ALL_FILTER, ctls);
-
- // Exactly one entry in result
- assertTrue(enm.hasMore());
- SearchResult sr = (SearchResult) enm.next();
- assertFalse(enm.hasMore());
-
- // The right entry in result
- Attributes attrs = sr.getAttributes();
- Attribute ou = attrs.get("ou");
- assertTrue(ou.contains(UNITS_NAME));
- }
-
- public void testBaseScopeNotExistingBase() throws NamingException
- {
-
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
- ctls.setReturningAttributes(new String[] { "ou" });
-
- try {
- ctx.search(UNITS_RDN + "_", MATCH_ALL_FILTER, ctls);
- fail("Search on a not existing base should fail");
- } catch (NameNotFoundException nnfe) {
- // expected behaviour
- }
- }
-
- public void testOneLevelScope() throws NamingException
- {
-
- SearchControls ctls = new SearchControls();
- ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- ctls.setReturningAttributes(new String[] { "ou" });
-
- // Search op
- //
- NamingEnumeration enm = ctx.search(UNITS_RDN, MATCH_ALL_FILTER, ctls);
-
- // Analyse result data
- assertTrue(enm.hasMore());
- Set entries = new HashSet();
- int count = 0;
- while (enm.hasMore()) {
- count++;
- SearchResult sr = (SearchResult) enm.next();
- Attribute ou = sr.getAttributes().get("ou");
- entries.add(ou.get());
- }
- assertEquals("number of entries in result", ENTRIES_PER_LEVEL, count);
- assertEquals("number of different entries in result", ENTRIES_PER_LEVEL, entries.size());
- assertFalse("base included in result", entries.contains(UNITS_NAME));
- }
-}
\ No newline at end of file
+/*
+ * 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.search;
+
+import java.util.HashSet;
+import java.util.Set;
+
+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.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+import org.apache.ldap.testsuite.ldaptests.jndi.util.AttributesFactory;
+
+/**
+ * Tests for the search operations with JNDI.
+ *
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SearchScopeTest extends BaseProtocolTest
+{
+
+ private DirContext ctx;
+
+ private static final String MATCH_ALL_FILTER = "(objectClass=*)";
+
+ private static final String UNITS_NAME = "units";
+
+ private static final String UNITS_RDN = "ou=" + UNITS_NAME;
+
+ private static final int SUBTREE_LEVEL_DEPTH = 2;
+
+ private static final int ENTRIES_PER_LEVEL = 3;
+
+ protected void createSubtrees(DirContext target, int depth, int maxDepth, int count) throws NamingException
+ {
+ if (depth < maxDepth) {
+ for (int i = 0; i < count; ++i) {
+ String ou = "unit_" + depth + "_" + (i);
+ Attributes attr = AttributesFactory.createOrganizationalUnitAttributes(ou);
+ DirContext entry = target.createSubcontext("ou=" + ou, attr);
+ createSubtrees(entry, depth + 1, maxDepth, count);
+ }
+ }
+
+ }
+
+ public void setUp() throws NamingException
+ {
+ super.setUp();
+
+ ctx = this.createContext();
+ ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
+
+ DirContext units = ctx.createSubcontext(UNITS_RDN, AttributesFactory.createOrganizationalUnitAttributes(UNITS_NAME));
+ createSubtrees(units, 0, SUBTREE_LEVEL_DEPTH, ENTRIES_PER_LEVEL);
+
+ }
+
+ public void tearDown() throws NamingException
+ {
+ ctx.close();
+ ctx = null;
+
+ super.tearDown();
+ }
+
+ public void testBaseScopeExisting() throws NamingException
+ {
+
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+ ctls.setReturningAttributes(new String[] { "ou" });
+
+ // Search
+ NamingEnumeration enm = ctx.search(UNITS_RDN, MATCH_ALL_FILTER, ctls);
+
+ // Exactly one entry in result
+ assertTrue(enm.hasMore());
+ SearchResult sr = (SearchResult) enm.next();
+ assertFalse(enm.hasMore());
+
+ // The right entry in result
+ Attributes attrs = sr.getAttributes();
+ Attribute ou = attrs.get("ou");
+ assertTrue(ou.contains(UNITS_NAME));
+ }
+
+ public void testBaseScopeNotExistingBase() throws NamingException
+ {
+
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+ ctls.setReturningAttributes(new String[] { "ou" });
+
+ try {
+ ctx.search(UNITS_RDN + "_", MATCH_ALL_FILTER, ctls);
+ fail("Search on a not existing base should fail");
+ } catch (NameNotFoundException nnfe) {
+ // expected behaviour
+ }
+ }
+
+ public void testOneLevelScope() throws NamingException
+ {
+
+ SearchControls ctls = new SearchControls();
+ ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+ ctls.setReturningAttributes(new String[] { "ou" });
+
+ // Search op
+ //
+ NamingEnumeration enm = ctx.search(UNITS_RDN, MATCH_ALL_FILTER, ctls);
+
+ // Analyse result data
+ assertTrue(enm.hasMore());
+ Set entries = new HashSet();
+ int count = 0;
+ while (enm.hasMore()) {
+ count++;
+ SearchResult sr = (SearchResult) enm.next();
+ Attribute ou = sr.getAttributes().get("ou");
+ entries.add(ou.get());
+ }
+ assertEquals("number of entries in result", ENTRIES_PER_LEVEL, count);
+ assertEquals("number of different entries in result", ENTRIES_PER_LEVEL, entries.size());
+ assertFalse("base included in result", entries.contains(UNITS_NAME));
+ }
+}
Modified: directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/util/AttributesFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/util/AttributesFactory.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/util/AttributesFactory.java (original)
+++ directory/trunks/testsuites/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/util/AttributesFactory.java Fri May 5 05:52:49 2006
@@ -1,114 +1,114 @@
-/*
- * 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.util;
-
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-
-/**
- * Convenience methods to create attributes for entries of common objectclasses.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
- */
-public class AttributesFactory
-{
- /**
- * Creates the required attributes for a person as defined in RFC 2256. The
- * result contains an objectClass attribute with values top and person, and
- * the attributes sn and cn.
- *
- * @param cn
- * common name of person
- * @param sn
- * surname of person
- *
- * @return attributes object with the required attributes for a person
- */
- public static final 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;
- }
-
- /**
- * Creates the required attributes for an inetOrgPerson as defined in RFC
- * 2798 ("Definition of the inetOrgPerson LDAP Object Class"). The result
- * contains an objectClass attribute with the appropriate values, and the
- * attributes sn and cn, which are required from person.
- *
- * @param cn
- * common name of person
- * @param sn
- * surname of person
- *
- * @return attributes object with the required attributes for an inetOrgPerson
- */
- public static final Attributes createInetOrgPersonAttributes(String cn, String sn)
- {
- Attributes person = new BasicAttributes();
-
- Attribute ocls = new BasicAttribute("objectClass");
- ocls.add("top");
- ocls.add("person");
- ocls.add("organizationalPerson");
- ocls.add("inetOrgPerson");
- person.put(ocls);
-
- person.put("cn", cn);
- person.put("sn", sn);
-
- return person;
- }
-
- /**
- * Creates the required attributes for an organizational unit as defined in
- * RFC 2256. The result contains an objectClass attribute with values top
- * and organizationalUnit, and the mandatory attribute ou.
- *
- * @param ou
- * common name of person
- *
- * @return attributes object with the required attributes for an
- * organizational unit
- */
- public static final Attributes createOrganizationalUnitAttributes(String ou)
- {
- Attributes person = new BasicAttributes();
-
- Attribute ocls = new BasicAttribute("objectClass");
- ocls.add("top");
- ocls.add("organizationalUnit");
- person.put(ocls);
-
- person.put("ou", ou);
-
- return person;
- }
-
-}
+/*
+ * 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.util;
+
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+
+/**
+ * Convenience methods to create attributes for entries of common objectclasses.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AttributesFactory
+{
+ /**
+ * Creates the required attributes for a person as defined in RFC 2256. The
+ * result contains an objectClass attribute with values top and person, and
+ * the attributes sn and cn.
+ *
+ * @param cn
+ * common name of person
+ * @param sn
+ * surname of person
+ *
+ * @return attributes object with the required attributes for a person
+ */
+ public static final 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;
+ }
+
+ /**
+ * Creates the required attributes for an inetOrgPerson as defined in RFC
+ * 2798 ("Definition of the inetOrgPerson LDAP Object Class"). The result
+ * contains an objectClass attribute with the appropriate values, and the
+ * attributes sn and cn, which are required from person.
+ *
+ * @param cn
+ * common name of person
+ * @param sn
+ * surname of person
+ *
+ * @return attributes object with the required attributes for an inetOrgPerson
+ */
+ public static final Attributes createInetOrgPersonAttributes(String cn, String sn)
+ {
+ Attributes person = new BasicAttributes();
+
+ Attribute ocls = new BasicAttribute("objectClass");
+ ocls.add("top");
+ ocls.add("person");
+ ocls.add("organizationalPerson");
+ ocls.add("inetOrgPerson");
+ person.put(ocls);
+
+ person.put("cn", cn);
+ person.put("sn", sn);
+
+ return person;
+ }
+
+ /**
+ * Creates the required attributes for an organizational unit as defined in
+ * RFC 2256. The result contains an objectClass attribute with values top
+ * and organizationalUnit, and the mandatory attribute ou.
+ *
+ * @param ou
+ * common name of person
+ *
+ * @return attributes object with the required attributes for an
+ * organizational unit
+ */
+ public static final Attributes createOrganizationalUnitAttributes(String ou)
+ {
+ Attributes person = new BasicAttributes();
+
+ Attribute ocls = new BasicAttribute("objectClass");
+ ocls.add("top");
+ ocls.add("organizationalUnit");
+ person.put(ocls);
+
+ person.put("ou", ou);
+
+ return person;
+ }
+
+}