Search in sources :

Example 11 with AsyncQuery

use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.

the class GraphQLAsyncQueryOperationTest method testProcessQueryGraphQlInvalidResponse.

@Test
public void testProcessQueryGraphQlInvalidResponse() throws URISyntaxException {
    AsyncQuery queryObj = new AsyncQuery();
    String responseBody = "ResponseBody";
    ElideResponse response = new ElideResponse(200, responseBody);
    String query = "{\"query\":\"{ group { edges { node { name commonName description } } } }\",\"variables\":null}";
    String id = "edc4a871-dff2-4054-804e-d80075cf827d";
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
    when(runner.run(any(), any(), any(), any(), any())).thenReturn(response);
    GraphQLAsyncQueryOperation graphQLOperation = new GraphQLAsyncQueryOperation(asyncExecutorService, queryObj, requestScope);
    AsyncQueryResult queryResultObj = (AsyncQueryResult) graphQLOperation.call();
    assertEquals(responseBody, queryResultObj.getResponseBody());
    assertEquals(200, queryResultObj.getHttpStatus());
    assertEquals(0, queryResultObj.getRecordCount());
}
Also used : ElideResponse(com.yahoo.elide.ElideResponse) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) AsyncQueryResult(com.yahoo.elide.async.models.AsyncQueryResult) Test(org.junit.jupiter.api.Test)

Example 12 with AsyncQuery

use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.

the class GraphQLAsyncQueryOperationTest method testProcessQueryGraphQlApiVersionNotSupported.

@Test
public void testProcessQueryGraphQlApiVersionNotSupported() {
    AsyncQuery queryObj = new AsyncQuery();
    String query = "{\"query\":\"{ group { edges { node { name commonName description } } } }\",\"variables\":null}";
    String id = "edc4a871-dff2-4054-804e-d80075cf827d";
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
    when(requestScope.getApiVersion()).thenReturn("v2");
    GraphQLAsyncQueryOperation graphQLOperation = new GraphQLAsyncQueryOperation(asyncExecutorService, queryObj, requestScope);
    assertThrows(InvalidOperationException.class, () -> graphQLOperation.call());
}
Also used : AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) Test(org.junit.jupiter.api.Test)

Example 13 with AsyncQuery

use of com.yahoo.elide.async.models.AsyncQuery in project elide by yahoo.

the class GraphQLAsyncQueryOperationTest method testProcessQueryGraphQl.

@Test
public void testProcessQueryGraphQl() throws URISyntaxException {
    AsyncQuery queryObj = new AsyncQuery();
    String responseBody = "{\"data\":{\"book\":{\"edges\":[{\"node\":{\"id\":\"1\",\"title\":\"Ender's Game\"}}," + "{\"node\":{\"id\":\"2\",\"title\":\"Song of Ice and Fire\"}}," + "{\"node\":{\"id\":\"3\",\"title\":\"For Whom the Bell Tolls\"}}]}}}";
    ElideResponse response = new ElideResponse(200, responseBody);
    String query = "{\"query\":\"{ group { edges { node { name commonName description } } } }\",\"variables\":null}";
    String id = "edc4a871-dff2-4054-804e-d80075cf827d";
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
    when(runner.run(any(), any(), any(), any(), any())).thenReturn(response);
    GraphQLAsyncQueryOperation graphQLOperation = new GraphQLAsyncQueryOperation(asyncExecutorService, queryObj, requestScope);
    AsyncQueryResult queryResultObj = (AsyncQueryResult) graphQLOperation.call();
    assertEquals(responseBody, queryResultObj.getResponseBody());
    assertEquals(200, queryResultObj.getHttpStatus());
    assertEquals(3, queryResultObj.getRecordCount());
}
Also used : ElideResponse(com.yahoo.elide.ElideResponse) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) AsyncQueryResult(com.yahoo.elide.async.models.AsyncQueryResult) Test(org.junit.jupiter.api.Test)

Aggregations

AsyncQuery (com.yahoo.elide.async.models.AsyncQuery)13 Test (org.junit.jupiter.api.Test)11 AsyncQueryResult (com.yahoo.elide.async.models.AsyncQueryResult)5 ElideResponse (com.yahoo.elide.ElideResponse)4 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)4 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)4 AsyncAPI (com.yahoo.elide.async.models.AsyncAPI)3 ArrayList (java.util.ArrayList)3 QueryStatus (com.yahoo.elide.async.models.QueryStatus)2 Elide (com.yahoo.elide.Elide)1 ElideSettings (com.yahoo.elide.ElideSettings)1 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)1 AsyncAPIResult (com.yahoo.elide.async.models.AsyncAPIResult)1 JSONAPIAsyncQueryOperation (com.yahoo.elide.async.operation.JSONAPIAsyncQueryOperation)1 DataStore (com.yahoo.elide.core.datastore.DataStore)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 Check (com.yahoo.elide.core.security.checks.Check)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 NoHttpResponseException (org.apache.http.NoHttpResponseException)1