use of org.dotwebstack.framework.core.query.model.RequestContext in project dotwebstack-framework by dotwebstack.
the class BackendDataFetcherTest method get_returnsFluxList_ifSourceNull_NotSubscription_and_ListTypeTrue.
@Test
void get_returnsFluxList_ifSourceNull_NotSubscription_and_ListTypeTrue() {
var requestContext = RequestContext.builder().objectField(mock(ObjectField.class)).source(null).build();
when(requestFactory.createRequestContext(environment)).thenReturn(requestContext);
when(environment.getSource()).thenReturn(null);
graphql.language.Field fieldMock = new Field("aaa");
lenient().when(environment.getField()).thenReturn(fieldMock);
GraphQLList listType = mock(GraphQLList.class);
when(environment.getFieldType()).thenReturn(listType);
mockOperationDefinition(OperationDefinition.Operation.QUERY);
CollectionRequest collectionRequestMock = CollectionRequest.builder().objectRequest(ObjectRequest.builder().build()).build();
DataFetchingFieldSelectionSet selectionSet = mock(DataFetchingFieldSelectionSet.class);
when(environment.getSelectionSet()).thenReturn(selectionSet);
var executionStepInfo = mockExecutionStepInfoWithResultPath("fff", "fff");
lenient().when(requestFactory.createCollectionRequest(eq(executionStepInfo), eq(selectionSet))).thenReturn(collectionRequestMock);
Map<String, Object> resultMock = new HashMap<>();
resultMock.put("aa", new String[] { "a", "b" });
when(backendLoader.loadMany(any(CollectionRequest.class), any(RequestContext.class))).thenReturn(Flux.just(resultMock));
mockGraphQlFieldDefinition(Map.of());
var result = ((CompletableFuture<?>) backendDataFetcher.get(environment)).join();
assertThat(result, CoreMatchers.is(notNullValue()));
assertTrue(result instanceof List);
assertThat(((List<?>) result).get(0), is(resultMock));
verify(requestFactory).createCollectionRequest(any(ExecutionStepInfo.class), any(DataFetchingFieldSelectionSet.class));
verify(backendLoader).loadMany(any(CollectionRequest.class), any(RequestContext.class));
}
use of org.dotwebstack.framework.core.query.model.RequestContext in project dotwebstack-framework by dotwebstack.
the class BackendDataFetcherTest method get_returnsMonoMap_ifSourceNull_SubscriptionFalse_and_ListTypeFalse.
@Test
void get_returnsMonoMap_ifSourceNull_SubscriptionFalse_and_ListTypeFalse() {
var requestContext = RequestContext.builder().objectField(mock(ObjectField.class)).source(null).build();
lenient().when(requestFactory.createRequestContext(environment)).thenReturn(requestContext);
when(environment.getSource()).thenReturn(null);
mockOperationDefinition(OperationDefinition.Operation.QUERY);
var objectRequest = ObjectRequest.builder().build();
DataFetchingFieldSelectionSet selectionSet = mock(DataFetchingFieldSelectionSet.class);
when(environment.getSelectionSet()).thenReturn(selectionSet);
var executionStepInfo = mockExecutionStepInfo("fff", "fff");
lenient().when(requestFactory.createObjectRequest(eq(executionStepInfo), eq(selectionSet))).thenReturn(objectRequest);
Map<String, Object> data = new HashMap<>();
data.put("aa", new String[] { "a", "b" });
when(backendLoader.loadSingle(objectRequest, requestContext)).thenReturn(Mono.just(data));
mockGraphQlFieldDefinition(Map.of());
var result = ((CompletableFuture<?>) backendDataFetcher.get(environment)).join();
assertTrue(result instanceof Map);
assertThat(((Map<?, ?>) result).get("aa"), is(data.get("aa")));
verify(requestFactory).createObjectRequest(any(ExecutionStepInfo.class), any(DataFetchingFieldSelectionSet.class));
verify(backendLoader).loadSingle(any(ObjectRequest.class), any(RequestContext.class));
}
use of org.dotwebstack.framework.core.query.model.RequestContext in project dotwebstack-framework by dotwebstack.
the class PagingBuilderTest method build_addLimit_forPaging.
@Test
void build_addLimit_forPaging() {
RequestContext context = RequestContext.builder().source(Map.of(OFFSET_KEY, 1, FIRST_KEY, 10)).build();
SelectQuery<Record> dataQuery = dslContext.selectQuery();
PagingBuilder.newPaging().requestContext(context).dataQuery(dataQuery).build();
assertThat(dataQuery.getSQL(), is("select 1 limit ? offset ?"));
assertThat(dataQuery.getBindValues().get(0), is(10L));
assertThat(dataQuery.getBindValues().get(1), is(1L));
}
use of org.dotwebstack.framework.core.query.model.RequestContext in project dotwebstack-framework by dotwebstack.
the class PagingBuilderTest method build_noLimitAddition_forMissingLimit.
@Test
void build_noLimitAddition_forMissingLimit() {
RequestContext context = RequestContext.builder().source(Map.of(FIRST_KEY, 10)).build();
testNoLimitAddition(context);
}
use of org.dotwebstack.framework.core.query.model.RequestContext in project dotwebstack-framework by dotwebstack.
the class QueryTest method createSelect_initQuery_forCollectionRequest.
@Test
void createSelect_initQuery_forCollectionRequest() {
Map<String, Object> source = new HashMap<>();
source.put("a", "bbb");
RequestContext requestContext = RequestContext.builder().objectField(mock(PostgresObjectField.class)).source(source).build();
ObjectRequest objectRequest = initObjectRequest();
CollectionRequest request = CollectionRequest.builder().objectRequest(objectRequest).sortCriterias(List.of()).build();
var result = new Query(request, requestContext);
assertThat(result, CoreMatchers.is(notNullValue()));
}
Aggregations