Search in sources :

Example 1 with InfixPredicate

use of com.yahoo.elide.core.filter.predicates.InfixPredicate in project elide by yahoo.

the class InMemoryFilterExecutorTest method prefixAndPostfixAndInfixPredicateTest.

@Test
public void prefixAndPostfixAndInfixPredicateTest() throws Exception {
    author = new Author();
    author.setId(1L);
    author.setName("AuthorForTest");
    // When prefix, infix, postfix are correctly matched
    expression = new PrefixPredicate(authorNameElement, "Author");
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new InfixPredicate(authorNameElement, "For");
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new PostfixPredicate(authorNameElement, "Test");
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    // When prefix, infix, postfix are correctly matched if case-insensitive
    expression = new PrefixPredicate(authorNameElement, "author");
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new InfixPredicate(authorNameElement, "for");
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new PostfixPredicate(authorNameElement, "test");
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    // When prefix, infix, postfix are correctly matched if case-insensitive
    expression = new PrefixInsensitivePredicate(authorNameElement, "author");
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new InfixInsensitivePredicate(authorNameElement, "for");
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new PostfixInsensitivePredicate(authorNameElement, "test");
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    // When prefix, infix, postfix are not matched
    expression = new PrefixPredicate(authorNameElement, "error");
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new InfixPredicate(authorNameElement, "error");
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new PostfixPredicate(authorNameElement, "error");
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    // When values is null
    author.setName(null);
    expression = new PrefixPredicate(authorNameElement, "Author");
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new InfixPredicate(authorNameElement, "For");
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new PostfixPredicate(authorNameElement, "Test");
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
}
Also used : InfixPredicate(com.yahoo.elide.core.filter.predicates.InfixPredicate) PostfixPredicate(com.yahoo.elide.core.filter.predicates.PostfixPredicate) PrefixPredicate(com.yahoo.elide.core.filter.predicates.PrefixPredicate) PostfixInsensitivePredicate(com.yahoo.elide.core.filter.predicates.PostfixInsensitivePredicate) PrefixInsensitivePredicate(com.yahoo.elide.core.filter.predicates.PrefixInsensitivePredicate) Author(example.Author) InfixInsensitivePredicate(com.yahoo.elide.core.filter.predicates.InfixInsensitivePredicate) Test(org.junit.jupiter.api.Test)

Example 2 with InfixPredicate

use of com.yahoo.elide.core.filter.predicates.InfixPredicate in project elide by yahoo.

the class AbstractHQLQueryBuilderTest method testSettingQueryParams.

@Test
public void testSettingQueryParams() {
    Path.PathElement idPath = new Path.PathElement(Book.class, Chapter.class, "id");
    Query query = mock(Query.class);
    FilterPredicate predicate = new InPredicate(idPath, ABC, DEF);
    supplyFilterQueryParameters(query, Arrays.asList(predicate));
    verify(query, times(2)).setParameter(anyString(), any());
    query = mock(Query.class);
    predicate = new InfixPredicate(idPath, ABC);
    supplyFilterQueryParameters(query, Arrays.asList(predicate));
    verify(query, times(1)).setParameter(anyString(), any());
}
Also used : Path(com.yahoo.elide.core.Path) InfixPredicate(com.yahoo.elide.core.filter.predicates.InfixPredicate) Query(com.yahoo.elide.datastores.jpql.porting.Query) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Test(org.junit.jupiter.api.Test)

Aggregations

InfixPredicate (com.yahoo.elide.core.filter.predicates.InfixPredicate)2 Test (org.junit.jupiter.api.Test)2 Path (com.yahoo.elide.core.Path)1 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)1 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)1 InfixInsensitivePredicate (com.yahoo.elide.core.filter.predicates.InfixInsensitivePredicate)1 PostfixInsensitivePredicate (com.yahoo.elide.core.filter.predicates.PostfixInsensitivePredicate)1 PostfixPredicate (com.yahoo.elide.core.filter.predicates.PostfixPredicate)1 PrefixInsensitivePredicate (com.yahoo.elide.core.filter.predicates.PrefixInsensitivePredicate)1 PrefixPredicate (com.yahoo.elide.core.filter.predicates.PrefixPredicate)1 Query (com.yahoo.elide.datastores.jpql.porting.Query)1 Author (example.Author)1