Search in sources :

Example 6 with SyncInfoValueDecorator

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlNewCookie.

// --------------------------------------------------------------------------------
// NewCookie choice tests
// --------------------------------------------------------------------------------
/**
 * Test the decoding of a SyncInfoValue control, newCookie choice
 */
@Test
public void testDecodeSyncInfoValueControlNewCookie() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x05);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0x80, // syncInfoValue ::= CHOICE {
    0x03, 'a', 'b', // newCookie [0] syncCookie
    'c' });
    bb.flip();
    SyncInfoValue decorator = new SyncInfoValueDecorator(codec);
    decorator.setSyncInfoValueType(SynchronizationInfoEnum.NEW_COOKIE);
    SyncInfoValue syncInfoValue = (SyncInfoValue) ((SyncInfoValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationInfoEnum.NEW_COOKIE, syncInfoValue.getSyncInfoValueType());
    assertEquals("abc", Strings.utf8ToString(syncInfoValue.getCookie()));
    // 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 7 with SyncInfoValueDecorator

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlSyncIdSetNoCookieNoRefreshDeletesUUIDsSet.

/**
 * Test the decoding of a SyncInfoValue control, syncIdSet choice, no cookie
 * no refreshDeletes flag, a UUID set with some values
 */
@Test
public void testDecodeSyncInfoValueControlSyncIdSetNoCookieNoRefreshDeletesUUIDsSet() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x3A);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA3, // syncInfoValue ::= CHOICE {
    0x38, // syncIdSet [3] SEQUENCE {
    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("", Strings.utf8ToString(syncInfoValue.getCookie()));
    assertFalse(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 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 8 with SyncInfoValueDecorator

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlSyncIdSetNoCookieRefreshDeletesNoSet.

/**
 * Test the decoding of a SyncInfoValue control, syncIdSet choice, no cookie
 * a refreshDeletes flag, but no UUID set
 */
@Test
public void testDecodeSyncInfoValueControlSyncIdSetNoCookieRefreshDeletesNoSet() {
    ByteBuffer bb = ByteBuffer.allocate(0x05);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA3, // syncInfoValue ::= CHOICE {
    0x03, // syncIdSet [3] SEQUENCE {
    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 9 with SyncInfoValueDecorator

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlEmptyNewCookie.

/**
 * Test the decoding of a SyncInfoValue control, empty newCookie choice
 */
@Test
public void testDecodeSyncInfoValueControlEmptyNewCookie() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x02);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0x80, // syncInfoValue ::= CHOICE {
    0x00 // newCookie [0] syncCookie
    });
    bb.flip();
    SyncInfoValue decorator = new SyncInfoValueDecorator(codec);
    decorator.setSyncInfoValueType(SynchronizationInfoEnum.NEW_COOKIE);
    SyncInfoValue syncInfoValue = (SyncInfoValue) ((SyncInfoValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationInfoEnum.NEW_COOKIE, syncInfoValue.getSyncInfoValueType());
    assertEquals("", Strings.utf8ToString(syncInfoValue.getCookie()));
    // 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 10 with SyncInfoValueDecorator

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlSyncIdSetTooLongUUID.

/**
 * Test the decoding of a SyncInfoValue control, syncIdSet choice, with some
 * invalid UUID
 */
@Test
public void testDecodeSyncInfoValueControlSyncIdSetTooLongUUID() {
    ByteBuffer bb = ByteBuffer.allocate(0x20);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA3, // syncInfoValue ::= CHOICE {
    0x1E, // syncIdSet [3] SEQUENCE {
    0x04, 0x03, 'a', 'b', // cookie         syncCookie OPTIONAL,
    'c', 0x01, 0x01, // refreshDeletes BOOLEAN DEFAULT FALSE,
    0x10, 0x31, // syncUUIDs SET OF syncUUID
    0x13, 0x04, // syncUUID
    0x11, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 });
    bb.flip();
    SyncInfoValue decorator = new SyncInfoValueDecorator(codec);
    decorator.setSyncInfoValueType(SynchronizationInfoEnum.SYNC_ID_SET);
    try {
        ((SyncInfoValueDecorator) decorator).decode(bb.array());
        fail("Should not be 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)

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