Search in sources :

Example 1 with GracefulShutdownRequestDecorator

use of org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator in project directory-ldap-api by apache.

the class GracefulShutdownTest method testDecodeGracefulShutdownSuccess.

/**
 * Test the decoding of a GracefulShutdown
 */
@Test
public void testDecodeGracefulShutdownSuccess() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x08);
    bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
    0x30, // GracefulShutdown ::= SEQUENCE {
    0x06, 0x02, 0x01, // timeOffline INTEGER (0..720) DEFAULT 0,
    0x01, (byte) 0x80, 0x01, // delay INTEGER (0..86400) DEFAULT
    0x01 // 0
    // }
    });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    GracefulShutdownContainer container = new GracefulShutdownContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
    assertEquals(1, gracefulShutdownRequest.getTimeOffline());
    assertEquals(1, gracefulShutdownRequest.getDelay());
    // Check the length
    assertEquals(0x08, gracefulShutdownRequest.computeLengthInternal());
    // Check the encoding
    try {
        ByteBuffer bb1 = gracefulShutdownRequest.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb1.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : GracefulShutdownRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) GracefulShutdownContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownContainer) Test(org.junit.Test)

Example 2 with GracefulShutdownRequestDecorator

use of org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator in project directory-ldap-api by apache.

the class GracefulShutdownTest method testDecodeGracefulShutdownDelay32768.

/**
 * Test the decoding of a GracefulShutdown with a delay above 32768
 */
@Test
public void testDecodeGracefulShutdownDelay32768() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x07);
    bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
    0x30, // GracefulShutdown ::= SEQUENCE {
    0x05, (byte) 0x80, 0x03, 0x00, (byte) 0x80, // delay
    (byte) 0x00 // INTEGER
    // (0..86400)
    // DEFAULT
    // 0
    });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    GracefulShutdownContainer container = new GracefulShutdownContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
    assertEquals(0, gracefulShutdownRequest.getTimeOffline());
    assertEquals(32768, gracefulShutdownRequest.getDelay());
    // Check the length
    assertEquals(0x07, gracefulShutdownRequest.computeLengthInternal());
    // Check the encoding
    try {
        ByteBuffer bb1 = gracefulShutdownRequest.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb1.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : GracefulShutdownRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) GracefulShutdownContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownContainer) Test(org.junit.Test)

Example 3 with GracefulShutdownRequestDecorator

use of org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator in project directory-ldap-api by apache.

the class GracefulShutdownTest method testDecodeGracefulShutdownDelay.

/**
 * Test the decoding of a GracefulShutdown with a delay only
 */
@Test
public void testDecodeGracefulShutdownDelay() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x05);
    bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
    0x30, // GracefulShutdown ::= SEQUENCE {
    0x03, (byte) 0x80, 0x01, // delay INTEGER (0..86400) DEFAULT
    0x01 // 0
    });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    GracefulShutdownContainer container = new GracefulShutdownContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
    assertEquals(0, gracefulShutdownRequest.getTimeOffline());
    assertEquals(1, gracefulShutdownRequest.getDelay());
    // Check the length
    assertEquals(0x05, gracefulShutdownRequest.computeLengthInternal());
    // Check the encoding
    try {
        ByteBuffer bb1 = gracefulShutdownRequest.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb1.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : GracefulShutdownRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) GracefulShutdownContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownContainer) Test(org.junit.Test)

Example 4 with GracefulShutdownRequestDecorator

use of org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator in project directory-ldap-api by apache.

the class GracefulShutdownTest method testDecodeGracefulShutdownEmpty.

/**
 * Test the decoding of a empty GracefulShutdown
 */
@Test
public void testDecodeGracefulShutdownEmpty() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x02);
    bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
    0x30, // GracefulShutdown ::= SEQUENCE {
    0x00 });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    GracefulShutdownContainer container = new GracefulShutdownContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
    assertEquals(0, gracefulShutdownRequest.getTimeOffline());
    assertEquals(0, gracefulShutdownRequest.getDelay());
    // Check the length
    assertEquals(0x02, gracefulShutdownRequest.computeLengthInternal());
    // Check the encoding
    try {
        ByteBuffer bb1 = gracefulShutdownRequest.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb1.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : GracefulShutdownRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) GracefulShutdownContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownContainer) Test(org.junit.Test)

Example 5 with GracefulShutdownRequestDecorator

use of org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator in project directory-ldap-api by apache.

the class GracefulShutdownTest method testDecodeGracefulShutdownDelay32767.

/**
 * Test the decoding of a GracefulShutdown with a delay equals 32767
 */
@Test
public void testDecodeGracefulShutdownDelay32767() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x06);
    bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
    0x30, // GracefulShutdown ::= SEQUENCE {
    0x04, (byte) 0x80, 0x02, 0x7F, // delay INTEGER
    (byte) 0xFF // (0..86400)
    // DEFAULT 0
    });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    GracefulShutdownContainer container = new GracefulShutdownContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
    assertEquals(0, gracefulShutdownRequest.getTimeOffline());
    assertEquals(32767, gracefulShutdownRequest.getDelay());
    // Check the length
    assertEquals(0x06, gracefulShutdownRequest.computeLengthInternal());
    // Check the encoding
    try {
        ByteBuffer bb1 = gracefulShutdownRequest.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb1.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : GracefulShutdownRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) GracefulShutdownContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownContainer) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)7 DecoderException (org.apache.directory.api.asn1.DecoderException)7 EncoderException (org.apache.directory.api.asn1.EncoderException)7 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)7 GracefulShutdownContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownContainer)7 GracefulShutdownRequestDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator)7 Test (org.junit.Test)7