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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations