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

Violette Roche-Montane
01.18.2013 8a55965faf6e9e8939bf21b0ea5c7e13afbc2433
OPENDJ-1162 Rest2LDAP returns an invalid binary attribute value
- added unit tests for attribute conversions.
- fixed wrong invalid conversion.
Thanks to Matt && Jean-Noel again :)
2 files modified
34 ■■■■■ changed files
opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java 2 ●●● patch | view | raw | blame | history
opendj3/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java 32 ●●●●● patch | view | raw | blame | history
opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java
@@ -546,7 +546,7 @@
            final org.opends.server.types.Attribute attribute) {
        Attribute sdkAttribute = new LinkedAttribute(attribute.getNameWithOptions());
        for (AttributeValue value : attribute) {
            sdkAttribute.add(value);
            sdkAttribute.add(from(value.getValue()));
        }
        return sdkAttribute;
    }
opendj3/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java
@@ -59,11 +59,15 @@
import org.forgerock.testng.ForgeRockTestCase;
import org.opends.server.core.BindOperation;
import org.opends.server.core.CompareOperation;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ExtendedOperation;
import org.opends.server.core.SearchOperation;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.ldap.LDAPFilter;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.AttributeValues;
import org.opends.server.types.Attributes;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.FilterType;
import org.opends.server.types.LDAPException;
@@ -439,6 +443,34 @@
    }
    /**
     * Converts an LDAP attribute to an SDK attribute.
     */
    @Test(groups = { "needRunningServer" })
    public final void testFromAttribute() throws DirectoryException {
        final org.opends.server.types.Attribute srvAttribute = Attributes.create("CN", "JOHN DOE");
        final org.forgerock.opendj.ldap.Attribute sdkAttribute = from(srvAttribute);
        assertThat(sdkAttribute.getAttributeDescriptionAsString()).isEqualTo("CN");
        assertThat(sdkAttribute.size()).isEqualTo(1);
        assertThat(sdkAttribute.firstValueAsString()).isEqualTo("JOHN DOE");
    }
    /**
     * Converts an LDAP attribute to an SDK attribute using binary attribute value.
     */
    @Test(groups = { "needRunningServer" })
    public final void testFromAttributeUsingBinary() throws DirectoryException {
        byte[] data = { 0x00, 0x01, 0x02, (byte) 0xff };
        AttributeValue value = AttributeValues.create(org.opends.server.types.ByteString.wrap(data),
                org.opends.server.types.ByteString.wrap(data));
        Attribute attribute = Attributes.create(DirectoryServer.getAttributeType("cn"), value);
        assertThat(from(attribute).firstValue().toByteArray()).isEqualTo(data);
    }
    /**
     * Converts an LDAP byte string to an SDK byte string.
     */
    @Test()