Search in sources :

Example 1 with SyncInfoValue

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlRefreshPresent.

// --------------------------------------------------------------------------------
// RefreshPresent choice tests
// --------------------------------------------------------------------------------
/**
 * Test the decoding of a SyncInfoValue control, refreshPresent choice,
 * refreshDone = true
 */
@Test
public void testDecodeSyncInfoValueControlRefreshPresent() 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) 0xFF });
    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()));
    assertTrue(syncInfoValue.isRefreshDone());
    // Check the encoding
    try {
        ByteBuffer buffer = ByteBuffer.allocate(0x07);
        buffer.put(new byte[] { // syncInfoValue ::= CHOICE {
        (byte) 0xA2, // syncInfoValue ::= CHOICE {
        0x05, // refreshPresent [2] 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 2 with SyncInfoValue

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlSyncIdSetEmpty.

// --------------------------------------------------------------------------------
// syncIdSet choice tests
// --------------------------------------------------------------------------------
/**
 * Test the decoding of a SyncInfoValue control, syncIdSet choice, empty
 */
@Test
public void testDecodeSyncInfoValueControlSyncIdSetEmpty() {
    ByteBuffer bb = ByteBuffer.allocate(0x02);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA3, // syncInfoValue ::= CHOICE {
    0x00 // syncIdSet [3] SEQUENCE {
    });
    bb.flip();
    SyncInfoValue decorator = new SyncInfoValueDecorator(codec);
    decorator.setSyncInfoValueType(SynchronizationInfoEnum.SYNC_ID_SET);
    try {
        ((SyncInfoValueDecorator) decorator).decode(bb.array());
        fail("Should not get there");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) 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 3 with SyncInfoValue

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlSyncIdSetCookieRefreshDeletesNoSet.

/**
 * Test the decoding of a SyncInfoValue control, syncIdSet choice, a cookie
 * a refreshDeletes flag, but no UUID set
 */
@Test
public void testDecodeSyncInfoValueControlSyncIdSetCookieRefreshDeletesNoSet() {
    ByteBuffer bb = ByteBuffer.allocate(0x0A);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA3, // syncInfoValue ::= CHOICE {
    0x08, // syncIdSet [3] SEQUENCE {
    0x04, 0x03, 'a', 'b', // cookie         syncCookie OPTIONAL,
    'c', 0x01, 0x01, // refreshDeletes BOOLEAN DEFAULT FALSE,
    0x00 });
    bb.flip();
    SyncInfoValue decorator = new SyncInfoValueDecorator(codec);
    decorator.setSyncInfoValueType(SynchronizationInfoEnum.SYNC_ID_SET);
    try {
        ((SyncInfoValueDecorator) decorator).decode(bb.array());
        fail("Should not get there");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) 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 4 with SyncInfoValue

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlSyncIdSetCookieRefreshDeletesUUIDsSet.

/**
 * Test the decoding of a SyncInfoValue control, syncIdSet choice, a cookie
 * a refreshDeletes flag, a UUID set with some values
 */
@Test
public void testDecodeSyncInfoValueControlSyncIdSetCookieRefreshDeletesUUIDsSet() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x42);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA3, // syncInfoValue ::= CHOICE {
    0x40, // syncIdSet [3] SEQUENCE {
    0x04, 0x03, 'a', 'b', // cookie         syncCookie OPTIONAL,
    'c', 0x01, 0x01, // refreshDeletes BOOLEAN DEFAULT FALSE,
    0x10, 0x31, // syncUUIDs SET OF syncUUID
    0x36, 0x04, // syncUUID
    0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, // syncUUID
    0x10, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, // syncUUID
    0x10, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 });
    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(3, syncInfoValue.getSyncUUIDs().size());
    for (int i = 0; i < 3; i++) {
        byte[] uuid = syncInfoValue.getSyncUUIDs().get(i);
        for (int j = 0; j < 16; j++) {
            assertEquals(i + 1, uuid[j]);
        }
    }
    // Check the encoding
    try {
        ByteBuffer buffer = ByteBuffer.allocate(0x42);
        buffer.put(new byte[] { // syncInfoValue ::= CHOICE {
        (byte) 0xA3, // syncInfoValue ::= CHOICE {
        0x40, // syncIdSet [3] SEQUENCE {
        0x04, 0x03, 'a', 'b', // cookie         syncCookie OPTIONAL,
        'c', 0x01, 0x01, // refreshDeletes BOOLEAN DEFAULT FALSE,
        (byte) 0xFF, 0x31, // syncUUIDs SET OF syncUUID
        0x36, 0x04, // syncUUID
        0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, // syncUUID
        0x10, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, // syncUUID
        0x10, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 });
        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 5 with SyncInfoValue

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlRefreshDeleteRefreshDoneFalse.

/**
 * Test the decoding of a SyncInfoValue control, refreshDelete choice,
 * refreshDone = false
 */
@Test
public void testDecodeSyncInfoValueControlRefreshDeleteRefreshDoneFalse() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0A);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA1, // syncInfoValue ::= CHOICE {
    0x08, // refreshDelete [1] 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_DELETE);
    SyncInfoValue syncInfoValue = (SyncInfoValue) ((SyncInfoValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationInfoEnum.REFRESH_DELETE, 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)

Aggregations

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