Search in sources :

Example 6 with GracefulDisconnectResponseDecorator

use of org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectResponseDecorator in project directory-ldap-api by apache.

the class GracefulDisconnectResponseTest method testDecodeGracefulDisconnectTimeOffline.

/**
 * Test the decoding of a GracefulDisconnect with a timeOffline only
 */
@Test
public void testDecodeGracefulDisconnectTimeOffline() {
    Asn1Decoder decoder = new GracefulDisconnectDecoder();
    ByteBuffer bb = ByteBuffer.allocate(0x05);
    bb.put(new byte[] { // GracefulDisconnect ::= SEQUENCE {
    0x30, // GracefulDisconnect ::= SEQUENCE {
    0x03, 0x02, 0x01, // timeOffline INTEGER (0..720) DEFAULT 0,
    0x01 });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    GracefulDisconnectContainer container = new GracefulDisconnectContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
    assertEquals(1, gracefulDisconnect.getTimeOffline());
    assertEquals(0, gracefulDisconnect.getDelay());
    assertEquals(0, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size());
    // Check the length
    assertEquals(0x05, gracefulDisconnect.computeLengthInternal());
    // Check the encoding
    try {
        ByteBuffer bb1 = gracefulDisconnect.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb1.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : GracefulDisconnectContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) GracefulDisconnectDecoder(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectDecoder) GracefulDisconnectResponseDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectResponseDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)6 DecoderException (org.apache.directory.api.asn1.DecoderException)6 EncoderException (org.apache.directory.api.asn1.EncoderException)6 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)6 GracefulDisconnectContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectContainer)6 GracefulDisconnectDecoder (org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectDecoder)6 GracefulDisconnectResponseDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectResponseDecorator)6 Test (org.junit.Test)6