Search in sources :

Example 6 with UnbindRequest

use of org.apache.directory.api.ldap.model.message.UnbindRequest in project directory-ldap-api by apache.

the class UnBindRequestTest method testDecodeUnBindRequestNoControls.

/**
 * Test the decoding of a UnBindRequest with no controls
 */
@Test
public void testDecodeUnBindRequestNoControls() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x07);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x05, 0x02, 0x01, // messageID MessageID
    0x01, 0x42, // CHOICE { ..., unbindRequest UnbindRequest,...
    0x00 // UnbindRequest ::= [APPLICATION 2] NULL
    });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<UnbindRequestDecorator> ldapMessageContainer = new LdapMessageContainer<UnbindRequestDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    UnbindRequest unbindRequest = ldapMessageContainer.getMessage();
    assertEquals(1, unbindRequest.getMessageId());
    // Check the encoding
    UnbindRequest internalUnbindRequest = new UnbindRequestImpl();
    internalUnbindRequest.setMessageId(unbindRequest.getMessageId());
    try {
        ByteBuffer bb = encoder.encodeMessage(internalUnbindRequest);
        // Check the length
        assertEquals(0x07, 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) UnbindRequestImpl(org.apache.directory.api.ldap.model.message.UnbindRequestImpl) UnbindRequestDecorator(org.apache.directory.api.ldap.codec.decorators.UnbindRequestDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) UnbindRequest(org.apache.directory.api.ldap.model.message.UnbindRequest) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

UnbindRequest (org.apache.directory.api.ldap.model.message.UnbindRequest)6 UnbindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.UnbindRequestDecorator)5 UnbindRequestImpl (org.apache.directory.api.ldap.model.message.UnbindRequestImpl)5 DecoderException (org.apache.directory.api.asn1.DecoderException)4 ByteBuffer (java.nio.ByteBuffer)3 EncoderException (org.apache.directory.api.asn1.EncoderException)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)3 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)3 Test (org.junit.Test)3 Control (org.apache.directory.api.ldap.model.message.Control)2 IOException (java.io.IOException)1 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)1 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