Search in sources :

Example 26 with SyncInfoValueDecorator

use of org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator 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

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