Search in sources :

Example 1 with PagedResults

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

the class PagedSearchControlTest method testEncodePagedSearchControlEmptyCookie.

/**
 * Test encoding of a PagedSearchControl with a empty cookie
 */
@Test
public void testEncodePagedSearchControlEmptyCookie() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x07);
    bb.put(new byte[] { // realSearchControlValue ::= SEQUENCE {
    0x30, // realSearchControlValue ::= SEQUENCE {
    0x05, 0x02, 0x01, // size INTEGER,
    0x20, 0x04, // cookie OCTET STRING,
    0x00 });
    bb.flip();
    PagedResultsDecorator decorator = new PagedResultsDecorator(codec);
    PagedResults pagedSearch = (PagedResults) decorator.decode(bb.array());
    assertEquals(32, pagedSearch.getSize());
    assertNull(pagedSearch.getCookie());
    PagedResultsDecorator ctrl = new PagedResultsDecorator(codec);
    ctrl.setSize(32);
    ctrl.setCookie(null);
    ByteBuffer buffer = ctrl.encode(ByteBuffer.allocate(ctrl.computeLength()));
    String decoded = Strings.dumpBytes(buffer.array());
    String expected = Strings.dumpBytes(bb.array());
    assertEquals(expected, decoded);
}
Also used : PagedResults(org.apache.directory.api.ldap.model.message.controls.PagedResults) PagedResultsDecorator(org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 2 with PagedResults

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

the class PagedSearchControlTest method testEncodePagedSearchControlNegativeSize.

/**
 * Test encoding of a PagedSearchControl with a negative size
 */
@Test
public void testEncodePagedSearchControlNegativeSize() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0b);
    bb.put(new byte[] { // realSearchControlValue ::= SEQUENCE {
    0x30, // realSearchControlValue ::= SEQUENCE {
    0x09, 0x02, 0x01, // size INTEGER,
    (byte) 0xFF, 0x04, 0x04, 't', 'e', 's', // cookie OCTET STRING,
    't' });
    bb.flip();
    PagedResultsDecorator decorator = new PagedResultsDecorator(codec);
    PagedResults pagedSearch = (PagedResults) decorator.decode(bb.array());
    assertEquals(Integer.MAX_VALUE, pagedSearch.getSize());
    assertTrue(Arrays.equals(Strings.getBytesUtf8("test"), pagedSearch.getCookie()));
    bb.flip();
    PagedResultsDecorator ctrl = new PagedResultsDecorator(codec);
    ctrl.setSize(-1);
    ctrl.setCookie(Strings.getBytesUtf8("test"));
    ByteBuffer buffer = ctrl.encode(ByteBuffer.allocate(ctrl.computeLength()));
    String decoded = Strings.dumpBytes(buffer.array());
    String expected = Strings.dumpBytes(bb.array());
    assertEquals(expected, decoded);
}
Also used : PagedResults(org.apache.directory.api.ldap.model.message.controls.PagedResults) PagedResultsDecorator(org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 3 with PagedResults

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

the class PagedSearchControlTest method testEncodePagedSearchControl.

/**
 * Test encoding of a PagedSearchControl.
 */
@Test
public void testEncodePagedSearchControl() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0B);
    bb.put(new byte[] { // realSearchControlValue ::= SEQUENCE {
    0x30, // realSearchControlValue ::= SEQUENCE {
    0x09, 0x02, 0x01, // size INTEGER,
    0x20, 0x04, 0x04, 't', 'e', 's', // cookie OCTET STRING,
    't' });
    bb.flip();
    PagedResultsDecorator decorator = new PagedResultsDecorator(codec);
    PagedResults pagedSearch = (PagedResults) decorator.decode(bb.array());
    assertEquals(32, pagedSearch.getSize());
    assertTrue(Arrays.equals(Strings.getBytesUtf8("test"), pagedSearch.getCookie()));
    bb.flip();
    PagedResultsDecorator ctrl = new PagedResultsDecorator(codec);
    ctrl.setSize(32);
    ctrl.setCookie(Strings.getBytesUtf8("test"));
    ByteBuffer buffer = ctrl.encode(ByteBuffer.allocate(ctrl.computeLength()));
    String decoded = Strings.dumpBytes(buffer.array());
    String expected = Strings.dumpBytes(bb.array());
    assertEquals(expected, decoded);
}
Also used : PagedResults(org.apache.directory.api.ldap.model.message.controls.PagedResults) PagedResultsDecorator(org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

ByteBuffer (java.nio.ByteBuffer)3 PagedResultsDecorator (org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsDecorator)3 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)3 PagedResults (org.apache.directory.api.ldap.model.message.controls.PagedResults)3 Test (org.junit.Test)3