Search in sources :

Example 6 with PagedResultsDecorator

use of org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsDecorator in project directory-ldap-api by apache.

the class PagedSearchControlTest method testDecodePagedSearchRequestNoSize.

/**
 * Test the decoding of a PagedSearchControl with no size
 */
@Test(expected = DecoderException.class)
public void testDecodePagedSearchRequestNoSize() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x08);
    bb.put(new byte[] { // realSearchControlValue ::= SEQUENCE {
    0x30, // realSearchControlValue ::= SEQUENCE {
    0x06, 0x04, 0x04, 't', 'e', 's', // cookie OCTET STRING,
    't' });
    bb.flip();
    PagedResultsDecorator decorator = new PagedResultsDecorator(codec);
    decorator.decode(bb.array());
}
Also used : 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 7 with PagedResultsDecorator

use of org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsDecorator 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)

Example 8 with PagedResultsDecorator

use of org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsDecorator in project directory-ldap-api by apache.

the class PagedSearchControlTest method testDecodePagedSearchRequestNoSizeNoCookie.

/**
 * Test the decoding of a PagedSearchControl with no size  and no cookie
 */
@Test(expected = DecoderException.class)
public void testDecodePagedSearchRequestNoSizeNoCookie() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x02);
    bb.put(new byte[] { // realSearchControlValue ::= SEQUENCE
    0x30, // realSearchControlValue ::= SEQUENCE
    0x00 });
    bb.flip();
    PagedResultsDecorator decorator = new PagedResultsDecorator(codec);
    decorator.decode(bb.array());
}
Also used : 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)8 PagedResultsDecorator (org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsDecorator)8 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)8 Test (org.junit.Test)8 PagedResults (org.apache.directory.api.ldap.model.message.controls.PagedResults)3 DecoderException (org.apache.directory.api.asn1.DecoderException)1 EncoderException (org.apache.directory.api.asn1.EncoderException)1 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)1 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)1 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)1 BindResponseDecorator (org.apache.directory.api.ldap.codec.decorators.BindResponseDecorator)1 BindResponse (org.apache.directory.api.ldap.model.message.BindResponse)1 Control (org.apache.directory.api.ldap.model.message.Control)1