Search in sources :

Example 6 with SearchResultDoneDecorator

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

the class SearchResultDoneTest method testDecodeSearchResultDoneSuccess.

/**
 * Test the decoding of a SearchResultDone
 */
@Test
public void testDecodeSearchResultDoneSuccess() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x0E);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x0C, 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 // referral [3] Referral OPTIONAL }
    // }
    });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a SearchResultDone 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 encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(searchResultDone);
        // Check the length
        assertEquals(0x0E, 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) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) SearchResultDoneDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

SearchResultDoneDecorator (org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator)6 ByteBuffer (java.nio.ByteBuffer)4 DecoderException (org.apache.directory.api.asn1.DecoderException)4 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)4 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)4 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)4 SearchResultDone (org.apache.directory.api.ldap.model.message.SearchResultDone)4 Test (org.junit.Test)4 EncoderException (org.apache.directory.api.asn1.EncoderException)3 Control (org.apache.directory.api.ldap.model.message.Control)2 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)1 AbandonRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator)1 AddRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator)1 AddResponseDecorator (org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator)1 BindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator)1 BindResponseDecorator (org.apache.directory.api.ldap.codec.decorators.BindResponseDecorator)1 CompareRequestDecorator (org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator)1 CompareResponseDecorator (org.apache.directory.api.ldap.codec.decorators.CompareResponseDecorator)1 DeleteRequestDecorator (org.apache.directory.api.ldap.codec.decorators.DeleteRequestDecorator)1 DeleteResponseDecorator (org.apache.directory.api.ldap.codec.decorators.DeleteResponseDecorator)1