Search in sources :

Example 1 with CodecControl

use of org.apache.directory.api.ldap.codec.api.CodecControl in project directory-ldap-api by apache.

the class SearchResultEntryTest method testDecodeSearchResultEntryEmptyAttributeValueWithControls.

/**
 * Test the decoding of a SearchResultEntry with an empty attribute value
 * with controls
 */
@Test
public void testDecodeSearchResultEntryEmptyAttributeValueWithControls() throws NamingException {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x56);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x54, 0x02, 0x01, // messageID MessageID
    0x01, 0x64, // CHOICE { ..., searchResEntry SearchResultEntry,
    0x32, // objectName LDAPDN,
    0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm', // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
    0x30, 0x13, 0x30, 0x11, // type AttributeDescription,
    0x04, 0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // vals SET OF AttributeValue }
    0x31, 0x02, // AttributeValue ::= OCTET STRING
    0x04, 0x00, (byte) 0xA0, // A control
    0x1B, 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultEntryDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
    assertEquals(1, searchResultEntry.getMessageId());
    assertEquals("ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString());
    Entry entry = searchResultEntry.getEntry();
    assertEquals(1, entry.size());
    for (int i = 0; i < entry.size(); i++) {
        Attribute attribute = entry.get("objectclass");
        assertEquals(Strings.toLowerCaseAscii("objectClass"), Strings.toLowerCaseAscii(attribute.getUpId()));
        assertTrue(attribute.contains(""));
    }
    // Check the Control
    Map<String, Control> controls = searchResultEntry.getControls();
    assertEquals(1, controls.size());
    @SuppressWarnings("unchecked") CodecControl<Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<Control>) controls.get("2.16.840.1.113730.3.4.2");
    assertEquals("2.16.840.1.113730.3.4.2", control.getOid());
    assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(searchResultEntry);
        // Check the length
        assertEquals(0x56, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) SearchResultEntryDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator) ByteBuffer(java.nio.ByteBuffer) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) Control(org.apache.directory.api.ldap.model.message.Control) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 2 with CodecControl

use of org.apache.directory.api.ldap.codec.api.CodecControl in project directory-ldap-api by apache.

the class SearchResultReferenceTest method testDecodeSearchResultReferenceSuccessWithControls.

/**
 * Test the decoding of a SearchResultReference with controls
 */
@Test
public void testDecodeSearchResultReferenceSuccessWithControls() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x3F5);
    String[] ldapUrls = new String[] { "ldap:///", "ldap://directory.apache.org:80/", "ldap://d-a.org:80/", "ldap://1.2.3.4/", "ldap://1.2.3.4:80/", "ldap://1.1.1.100000.a/", "ldap://directory.apache.org:389/dc=example,dc=org/", "ldap://directory.apache.org:389/dc=example", "ldap://directory.apache.org:389/dc=example%202,dc=org", "ldap://directory.apache.org:389/dc=example,dc=org?ou", "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc", "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou", "ldap:///o=University%20of%20Michigan,c=US", "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US", "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress", "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)", "ldap://ldap.itd.umich.edu/c=GB?objectClass?one", "ldap://ldap.question.com/o=Question%3f,c=US?mail", "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", "ldap:///??sub??bindname=cn=Manager%2co=Foo", "ldap:///??sub??!bindname=cn=Manager%2co=Foo" };
    stream.put(new byte[] { // LDAPMessage
    0x30, // LDAPMessage
    (byte) 0x82, // LDAPMessage
    0x03, // LDAPMessage
    (byte) 0xF1, // ::=SEQUENCE {
    0x02, 0x01, // messageID MessageID
    0x01, 0x73, (byte) 0x82, 0x03, // CHOICE { ...,
    (byte) 0xcd // searchResEntry
    // SearchResultEntry,
    // ...
    // SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL
    });
    for (int i = 0; i < ldapUrls.length; i++) {
        stream.put((byte) 0x04);
        stream.put((byte) Strings.getBytesUtf8(ldapUrls[i]).length);
        byte[] bytes = Strings.getBytesUtf8(ldapUrls[i]);
        for (int j = 0; j < bytes.length; j++) {
            stream.put(bytes[j]);
        }
    }
    byte[] controlBytes = new byte[] { (byte) 0xA0, // A control
    0x1B, 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 };
    for (int i = 0; i < controlBytes.length; i++) {
        stream.put(controlBytes[i]);
    }
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchResultReferenceDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultReferenceDecorator>(codec);
    try {
        ldapMessageContainer.clean();
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    stream.flip();
    SearchResultReference searchResultReference = ldapMessageContainer.getMessage();
    assertEquals(1, searchResultReference.getMessageId());
    Set<String> ldapUrlsSet = new HashSet<String>();
    for (int i = 0; i < ldapUrls.length; i++) {
        ldapUrlsSet.add(ldapUrls[i]);
    }
    Referral referral = searchResultReference.getReferral();
    assertNotNull(referral);
    for (String ldapUrl : referral.getLdapUrls()) {
        if (ldapUrlsSet.contains(ldapUrl)) {
            ldapUrlsSet.remove(ldapUrl);
        } else {
            fail(ldapUrl.toString() + " is not present");
        }
    }
    assertTrue(ldapUrlsSet.size() == 0);
    // Check the Control
    Map<String, Control> controls = searchResultReference.getControls();
    assertEquals(1, controls.size());
    @SuppressWarnings("unchecked") CodecControl<Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<Control>) controls.get("2.16.840.1.113730.3.4.2");
    assertEquals("2.16.840.1.113730.3.4.2", control.getOid());
    assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(searchResultReference);
        // Check the length
        assertEquals(0x3F5, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) ByteBuffer(java.nio.ByteBuffer) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Control(org.apache.directory.api.ldap.model.message.Control) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) Referral(org.apache.directory.api.ldap.model.message.Referral) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) SearchResultReferenceDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultReferenceDecorator) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 3 with CodecControl

use of org.apache.directory.api.ldap.codec.api.CodecControl in project directory-ldap-api by apache.

the class SearchResultDoneTest method testDecodeSearchResultDoneSuccessWithControls.

/**
 * Test the decoding of a SearchResultDone with controls
 */
@Test
public void testDecodeSearchResultDoneSuccessWithControls() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x2B);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x29, 0x02, 0x01, // messageID MessageID
    0x01, 0x65, // CHOICE { ..., searchResDone SearchResultDone, ...
    0x07, // SearchResultDone ::= [APPLICATION 5] LDAPResult
    0x0A, 0x01, // LDAPResult ::= SEQUENCE {
    0x00, // },
    0x04, // matchedDN LDAPDN,
    0x00, 0x04, // errorMessage LDAPString,
    0x00, // }
    (byte) 0xA0, // A control
    0x1B, 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchResultDoneDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultDoneDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchResultDone searchResultDone = ldapMessageContainer.getMessage();
    assertEquals(1, searchResultDone.getMessageId());
    assertEquals(ResultCodeEnum.SUCCESS, searchResultDone.getLdapResult().getResultCode());
    assertEquals("", searchResultDone.getLdapResult().getMatchedDn().getName());
    assertEquals("", searchResultDone.getLdapResult().getDiagnosticMessage());
    // Check the Control
    Map<String, Control> controls = searchResultDone.getControls();
    assertEquals(1, controls.size());
    @SuppressWarnings("unchecked") CodecControl<Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<Control>) controls.get("2.16.840.1.113730.3.4.2");
    assertEquals("2.16.840.1.113730.3.4.2", control.getOid());
    assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(searchResultDone);
        // Check the length
        assertEquals(0x2B, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) ByteBuffer(java.nio.ByteBuffer) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Control(org.apache.directory.api.ldap.model.message.Control) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) SearchResultDoneDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 4 with CodecControl

use of org.apache.directory.api.ldap.codec.api.CodecControl in project directory-ldap-api by apache.

the class AbandonRequestTest method testDecodeAbandonRequestWithControls.

/**
 * Test the decoding of a AbandonRequest with controls
 */
@Test
public void testDecodeAbandonRequestWithControls() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x64);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x62, 0x02, 0x01, // messageID MessageID
    0x03, 0x50, 0x01, // CHOICE { ..., abandonRequest
    0x02, // AbandonRequest,...
    (byte) 0xA0, // controls [0] Controls OPTIONAL }
    0x5A, 0x30, // Control ::= SEQUENCE {
    0x1A, // controlType LDAPOID,
    0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1', // criticality BOOLEAN DEFAULT FALSE,
    0x01, 0x01, (byte) 0xFF, // controlValue OCTET STRING OPTIONAL }
    0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 0x30, // Control ::= SEQUENCE {
    0x17, // controlType LDAPOID,
    0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', // controlValue OCTET STRING OPTIONAL }
    0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l', 0x30, // Control ::= SEQUENCE {
    0x12, // controlType LDAPOID,
    0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3', // criticality BOOLEAN DEFAULT FALSE }
    0x01, 0x01, (byte) 0xFF, 0x30, // Control ::= SEQUENCE {
    0x0F, // controlType LDAPOID}
    0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' });
    stream.flip();
    // Allocate a LdapMessageContainer Container
    LdapMessageContainer<AbandonRequestDecorator> ldapMessageContainer = new LdapMessageContainer<AbandonRequestDecorator>(codec);
    // Decode the PDU
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    // Check that everything is OK
    AbandonRequestDecorator abandonRequest = ldapMessageContainer.getMessage();
    // Copy the message
    AbandonRequest internalAbandonRequest = new AbandonRequestImpl(abandonRequest.getAbandoned());
    internalAbandonRequest.setMessageId(abandonRequest.getMessageId());
    assertEquals(3, abandonRequest.getMessageId());
    assertEquals(2, abandonRequest.getAbandoned());
    // Check the Controls
    Map<String, Control> controls = abandonRequest.getControls();
    assertEquals(4, controls.size());
    CodecControl<? extends Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<?>) controls.get("1.3.6.1.5.5.1");
    assertEquals("1.3.6.1.5.5.1", control.getOid());
    assertEquals("0x61 0x62 0x63 0x64 0x65 0x66 ", Strings.dumpBytes((byte[]) control.getValue()));
    assertTrue(control.isCritical());
    internalAbandonRequest.addControl(control);
    control = (org.apache.directory.api.ldap.codec.api.CodecControl<?>) controls.get("1.3.6.1.5.5.2");
    assertEquals("1.3.6.1.5.5.2", control.getOid());
    assertEquals("0x67 0x68 0x69 0x6A 0x6B 0x6C ", Strings.dumpBytes((byte[]) control.getValue()));
    assertFalse(control.isCritical());
    internalAbandonRequest.addControl(control);
    control = (org.apache.directory.api.ldap.codec.api.CodecControl<?>) controls.get("1.3.6.1.5.5.3");
    assertEquals("1.3.6.1.5.5.3", control.getOid());
    assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
    assertTrue(control.isCritical());
    internalAbandonRequest.addControl(control);
    control = (org.apache.directory.api.ldap.codec.api.CodecControl<?>) controls.get("1.3.6.1.5.5.4");
    assertEquals("1.3.6.1.5.5.4", control.getOid());
    assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
    assertFalse(control.isCritical());
    internalAbandonRequest.addControl(control);
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(internalAbandonRequest);
        // Check the length
        assertEquals(0x64, bb.limit());
        // So we decode the generated PDU, and we compare it with the initial message
        try {
            ldapDecoder.decode(bb, ldapMessageContainer);
        } catch (DecoderException de) {
            de.printStackTrace();
            fail(de.getMessage());
        }
        AbandonRequest abandonRequest2 = ldapMessageContainer.getMessage();
        assertEquals(abandonRequest, abandonRequest2);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) AbandonRequest(org.apache.directory.api.ldap.model.message.AbandonRequest) ByteBuffer(java.nio.ByteBuffer) AbandonRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator) AbandonRequestImpl(org.apache.directory.api.ldap.model.message.AbandonRequestImpl) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Control(org.apache.directory.api.ldap.model.message.Control) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 5 with CodecControl

use of org.apache.directory.api.ldap.codec.api.CodecControl in project directory-ldap-api by apache.

the class AddRequestTest method testDecodeAddRequestEmptyAttributeValueWithControl.

/**
 * Test the decoding of a AddRequest with a empty attributeList and a
 * control
 */
@Test
public void testDecodeAddRequestEmptyAttributeValueWithControl() throws NamingException {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x51);
    stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
    0x4F, 0x02, 0x01, // messageID MessageID
    0x01, 0x68, // CHOICE { ..., addRequest AddRequest, ...
    0x2D, // entry LDAPDN,
    0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', // attributes AttributeList }
    0x30, // AttributeList ::= SEQUENCE OF SEQUENCE {
    0x09, 0x30, // attribute 1
    0x07, 0x04, 0x01, // type AttributeDescription,
    'l', 0x31, 0x02, 0x04, 0x00, (byte) 0xA0, // A control
    0x1B, 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<AddRequestDecorator> container = new LdapMessageContainer<AddRequestDecorator>(codec);
    // Decode a AddRequest message
    try {
        ldapDecoder.decode(stream, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    AddRequest addRequest = container.getMessage();
    // Check the decoded message
    assertEquals(1, addRequest.getMessageId());
    assertEquals("cn=testModify,ou=users,ou=system", addRequest.getEntryDn().toString());
    Entry entry = addRequest.getEntry();
    assertEquals(1, entry.size());
    Attribute attribute = entry.get("l");
    assertEquals("l", Strings.toLowerCaseAscii(attribute.getId()));
    for (Value value : attribute) {
        assertEquals("", value.getValue());
    }
    // Check the Control
    Map<String, Control> controls = addRequest.getControls();
    assertEquals(1, controls.size());
    assertTrue(addRequest.hasControl("2.16.840.1.113730.3.4.2"));
    @SuppressWarnings("unchecked") CodecControl<Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<Control>) controls.get("2.16.840.1.113730.3.4.2");
    assertEquals("2.16.840.1.113730.3.4.2", control.getOid());
    assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(addRequest);
        // Check the length
        assertEquals(0x51, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) ByteBuffer(java.nio.ByteBuffer) AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Entry(org.apache.directory.api.ldap.model.entry.Entry) Control(org.apache.directory.api.ldap.model.message.Control) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) Value(org.apache.directory.api.ldap.model.entry.Value) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) AddRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)34 Control (org.apache.directory.api.ldap.model.message.Control)34 ByteBuffer (java.nio.ByteBuffer)33 DecoderException (org.apache.directory.api.asn1.DecoderException)32 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)32 Test (org.junit.Test)32 EncoderException (org.apache.directory.api.asn1.EncoderException)31 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)31 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)31 ExtendedResponseDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator)4 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)4 BindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator)3 Entry (org.apache.directory.api.ldap.model.entry.Entry)3 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)3 AbandonRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator)2 ExtendedRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator)2 IntermediateResponseDecorator (org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator)2 ModifyDnRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyDnRequestDecorator)2 SearchResultEntryDecorator (org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator)2 UpdateControls (org.apache.directory.api.ldap.extras.extended.endTransaction.UpdateControls)2