Search in sources :

Example 6 with GracefulShutdownContainer

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

the class GracefulShutdownTest method testDecodeGracefulShutdownTimeOfflineOffLimit.

// Defensive tests
/**
 * Test the decoding of a GracefulShutdown with a timeOffline off limit
 */
@Test
public void testDecodeGracefulShutdownTimeOfflineOffLimit() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x06);
    bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
    0x30, // GracefulShutdown ::= SEQUENCE {
    0x04, 0x02, 0x02, 0x03, // timeOffline INTEGER (0..720)
    (byte) 0xE8 // DEFAULT 0,
    });
    bb.flip();
    GracefulShutdownContainer container = new GracefulShutdownContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        assertTrue(true);
        return;
    }
    fail("We should not reach this point");
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) 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 7 with GracefulShutdownContainer

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

the class GracefulShutdownTest method testDecodeGracefulShutdownDelayEmpty.

/**
 * Test the decoding of a GracefulShutdown with an empty delay
 */
@Test
public void testDecodeGracefulShutdownDelayEmpty() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x0b);
    bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
    0x30, // GracefulShutdown ::= SEQUENCE {
    0x02, (byte) 0x80, // delay INTEGER (0..86400) DEFAULT 0
    0x00 });
    bb.flip();
    GracefulShutdownContainer container = new GracefulShutdownContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        assertTrue(true);
        return;
    }
    fail("We should not reach this point");
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) 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 8 with GracefulShutdownContainer

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

Example 9 with GracefulShutdownContainer

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

the class GracefulShutdownTest method testDecodeGracefulShutdownDelayHigh.

/**
 * Test the decoding of a GracefulShutdown with a delay above 128
 */
@Test
public void testDecodeGracefulShutdownDelayHigh() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x06);
    bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
    0x30, // GracefulShutdown ::= SEQUENCE {
    0x04, (byte) 0x80, 0x02, 0x01, // delay INTEGER
    (byte) 0xF4 // (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(500, 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)

Example 10 with GracefulShutdownContainer

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

the class GracefulShutdownTest method testDecodeGracefulShutdownTimeOfflineEmpty.

/**
 * Test the decoding of a GracefulShutdown with an empty TimeOffline
 */
@Test
public void testDecodeGracefulShutdownTimeOfflineEmpty() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x0b);
    bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
    0x30, // GracefulShutdown ::= SEQUENCE {
    0x02, 0x02, // timeOffline INTEGER (0..720) DEFAULT 0,
    0x00 });
    bb.flip();
    GracefulShutdownContainer container = new GracefulShutdownContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        assertTrue(true);
        return;
    }
    fail("We should not reach this point");
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) 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)11 DecoderException (org.apache.directory.api.asn1.DecoderException)11 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)11 GracefulShutdownContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownContainer)11 Test (org.junit.Test)11 EncoderException (org.apache.directory.api.asn1.EncoderException)7 GracefulShutdownRequestDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator)7