Search in sources :

Example 1 with NotInPredicate

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

the class InMemoryFilterExecutorTest method inAndNotInPredicateTest.

@Test
public void inAndNotInPredicateTest() throws Exception {
    author = new Author();
    author.setId(1L);
    author.setName("AuthorForTest");
    // Test exact match
    expression = new InPredicate(authorIdElement, 1L);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new NotInPredicate(authorIdElement, 1L);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    // Test exact match insensitive
    expression = new InInsensitivePredicate(authorNameElement, author.getName().toUpperCase(Locale.ENGLISH));
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new NotInInsensitivePredicate(authorNameElement, author.getName().toUpperCase(Locale.ENGLISH));
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    // Test contains works
    expression = new InPredicate(authorIdElement, 1, 2);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new NotInPredicate(authorIdElement, 1, 2);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    // Test type
    expression = new InPredicate(authorIdElement, "1");
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new NotInPredicate(authorIdElement, "1");
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    // Test not in
    expression = new InPredicate(authorIdElement, 3L);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new NotInPredicate(authorIdElement, 3L);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    // Test empty
    expression = new InPredicate(authorIdElement, Collections.emptyList());
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new NotInPredicate(authorIdElement, Collections.emptyList());
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    // Test TRUE/FALSE
    expression = new TruePredicate(authorIdElement);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new FalsePredicate(authorIdElement);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    // Test null
    author.setId(null);
    expression = new InPredicate(authorIdElement, 1);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new NotInPredicate(authorIdElement, 1);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
}
Also used : InInsensitivePredicate(com.yahoo.elide.core.filter.predicates.InInsensitivePredicate) NotInInsensitivePredicate(com.yahoo.elide.core.filter.predicates.NotInInsensitivePredicate) TruePredicate(com.yahoo.elide.core.filter.predicates.TruePredicate) Author(example.Author) NotInPredicate(com.yahoo.elide.core.filter.predicates.NotInPredicate) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) NotInPredicate(com.yahoo.elide.core.filter.predicates.NotInPredicate) NotInInsensitivePredicate(com.yahoo.elide.core.filter.predicates.NotInInsensitivePredicate) FalsePredicate(com.yahoo.elide.core.filter.predicates.FalsePredicate) Test(org.junit.jupiter.api.Test)

Aggregations

FalsePredicate (com.yahoo.elide.core.filter.predicates.FalsePredicate)1 InInsensitivePredicate (com.yahoo.elide.core.filter.predicates.InInsensitivePredicate)1 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)1 NotInInsensitivePredicate (com.yahoo.elide.core.filter.predicates.NotInInsensitivePredicate)1 NotInPredicate (com.yahoo.elide.core.filter.predicates.NotInPredicate)1 TruePredicate (com.yahoo.elide.core.filter.predicates.TruePredicate)1 Author (example.Author)1 Test (org.junit.jupiter.api.Test)1