Search in sources :

Example 1 with DisallowTransfer

use of graphqlEndpointTestModels.DisallowTransfer 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);
}
Also used : Response(javax.ws.rs.core.Response) Author(graphqlEndpointTestModels.Author) DisallowTransfer(graphqlEndpointTestModels.DisallowTransfer) Test(org.junit.jupiter.api.Test)

Example 2 with DisallowTransfer

use of graphqlEndpointTestModels.DisallowTransfer 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);
}
Also used : HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Check(com.yahoo.elide.core.security.checks.Check) DisallowTransfer(graphqlEndpointTestModels.DisallowTransfer) AbstractMap(java.util.AbstractMap) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Book(graphqlEndpointTestModels.Book) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Author(graphqlEndpointTestModels.Author) Elide(com.yahoo.elide.Elide) CommitChecks(graphqlEndpointTestModels.security.CommitChecks) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Author (graphqlEndpointTestModels.Author)2 DisallowTransfer (graphqlEndpointTestModels.DisallowTransfer)2 Elide (com.yahoo.elide.Elide)1 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)1 Check (com.yahoo.elide.core.security.checks.Check)1 Book (graphqlEndpointTestModels.Book)1 CommitChecks (graphqlEndpointTestModels.security.CommitChecks)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1 Response (javax.ws.rs.core.Response)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1