Search in sources :

Example 26 with AndNode

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

the class SearchRequestTest method testDecodeSearchRequestDIRSERVER_651.

/**
 * Test the decoding of a SearchRequest with a greaterOrEqual filter and an
 * empty attributeValue, and an '*' attribute List
 */
@Test
public void testDecodeSearchRequestDIRSERVER_651() {
    byte[] asn1BER = new byte[] { 0x30, 0x60, 0x02, 0x01, 0x02, 0x63, 0x5b, 0x04, 0x0a, 'd', 'c', '=', 'p', 'g', 'p', 'k', 'e', 'y', 's', 0x0a, 01, 02, 0x0a, 01, 00, 0x02, 01, 00, 0x02, 01, 00, 0x01, 01, 00, (byte) 0xa0, 0x3c, (byte) 0xa4, 0x28, 0x04, 0x09, 'p', 'g', 'p', 'u', 's', 'e', 'r', 'i', 'd', 0x30, 0x1b, (byte) 0x80, 0x19, 'v', 'g', 'j', 'o', 'k', 'j', 'e', 'v', '@', 'n', 'e', 't', 'c', 'e', 't', 'e', 'r', 'a', '.', 'c', 'o', 'm', '.', 'm', 'k', (byte) 0xa3, 0x10, 0x04, 0x0b, 'p', 'g', 'p', 'd', 'i', 's', 'a', 'b', 'l', 'e', 'd', 0x04, 0x01, '0', 0x30, 0x00 };
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
    stream.put(asn1BER);
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    // Decode a SearchRequest message
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(2, searchRequest.getMessageId());
    assertEquals("dc=pgpkeys", searchRequest.getBase().toString());
    assertEquals(SearchScope.SUBTREE, searchRequest.getScope());
    assertEquals(AliasDerefMode.NEVER_DEREF_ALIASES, searchRequest.getDerefAliases());
    assertEquals(0, searchRequest.getSizeLimit());
    assertEquals(0, searchRequest.getTimeLimit());
    assertEquals(false, searchRequest.getTypesOnly());
    // And
    ExprNode filter = searchRequest.getFilter();
    AndNode andNode = (AndNode) filter;
    assertNotNull(andNode);
    List<ExprNode> andNodes = andNode.getChildren();
    assertEquals(2, andNodes.size());
    SubstringNode substringNode = (SubstringNode) andNodes.get(0);
    assertNotNull(substringNode);
    assertEquals("pgpuserid", substringNode.getAttribute());
    assertEquals("vgjokjev@netcetera.com.mk", substringNode.getInitial());
    assertEquals(0, substringNode.getAny().size());
    assertEquals(null, substringNode.getFinal());
    EqualityNode<?> equalityNode = (EqualityNode<?>) andNodes.get(1);
    assertNotNull(equalityNode);
    assertEquals("pgpdisabled", equalityNode.getAttribute());
    assertEquals("0", equalityNode.getValue().getValue());
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x62, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } 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) AndNode(org.apache.directory.api.ldap.model.filter.AndNode) 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) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) EqualityNode(org.apache.directory.api.ldap.model.filter.EqualityNode) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

AndNode (org.apache.directory.api.ldap.model.filter.AndNode)26 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)24 Test (org.junit.Test)21 DecoderException (org.apache.directory.api.asn1.DecoderException)20 EqualityNode (org.apache.directory.api.ldap.model.filter.EqualityNode)20 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)20 ByteBuffer (java.nio.ByteBuffer)19 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)19 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)19 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)19 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)19 EncoderException (org.apache.directory.api.asn1.EncoderException)15 OrNode (org.apache.directory.api.ldap.model.filter.OrNode)14 NotNode (org.apache.directory.api.ldap.model.filter.NotNode)9 PresenceNode (org.apache.directory.api.ldap.model.filter.PresenceNode)8 GreaterEqNode (org.apache.directory.api.ldap.model.filter.GreaterEqNode)7 SubstringNode (org.apache.directory.api.ldap.model.filter.SubstringNode)7 ApproximateNode (org.apache.directory.api.ldap.model.filter.ApproximateNode)5 Value (org.apache.directory.api.ldap.model.entry.Value)4 ExtensibleNode (org.apache.directory.api.ldap.model.filter.ExtensibleNode)4