Search in sources :

Example 6 with SyncRequestValue

use of org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue in project directory-ldap-api by apache.

the class SyncRequestValueControlTest method testDecodeSyncRequestValueControlNoMode.

/**
 * Test the decoding of a SyncRequestValue control with no mode
 */
@Test
public void testDecodeSyncRequestValueControlNoMode() {
    ByteBuffer bb = ByteBuffer.allocate(0x07);
    bb.put(new byte[] { // syncRequestValue ::= SEQUENCE {
    0x30, // syncRequestValue ::= SEQUENCE {
    0x05, 0x04, 0x03, 'a', 'b', // cookie syncCookie OPTIONAL,
    'c' });
    bb.flip();
    SyncRequestValue decorator = new SyncRequestValueDecorator(codec);
    try {
        ((SyncRequestValueDecorator) decorator).decode(bb.array());
        fail("we should not get there");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) SyncRequestValue(org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue) ByteBuffer(java.nio.ByteBuffer) SyncRequestValueDecorator(org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 7 with SyncRequestValue

use of org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue in project directory-ldap-api by apache.

the class SyncRequestValueControlTest method testDecodeSyncRequestValueControlRefreshOnlySuccess.

/**
 * Test the decoding of a SyncRequestValue control with a refreshOnly mode
 */
@Test
public void testDecodeSyncRequestValueControlRefreshOnlySuccess() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0D);
    bb.put(new byte[] { // syncRequestValue ::= SEQUENCE {
    0x30, // syncRequestValue ::= SEQUENCE {
    0x0B, // mode ENUMERATED {
    0x0A, // mode ENUMERATED {
    0x01, // mode ENUMERATED {
    0x01, // }
    0x04, 0x03, // cookie syncCookie OPTIONAL,
    'a', // cookie syncCookie OPTIONAL,
    'b', // cookie syncCookie OPTIONAL,
    'c', // reloadHint BOOLEAN DEFAULT FALSE
    0x01, // reloadHint BOOLEAN DEFAULT FALSE
    0x01, // reloadHint BOOLEAN DEFAULT FALSE
    0x00 });
    bb.flip();
    SyncRequestValue decorator = new SyncRequestValueDecorator(codec);
    SyncRequestValue syncRequestValue = (SyncRequestValue) ((SyncRequestValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationModeEnum.REFRESH_ONLY, syncRequestValue.getMode());
    assertEquals("abc", Strings.utf8ToString(syncRequestValue.getCookie()));
    assertEquals(false, syncRequestValue.isReloadHint());
    // Check the encoding
    try {
        bb = ByteBuffer.allocate(0x0A);
        bb.put(new byte[] { // syncRequestValue ::= SEQUENCE {
        0x30, // syncRequestValue ::= SEQUENCE {
        0x08, 0x0A, 0x01, // mode ENUMERATED {
        0x01, // }
        0x04, 0x03, 'a', 'b', // cookie syncCookie OPTIONAL,
        'c' });
        bb.flip();
        ByteBuffer buffer = ((SyncRequestValueDecorator) syncRequestValue).encode(ByteBuffer.allocate(((SyncRequestValueDecorator) syncRequestValue).computeLength()));
        String decoded = Strings.dumpBytes(bb.array());
        String expected = Strings.dumpBytes(buffer.array());
        assertEquals(expected, decoded);
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncRequestValue(org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue) ByteBuffer(java.nio.ByteBuffer) SyncRequestValueDecorator(org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 8 with SyncRequestValue

use of org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue in project directory-ldap-api by apache.

the class SyncRequestValueControlTest method testDecodeSyncRequestValueControlNoCookie.

/**
 * Test the decoding of a SyncRequestValue control with no cookie
 */
@Test
public void testDecodeSyncRequestValueControlNoCookie() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x08);
    bb.put(new byte[] { // syncRequestValue ::= SEQUENCE {
    0x30, // syncRequestValue ::= SEQUENCE {
    0x06, 0x0A, 0x01, // mode ENUMERATED {
    0x03, // }
    0x01, 0x01, // reloadHint BOOLEAN DEFAULT FALSE
    0x00 });
    bb.flip();
    SyncRequestValue decorator = new SyncRequestValueDecorator(codec);
    SyncRequestValue syncRequestValue = (SyncRequestValue) ((SyncRequestValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationModeEnum.REFRESH_AND_PERSIST, syncRequestValue.getMode());
    assertNull(syncRequestValue.getCookie());
    assertEquals(false, syncRequestValue.isReloadHint());
    // Check the encoding
    try {
        bb = ByteBuffer.allocate(0x05);
        bb.put(new byte[] { // syncRequestValue ::= SEQUENCE {
        0x30, // syncRequestValue ::= SEQUENCE {
        0x03, 0x0A, 0x01, // mode ENUMERATED {
        0x03 // refreshAndPersist (3)
        // }
        });
        bb.flip();
        ByteBuffer buffer = ((SyncRequestValueDecorator) syncRequestValue).encode(ByteBuffer.allocate(((SyncRequestValueDecorator) syncRequestValue).computeLength()));
        String decoded = Strings.dumpBytes(buffer.array());
        String expected = Strings.dumpBytes(bb.array());
        assertEquals(expected, decoded);
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncRequestValue(org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue) ByteBuffer(java.nio.ByteBuffer) SyncRequestValueDecorator(org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 9 with SyncRequestValue

use of org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue in project directory-ldap-api by apache.

the class SyncRequestValueControlTest method testDecodeSyncRequestValueControlEmptyCookie.

/**
 * Test the decoding of a SyncRequestValue control with an empty cookie
 */
@Test
public void testDecodeSyncRequestValueControlEmptyCookie() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x07);
    bb.put(new byte[] { // syncRequestValue ::= SEQUENCE {
    0x30, // syncRequestValue ::= SEQUENCE {
    0x05, 0x0A, 0x01, // mode ENUMERATED {
    0x03, // }
    0x04, // cookie syncCookie OPTIONAL,
    0x00 });
    bb.flip();
    SyncRequestValue decorator = new SyncRequestValueDecorator(codec);
    SyncRequestValue syncRequestValue = (SyncRequestValue) ((SyncRequestValueDecorator) decorator).decode(bb.array());
    assertEquals(SynchronizationModeEnum.REFRESH_AND_PERSIST, syncRequestValue.getMode());
    assertEquals("", Strings.utf8ToString(syncRequestValue.getCookie()));
    assertEquals(false, syncRequestValue.isReloadHint());
    // Check the encoding
    try {
        bb = ByteBuffer.allocate(0x05);
        bb.put(new byte[] { // syncRequestValue ::= SEQUENCE {
        0x30, // syncRequestValue ::= SEQUENCE {
        0x03, 0x0A, 0x01, // mode ENUMERATED {
        0x03 // refreshAndPersist (3)
        // }
        });
        bb.flip();
        ByteBuffer buffer = ((SyncRequestValueDecorator) syncRequestValue).encode(ByteBuffer.allocate(((SyncRequestValueDecorator) syncRequestValue).computeLength()));
        String decoded = Strings.dumpBytes(buffer.array());
        String expected = Strings.dumpBytes(bb.array());
        assertEquals(expected, decoded);
    } catch (EncoderException ee) {
        fail();
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SyncRequestValue(org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue) ByteBuffer(java.nio.ByteBuffer) SyncRequestValueDecorator(org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Example 10 with SyncRequestValue

use of org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue in project directory-ldap-api by apache.

the class SyncRequestValueControlTest method testEncodeSyncRequestValue.

@Test
public void testEncodeSyncRequestValue() throws Exception {
    SyncRequestValue syncRequestValue = new SyncRequestValueImpl();
    syncRequestValue.setMode(SynchronizationModeEnum.REFRESH_ONLY);
    SyncRequestValueDecorator decorator = new SyncRequestValueDecorator(codec, syncRequestValue);
    ByteBuffer buffer = decorator.encode(ByteBuffer.allocate(decorator.computeLength()));
    String expected = Strings.dumpBytes(new byte[] { 0x30, 0x03, 0x0A, 0x01, 0x01 });
    assertEquals(expected, Strings.dumpBytes(buffer.array()));
}
Also used : SyncRequestValue(org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue) SyncRequestValueImpl(org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValueImpl) ByteBuffer(java.nio.ByteBuffer) SyncRequestValueDecorator(org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)

Aggregations

ByteBuffer (java.nio.ByteBuffer)10 AbstractCodecServiceTest (org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)10 SyncRequestValue (org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue)10 SyncRequestValueDecorator (org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator)10 Test (org.junit.Test)10 EncoderException (org.apache.directory.api.asn1.EncoderException)7 DecoderException (org.apache.directory.api.asn1.DecoderException)2 SyncRequestValueImpl (org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValueImpl)1