Search in sources :

Example 1 with AsyncQueryResult

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);
}
Also used : HashMap(java.util.HashMap) Check(com.yahoo.elide.core.security.checks.Check) AsyncQueryResult(com.yahoo.elide.async.models.AsyncQueryResult) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) DataStore(com.yahoo.elide.core.datastore.DataStore) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) ElideSettings(com.yahoo.elide.ElideSettings) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with AsyncQueryResult

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());
}
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 3 with AsyncQueryResult

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;
}
Also used : ElideResponse(com.yahoo.elide.ElideResponse) AsyncQueryResult(com.yahoo.elide.async.models.AsyncQueryResult) Date(java.util.Date)

Example 4 with AsyncQueryResult

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());
}
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 5 with AsyncQueryResult

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

AsyncQueryResult (com.yahoo.elide.async.models.AsyncQueryResult)6 ElideResponse (com.yahoo.elide.ElideResponse)5 AsyncQuery (com.yahoo.elide.async.models.AsyncQuery)5 Test (org.junit.jupiter.api.Test)4 Elide (com.yahoo.elide.Elide)1 ElideSettings (com.yahoo.elide.ElideSettings)1 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)1 DataStore (com.yahoo.elide.core.datastore.DataStore)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)1 Check (com.yahoo.elide.core.security.checks.Check)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1