Search in sources :

Example 96 with EncoderException

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

the class SyncDoneValueControlTest method testSyncDoneValueControl.

@Test
public void testSyncDoneValueControl() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(11);
    bb.put(new byte[] { 0x30, 0x09, // the cookie
    0x04, // the cookie
    0x04, // the cookie
    'x', // the cookie
    'k', // the cookie
    'c', // the cookie
    'd', 0x01, 0x01, // refreshDeletes flag TRUE
    (byte) 0xFF });
    bb.flip();
    SyncDoneValue decorator = new SyncDoneValueDecorator(codec);
    SyncDoneValue control = (SyncDoneValue) ((SyncDoneValueDecorator) decorator).decode(bb.array());
    assertEquals("xkcd", Strings.utf8ToString(control.getCookie()));
    assertTrue(control.isRefreshDeletes());
    // test encoding
    try {
        ByteBuffer buffer = ((SyncDoneValueDecorator) control).encode(ByteBuffer.allocate(((SyncDoneValueDecorator) control).computeLength()));
        String expected = Strings.dumpBytes(bb.array());
        String decoded = Strings.dumpBytes(buffer.array());
        assertEquals(expected, decoded);
    } catch (EncoderException e) {
        fail(e.getMessage());
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncDoneValueDecorator(org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncDoneValueDecorator) SyncDoneValue(org.apache.directory.api.ldap.extras.controls.syncrepl.syncDone.SyncDoneValue) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 97 with EncoderException

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

the class SyncRequestValueControlTest method testDecodeSyncRequestValueControlNoReloadHintSuccess.

/**
 * Test the decoding of a SyncRequestValue control with no reloadHint
 */
@Test
public void testDecodeSyncRequestValueControlNoReloadHintSuccess() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0A);
    bb.put(new byte[] { // syncRequestValue ::= SEQUENCE {
    0x30, // syncRequestValue ::= SEQUENCE {
    0x08, 0x0A, 0x01, // mode ENUMERATED {
    0x03, // }
    0x04, 0x03, 'a', 'b', // cookie syncCookie OPTIONAL,
    'c' });
    bb.flip();
    SyncRequestValue decorator = new SyncRequestValueDecorator(codec);
    SyncRequestValue syncRequestValue = (SyncRequestValue) ((SyncRequestValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationModeEnum.REFRESH_AND_PERSIST, syncRequestValue.getMode());
    assertEquals("abc", Strings.utf8ToString(syncRequestValue.getCookie()));
    assertEquals(false, syncRequestValue.isReloadHint());
    // Check the encoding
    try {
        ByteBuffer buffer = ((SyncRequestValueDecorator) syncRequestValue).encode(ByteBuffer.allocate(((SyncRequestValueDecorator) syncRequestValue).computeLength()));
        String decoded = Strings.dumpBytes(buffer.array());
        String expected = Strings.dumpBytes(bb.array());
        assertEquals(expected, decoded);
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncRequestValue(org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue) ByteBuffer(java.nio.ByteBuffer) SyncRequestValueDecorator(org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 98 with EncoderException

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

the class SyncRequestValueControlTest method testDecodeSyncRequestValueControlNoCookieReloadHintTrue.

/**
 * Test the decoding of a SyncRequestValue control with no cookie, a true
 * reloadHint
 */
@Test
public void testDecodeSyncRequestValueControlNoCookieReloadHintTrue() throws Exception {
    ByteBuffer buffer = ByteBuffer.allocate(0x08);
    buffer.put(new byte[] { // syncRequestValue ::= SEQUENCE {
    0x30, // syncRequestValue ::= SEQUENCE {
    0x06, 0x0A, 0x01, // mode ENUMERATED {
    0x03, // }
    0x01, 0x01, // reloadHint BOOLEAN DEFAULT FALSE
    (byte) 0xFF });
    buffer.flip();
    SyncRequestValue decorator = new SyncRequestValueDecorator(codec);
    SyncRequestValue syncRequestValue = (SyncRequestValue) ((SyncRequestValueDecorator) decorator).decode(buffer.array());
    assertEquals(SynchronizationModeEnum.REFRESH_AND_PERSIST, syncRequestValue.getMode());
    assertNull(syncRequestValue.getCookie());
    assertEquals(true, syncRequestValue.isReloadHint());
    // Check the encoding
    try {
        ByteBuffer bb = ((SyncRequestValueDecorator) syncRequestValue).encode(ByteBuffer.allocate(((SyncRequestValueDecorator) syncRequestValue).computeLength()));
        String decoded = Strings.dumpBytes(bb.array());
        String expected = Strings.dumpBytes(buffer.array());
        assertEquals(expected, decoded);
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncRequestValue(org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue) ByteBuffer(java.nio.ByteBuffer) SyncRequestValueDecorator(org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 99 with EncoderException

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

the class SyncRequestValueControlTest method testDecodeSyncRequestValueControlNoCookieNoReloadHint.

/**
 * Test the decoding of a SyncRequestValue control with no cookie, no
 * reloadHint
 */
@Test
public void testDecodeSyncRequestValueControlNoCookieNoReloadHint() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x05);
    bb.put(new byte[] { // syncRequestValue ::= SEQUENCE {
    0x30, // syncRequestValue ::= SEQUENCE {
    0x03, 0x0A, 0x01, // mode ENUMERATED {
    0x03 // refreshAndPersist (3)
    // }
    });
    bb.flip();
    SyncRequestValue decorator = new SyncRequestValueDecorator(codec);
    SyncRequestValue syncRequestValue = (SyncRequestValue) ((SyncRequestValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationModeEnum.REFRESH_AND_PERSIST, syncRequestValue.getMode());
    assertNull(syncRequestValue.getCookie());
    assertEquals(false, syncRequestValue.isReloadHint());
    // Check the encoding
    try {
        ByteBuffer buffer = ((SyncRequestValueDecorator) syncRequestValue).encode(ByteBuffer.allocate(((SyncRequestValueDecorator) syncRequestValue).computeLength()));
        String decoded = Strings.dumpBytes(buffer.array());
        String expected = Strings.dumpBytes(bb.array());
        assertEquals(expected, decoded);
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncRequestValue(org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue) ByteBuffer(java.nio.ByteBuffer) SyncRequestValueDecorator(org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 100 with EncoderException

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

the class SyncRequestValueControlTest method testDecodeSyncRequestValueControlRefreshAndPersistSuccess.

/**
 * Test the decoding of a SyncRequestValue control with a refreshAndPersist mode
 */
@Test
public void testDecodeSyncRequestValueControlRefreshAndPersistSuccess() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0D);
    bb.put(new byte[] { // syncRequestValue ::= SEQUENCE {
    0x30, // syncRequestValue ::= SEQUENCE {
    0x0B, 0x0A, 0x01, // mode ENUMERATED {
    0x03, // }
    0x04, 0x03, 'a', 'b', // cookie syncCookie OPTIONAL,
    'c', 0x01, 0x01, // reloadHint BOOLEAN DEFAULT FALSE
    0x00 });
    bb.flip();
    SyncRequestValue decorator = new SyncRequestValueDecorator(codec);
    SyncRequestValue syncRequestValue = (SyncRequestValue) ((SyncRequestValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationModeEnum.REFRESH_AND_PERSIST, syncRequestValue.getMode());
    assertEquals("abc", Strings.utf8ToString(syncRequestValue.getCookie()));
    assertEquals(false, syncRequestValue.isReloadHint());
    // Check the encoding
    try {
        ByteBuffer buffer = ByteBuffer.allocate(0x0A);
        buffer.put(new byte[] { // syncRequestValue ::= SEQUENCE {
        0x30, // syncRequestValue ::= SEQUENCE {
        0x08, 0x0A, 0x01, // mode ENUMERATED {
        0x03, // }
        0x04, 0x03, 'a', 'b', // cookie syncCookie OPTIONAL,
        'c' });
        buffer.flip();
        bb = ((SyncRequestValueDecorator) syncRequestValue).encode(ByteBuffer.allocate(((SyncRequestValueDecorator) syncRequestValue).computeLength()));
        String decoded = Strings.dumpBytes(bb.array());
        String expected = Strings.dumpBytes(buffer.array());
        assertEquals(expected, decoded);
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncRequestValue(org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue) ByteBuffer(java.nio.ByteBuffer) SyncRequestValueDecorator(org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator) 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