Search in sources :

Example 1 with StoredProcedureDecoder

use of org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureDecoder 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 2 with StoredProcedureDecoder

use of org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureDecoder in project directory-ldap-api by apache.

the class StoredProcedureTest method testDecodeStoredProcedureNParams.

@Test
public void testDecodeStoredProcedureNParams() throws IntegerDecoderException {
    Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x44);
    stream.put(new byte[] { 0x30, 0x42, 0x04, 0x04, 'J', 'a', 'v', 'a', 0x04, 0x07, 'e', 'x', 'e', 'c', 'u', 't', 'e', 0x30, 0x31, 0x30, 0x08, 0x04, 0x03, 'i', 'n', 't', 0x04, 0x01, 0x01, 0x30, 0x0F, 0x04, 0x07, 'b', 'o', 'o', 'l', 'e', 'a', 'n', 0x04, 0x04, 't', 'r', 'u', 'e', 0x30, 0x14, 0x04, 0x06, 'S', 't', 'r', 'i', 'n', 'g', 0x04, 0x0A, 'p', 'a', 'r', 'a', 'm', 'e', 't', 'e', 'r', '3' });
    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(3, storedProcedure.size());
    assertEquals("int", Strings.utf8ToString((byte[]) storedProcedure.getParameterType(0)));
    assertEquals(1, IntegerDecoder.parse(new BerValue((byte[]) storedProcedure.getParameterValue(0))));
    assertEquals("boolean", Strings.utf8ToString((byte[]) storedProcedure.getParameterType(1)));
    assertEquals("true", Strings.utf8ToString((byte[]) storedProcedure.getParameterValue(1)));
    assertEquals("String", Strings.utf8ToString((byte[]) storedProcedure.getParameterType(2)));
    assertEquals("parameter3", Strings.utf8ToString((byte[]) storedProcedure.getParameterValue(2)));
    // 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 3 with StoredProcedureDecoder

use of org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureDecoder in project directory-ldap-api by apache.

the class StoredProcedureTest method testDecodeStoredProcedureNoParam.

@Test
public void testDecodeStoredProcedureNoParam() {
    Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x13);
    stream.put(new byte[] { 0x30, 0x11, 0x04, 0x04, 'J', 'a', 'v', 'a', 0x04, 0x07, 'e', 'x', 'e', 'c', 'u', 't', 'e', 0x30, 0x00 });
    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(0, storedProcedure.size());
    // 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) StoredProcedureRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureRequestDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)3 DecoderException (org.apache.directory.api.asn1.DecoderException)3 EncoderException (org.apache.directory.api.asn1.EncoderException)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 IntegerDecoderException (org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)3 StoredProcedureContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureContainer)3 StoredProcedureDecoder (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureDecoder)3 StoredProcedureRequestDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureRequestDecorator)3 Test (org.junit.Test)3 BerValue (org.apache.directory.api.asn1.ber.tlv.BerValue)2