Search in sources :

Example 1 with CancelContainer

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

the class CancelRequestTest method testDecodeCancelBadCancelId.

/**
 * Test a Cancel message with a bad cancelId
 */
@Test
public void testDecodeCancelBadCancelId() {
    Asn1Decoder cancelDecoder = new CancelDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x08);
    stream.put(new byte[] { 0x30, 0x06, 0x02, 0x04, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }).flip();
    // Allocate a Cancel Container
    Asn1Container cancelContainer = new CancelContainer();
    // Decode a Cancel message
    try {
        cancelDecoder.decode(stream, cancelContainer);
        fail("CancelID expected");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) 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) CancelContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with CancelContainer

use of org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer 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)

Example 3 with CancelContainer

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

the class CancelRequestTest method testDecodeCancelEmptyCancelId.

/**
 * Test a Cancel message with an empty cancelId
 */
@Test
public void testDecodeCancelEmptyCancelId() {
    Asn1Decoder cancelDecoder = new CancelDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x04);
    stream.put(new byte[] { 0x30, 0x02, 0x02, 0x00 }).flip();
    // Allocate a Cancel Container
    Asn1Container cancelContainer = new CancelContainer();
    // Decode a Cancel message
    try {
        cancelDecoder.decode(stream, cancelContainer);
        fail("CancelID expected");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) 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) CancelContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with CancelContainer

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

the class CancelRequestTest method testDecodeCancelMoreThanOneCancelId.

/**
 * Test a Cancel message with more than one cancelId
 */
@Test
public void testDecodeCancelMoreThanOneCancelId() {
    Asn1Decoder cancelDecoder = new CancelDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x08);
    stream.put(new byte[] { 0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x02 }).flip();
    // Allocate a Cancel Container
    Asn1Container cancelContainer = new CancelContainer();
    // Decode a Cancel message
    try {
        cancelDecoder.decode(stream, cancelContainer);
        fail("CancelID expected");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) 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) CancelContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with CancelContainer

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

the class CancelRequestTest method testDecodeCancelNoCancelId.

/**
 * Test a Cancel message with no cancelId
 */
@Test
public void testDecodeCancelNoCancelId() {
    Asn1Decoder cancelDecoder = new CancelDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x02);
    stream.put(new byte[] { 0x30, 0x00 }).flip();
    // Allocate a Cancel Container
    Asn1Container cancelContainer = new CancelContainer();
    // Decode a Cancel message
    try {
        cancelDecoder.decode(stream, cancelContainer);
        fail("CancelID expected");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) 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) 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)5 DecoderException (org.apache.directory.api.asn1.DecoderException)5 Asn1Container (org.apache.directory.api.asn1.ber.Asn1Container)5 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)5 CancelContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer)5 CancelDecoder (org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder)5 Test (org.junit.Test)5 EncoderException (org.apache.directory.api.asn1.EncoderException)1 CancelRequestDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelRequestDecorator)1