mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
14.49.2012 0d5f5ba8ed70611b05aeef5bcd368b8bbe16b5e8
Fix OPENDJ-592: Make it easier to create child DNs
2 files modified
47 ■■■■■ changed files
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/DN.java 23 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/DNTestCase.java 24 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/DN.java
@@ -343,6 +343,29 @@
    }
    /**
     * Returns a DN which is an immediate child of this DN and with an RDN
     * having the provided attribute type and value decoded using the default
     * schema.
     * <p>
     * If {@code attributeValue} is not an instance of {@code ByteString} then
     * it will be converted using the {@link ByteString#valueOf(Object)} method.
     *
     * @param attributeType
     *            The attribute type.
     * @param attributeValue
     *            The attribute value.
     * @return The child DN.
     * @throws UnknownSchemaElementException
     *             If {@code attributeType} was not found in the default schema.
     * @throws NullPointerException
     *             If {@code attributeType} or {@code attributeValue} was
     *             {@code null}.
     */
    public DN child(final String attributeType, final Object attributeValue) {
        return child(new RDN(attributeType, attributeValue));
    }
    /**
     * {@inheritDoc}
     */
    public int compareTo(final DN dn) {
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/DNTestCase.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright 2010 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS.
 *      Portions copyright 2011-2012 ForgeRock AS.
 */
package org.forgerock.opendj.ldap;
@@ -435,6 +435,28 @@
    }
    /**
     * Test the child(String attributeType, Object attributeValue) method.
     *
     * @param s
     *            The test DN string.
     * @param r
     *            The RDN to be appended.
     * @param e
     *            The expected DN.
     * @throws Exception
     *             If the test failed unexpectedly.
     */
    @Test(dataProvider = "createChildRDNTestData")
    public void testChildTypeValue(final String s, final String r, final String e) throws Exception {
        final DN dn = DN.valueOf(s);
        final RDN rdn = RDN.valueOf(r);
        final DN expected = DN.valueOf(e);
        assertEquals(dn.child(rdn.getFirstAVA().getAttributeType().getNameOrOID(), rdn
                .getFirstAVA().getAttributeValue()), expected);
    }
    /**
     * Test DN compareTo
     *
     * @param first