org.apache.directory.api.ldap.model.filter.ExprNode Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.filter.ExprNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseSubtreeSpecification.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a subtree which may be a refinement filter where all aspects of
 * the specification can be set. If the refinement filter is null this
 * defaults to {@link #BaseSubtreeSpecification(org.apache.directory.api.ldap.model.name.Dn, int, int, Set, Set)}.
 *
 * @param base the base of the subtree relative to the administrative point
 * @param minBaseDistance the minimum distance below base to start including entries
 * @param maxBaseDistance the maximum distance from base past which entries are excluded
 * @param chopAfter the set of subordinates entries whose subordinates are to be
 * excluded
 * @param chopBefore the set of subordinates entries and their subordinates to
 * exclude
 * @param refinement the filter expression only composed of objectClass attribute
 * value assertions
 */
public BaseSubtreeSpecification( Dn base, int minBaseDistance, int maxBaseDistance,
    Set<Dn> chopAfter, Set<Dn> chopBefore, ExprNode refinement )
{
    this.base = base;
    this.minBaseDistance = minBaseDistance;

    if ( maxBaseDistance < 0 )
    {
        this.maxBaseDistance = UNBOUNDED_MAX;
    }
    else
    {
        this.maxBaseDistance = maxBaseDistance;
    }

    this.chopAfter = chopAfter;
    this.chopBefore = chopBefore;
    this.refinement = refinement;
}
 
Example #2
Source File: SearchRequestFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Encode a BranchNode.
 * <br>
 * BranchFilter :
 * <pre>
 * 0xA1/0xA2/0xA3 LL
 *  filter.encode() ... filter.encode()
 * </pre>
 *
 * @param buffer The buffer where to put the PDU
 * @param node The Branch filter to encode
 * @param tag the ASN.1 type
 */
private void encodeFilter( Asn1Buffer buffer, BranchNode node, byte tag )
{
    int start = buffer.getPos();

    // encode each filter
    List<ExprNode> children = node.getChildren();

    if ( ( children != null ) && ( !children.isEmpty() ) )
    {
        encodeFilters( buffer, children.iterator() );
    }

    // The BranchNode sequence
    BerValue.encodeSequence( buffer, tag, start );
}
 
Example #3
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public EntryFilteringCursor search( Dn dn, String filter, boolean ignoreReferrals ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();
    ExprNode filterNode = null;

    try
    {
        filterNode = FilterParser.parse( directoryService.getSchemaManager(), filter );
    }
    catch ( ParseException pe )
    {
        throw new LdapInvalidSearchFilterException( pe.getMessage() );
    }

    SearchOperationContext searchContext = new SearchOperationContext( this, dn, SearchScope.OBJECT, filterNode,
        ( String ) null );
    searchContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
    setReferralHandling( searchContext, ignoreReferrals );

    return operationManager.search( searchContext );
}
 
Example #4
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with an Or Filter
 */
@Test
public void testRequestWithNotFilter()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_not.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof NotNode );
}
 
Example #5
Source File: LDAPConnectionService.java    From guacamole-client with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a SearchRequest object using the given Base DN and filter
 * and retrieving other properties from the LDAP configuration service.
 * 
 * @param baseDn
 *     The LDAP Base DN at which to search the search.
 * 
 * @param filter
 *     A string representation of a LDAP filter to use for the search.
 * 
 * @return
 *     The properly-configured SearchRequest object.
 * 
 * @throws GuacamoleException
 *     If an error occurs retrieving any of the configuration values.
 */
public SearchRequest getSearchRequest(Dn baseDn, ExprNode filter)
        throws GuacamoleException {
    
    SearchRequest searchRequest = new SearchRequestImpl();
    searchRequest.setBase(baseDn);
    searchRequest.setDerefAliases(confService.getDereferenceAliases());
    searchRequest.setScope(SearchScope.SUBTREE);
    searchRequest.setFilter(filter);
    searchRequest.setSizeLimit(confService.getMaxResults());
    searchRequest.setTimeLimit(confService.getOperationTimeout());
    searchRequest.setTypesOnly(false);
    
    if (confService.getFollowReferrals())
        searchRequest.followReferrals();
    
    return searchRequest;
}
 
Example #6
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with an And Filter
 */
@Test
public void testRequestWithAndFilter()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_and.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof AndNode );
}
 
Example #7
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with an Or Filter
 */
@Test
public void testRequestWithOrFilter()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser
            .setInput( SearchRequestTest.class.getResource( "filters/request_with_or.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof OrNode );
}
 
Example #8
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
public Cursor<Entry> search( Dn dn, SearchScope scope, ExprNode filter, AliasDerefMode aliasDerefMode,
    String... returningAttributes ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();

    SearchOperationContext searchContext = new SearchOperationContext( this, dn, scope, filter, returningAttributes );
    searchContext.setAliasDerefMode( aliasDerefMode );

    return operationManager.search( searchContext );
}
 
Example #9
Source File: SearchRequestFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Recursively encode the children of a connector node (AND, OR, NOT)
 *
 * @param buffer The buffer where to put the PDU
 * @param children The children to encode
 */
private void encodeFilters( Asn1Buffer buffer, Iterator<ExprNode> children )
{
    if ( children.hasNext() )
    {
        ExprNode child = children.next();

        // Recurse
        encodeFilters( buffer, children );

        // And finally the child, at the right position
        encodeFilter( buffer, child );
    }
}
 
Example #10
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
public EntryFilteringCursor search( Dn dn, SearchScope scope, ExprNode filter, AliasDerefMode aliasDerefMode,
    String... returningAttributes ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();

    SearchOperationContext searchContext = new SearchOperationContext( this, dn, scope, filter, returningAttributes );
    searchContext.setAliasDerefMode( aliasDerefMode );

    return operationManager.search( searchContext );
}
 
Example #11
Source File: MyVDInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private Filter generateMyVDFilter(ExprNode root) {
	
	FilterNode myvdroot = copyNode(root);
	
	if (myvdroot == null) {
		return null;
	} else { 
		return new Filter(myvdroot);
	}
	
}
 
Example #12
Source File: ProtectedItem_ClassesTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize name instances
 */
@BeforeEach
public void initNames() throws Exception
{
    ExprNode filterA = FilterParser.parse( "(&(cn=test)(sn=test))" );
    ExprNode filterB = FilterParser.parse( "(&(cn=test)(sn=test))" );
    ExprNode filterC = FilterParser.parse( "(&(cn=sample)(sn=sample))" );
    classesA = new ClassesItem( filterA );
    classesACopy = new ClassesItem( filterA );
    classesB = new ClassesItem( filterB );
    classesC = new ClassesItem( filterC );
}
 
Example #13
Source File: MyVDInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private Filter generateMyVDFilter(ExprNode root) {
	
	FilterNode myvdroot = copyNode(root);
	
	if (myvdroot == null) {
		return null;
	} else { 
		return new Filter(myvdroot);
	}
	
}
 
Example #14
Source File: RangeOfValuesItem.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param filter the expression
 */
public RangeOfValuesItem( ExprNode filter )
{
    if ( filter == null )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_07000_FILTER ) );
    }

    this.filter = filter;
}
 
Example #15
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 Final element
 */
@Test
public void testRequestWithSubstrings1Final()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_substrings_1_final.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    assertEquals( "john", substringFilter.getFinal().toString() );
}
 
Example #16
Source File: SearchRequestImpl.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public SearchRequest setFilter( ExprNode filter )
{
    this.filterNode = filter;
    return this;
}
 
Example #17
Source File: BaseSubtreeSpecification.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a simple subtree refinement whose administrative point is
 * necessarily the base and only those subordinates selected by the
 * refinement filter are included.
 *
 * @param refinement the filter expression only composed of objectClass attribute
 *  value assertions
 */
@SuppressWarnings("unchecked")
public BaseSubtreeSpecification( ExprNode refinement )
{
    this.base = new Dn();
    this.minBaseDistance = 0;
    this.maxBaseDistance = UNBOUNDED_MAX;
    this.chopAfter = Collections.EMPTY_SET;
    this.chopBefore = Collections.EMPTY_SET;
    this.refinement = refinement;
}
 
Example #18
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a nested nodes DIRSHARED-137
 */
@Test
public void testRequestWithNestedNodes()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_nested_connector_nodes.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequestDsml searchRequest = ( SearchRequestDsml ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof AndNode );

    assertEquals( "(&(|(sn=*foo*)(cn=*foo*))(|(ou=*josopuram*)(o=*k*)))", filter.toString() );
    
    //System.out.println( searchRequest.toDsml( new DefaultElement( "root" ) ).asXML() );
}
 
Example #19
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 empty Final element
 */
@Test
public void testRequestWithSubstrings1EmptyFinal()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_substrings_1_empty_final.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    assertNull( substringFilter.getFinal() );
}
 
Example #20
Source File: UserGroupService.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the base search filter which should be used to retrieve user
 * groups which do not represent Guacamole connections. As excluding the
 * guacConfigGroup object class may not work as expected if it is not
 * defined (may always return zero results), it should only be explicitly
 * excluded if it is expected to have been defined.
 *
 * @return
 *     The base search filter which should be used to retrieve user groups.
 *
 * @throws GuacamoleException
 *     If guacamole.properties cannot be parsed.
 */
private ExprNode getGroupSearchFilter() throws GuacamoleException {

    // Explicitly exclude guacConfigGroup object class only if it should
    // be assumed to be defined (query may fail due to no such object
    // class existing otherwise)
    if (confService.getConfigurationBaseDN() != null)
        return new NotNode(new EqualityNode("objectClass","guacConfigGroup"));

    // Read any object as a group if LDAP is not being used for connection
    // storage (guacConfigGroup)
    return new PresenceNode("objectClass");

}
 
Example #21
Source File: ConnectionService.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an LDAP search filter which queries all connections accessible
 * by the user having the given DN.
 *
 * @param userDN
 *     DN of the user to search for associated guacConfigGroup connections.
 *
 * @param ldapConnection
 *     LDAP connection to use if additional information must be queried to
 *     produce the filter, such as groups driving RBAC.
 *
 * @return
 *     An LDAP search filter which queries all guacConfigGroup objects
 *     accessible by the user having the given DN.
 *
 * @throws LdapException
 *     If an error occurs preventing retrieval of user groups.
 *
 * @throws GuacamoleException
 *     If an error occurs retrieving the group base DN.
 */
private ExprNode getConnectionSearchFilter(Dn userDN,
        LdapNetworkConnection ldapConnection)
        throws LdapException, GuacamoleException {

    AndNode searchFilter = new AndNode();

    // Add the prefix to the search filter, prefix filter searches for guacConfigGroups with the userDN as the member attribute value
    searchFilter.addNode(new EqualityNode("objectClass","guacConfigGroup"));
    
    // Apply group filters
    OrNode groupFilter = new OrNode();
    groupFilter.addNode(new EqualityNode(confService.getMemberAttribute(),
        userDN.toString()));

    // Additionally filter by group membership if the current user is a
    // member of any user groups
    List<Entry> userGroups = userGroupService.getParentUserGroupEntries(ldapConnection, userDN);
    if (!userGroups.isEmpty()) {
        userGroups.forEach(entry ->
            groupFilter.addNode(new EqualityNode("seeAlso",entry.getDn().toString()))
        );
    }

    // Complete the search filter.
    searchFilter.addNode(groupFilter);

    return searchFilter;
}
 
Example #22
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 Any and 1 Final elements
 */
@Test
public void testRequestWithSubstrings1Any1Final()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_substrings_1_any_1_final.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    List<String> initials = substringFilter.getAny();

    assertEquals( 1, initials.size() );

    assertEquals( "kate", initials.get( 0 ) );

    assertEquals( "john", substringFilter.getFinal() );
}
 
Example #23
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 Any element
 */
@Test
public void testRequestWithSubstrings2Any()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_substrings_2_any.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    List<String> initials = substringFilter.getAny();

    assertEquals( 2, initials.size() );

    assertEquals( "kate", initials.get( 0 ) );

    assertEquals( "sawyer", initials.get( 1 ) );
}
 
Example #24
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 empty Any element
 */
@Test
public void testRequestWithSubstrings1EmptyAny()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_substrings_1_empty_any.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    List<String> initials = substringFilter.getAny();

    assertEquals( 0, initials.size() );
}
 
Example #25
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 Any element
 */
@Test
public void testRequestWithSubstrings1Base64Any()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_substrings_1_base64_any.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    List<String> initials = substringFilter.getAny();

    assertEquals( 1, initials.size() );
    assertEquals( "DSMLv2.0 rocks!!", initials.get( 0 ) );
}
 
Example #26
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 Any element
 */
@Test
public void testRequestWithSubstrings1Any()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_substrings_1_any.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    List<String> initials = substringFilter.getAny();

    assertEquals( 1, initials.size() );
    assertEquals( "kate", initials.get( 0 ) );
}
 
Example #27
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 Initial and 1 Final elements
 */
@Test
public void testRequestWithSubstrings1Initial1Final()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource(
            "filters/request_with_substrings_1_initial_1_final.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    assertEquals( "jack", substringFilter.getInitial() );

    assertEquals( "john", substringFilter.getFinal() );
}
 
Example #28
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 Initial and 1 Any elements
 */
@Test
public void testRequestWithSubstrings1Initial1Any()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class
            .getResource( "filters/request_with_substrings_1_initial_1_any.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    assertEquals( "jack", substringFilter.getInitial() );

    List<String> initials = substringFilter.getAny();

    assertEquals( 1, initials.size() );

    assertEquals( "kate", initials.get( 0 ).toString() );
}
 
Example #29
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 emptyInitial element
 */
@Test
public void testRequestWithSubstrings1EmptyInitial()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class
            .getResource( "filters/request_with_substrings_1_empty_initial.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    assertNull( substringFilter.getInitial() );
}
 
Example #30
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a Substrings Filter with 1 Initial element with Base64 value
 */
@Test
public void testRequestWithSubstrings1Base64Initial()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource(
            "filters/request_with_substrings_1_base64_initial.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    ExprNode filter = searchRequest.getFilter();

    assertTrue( filter instanceof SubstringNode );

    SubstringNode substringFilter = ( SubstringNode ) filter;

    assertEquals( "DSMLv2.0 rocks!!", substringFilter.getInitial().toString() );
}