Search in sources :

Example 1 with SortRequest

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

the class SortRequestControlTest method testDecodeControl.

@Test
public void testDecodeControl() throws Exception {
    ByteBuffer buffer = ByteBuffer.allocate(16);
    buffer.put(new byte[] { 0x30, 0x0E, 0x30, 0x0C, 0x04, 0x02, 'c', 'n', (byte) 0x80, 0x03, 'o', 'i', 'd', (byte) 0x81, 0x01, 0x00 });
    buffer.flip();
    SortRequestDecorator decorator = new SortRequestDecorator(codec);
    SortRequest control = (SortRequest) decorator.decode(buffer.array());
    assertEquals(1, control.getSortKeys().size());
    SortKey sk = control.getSortKeys().get(0);
    assertEquals("cn", sk.getAttributeTypeDesc());
    assertEquals("oid", sk.getMatchingRuleId());
    assertFalse(sk.isReverseOrder());
    // default value of false reverseOrder will not be encoded
    int skipBytes = 3;
    ByteBuffer encoded = ByteBuffer.allocate(buffer.capacity() - skipBytes);
    decorator.computeLength();
    decorator.encode(encoded);
    assertFalse(Arrays.equals(buffer.array(), encoded.array()));
    assertEquals(buffer.array().length - skipBytes, encoded.array().length);
}
Also used : SortRequest(org.apache.directory.api.ldap.model.message.controls.SortRequest) SortKey(org.apache.directory.api.ldap.model.message.controls.SortKey) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest) Test(org.junit.Test)

Example 2 with SortRequest

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

the class SortRequestControlTest method testDecodeControlWithoutMrOid.

@Test
public void testDecodeControlWithoutMrOid() throws Exception {
    ByteBuffer buffer = ByteBuffer.allocate(11);
    buffer.put(new byte[] { 0x30, 0x09, 0x30, 0x07, 0x04, 0x02, 'c', 'n', (byte) 0x81, 0x01, (byte) 0xFF });
    buffer.flip();
    SortRequestDecorator decorator = new SortRequestDecorator(codec);
    SortRequest control = (SortRequest) decorator.decode(buffer.array());
    assertEquals(1, control.getSortKeys().size());
    SortKey sk = control.getSortKeys().get(0);
    assertEquals("cn", sk.getAttributeTypeDesc());
    assertNull(sk.getMatchingRuleId());
    assertTrue(sk.isReverseOrder());
    ByteBuffer encoded = ByteBuffer.allocate(buffer.capacity());
    decorator.computeLength();
    decorator.encode(encoded);
    assertTrue(Arrays.equals(buffer.array(), encoded.array()));
}
Also used : SortRequest(org.apache.directory.api.ldap.model.message.controls.SortRequest) SortKey(org.apache.directory.api.ldap.model.message.controls.SortKey) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest) Test(org.junit.Test)

Example 3 with SortRequest

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

the class SortRequestControlTest method testDecodeControlWithAtDescOnly.

@Test
public void testDecodeControlWithAtDescOnly() throws Exception {
    ByteBuffer buffer = ByteBuffer.allocate(8);
    buffer.put(new byte[] { 0x30, 0x06, 0x30, 0x04, 0x04, 0x02, 'c', 'n' });
    buffer.flip();
    SortRequestDecorator decorator = new SortRequestDecorator(codec);
    SortRequest control = (SortRequest) decorator.decode(buffer.array());
    assertEquals(1, control.getSortKeys().size());
    SortKey sk = control.getSortKeys().get(0);
    assertEquals("cn", sk.getAttributeTypeDesc());
    assertNull(sk.getMatchingRuleId());
    assertFalse(sk.isReverseOrder());
    ByteBuffer encoded = ByteBuffer.allocate(buffer.capacity());
    decorator.computeLength();
    decorator.encode(encoded);
    assertTrue(Arrays.equals(buffer.array(), encoded.array()));
}
Also used : SortRequest(org.apache.directory.api.ldap.model.message.controls.SortRequest) SortKey(org.apache.directory.api.ldap.model.message.controls.SortKey) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest) Test(org.junit.Test)

Example 4 with SortRequest

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

the class SortRequestControlTest method testDecodeControlWithMultipleAtDescOnly.

@Test
public void testDecodeControlWithMultipleAtDescOnly() throws Exception {
    ByteBuffer buffer = ByteBuffer.allocate(0x0E);
    buffer.put(new byte[] { 0x30, 0x0C, 0x30, 0x04, 0x04, 0x02, 'c', 'n', 0x30, 0x04, 0x04, 0x02, 's', 'n' });
    buffer.flip();
    SortRequestDecorator decorator = new SortRequestDecorator(codec);
    SortRequest control = (SortRequest) decorator.decode(buffer.array());
    assertEquals(2, control.getSortKeys().size());
    SortKey sk = control.getSortKeys().get(0);
    assertEquals("cn", sk.getAttributeTypeDesc());
    assertNull(sk.getMatchingRuleId());
    assertFalse(sk.isReverseOrder());
    sk = control.getSortKeys().get(1);
    assertEquals("sn", sk.getAttributeTypeDesc());
    assertNull(sk.getMatchingRuleId());
    assertFalse(sk.isReverseOrder());
    ByteBuffer encoded = ByteBuffer.allocate(buffer.capacity());
    decorator.computeLength();
    decorator.encode(encoded);
    assertTrue(Arrays.equals(buffer.array(), encoded.array()));
}
Also used : SortRequest(org.apache.directory.api.ldap.model.message.controls.SortRequest) SortKey(org.apache.directory.api.ldap.model.message.controls.SortKey) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest) Test(org.junit.Test)

Example 5 with SortRequest

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

the class SortRequestControlTest method testDecodeControlWithMultipleSortKeys.

@Test
public void testDecodeControlWithMultipleSortKeys() throws Exception {
    ByteBuffer buffer = ByteBuffer.allocate(0x1E);
    buffer.put(new byte[] { 0x30, 0x1C, 0x30, 0x0C, 0x04, 0x02, 'c', 'n', (byte) 0x80, 0x03, 'o', 'i', 'd', (byte) 0x81, 0x01, (byte) 0xFF, 0x30, 0x0C, 0x04, 0x02, 's', 'n', (byte) 0x80, 0x03, 'i', 'o', 'd', (byte) 0x81, 0x01, (byte) 0xFF });
    buffer.flip();
    SortRequestDecorator decorator = new SortRequestDecorator(codec);
    SortRequest control = (SortRequest) decorator.decode(buffer.array());
    assertEquals(2, control.getSortKeys().size());
    SortKey sk = control.getSortKeys().get(0);
    assertEquals("cn", sk.getAttributeTypeDesc());
    assertEquals("oid", sk.getMatchingRuleId());
    assertTrue(sk.isReverseOrder());
    sk = control.getSortKeys().get(1);
    assertEquals("sn", sk.getAttributeTypeDesc());
    assertEquals("iod", sk.getMatchingRuleId());
    assertTrue(sk.isReverseOrder());
    ByteBuffer encoded = ByteBuffer.allocate(buffer.capacity());
    decorator.computeLength();
    decorator.encode(encoded);
    assertTrue(Arrays.equals(buffer.array(), encoded.array()));
}
Also used : SortRequest(org.apache.directory.api.ldap.model.message.controls.SortRequest) SortKey(org.apache.directory.api.ldap.model.message.controls.SortKey) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)5 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)5 SortKey (org.apache.directory.api.ldap.model.message.controls.SortKey)5 SortRequest (org.apache.directory.api.ldap.model.message.controls.SortRequest)5 Test (org.junit.Test)5