Search in sources :

Example 1 with Price

use of example.Price 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 2 with Price

use of example.Price in project elide by yahoo.

the class EntityProjectionMakerTest method testNestedCollectionWithSingleInclude.

@Test
public void testNestedCollectionWithSingleInclude() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.add("include", "books");
    String path = "/author/1/books/3/publisher";
    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().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()).type(Book.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).pagination(PaginationImpl.getDefaultPagination(ClassType.of(Publisher.class))).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) 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 3 with Price

use of example.Price in project elide by yahoo.

the class GraphQLIT method createBookAndAuthor.

@BeforeEach
public void createBookAndAuthor() throws IOException {
    // before each test, create a new book and a new author
    Book book = new Book();
    book.setId(1);
    book.setTitle("1984");
    Price price = new Price();
    price.setTotal(BigDecimal.valueOf(10.0));
    price.setCurrency(new Currency("USD"));
    book.setPrice(price);
    Author author = new Author();
    author.setId(1L);
    author.setName("George Orwell");
    String graphQLQuery = document(mutation(selection(field("book", arguments(argument("op", "UPSERT"), argument("data", book)), selections(field("id"), field("title"), field("authors", arguments(argument("op", "UPSERT"), argument("data", author)), selections(field("id"), field("name")))))))).toQuery();
    String expectedResponse = document(selection(field("book", selections(field("id", "1"), field("title", "1984"), field("authors", selections(field("id", "1"), field("name", "George Orwell"))))))).toResponse();
    runQueryWithExpectedResult(graphQLQuery, expectedResponse);
}
Also used : Price(example.Price) Currency(example.Currency) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Price

use of example.Price in project elide by yahoo.

the class PersistentResourceTest method testUpdateComplexAttributeCloneWithHook.

@Test
public void testUpdateComplexAttributeCloneWithHook() {
    reset(bookUpdatePrice);
    Book book = new Book();
    Price originalPrice = new Price();
    originalPrice.setUnits(new BigDecimal(1.0));
    originalPrice.setCurrency(Currency.getInstance("USD"));
    book.setPrice(originalPrice);
    Map<String, Object> newPrice = new HashMap<>();
    newPrice.put("units", new BigDecimal(2.0));
    newPrice.put("currency", Currency.getInstance("CNY"));
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<Book> bookResource = new PersistentResource<>(book, "1", goodScope);
    bookResource.updateAttribute("price", newPrice);
    // check that original value was unmodified.
    assertEquals(Currency.getInstance("USD"), originalPrice.getCurrency());
    assertEquals(new BigDecimal(1.0), originalPrice.getUnits());
    // check that new value matches expected.
    assertEquals(Currency.getInstance("CNY"), book.getPrice().getCurrency());
    assertEquals(new BigDecimal(2.0), book.getPrice().getUnits());
    goodScope.saveOrCreateObjects();
    verify(tx, times(1)).save(book, goodScope);
    ArgumentCaptor<CRUDEvent> eventCapture = ArgumentCaptor.forClass(CRUDEvent.class);
    verify(bookUpdatePrice, times(1)).execute(eq(UPDATE), eq(PRESECURITY), eventCapture.capture());
    assertEquals(originalPrice, eventCapture.getValue().getChanges().get().getOriginal());
    assertEquals(book.getPrice(), eventCapture.getValue().getChanges().get().getModified());
}
Also used : CRUDEvent(com.yahoo.elide.core.lifecycle.CRUDEvent) Price(example.Price) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Book(example.Book) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 5 with Price

use of example.Price in project elide by yahoo.

the class EntityProjectionMakerTest method testRootCollectionWithNestedInclude.

@Test
public void testRootCollectionWithNestedInclude() throws Exception {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.add("include", "books");
    queryParams.add("include", "books.publisher,books.editor");
    String path = "/author";
    RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
    EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
    EntityProjection expected = EntityProjection.builder().type(Author.class).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("name").type(String.class).build()).attribute(Attribute.builder().name("type").type(Author.AuthorType.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()).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("editor", EntityProjection.builder().type(Editor.class).attribute(Attribute.builder().name("firstName").type(String.class).build()).attribute(Attribute.builder().name("lastName").type(String.class).build()).attribute(Attribute.builder().name("fullName").type(String.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).build()).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()).relationship("authors", EntityProjection.builder().type(Author.class).build()).build()).pagination(PaginationImpl.getDefaultPagination(ClassType.of(Author.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) Author(example.Author) Collection(java.util.Collection) Editor(example.Editor) Test(org.junit.jupiter.api.Test)

Aggregations

Price (example.Price)8 Publisher (example.Publisher)6 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)6 Test (org.junit.jupiter.api.Test)6 RequestScope (com.yahoo.elide.core.RequestScope)5 TestRequestScope (com.yahoo.elide.core.TestRequestScope)5 EntityProjection (com.yahoo.elide.core.request.EntityProjection)5 Book (example.Book)5 Author (example.Author)3 Editor (example.Editor)2 BigDecimal (java.math.BigDecimal)2 Collection (java.util.Collection)2 Set (java.util.Set)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 CRUDEvent (com.yahoo.elide.core.lifecycle.CRUDEvent)1 PatchRequestScope (com.yahoo.elide.jsonapi.extensions.PatchRequestScope)1 Currency (example.Currency)1 Pseudonym (example.Pseudonym)1 Date (java.util.Date)1