Search in sources :

Example 26 with SubstringNode

use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.

the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringInitialAnyAnyFinal.

/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=t*t*)
 */
@Test
public void testDecodeSearchRequestSubstringInitialAnyAnyFinal() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x67);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x65, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
    0x60, // SearchRequest ::= APPLICATION[3] SEQUENCE {
    0x04, // baseObject LDAPDN,
    0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, // scope
    0x01, // wholeSubtree (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, 0x01, 0x01, // typesOnly
    (byte) 0xFF, // filter Filter,
    (byte) 0xA4, // Filter ::= CHOICE {
    0x15, // SubstringFilter ::= SEQUENCE {
    0x04, // type AttributeDescription,
    0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x06, (byte) 0x80, 0x01, // 
    't', (byte) 0x81, 0x01, // 
    't', 0x30, // AttributeDescriptionList ::= SEQUENCE OF
    0x15, // AttributeDescription
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '0', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '1', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::=
    '2' // LDAPString
    });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(1, searchRequest.getMessageId());
    assertEquals("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(1000, searchRequest.getSizeLimit());
    assertEquals(1000, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = (SubstringNode) node;
    assertNotNull(substringNode);
    assertEquals("objectclass", substringNode.getAttribute());
    assertEquals("t", substringNode.getInitial());
    assertEquals("t", substringNode.getAny().get(0));
    // The attributes
    List<String> attributes = searchRequest.getAttributes();
    for (String attribute : attributes) {
        assertNotNull(attribute);
    }
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x67, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu.substring(0, 0x58), decodedPdu.substring(0, 0x58));
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 27 with SubstringNode

use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.

the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringInitialAnyWithControls.

/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=t*) With controls
 */
@Test
public void testDecodeSearchRequestSubstringInitialAnyWithControls() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x0081);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x7F, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
    0x5D, // SearchRequest ::= APPLICATION[3] SEQUENCE {
    0x04, // baseObject LDAPDN,
    0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, // scope
    0x01, // wholeSubtree (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, 0x01, 0x01, // typesOnly
    (byte) 0xFF, // filter Filter,
    (byte) 0xA4, // Filter ::= CHOICE {
    0x12, // SubstringFilter ::= SEQUENCE {
    0x04, // type AttributeDescription,
    0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x03, (byte) 0x80, 0x01, // 
    't', 0x30, // AttributeDescriptionList ::= SEQUENCE OF
    0x15, // AttributeDescription
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '0', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '1', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '2', // ::= LDAPString
    (byte) 0xA0, // A control
    0x1B, 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(1, searchRequest.getMessageId());
    assertEquals("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(1000, searchRequest.getSizeLimit());
    assertEquals(1000, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = (SubstringNode) node;
    assertNotNull(substringNode);
    assertEquals("objectclass", substringNode.getAttribute());
    assertEquals("t", substringNode.getInitial());
    // The attributes
    List<String> attributes = searchRequest.getAttributes();
    for (String attribute : attributes) {
        assertNotNull(attribute);
    }
    // Check the Control
    Map<String, Control> controls = searchRequest.getControls();
    assertEquals(1, controls.size());
    @SuppressWarnings("unchecked") CodecControl<Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<Control>) searchRequest.getControl("2.16.840.1.113730.3.4.2");
    assertEquals("2.16.840.1.113730.3.4.2", control.getOid());
    assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x0081, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu.substring(0, 0x53), decodedPdu.substring(0, 0x53));
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) ByteBuffer(java.nio.ByteBuffer) ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Control(org.apache.directory.api.ldap.model.message.Control) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 28 with SubstringNode

use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.

the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringAnyAnyAny.

/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=*t*t*t*)
 */
@Test
public void testDecodeSearchRequestSubstringAnyAnyAny() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x6A);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x68, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
    0x63, // SearchRequest ::= APPLICATION[3] SEQUENCE {
    0x04, // baseObject LDAPDN,
    0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, // scope
    0x01, // wholeSubtree (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, 0x01, 0x01, // typesOnly
    (byte) 0xFF, // filter Filter,
    (byte) 0xA4, // Filter ::= CHOICE {
    0x18, // SubstringFilter ::= SEQUENCE {
    0x04, // type AttributeDescription,
    0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x09, (byte) 0x81, 0x01, // 
    't', (byte) 0x81, 0x01, // 
    't', (byte) 0x81, 0x01, // 
    't', 0x30, // AttributeDescriptionList ::= SEQUENCE OF
    0x15, // AttributeDescription
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '0', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '1', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::=
    '2' // LDAPString
    });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(1, searchRequest.getMessageId());
    assertEquals("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(1000, searchRequest.getSizeLimit());
    assertEquals(1000, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = (SubstringNode) node;
    assertNotNull(substringNode);
    assertEquals("objectclass", substringNode.getAttribute());
    assertEquals(null, substringNode.getInitial());
    assertEquals("t", substringNode.getAny().get(0));
    assertEquals("t", substringNode.getAny().get(1));
    assertEquals("t", substringNode.getAny().get(2));
    assertEquals(null, substringNode.getFinal());
    // The attributes
    List<String> attributes = searchRequest.getAttributes();
    for (String attribute : attributes) {
        assertNotNull(attribute);
    }
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x6A, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu.substring(0, 0x5B), decodedPdu.substring(0, 0x5B));
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 29 with SubstringNode

use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.

the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringInitialAny.

/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=t*)
 */
@Test
public void testDecodeSearchRequestSubstringInitialAny() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x64);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x62, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, // CHOICE { ...,
    0x5D, // SearchRequest ::= APPLICATION[3] SEQUENCE {
    0x04, // baseObject LDAPDN,
    0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, // scope ENUMERATED {
    0x01, // wholeSubtree    (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // derefAlways         (3) },
    0x02, 0x02, 0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
    (byte) 0xE8, 0x02, 0x02, 0x03, // timeLimit INTEGER (0 .. maxInt), (1000)
    (byte) 0xE8, 0x01, 0x01, // typesOnly
    (byte) 0xFF, // filter Filter,
    (byte) 0xA4, // Filter ::= CHOICE {
    0x12, // SubstringFilter ::= SEQUENCE {
    0x04, // type AttributeDescription,
    0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x03, (byte) 0x80, 0x01, // 
    't', 0x30, // AttributeDescriptionList ::= SEQUENCE OF
    0x15, // AttributeDescription
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '0', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '1', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::=
    '2' // LDAPString
    });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(1, searchRequest.getMessageId());
    assertEquals("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(1000, searchRequest.getSizeLimit());
    assertEquals(1000, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = (SubstringNode) node;
    assertNotNull(substringNode);
    assertEquals("objectclass", substringNode.getAttribute());
    assertEquals("t", substringNode.getInitial());
    // The attributes
    List<String> attributes = searchRequest.getAttributes();
    for (String attribute : attributes) {
        assertNotNull(attribute);
    }
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x64, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu.substring(0, 0x53), decodedPdu.substring(0, 0x53));
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 30 with SubstringNode

use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.

the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringInitialAnyFinal.

/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=t*t*t)
 */
@Test
public void testDecodeSearchRequestSubstringInitialAnyFinal() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x6A);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x68, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
    0x63, // SearchRequest ::= APPLICATION[3] SEQUENCE {
    0x04, // baseObject LDAPDN,
    0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, // scope
    0x01, // wholeSubtree (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, 0x01, 0x01, // typesOnly
    (byte) 0xFF, // filter Filter,
    (byte) 0xA4, // Filter ::= CHOICE {
    0x18, // SubstringFilter ::= SEQUENCE {
    0x04, // type AttributeDescription,
    0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x09, (byte) 0x80, 0x01, // 
    't', (byte) 0x81, 0x01, // 
    't', (byte) 0x82, 0x01, // 
    't', 0x30, // AttributeDescriptionList ::= SEQUENCE OF
    0x15, // AttributeDescription
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '0', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '1', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::=
    '2' // LDAPString
    });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(1, searchRequest.getMessageId());
    assertEquals("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(1000, searchRequest.getSizeLimit());
    assertEquals(1000, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = (SubstringNode) node;
    assertNotNull(substringNode);
    assertEquals("objectclass", substringNode.getAttribute());
    assertEquals("t", substringNode.getInitial());
    assertEquals("t", substringNode.getAny().get(0));
    assertEquals("t", substringNode.getFinal());
    // The attributes
    List<String> attributes = searchRequest.getAttributes();
    for (String attribute : attributes) {
        assertNotNull(attribute);
    }
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x6A, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu.substring(0, 0x5B), decodedPdu.substring(0, 0x5B));
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

SubstringNode (org.apache.directory.api.ldap.model.filter.SubstringNode)32 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)29 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)26 Test (org.junit.Test)26 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)14 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)14 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)14 DecoderException (org.apache.directory.api.asn1.DecoderException)13 ByteBuffer (java.nio.ByteBuffer)12 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)12 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)12 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)12 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)12 EncoderException (org.apache.directory.api.asn1.EncoderException)11 AndNode (org.apache.directory.api.ldap.model.filter.AndNode)7 EqualityNode (org.apache.directory.api.ldap.model.filter.EqualityNode)6 OrNode (org.apache.directory.api.ldap.model.filter.OrNode)6 PresenceNode (org.apache.directory.api.ldap.model.filter.PresenceNode)5 Value (org.apache.directory.api.ldap.model.entry.Value)4 ApproximateNode (org.apache.directory.api.ldap.model.filter.ApproximateNode)4