use of graphqlEndpointTestModels.Author in project elide by yahoo.
the class GraphQLEndpointTest method testNonShareable.
@Test
void testNonShareable() throws IOException, JSONException {
DisallowTransfer noShare = new DisallowTransfer();
noShare.setId(1L);
Author author = new Author();
author.setId(123L);
author.setName("my new author");
author.setNoShare(noShare);
String graphQLRequest = document(mutation(selection(field("book", selections(field("id"), field("authors", arguments(argument("op", "UPSERT"), argument("data", author)), selections(field("id"), field("name"), field("noShare", selection(field("id")))))))))).toQuery();
Response response = endpoint.post(uriInfo, requestHeaders, user1, graphQLRequestToJSON(graphQLRequest));
assertHasErrors(response);
graphQLRequest = document(selection(field("book", selections(field("id"), field("authors", selections(field("id"), field("name"), field("noShare", selection(field("id"))))))))).toQuery();
String expected = document(selection(field("book", selections(field("id", "1"), field("authors", selections(field("id", "1"), field("name", "Ricky Carmichael"), field("noShare", "", false))))))).toResponse();
response = endpoint.post(uriInfo, requestHeaders, user1, graphQLRequestToJSON(graphQLRequest));
assert200EqualBody(response, expected);
}
use of graphqlEndpointTestModels.Author in project elide by yahoo.
the class GraphQLEndpointTest method setupTest.
@BeforeEach
public void setupTest() throws Exception {
HashMapDataStore inMemoryStore = new HashMapDataStore(DefaultClassScanner.getInstance(), Book.class.getPackage());
Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
checkMappings.put(UserChecks.IS_USER_1, UserChecks.IsUserId.One.class);
checkMappings.put(UserChecks.IS_USER_2, UserChecks.IsUserId.Two.class);
checkMappings.put(CommitChecks.IS_NOT_USER_3, CommitChecks.IsNotUser3.class);
elide = spy(new Elide(new ElideSettingsBuilder(inMemoryStore).withEntityDictionary(EntityDictionary.builder().checks(checkMappings).build()).withAuditLogger(audit).build()));
elide.doScans();
endpoint = new GraphQLEndpoint(elide);
DataStoreTransaction tx = inMemoryStore.beginTransaction();
// Initial data
Book book1 = new Book();
Author author1 = new Author();
Author author2 = new Author();
DisallowTransfer noShare = new DisallowTransfer();
book1.setId(1L);
book1.setTitle("My first book");
book1.setAuthors(Sets.newHashSet(author1));
author1.setId(1L);
author1.setName("Ricky Carmichael");
author1.setBooks(Sets.newHashSet(book1));
author1.setBookTitlesAndAwards(Stream.of(new AbstractMap.SimpleImmutableEntry<>("Bookz", "Pulitzer Prize"), new AbstractMap.SimpleImmutableEntry<>("Lost in the Data", "PEN/Faulkner Award")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
author2.setId(2L);
author2.setName("The Silent Author");
author2.setBookTitlesAndAwards(Stream.of(new AbstractMap.SimpleImmutableEntry<>("Working Hard or Hardly Working", "Booker Prize")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
noShare.setId(1L);
tx.createObject(book1, null);
tx.createObject(author1, null);
tx.createObject(author2, null);
tx.createObject(noShare, null);
tx.save(book1, null);
tx.save(author1, null);
tx.save(author2, null);
tx.save(noShare, null);
tx.commit(null);
}
use of graphqlEndpointTestModels.Author in project elide by yahoo.
the class GraphQLEndpointTest method testSuccessfulMutation.
@Test
void testSuccessfulMutation() throws JSONException {
Author author = new Author();
author.setId(2L);
Book book = new Book();
book.setId(123);
book.setTitle("my new book!");
book.setAuthors(Sets.newHashSet(author));
String graphQLRequest = document(mutation(selection(field("book", arguments(argument("op", "UPSERT"), argument("data", book)), selections(field("id"), field("title"), field("user1SecretField")))))).toQuery();
String expected = document(selection(field("book", selections(field("id", "2"), field("title", "my new book!"), field("user1SecretField", "this is a secret for user 1 only1"))))).toResponse();
Response response = endpoint.post(uriInfo, requestHeaders, user1, graphQLRequestToJSON(graphQLRequest));
assert200EqualBody(response, expected);
graphQLRequest = document(selection(field("book", selections(field("id"), field("title"), field("authors", selections(field("id"), field("name"))))))).toQuery();
expected = document(selection(field("book", selections(field("id", "1"), field("title", "My first book"), field("authors", selections(field("id", "1"), field("name", "Ricky Carmichael")))), selections(field("id", "2"), field("title", "my new book!"), field("authors", selections(field("id", "2"), field("name", "The Silent Author"))))))).toResponse();
response = endpoint.post(uriInfo, requestHeaders, user1, graphQLRequestToJSON(graphQLRequest));
assert200EqualBody(response, expected);
}
use of graphqlEndpointTestModels.Author in project elide by yahoo.
the class GraphQLEndpointTest method testFailedMutationAndRead.
@Test
void testFailedMutationAndRead() throws IOException, JSONException {
Author author = new Author();
author.setId(2L);
Book book = new Book();
book.setId(1);
book.setTitle("my new book!");
book.setAuthors(Sets.newHashSet(author));
String graphQLRequest = document(selection(field("book", arguments(argument("op", "UPSERT"), argument("data", book)), selections(field("id"), field("title"))))).toQuery();
Response response = endpoint.post(uriInfo, requestHeaders, user2, graphQLRequestToJSON(graphQLRequest));
assertHasErrors(response);
graphQLRequest = document(selection(field("book", selections(field("id"), field("title"))))).toQuery();
String expected = document(selection(field("book", selections(field("id", "1"), field("title", "My first book"))))).toResponse();
response = endpoint.post(uriInfo, requestHeaders, user2, graphQLRequestToJSON(graphQLRequest));
assert200EqualBody(response, expected);
}
Aggregations