Search in sources :

Example 1 with Subentries

use of org.apache.directory.api.ldap.model.message.controls.Subentries in project directory-ldap-api by apache.

the class SubEntryControlTest method testDecodeSubEntryVisibilityFalse.

/**
 * Test the decoding of a SubEntryControl with a false visibility
 */
@Test
public void testDecodeSubEntryVisibilityFalse() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x03);
    bb.put(new byte[] { // Visibility ::= BOOLEAN
    0x01, // Visibility ::= BOOLEAN
    0x01, // Visibility ::= BOOLEAN
    0x00 });
    bb.flip();
    SubentriesDecorator decorator = new SubentriesDecorator(codec);
    Subentries subentries = (Subentries) decorator.decode(bb.array());
    assertFalse(subentries.isVisible());
    // test encoding
    try {
        ByteBuffer buffer = decorator.encode(ByteBuffer.allocate(decorator.computeLength()));
        String expected = Strings.dumpBytes(bb.array());
        String decoded = Strings.dumpBytes(buffer.array());
        assertEquals(expected, decoded);
    } catch (EncoderException e) {
        fail(e.getMessage());
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SubentriesDecorator(org.apache.directory.api.ldap.codec.controls.search.subentries.SubentriesDecorator) Subentries(org.apache.directory.api.ldap.model.message.controls.Subentries) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 2 with Subentries

use of org.apache.directory.api.ldap.model.message.controls.Subentries in project directory-ldap-api by apache.

the class SubEntryControlTest method testDecodeSubEntryVisibilityTrue.

/**
 * Test the decoding of a SubEntryControl with a true visibility
 */
@Test
public void testDecodeSubEntryVisibilityTrue() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x03);
    bb.put(new byte[] { // Visibility ::= BOOLEAN
    0x01, // Visibility ::= BOOLEAN
    0x01, // Visibility ::= BOOLEAN
    (byte) 0xFF });
    bb.flip();
    SubentriesDecorator decorator = new SubentriesDecorator(codec);
    Subentries subentries = (Subentries) decorator.decode(bb.array());
    assertTrue(subentries.isVisible());
    // test encoding
    try {
        ByteBuffer buffer = decorator.encode(ByteBuffer.allocate(decorator.computeLength()));
        String expected = Strings.dumpBytes(bb.array());
        String decoded = Strings.dumpBytes(buffer.array());
        assertEquals(expected, decoded);
    } catch (EncoderException e) {
        fail(e.getMessage());
    }
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SubentriesDecorator(org.apache.directory.api.ldap.codec.controls.search.subentries.SubentriesDecorator) Subentries(org.apache.directory.api.ldap.model.message.controls.Subentries) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

ByteBuffer (java.nio.ByteBuffer)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 SubentriesDecorator (org.apache.directory.api.ldap.codec.controls.search.subentries.SubentriesDecorator)2 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)2 Subentries (org.apache.directory.api.ldap.model.message.controls.Subentries)2 Test (org.junit.Test)2