Search in sources :

Example 11 with SyncInfoValueDecorator

use of org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator in project directory-ldap-api by apache.

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlRefreshDelete.

// --------------------------------------------------------------------------------
// RefreshDelete choice tests
// --------------------------------------------------------------------------------
/**
 * Test the decoding of a SyncInfoValue control, refreshDelete choice,
 * refreshDone = true
 */
@Test
public void testDecodeSyncInfoValueControlRefreshDelete() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0A);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA1, // syncInfoValue ::= CHOICE {
    0x08, // refreshDelete [1] SEQUENCE {
    0x04, 0x03, // cookie       syncCookie OPTIONAL,
    'a', // cookie       syncCookie OPTIONAL,
    'b', // cookie       syncCookie OPTIONAL,
    'c', // refreshDone  BOOLEAN DEFAULT TRUE
    0x01, // refreshDone  BOOLEAN DEFAULT TRUE
    0x01, // refreshDone  BOOLEAN DEFAULT TRUE
    (byte) 0xFF });
    bb.flip();
    SyncInfoValue decorator = new SyncInfoValueDecorator(codec);
    decorator.setSyncInfoValueType(SynchronizationInfoEnum.REFRESH_DELETE);
    SyncInfoValue syncInfoValue = (SyncInfoValue) ((SyncInfoValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationInfoEnum.REFRESH_DELETE, syncInfoValue.getSyncInfoValueType());
    assertEquals("abc", Strings.utf8ToString(syncInfoValue.getCookie()));
    assertTrue(syncInfoValue.isRefreshDone());
    // Check the encoding
    try {
        ByteBuffer buffer = ByteBuffer.allocate(0x07);
        buffer.put(new byte[] { // syncInfoValue ::= CHOICE {
        (byte) 0xA1, // syncInfoValue ::= CHOICE {
        0x05, // refreshDelete [1] SEQUENCE {
        0x04, 0x03, 'a', 'b', // cookie       syncCookie OPTIONAL,
        'c' });
        buffer.flip();
        ByteBuffer encoded = ((SyncInfoValueDecorator) syncInfoValue).encode(ByteBuffer.allocate(((SyncInfoValueDecorator) syncInfoValue).computeLength()));
        assertEquals(Strings.dumpBytes(buffer.array()), Strings.dumpBytes(encoded.array()));
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncInfoValueDecorator(org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator) SyncInfoValue(org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValue) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 12 with SyncInfoValueDecorator

use of org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator in project directory-ldap-api by apache.

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlRefreshPresentRefreshDoneFalse.

/**
 * Test the decoding of a SyncInfoValue control, refreshPresent choice,
 * refreshDone = false
 */
@Test
public void testDecodeSyncInfoValueControlRefreshPresentRefreshDoneFalse() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0A);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA2, // syncInfoValue ::= CHOICE {
    0x08, // refreshPresent [2] SEQUENCE {
    0x04, 0x03, 'a', 'b', // cookie       syncCookie OPTIONAL,
    'c', 0x01, 0x01, // refreshDone  BOOLEAN DEFAULT TRUE
    (byte) 0x00 });
    bb.flip();
    SyncInfoValue decorator = new SyncInfoValueDecorator(codec);
    decorator.setSyncInfoValueType(SynchronizationInfoEnum.REFRESH_PRESENT);
    SyncInfoValue syncInfoValue = (SyncInfoValue) ((SyncInfoValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationInfoEnum.REFRESH_PRESENT, syncInfoValue.getSyncInfoValueType());
    assertEquals("abc", Strings.utf8ToString(syncInfoValue.getCookie()));
    assertFalse(syncInfoValue.isRefreshDone());
    // Check the encoding
    try {
        ByteBuffer encoded = ((SyncInfoValueDecorator) syncInfoValue).encode(ByteBuffer.allocate(((SyncInfoValueDecorator) syncInfoValue).computeLength()));
        assertEquals(Strings.dumpBytes(bb.array()), Strings.dumpBytes(encoded.array()));
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncInfoValueDecorator(org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator) SyncInfoValue(org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValue) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 13 with SyncInfoValueDecorator

use of org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator in project directory-ldap-api by apache.

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlSyncIdSetCookieRefreshDeletesEmptySet.

/**
 * Test the decoding of a SyncInfoValue control, syncIdSet choice, a cookie
 * a refreshDeletes flag, an empty UUID set
 */
@Test
public void testDecodeSyncInfoValueControlSyncIdSetCookieRefreshDeletesEmptySet() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0C);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA3, // syncInfoValue ::= CHOICE {
    0x0A, // syncIdSet [3] SEQUENCE {
    0x04, 0x03, 'a', 'b', // cookie         syncCookie OPTIONAL,
    'c', 0x01, 0x01, // refreshDeletes BOOLEAN DEFAULT FALSE,
    0x10, 0x31, // syncUUIDs SET OF syncUUID
    0x00 });
    bb.flip();
    SyncInfoValue decorator = new SyncInfoValueDecorator(codec);
    decorator.setSyncInfoValueType(SynchronizationInfoEnum.SYNC_ID_SET);
    SyncInfoValue syncInfoValue = (SyncInfoValue) ((SyncInfoValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationInfoEnum.SYNC_ID_SET, syncInfoValue.getSyncInfoValueType());
    assertEquals("abc", Strings.utf8ToString(syncInfoValue.getCookie()));
    assertTrue(syncInfoValue.isRefreshDeletes());
    assertEquals(0, syncInfoValue.getSyncUUIDs().size());
    // Check the encoding
    try {
        ByteBuffer buffer = ByteBuffer.allocate(0x0C);
        buffer.put(new byte[] { // syncInfoValue ::= CHOICE {
        (byte) 0xA3, // syncInfoValue ::= CHOICE {
        0x0A, // syncIdSet [3] SEQUENCE {
        0x04, 0x03, 'a', 'b', // cookie         syncCookie OPTIONAL,
        'c', 0x01, 0x01, // refreshDeletes BOOLEAN DEFAULT FALSE,
        (byte) 0xFF, 0x31, // syncUUIDs SET OF syncUUID
        0x00 });
        buffer.flip();
        ByteBuffer encoded = ((SyncInfoValueDecorator) syncInfoValue).encode(ByteBuffer.allocate(((SyncInfoValueDecorator) syncInfoValue).computeLength()));
        assertEquals(Strings.dumpBytes(buffer.array()), Strings.dumpBytes(encoded.array()));
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncInfoValueDecorator(org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator) SyncInfoValue(org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValue) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 14 with SyncInfoValueDecorator

use of org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator in project directory-ldap-api by apache.

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlSyncIdSetNoCookieNoRefreshDeletesEmptySet.

/**
 * Test the decoding of a SyncInfoValue control, syncIdSet choice, no cookie
 * no refreshDeletes flag, an empty UUID set
 */
@Test
public void testDecodeSyncInfoValueControlSyncIdSetNoCookieNoRefreshDeletesEmptySet() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x04);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA3, // syncInfoValue ::= CHOICE {
    0x02, // syncIdSet [3] SEQUENCE {
    0x31, // syncUUIDs SET OF syncUUID
    0x00 });
    bb.flip();
    SyncInfoValue decorator = new SyncInfoValueDecorator(codec);
    decorator.setSyncInfoValueType(SynchronizationInfoEnum.SYNC_ID_SET);
    SyncInfoValue syncInfoValue = (SyncInfoValue) ((SyncInfoValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationInfoEnum.SYNC_ID_SET, syncInfoValue.getSyncInfoValueType());
    assertEquals("", Strings.utf8ToString(syncInfoValue.getCookie()));
    assertFalse(syncInfoValue.isRefreshDeletes());
    assertEquals(0, syncInfoValue.getSyncUUIDs().size());
    // Check the encoding
    try {
        ByteBuffer encoded = ((SyncInfoValueDecorator) syncInfoValue).encode(ByteBuffer.allocate(((SyncInfoValueDecorator) syncInfoValue).computeLength()));
        assertEquals(Strings.dumpBytes(bb.array()), Strings.dumpBytes(encoded.array()));
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncInfoValueDecorator(org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator) SyncInfoValue(org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValue) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 15 with SyncInfoValueDecorator

use of org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator in project directory-ldap-api by apache.

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlSyncIdSetCookieNoRefreshDeletesEmptySet.

/**
 * Test the decoding of a SyncInfoValue control, syncIdSet choice, A cookie
 * no refreshDeletes flag, an empty UUID set
 */
@Test
public void testDecodeSyncInfoValueControlSyncIdSetCookieNoRefreshDeletesEmptySet() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x09);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA3, // syncInfoValue ::= CHOICE {
    0x07, // syncIdSet [3] SEQUENCE {
    0x04, 0x03, 'a', 'b', // cookie         syncCookie OPTIONAL,
    'c', 0x31, // syncUUIDs SET OF syncUUID
    0x00 });
    bb.flip();
    SyncInfoValue decorator = new SyncInfoValueDecorator(codec);
    decorator.setSyncInfoValueType(SynchronizationInfoEnum.SYNC_ID_SET);
    SyncInfoValue syncInfoValue = (SyncInfoValue) ((SyncInfoValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationInfoEnum.SYNC_ID_SET, syncInfoValue.getSyncInfoValueType());
    assertEquals("abc", Strings.utf8ToString(syncInfoValue.getCookie()));
    assertFalse(syncInfoValue.isRefreshDeletes());
    assertEquals(0, syncInfoValue.getSyncUUIDs().size());
    // Check the encoding
    try {
        ByteBuffer encoded = ((SyncInfoValueDecorator) syncInfoValue).encode(ByteBuffer.allocate(((SyncInfoValueDecorator) syncInfoValue).computeLength()));
        assertEquals(Strings.dumpBytes(bb.array()), Strings.dumpBytes(encoded.array()));
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncInfoValueDecorator(org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator) SyncInfoValue(org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValue) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Aggregations

ByteBuffer (java.nio.ByteBuffer)26 AbstractCodecServiceTest (org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)26 SyncInfoValue (org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValue)26 SyncInfoValueDecorator (org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator)26 Test (org.junit.Test)26 EncoderException (org.apache.directory.api.asn1.EncoderException)20 DecoderException (org.apache.directory.api.asn1.DecoderException)6