Search in sources :

Example 1 with Book

use of example.Book in project elide by yahoo.

the class EntityProjectionMakerTest method testRootEntityWithSingleInclude.

@Test
public void testRootEntityWithSingleInclude() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.add("include", "authors");
    String path = "/book/1";
    RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
    EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
    EntityProjection expected = EntityProjection.builder().type(Book.class).attribute(Attribute.builder().name("title").type(String.class).build()).attribute(Attribute.builder().name("awards").type(Collection.class).build()).attribute(Attribute.builder().name("genre").type(String.class).build()).attribute(Attribute.builder().name("language").type(String.class).build()).attribute(Attribute.builder().name("publishDate").type(long.class).build()).attribute(Attribute.builder().name("authorTypes").type(Collection.class).build()).attribute(Attribute.builder().name("price").type(Price.class).build()).relationship("authors", EntityProjection.builder().type(Author.class).attribute(Attribute.builder().name("name").type(String.class).build()).attribute(Attribute.builder().name("type").type(Author.AuthorType.class).build()).attribute(Attribute.builder().name("homeAddress").type(Address.class).build()).attribute(Attribute.builder().name("vacationHomes").type(Set.class).build()).attribute(Attribute.builder().name("stuff").type(Map.class).build()).attribute(Attribute.builder().name("awards").type(Collection.class).build()).relationship("books", EntityProjection.builder().type(Book.class).build()).build()).relationship("publisher", EntityProjection.builder().type(Publisher.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).build();
    EntityProjection actual = maker.parsePath(path);
    projectionEquals(expected, actual);
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Address(example.Address) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Book(example.Book) Collection(java.util.Collection) Author(example.Author) Editor(example.Editor) Map(java.util.Map) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.junit.jupiter.api.Test)

Example 2 with Book

use of example.Book in project elide by yahoo.

the class EntityProjectionMakerTest method testRootEntityNoQueryParams.

@Test
public void testRootEntityNoQueryParams() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    String path = "/book/1";
    RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
    EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
    EntityProjection expected = EntityProjection.builder().type(Book.class).attribute(Attribute.builder().name("title").type(String.class).build()).attribute(Attribute.builder().name("awards").type(Collection.class).build()).attribute(Attribute.builder().name("genre").type(String.class).build()).attribute(Attribute.builder().name("language").type(String.class).build()).attribute(Attribute.builder().name("publishDate").type(long.class).build()).attribute(Attribute.builder().name("authorTypes").type(Collection.class).build()).attribute(Attribute.builder().name("price").type(Price.class).build()).relationship("authors", EntityProjection.builder().type(Author.class).build()).relationship("publisher", EntityProjection.builder().type(Publisher.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).build();
    EntityProjection actual = maker.parsePath(path);
    projectionEquals(expected, actual);
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) TestRequestScope(com.yahoo.elide.core.TestRequestScope) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Book(example.Book) Collection(java.util.Collection) Author(example.Author) Editor(example.Editor) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) Test(org.junit.jupiter.api.Test)

Example 3 with Book

use of example.Book in project elide by yahoo.

the class EntityProjectionMakerTest method testRootCollectionNoQueryParams.

@Test
public void testRootCollectionNoQueryParams() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    String path = "/book";
    RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
    EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
    EntityProjection expected = EntityProjection.builder().type(Book.class).attribute(Attribute.builder().name("title").type(String.class).build()).attribute(Attribute.builder().name("awards").type(Collection.class).build()).attribute(Attribute.builder().name("genre").type(String.class).build()).attribute(Attribute.builder().name("language").type(String.class).build()).attribute(Attribute.builder().name("publishDate").type(long.class).build()).attribute(Attribute.builder().name("authorTypes").type(Collection.class).build()).attribute(Attribute.builder().name("price").type(Price.class).build()).relationship("authors", EntityProjection.builder().type(Author.class).build()).relationship("publisher", EntityProjection.builder().type(Publisher.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).pagination(PaginationImpl.getDefaultPagination(ClassType.of(Book.class))).build();
    EntityProjection actual = maker.parsePath(path);
    projectionEquals(expected, actual);
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) TestRequestScope(com.yahoo.elide.core.TestRequestScope) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Price(example.Price) Book(example.Book) Publisher(example.Publisher) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) Test(org.junit.jupiter.api.Test)

Example 4 with Book

use of example.Book in project elide by yahoo.

the class EntityProjectionMakerTest method testRelationshipsAndIncludeWithFilterAndSort.

@Test
public void testRelationshipsAndIncludeWithFilterAndSort() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.add("include", "authors");
    queryParams.add("filter[author]", "name=='Foo'");
    queryParams.add("filter[publisher]", "name=='Foo'");
    queryParams.add("sort", "name");
    String path = "/book/1/relationships/publisher";
    Sorting sorting = SortingImpl.parseSortRule("name", ClassType.of(Publisher.class), dictionary);
    RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
    EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
    EntityProjection expected = EntityProjection.builder().type(Book.class).relationship("publisher", EntityProjection.builder().type(Publisher.class).filterExpression(new InPredicate(new Path(Publisher.class, dictionary, "name"), "Foo")).sorting(sorting).pagination(PaginationImpl.getDefaultPagination(ClassType.of(Publisher.class))).build()).relationship("authors", EntityProjection.builder().attribute(Attribute.builder().name("name").type(String.class).build()).attribute(Attribute.builder().name("type").type(Author.AuthorType.class).build()).attribute(Attribute.builder().name("homeAddress").type(Address.class).build()).attribute(Attribute.builder().name("vacationHomes").type(Set.class).build()).attribute(Attribute.builder().name("stuff").type(Map.class).build()).attribute(Attribute.builder().name("awards").type(Collection.class).build()).filterExpression(new InPredicate(new Path(Author.class, dictionary, "name"), "Foo")).relationship("books", EntityProjection.builder().type(Book.class).build()).type(Author.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).build();
    EntityProjection actual = maker.parsePath(path);
    projectionEquals(expected, actual);
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Path(com.yahoo.elide.core.Path) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Set(java.util.Set) Publisher(example.Publisher) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) Sorting(com.yahoo.elide.core.request.Sorting) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Book(example.Book) Collection(java.util.Collection) Editor(example.Editor) Test(org.junit.jupiter.api.Test)

Example 5 with Book

use of example.Book in project elide by yahoo.

the class EntityProjectionMakerTest method testRootCollectionWithGlobalFilter.

@Test
public void testRootCollectionWithGlobalFilter() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.add("filter", "genre=='Science Fiction'");
    String path = "/book";
    RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
    FilterExpression expression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Science Fiction");
    EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
    EntityProjection expected = EntityProjection.builder().type(Book.class).attribute(Attribute.builder().name("language").type(String.class).build()).attribute(Attribute.builder().name("genre").type(String.class).build()).attribute(Attribute.builder().name("title").type(String.class).build()).attribute(Attribute.builder().name("awards").type(Collection.class).build()).attribute(Attribute.builder().name("publishDate").type(long.class).build()).attribute(Attribute.builder().name("authorTypes").type(Collection.class).build()).attribute(Attribute.builder().name("price").type(Price.class).build()).filterExpression(expression).relationship("publisher", EntityProjection.builder().type(Publisher.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).relationship("authors", EntityProjection.builder().type(Author.class).build()).pagination(PaginationImpl.getDefaultPagination(ClassType.of(Book.class))).build();
    EntityProjection actual = maker.parsePath(path);
    projectionEquals(expected, actual);
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Path(com.yahoo.elide.core.Path) EntityProjection(com.yahoo.elide.core.request.EntityProjection) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Book(example.Book) Collection(java.util.Collection) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Editor(example.Editor) Test(org.junit.jupiter.api.Test)

Aggregations

Book (example.Book)70 Test (org.junit.jupiter.api.Test)61 Author (example.Author)38 EntityProjection (com.yahoo.elide.core.request.EntityProjection)26 RequestScope (com.yahoo.elide.core.RequestScope)22 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)19 Relationship (com.yahoo.elide.core.request.Relationship)17 Publisher (example.Publisher)17 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)16 TestRequestScope (com.yahoo.elide.core.TestRequestScope)15 PersistentResource (com.yahoo.elide.core.PersistentResource)13 Path (com.yahoo.elide.core.Path)12 RelationshipImpl (com.yahoo.elide.datastores.jpql.query.RelationshipImpl)12 Collection (java.util.Collection)12 RSQLFilterDialect (com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)11 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)11 HashMap (java.util.HashMap)11 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)11 DataStoreIterableBuilder (com.yahoo.elide.core.datastore.DataStoreIterableBuilder)10 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)10