Search in sources :

Example 41 with TestRequestScope

use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.

the class UpdateOnCreateTest method updatePermissionInheritedForAttributeSuccessCase.

// ----------------------------------------- ** Update Attribute ** ------------------------------------------------
// Expression for field inherited from class level expression
@Test
public void updatePermissionInheritedForAttributeSuccessCase() {
    com.yahoo.elide.core.RequestScope userTwoScope = new TestRequestScope(tx, userTwo, dictionary);
    UpdateAndCreate updateAndCreateExistingObject = new UpdateAndCreate();
    when(tx.loadObject(any(), eq(1L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(updateAndCreateExistingObject);
    com.yahoo.elide.core.PersistentResource<UpdateAndCreate> loaded = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(UpdateAndCreate.class).build(), "1", userTwoScope);
    loaded.updateAttribute("name", "");
    loaded.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 42 with TestRequestScope

use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.

the class EntityProjectionMakerTest method testNestedEntityNoQueryParams.

@Test
public void testNestedEntityNoQueryParams() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    String path = "/author/1/books/3/publisher/1";
    RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
    EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
    EntityProjection expected = EntityProjection.builder().type(Author.class).relationship("books", EntityProjection.builder().type(Book.class).relationship("publisher", EntityProjection.builder().type(Publisher.class).attribute(Attribute.builder().name("name").type(String.class).build()).attribute(Attribute.builder().name("updateHookInvoked").type(boolean.class).build()).relationship("books", EntityProjection.builder().type(Book.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).build()).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) Publisher(example.Publisher) Editor(example.Editor) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) Test(org.junit.jupiter.api.Test)

Example 43 with TestRequestScope

use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.

the class EntityProjectionMakerTest method testRootEntityWithNestedIncludeAndSparseFields.

@Test
public void testRootEntityWithNestedIncludeAndSparseFields() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.add("include", "books");
    queryParams.add("include", "books.publisher,books.editor");
    queryParams.add("fields[publisher]", "name");
    queryParams.add("fields[editor]", "fullName");
    queryParams.add("fields[book]", "publisher,editor,title");
    String path = "/author/1";
    RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
    EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
    EntityProjection expected = 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).attribute(Attribute.builder().name("title").type(String.class).build()).relationship("publisher", EntityProjection.builder().type(Publisher.class).attribute(Attribute.builder().name("name").type(String.class).build()).build()).relationship("editor", EntityProjection.builder().type(Editor.class).attribute(Attribute.builder().name("fullName").type(String.class).build()).build()).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) Address(example.Address) Author(example.Author) Publisher(example.Publisher) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) Map(java.util.Map) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.junit.jupiter.api.Test)

Example 44 with TestRequestScope

use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.

the class EntityProjectionMakerTest method testRootCollectionSparseFields.

@Test
public void testRootCollectionSparseFields() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.add("fields[book]", "title,publishDate,authors");
    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("publishDate").type(long.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 : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) TestRequestScope(com.yahoo.elide.core.TestRequestScope) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Book(example.Book) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) Test(org.junit.jupiter.api.Test)

Example 45 with TestRequestScope

use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.

the class EntityProjectionMakerTest method testRootCollectionWithSingleInclude.

@Test
public void testRootCollectionWithSingleInclude() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.add("include", "authors");
    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).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()).pagination(PaginationImpl.getDefaultPagination(ClassType.of(Book.class))).build();
    EntityProjection actual = maker.parsePath(path);
    projectionEquals(expected, actual);
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Set(java.util.Set) Publisher(example.Publisher) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Price(example.Price) Book(example.Book) Author(example.Author) Collection(java.util.Collection) Test(org.junit.jupiter.api.Test)

Aggregations

TestRequestScope (com.yahoo.elide.core.TestRequestScope)48 RequestScope (com.yahoo.elide.core.RequestScope)47 Test (org.junit.jupiter.api.Test)47 Book (example.Book)20 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)20 UpdateAndCreate (example.UpdateAndCreate)19 EntityProjection (com.yahoo.elide.core.request.EntityProjection)18 Publisher (example.Publisher)13 Author (example.Author)11 Editor (example.Editor)9 Collection (java.util.Collection)8 Parent (example.Parent)7 PersistentResource (com.yahoo.elide.core.PersistentResource)6 JsonApiDocument (com.yahoo.elide.jsonapi.models.JsonApiDocument)6 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)5 Resource (com.yahoo.elide.jsonapi.models.Resource)5 Child (example.Child)5 Price (example.Price)5 Path (com.yahoo.elide.core.Path)4 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)4