Search in sources :

Example 1 with EndTransactionRequest

use of org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest in project directory-ldap-api by apache.

the class EndTransactionRequestTest method testEndTransactionRequestNoCommitIdentifier.

/**
 * Test the decoding of a EndTransactionRequest with an identifier but no commit
 * @throws EncoderException
 */
@Test
public void testEndTransactionRequestNoCommitIdentifier() throws EncoderException {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x08);
    bb.put(new byte[] { // EndTransactionRequest ::= SEQUENCE {
    0x30, // EndTransactionRequest ::= SEQUENCE {
    0x06, // identifier (test)
    0x04, // identifier (test)
    0x04, // identifier (test)
    't', // identifier (test)
    'e', // identifier (test)
    's', // identifier (test)
    't' });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    EndTransactionRequestContainer container = new EndTransactionRequestContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    EndTransactionRequest endTransactionRequest = container.getEndTransactionRequest();
    assertTrue(endTransactionRequest.getCommit());
    assertEquals("test", Strings.utf8ToString(endTransactionRequest.getTransactionId()));
    // Check the length
    assertEquals(0x08, ((EndTransactionRequestDecorator) endTransactionRequest).computeLengthInternal());
    // Check the encoding
    ByteBuffer bb1 = ((EndTransactionRequestDecorator) endTransactionRequest).encodeInternal();
    String encodedPdu = Strings.dumpBytes(bb1.array());
    assertEquals(encodedPdu, decodedPdu);
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) EndTransactionRequest(org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest) Test(org.junit.Test)

Example 2 with EndTransactionRequest

use of org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest in project directory-ldap-api by apache.

the class EndTransactionRequestTest method testEndTransactionRequesoCommitEmptyIdentifier.

/**
 * Test the decoding of a EndTransactionRequest with an empty identifier and a commit
 * @throws EncoderException
 */
@Test
public void testEndTransactionRequesoCommitEmptyIdentifier() throws EncoderException {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x07);
    bb.put(new byte[] { // EndTransactionRequest ::= SEQUENCE {
    0x30, // EndTransactionRequest ::= SEQUENCE {
    0x05, // Commit, FALSE
    0x01, // Commit, FALSE
    0x01, // Commit, FALSE
    0x00, // identifier (empty)
    0x04, // identifier (empty)
    0x00 });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    EndTransactionRequestContainer container = new EndTransactionRequestContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    EndTransactionRequest endTransactionRequest = container.getEndTransactionRequest();
    assertFalse(endTransactionRequest.getCommit());
    assertEquals(0, endTransactionRequest.getTransactionId().length);
    // Check the length
    assertEquals(0x07, ((EndTransactionRequestDecorator) endTransactionRequest).computeLengthInternal());
    // Check the encoding
    ByteBuffer bb1 = ((EndTransactionRequestDecorator) endTransactionRequest).encodeInternal();
    String encodedPdu = Strings.dumpBytes(bb1.array());
    assertEquals(encodedPdu, decodedPdu);
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) EndTransactionRequest(org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest) Test(org.junit.Test)

Example 3 with EndTransactionRequest

use of org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest in project directory-ldap-api by apache.

the class EndTransactionRequestTest method testEndTransactionRequesoCommitIdentifier.

/**
 * Test the decoding of a EndTransactionRequest with an identifier and a commit
 * @throws EncoderException
 */
@Test
public void testEndTransactionRequesoCommitIdentifier() throws EncoderException {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x0B);
    bb.put(new byte[] { // EndTransactionRequest ::= SEQUENCE {
    0x30, // EndTransactionRequest ::= SEQUENCE {
    0x09, // Commit, FALSE
    0x01, // Commit, FALSE
    0x01, // Commit, FALSE
    0x00, // identifier (test)
    0x04, // identifier (test)
    0x04, // identifier (test)
    't', // identifier (test)
    'e', // identifier (test)
    's', // identifier (test)
    't' });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    EndTransactionRequestContainer container = new EndTransactionRequestContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    EndTransactionRequest endTransactionRequest = container.getEndTransactionRequest();
    assertFalse(endTransactionRequest.getCommit());
    assertEquals("test", Strings.utf8ToString(endTransactionRequest.getTransactionId()));
    // Check the length
    assertEquals(0x0B, ((EndTransactionRequestDecorator) endTransactionRequest).computeLengthInternal());
    // Check the encoding
    ByteBuffer bb1 = ((EndTransactionRequestDecorator) endTransactionRequest).encodeInternal();
    String encodedPdu = Strings.dumpBytes(bb1.array());
    assertEquals(encodedPdu, decodedPdu);
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) EndTransactionRequest(org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)3 DecoderException (org.apache.directory.api.asn1.DecoderException)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 EndTransactionRequest (org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest)3 Test (org.junit.Test)3