use of com.yahoo.elide.async.models.AsyncQueryResult in project elide by yahoo.
the class DefaultAsyncAPIDAOTest method setupMocks.
@BeforeEach
public void setupMocks() {
dataStore = mock(DataStore.class);
asyncQuery = mock(AsyncQuery.class);
asyncQueryResult = mock(AsyncQueryResult.class);
filter = mock(FilterExpression.class);
tx = mock(DataStoreTransaction.class);
Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
EntityDictionary dictionary = EntityDictionary.builder().checks(checkMappings).build();
dictionary.bindEntity(AsyncQuery.class);
dictionary.bindEntity(AsyncQueryResult.class);
ElideSettings elideSettings = new ElideSettingsBuilder(dataStore).withEntityDictionary(dictionary).withJoinFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withSubqueryFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build();
elide = new Elide(elideSettings);
when(dataStore.beginTransaction()).thenReturn(tx);
asyncAPIDAO = new DefaultAsyncAPIDAO(elide.getElideSettings(), dataStore);
}
use of com.yahoo.elide.async.models.AsyncQueryResult in project elide by yahoo.
the class JSONAPIAsyncQueryOperationTest method testProcessQueryNonSuccessResponse.
@Test
public void testProcessQueryNonSuccessResponse() throws URISyntaxException {
AsyncQuery queryObj = new AsyncQuery();
String responseBody = "ResponseBody";
ElideResponse response = new ElideResponse(201, responseBody);
String query = "/group?sort=commonName&fields%5Bgroup%5D=commonName,description";
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.JSONAPI_V1_0);
when(elide.get(any(), any(), any(), any(), any(), any(), any())).thenReturn(response);
JSONAPIAsyncQueryOperation jsonOperation = new JSONAPIAsyncQueryOperation(asyncExecutorService, queryObj, requestScope);
AsyncQueryResult queryResultObj = (AsyncQueryResult) jsonOperation.call();
assertEquals(responseBody, queryResultObj.getResponseBody());
assertEquals(201, queryResultObj.getHttpStatus());
assertNull(queryResultObj.getRecordCount());
}
use of com.yahoo.elide.async.models.AsyncQueryResult in project elide by yahoo.
the class AsyncQueryOperation method call.
@Override
public AsyncAPIResult call() throws URISyntaxException {
ElideResponse response = null;
log.debug("AsyncQuery Object from request: {}", queryObj);
response = execute(queryObj, scope);
nullResponseCheck(response);
AsyncQueryResult queryResult = new AsyncQueryResult();
queryResult.setHttpStatus(response.getResponseCode());
queryResult.setCompletedOn(new Date());
queryResult.setResponseBody(response.getBody());
queryResult.setContentLength(response.getBody().length());
if (response.getResponseCode() == 200) {
queryResult.setRecordCount(calculateRecordCount(queryObj, response));
}
return queryResult;
}
use of com.yahoo.elide.async.models.AsyncQueryResult in project elide by yahoo.
the class JSONAPIAsyncQueryOperationTest method testProcessQueryJsonApi.
@Test
public void testProcessQueryJsonApi() throws URISyntaxException {
AsyncQuery queryObj = new AsyncQuery();
String responseBody = "{\"data\":" + "[{\"type\":\"book\",\"id\":\"3\",\"attributes\":{\"title\":\"For Whom the Bell Tolls\"}}" + ",{\"type\":\"book\",\"id\":\"2\",\"attributes\":{\"title\":\"Song of Ice and Fire\"}}," + "{\"type\":\"book\",\"id\":\"1\",\"attributes\":{\"title\":\"Ender's Game\"}}]}";
ElideResponse response = new ElideResponse(200, responseBody);
String query = "/group?sort=commonName&fields%5Bgroup%5D=commonName,description";
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.JSONAPI_V1_0);
when(elide.get(any(), any(), any(), any(), any(), any(), any())).thenReturn(response);
JSONAPIAsyncQueryOperation jsonOperation = new JSONAPIAsyncQueryOperation(asyncExecutorService, queryObj, requestScope);
AsyncQueryResult queryResultObj = (AsyncQueryResult) jsonOperation.call();
assertEquals(responseBody, queryResultObj.getResponseBody());
assertEquals(200, queryResultObj.getHttpStatus());
assertEquals(3, queryResultObj.getRecordCount());
}
use of com.yahoo.elide.async.models.AsyncQueryResult 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());
}
Aggregations