Search in sources :

Example 1 with SyncDoneValueDecorator

use of org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncDoneValueDecorator 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 2 with SyncDoneValueDecorator

use of org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncDoneValueDecorator in project directory-ldap-api by apache.

the class SyncDoneValueControlTest method testSyncDoneValueWithSequenceOnly.

@Test
public void testSyncDoneValueWithSequenceOnly() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(2);
    bb.put(new byte[] { 0x30, 0x00 });
    bb.flip();
    SyncDoneValue decorator = new SyncDoneValueDecorator(codec);
    SyncDoneValue control = (SyncDoneValue) ((SyncDoneValueDecorator) decorator).decode(bb.array());
    assertNull(control.getCookie());
    assertFalse(control.isRefreshDeletes());
}
Also used : 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 3 with SyncDoneValueDecorator

use of org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncDoneValueDecorator in project directory-ldap-api by apache.

the class SyncDoneValueControlTest method testSyncDoneValueControlWithEmptyCookie.

@Test
public void testSyncDoneValueControlWithEmptyCookie() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(7);
    bb.put(new byte[] { 0x30, 0x05, // empty cookie
    0x04, // empty cookie
    0x00, 0x01, 0x01, // refreshDeletes flag FALSE
    0x00 });
    bb.flip();
    SyncDoneValue decorator = new SyncDoneValueDecorator(codec);
    SyncDoneValue control = (SyncDoneValue) ((SyncDoneValueDecorator) decorator).decode(bb.array());
    assertEquals("", Strings.utf8ToString(control.getCookie()));
    assertFalse(control.isRefreshDeletes());
    // test encoding
    try {
        ByteBuffer buffer = ((SyncDoneValueDecorator) control).encode(ByteBuffer.allocate(((SyncDoneValueDecorator) control).computeLength()));
        String decoded = Strings.dumpBytes(buffer.array());
        assertEquals("0x30 0x00 ", decoded);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : 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) EncoderException(org.apache.directory.api.asn1.EncoderException) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 4 with SyncDoneValueDecorator

use of org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncDoneValueDecorator in project directory-ldap-api by apache.

the class SyncDoneValueControlTest method testSyncDoneValueControlWithoutCookie.

@Test
public void testSyncDoneValueControlWithoutCookie() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(5);
    bb.put(new byte[] { 0x30, 0x03, // null cookie
    0x01, 0x01, // refreshDeletes flag TRUE
    (byte) 0xFF });
    bb.flip();
    SyncDoneValue decorator = new SyncDoneValueDecorator(codec);
    SyncDoneValue control = (SyncDoneValue) ((SyncDoneValueDecorator) decorator).decode(bb.array());
    assertNull(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)

Aggregations

ByteBuffer (java.nio.ByteBuffer)4 AbstractCodecServiceTest (org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)4 SyncDoneValue (org.apache.directory.api.ldap.extras.controls.syncrepl.syncDone.SyncDoneValue)4 SyncDoneValueDecorator (org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncDoneValueDecorator)4 Test (org.junit.Test)4 EncoderException (org.apache.directory.api.asn1.EncoderException)3