Search in sources :

Example 26 with SyncInfoValue

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlRefreshPresentNoCookie.

/**
 * Test the decoding of a SyncInfoValue control, refreshPresent choice,
 * no cookie
 */
@Test
public void testDecodeSyncInfoValueControlRefreshPresentNoCookie() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x05);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA2, // syncInfoValue ::= CHOICE {
    0x03, // refreshPresent [2] SEQUENCE {
    0x01, 0x01, // refreshDone  BOOLEAN DEFAULT TRUE
    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("", 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 27 with SyncInfoValue

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

the class SyncInfoValueControlTest method testDecodeSyncInfoValueControlRefreshPresentNoRefreshDone.

/**
 * Test the decoding of a SyncInfoValue control, refreshPresent choice,
 * no refreshDone
 */
@Test
public void testDecodeSyncInfoValueControlRefreshPresentNoRefreshDone() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x07);
    bb.put(new byte[] { // syncInfoValue ::= CHOICE {
    (byte) 0xA2, // syncInfoValue ::= CHOICE {
    0x05, // refreshPresent [2] SEQUENCE {
    0x04, 0x03, 'a', 'b', // cookie       syncCookie OPTIONAL,
    'c' });
    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 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