Search in sources :

Example 1 with CancelRequestDecorator

use of org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelRequestDecorator in project directory-ldap-api by apache.

the class CancelRequestTest method testDecodeCancel.

/**
 * Test the normal Cancel message
 */
@Test
public void testDecodeCancel() {
    Asn1Decoder cancelDecoder = new CancelDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x05);
    stream.put(new byte[] { 0x30, 0x03, 0x02, 0x01, 0x01 }).flip();
    String decodedPdu = Strings.dumpBytes(stream.array());
    // Allocate a Cancel Container
    Asn1Container cancelContainer = new CancelContainer();
    // Decode a Cancel message
    try {
        cancelDecoder.decode(stream, cancelContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    CancelRequestDecorator cancel = ((CancelContainer) cancelContainer).getCancel();
    assertEquals(1, cancel.getCancelId());
    // Check the encoding
    try {
        ByteBuffer bb = cancel.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) CancelDecoder(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CancelRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelRequestDecorator) CancelContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 DecoderException (org.apache.directory.api.asn1.DecoderException)1 EncoderException (org.apache.directory.api.asn1.EncoderException)1 Asn1Container (org.apache.directory.api.asn1.ber.Asn1Container)1 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)1 CancelContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer)1 CancelDecoder (org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder)1 CancelRequestDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelRequestDecorator)1 Test (org.junit.Test)1