Search in sources :

Example 1 with Author

use of example.Author in project elide by yahoo.

the class InMemoryFilterExecutorTest method andExpressionTest.

@Test
public void andExpressionTest() throws Exception {
    author = new Author();
    author.setId(1L);
    author.setName("AuthorForTest");
    expression = new AndFilterExpression(new InPredicate(authorIdElement, 1L), new InPredicate(authorNameElement, "AuthorForTest"));
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new AndFilterExpression(new InPredicate(authorIdElement, 0L), new InPredicate(authorNameElement, "AuthorForTest"));
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new AndFilterExpression(new InPredicate(authorIdElement, 1L), new InPredicate(authorNameElement, "Fail"));
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new AndFilterExpression(new InPredicate(authorIdElement, 0L), new InPredicate(authorNameElement, "Fail"));
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
}
Also used : Author(example.Author) NotInPredicate(com.yahoo.elide.core.filter.predicates.NotInPredicate) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Test(org.junit.jupiter.api.Test)

Example 2 with Author

use of example.Author in project elide by yahoo.

the class InMemoryFilterExecutorTest method isnullAndNotnullPredicateTest.

@Test
public void isnullAndNotnullPredicateTest() throws Exception {
    author = new Author();
    author.setId(1L);
    author.setName("AuthorForTest");
    // When name is not null
    expression = new IsNullPredicate(authorNameElement);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new NotNullPredicate(authorNameElement);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    // When name is null
    author.setName(null);
    expression = new IsNullPredicate(authorNameElement);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new NotNullPredicate(authorNameElement);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
}
Also used : Author(example.Author) IsNullPredicate(com.yahoo.elide.core.filter.predicates.IsNullPredicate) NotNullPredicate(com.yahoo.elide.core.filter.predicates.NotNullPredicate) Test(org.junit.jupiter.api.Test)

Example 3 with Author

use of example.Author in project elide by yahoo.

the class InMemoryFilterExecutorTest method isemptyAndNotemptyPredicateTest.

@Test
public void isemptyAndNotemptyPredicateTest() throws Exception {
    author = new Author();
    author.setId(1L);
    // When name is empty and books are empty
    author.setBooks(new HashSet<>());
    author.setAwards(new HashSet<>());
    expression = new IsEmptyPredicate(authorAwardsElement);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new IsEmptyPredicate(authorBooksElement);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new NotEmptyPredicate(authorAwardsElement);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new NotEmptyPredicate(authorBooksElement);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    // When name and books are not empty
    author.setAwards(Arrays.asList("Bookery prize"));
    author.getBooks().add(new Book());
    expression = new IsEmptyPredicate(authorAwardsElement);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new IsEmptyPredicate(authorBooksElement);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new NotEmptyPredicate(authorAwardsElement);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new NotEmptyPredicate(authorBooksElement);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
}
Also used : IsEmptyPredicate(com.yahoo.elide.core.filter.predicates.IsEmptyPredicate) Book(example.Book) Author(example.Author) NotEmptyPredicate(com.yahoo.elide.core.filter.predicates.NotEmptyPredicate) Test(org.junit.jupiter.api.Test)

Example 4 with Author

use of example.Author in project elide by yahoo.

the class InMemoryFilterExecutorTest method negativeTests.

@Test
public void negativeTests() throws Exception {
    author = new Author();
    author.setId(10L);
    PathElement pathElement = new PathElement(Author.class, Long.class, "id");
    expression = new NotFilterExpression(new LTPredicate(pathElement, listEleven));
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new NotFilterExpression(new LEPredicate(pathElement, listTen));
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new NotFilterExpression(new GTPredicate(pathElement, listNine));
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new NotFilterExpression(new GEPredicate(pathElement, listTen));
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new NotFilterExpression(new LTPredicate(pathElement, listTen));
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new NotFilterExpression(new LEPredicate(pathElement, listNine));
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new NotFilterExpression(new GTPredicate(pathElement, listTen));
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new NotFilterExpression(new GEPredicate(pathElement, listEleven));
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
}
Also used : PathElement(com.yahoo.elide.core.Path.PathElement) GTPredicate(com.yahoo.elide.core.filter.predicates.GTPredicate) LEPredicate(com.yahoo.elide.core.filter.predicates.LEPredicate) GEPredicate(com.yahoo.elide.core.filter.predicates.GEPredicate) Author(example.Author) LTPredicate(com.yahoo.elide.core.filter.predicates.LTPredicate) Test(org.junit.jupiter.api.Test)

Example 5 with Author

use of example.Author in project elide by yahoo.

the class InMemoryFilterExecutorTest method compareOpPredicateTests.

@Test
public void compareOpPredicateTests() throws Exception {
    author = new Author();
    author.setId(10L);
    expression = new LTPredicate(authorIdElement, listEleven);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new LEPredicate(authorIdElement, listTen);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new GTPredicate(authorIdElement, listNine);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new GEPredicate(authorIdElement, listTen);
    fn = expression.accept(visitor);
    assertTrue(fn.test(author));
    expression = new LTPredicate(authorIdElement, listTen);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new LEPredicate(authorIdElement, listNine);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new GTPredicate(authorIdElement, listTen);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new GEPredicate(authorIdElement, listEleven);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    // when val is null
    author.setId(null);
    expression = new LTPredicate(authorIdElement, listTen);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new LEPredicate(authorIdElement, listTen);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new GTPredicate(authorIdElement, listTen);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
    expression = new GEPredicate(authorIdElement, listTen);
    fn = expression.accept(visitor);
    assertFalse(fn.test(author));
}
Also used : GTPredicate(com.yahoo.elide.core.filter.predicates.GTPredicate) LEPredicate(com.yahoo.elide.core.filter.predicates.LEPredicate) GEPredicate(com.yahoo.elide.core.filter.predicates.GEPredicate) Author(example.Author) LTPredicate(com.yahoo.elide.core.filter.predicates.LTPredicate) Test(org.junit.jupiter.api.Test)

Aggregations

Author (example.Author)53 Test (org.junit.jupiter.api.Test)48 Book (example.Book)29 EntityProjection (com.yahoo.elide.core.request.EntityProjection)15 Relationship (com.yahoo.elide.core.request.Relationship)12 RelationshipImpl (com.yahoo.elide.datastores.jpql.query.RelationshipImpl)11 RequestScope (com.yahoo.elide.core.RequestScope)10 Publisher (example.Publisher)10 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)8 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)8 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)8 TestRequestScope (com.yahoo.elide.core.TestRequestScope)7 SubCollectionFetchQueryBuilder (com.yahoo.elide.datastores.jpql.query.SubCollectionFetchQueryBuilder)7 Path (com.yahoo.elide.core.Path)6 HashMap (java.util.HashMap)6 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)5 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)4 Address (example.Address)4 UpdateAndCreate (example.UpdateAndCreate)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4