Search in sources :

Example 91 with EncoderException

use of org.apache.directory.api.asn1.EncoderException 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 92 with EncoderException

use of org.apache.directory.api.asn1.EncoderException 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 93 with EncoderException

use of org.apache.directory.api.asn1.EncoderException 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 94 with EncoderException

use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.

the class StoredProcedureTest method testDecodeStoredProcedureOneParam.

@Test
public void testDecodeStoredProcedureOneParam() throws IntegerDecoderException {
    Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x1D);
    stream.put(new byte[] { 0x30, 0x1B, 0x04, 0x04, 'J', 'a', 'v', 'a', 0x04, 0x07, 'e', 'x', 'e', 'c', 'u', 't', 'e', 0x30, 0x0A, 0x30, 0x08, 0x04, 0x03, 'i', 'n', 't', 0x04, 0x01, 0x01 });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a StoredProcedure Container
    StoredProcedureContainer storedProcedureContainer = new StoredProcedureContainer();
    // Decode a StoredProcedure message
    try {
        storedProcedureDecoder.decode(stream, storedProcedureContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    StoredProcedureRequestDecorator storedProcedure = storedProcedureContainer.getStoredProcedure();
    assertEquals("Java", storedProcedure.getLanguage());
    assertEquals("execute", storedProcedure.getProcedureSpecification());
    assertEquals(1, storedProcedure.size());
    assertEquals("int", Strings.utf8ToString((byte[]) storedProcedure.getParameterType(0)));
    assertEquals(1, IntegerDecoder.parse(new BerValue((byte[]) storedProcedure.getParameterValue(0))));
    // Check the encoding
    try {
        ByteBuffer bb = storedProcedure.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : StoredProcedureDecoder(org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureDecoder) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) StoredProcedureContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureContainer) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) StoredProcedureRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureRequestDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 95 with EncoderException

use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.

the class AdDirSyncControlTest method testAdDirSyncControl.

@Test
public void testAdDirSyncControl() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0F);
    bb.put(new byte[] { 0x30, 0x0D, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
    0x02, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
    0x02, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
    0x08, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
    0x01, // maxReturnLength (no limit)
    0x02, // maxReturnLength (no limit)
    0x01, // maxReturnLength (no limit)
    0x00, // the cookie
    0x04, // the cookie
    0x04, // the cookie
    'x', // the cookie
    'k', // the cookie
    'c', // the cookie
    'd' });
    bb.flip();
    AdDirSync decorator = new AdDirSyncDecorator(codec);
    AdDirSync adDirSync = (AdDirSync) ((AdDirSyncDecorator) decorator).decode(bb.array());
    assertEquals(EnumSet.of(AdDirSyncFlag.LDAP_DIRSYNC_OBJECT_SECURITY, AdDirSyncFlag.LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER), adDirSync.getFlags());
    assertEquals(0, adDirSync.getMaxReturnLength());
    assertEquals("xkcd", Strings.utf8ToString(adDirSync.getCookie()));
    // test encoding
    try {
        ByteBuffer buffer = ((AdDirSyncDecorator) adDirSync).encode(ByteBuffer.allocate(((AdDirSyncDecorator) adDirSync).computeLength()));
        String expected = "0x30 0x0D 0x02 0x02 0x08 0x01 0x02 0x01 0x00 0x04 0x04 0x78 0x6B 0x63 0x64 ";
        String decoded = Strings.dumpBytes(buffer.array());
        assertEquals(expected, decoded);
    } catch (EncoderException e) {
        fail(e.getMessage());
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) AdDirSyncDecorator(org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Aggregations

EncoderException (org.apache.directory.api.asn1.EncoderException)226 ByteBuffer (java.nio.ByteBuffer)191 Test (org.junit.Test)189 DecoderException (org.apache.directory.api.asn1.DecoderException)151 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)150 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)127 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)124 BufferOverflowException (java.nio.BufferOverflowException)40 Control (org.apache.directory.api.ldap.model.message.Control)38 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)35 AbstractCodecServiceTest (org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)35 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)33 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)33 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)28 SyncInfoValue (org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValue)20 SyncInfoValueDecorator (org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator)20 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)20 AndNode (org.apache.directory.api.ldap.model.filter.AndNode)15 Entry (org.apache.directory.api.ldap.model.entry.Entry)14 EqualityNode (org.apache.directory.api.ldap.model.filter.EqualityNode)14