use of org.dotwebstack.framework.core.model.ObjectField in project dotwebstack-framework by dotwebstack.
the class PostgresBackendLoaderTest method loadMany_returnsFluxObject.
@Test
void loadMany_returnsFluxObject() {
FetchSpec fetchSpec = mock(FetchSpec.class);
when(fetchSpec.all()).thenReturn(Flux.just(Collections.emptyMap()));
DatabaseClient.GenericExecuteSpec anotherSpec = mock(DatabaseClient.GenericExecuteSpec.class);
when(anotherSpec.fetch()).thenReturn(fetchSpec);
DatabaseClient.GenericExecuteSpec spec = mock(DatabaseClient.GenericExecuteSpec.class);
when(spec.bind(anyInt(), any())).thenReturn(anotherSpec);
when(databaseClient.sql(anyString())).thenReturn(spec);
Map<String, Object> source = new HashMap<>();
source.put("a", "bbb");
RequestContext requestContext = RequestContext.builder().objectField(mock(ObjectField.class)).source(source).build();
ObjectRequest objectRequest = initObjectRequest();
CollectionRequest request = CollectionRequest.builder().objectRequest(objectRequest).sortCriterias(List.of()).build();
var res = backendLoader.loadMany(request, requestContext);
assertThat(res, CoreMatchers.is(notNullValue()));
res.doOnNext(result -> assertTrue(result.isEmpty())).subscribe();
}
use of org.dotwebstack.framework.core.model.ObjectField in project dotwebstack-framework by dotwebstack.
the class BackendDataFetcherTest method get_returnsCompletableFuture_ifNotSubscription_ListTypeTrue_and_JoinCondition.
@Test
@Disabled("fix me")
void get_returnsCompletableFuture_ifNotSubscription_ListTypeTrue_and_JoinCondition() {
Map<String, Object> source = new HashMap<>();
source.put("a", "bbb");
Map<String, Object> condition = new HashMap<>();
condition.put("b", "ccc");
var joinCondition = JoinCondition.builder().key(condition).build();
source.put("$join:aaa", joinCondition);
graphql.language.Field fieldMock = new Field("aaa");
var requestContext = RequestContext.builder().objectField(mock(ObjectField.class)).source(source).build();
when(requestFactory.createRequestContext(environment)).thenReturn(requestContext);
when(environment.getSource()).thenReturn(source);
lenient().when(environment.getField()).thenReturn(fieldMock);
GraphQLList listType = mock(GraphQLList.class);
when(environment.getFieldType()).thenReturn(listType);
mockOperationDefinition(OperationDefinition.Operation.QUERY);
when(environment.getDataLoaderRegistry()).thenReturn(new DataLoaderRegistry());
var collectionRequest = 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(collectionRequest);
var result = backendDataFetcher.get(environment);
assertThat(result, notNullValue());
assertTrue(result instanceof CompletableFuture);
verify(requestFactory, times(2)).createCollectionRequest(any(ExecutionStepInfo.class), any(DataFetchingFieldSelectionSet.class));
verify(requestFactory).createRequestContext(any(DataFetchingEnvironment.class));
}
use of org.dotwebstack.framework.core.model.ObjectField in project dotwebstack-framework by dotwebstack.
the class BackendDataFetcherTest method get_returnsFluxMap_ifSourceNull_SubscriptionTrue.
@Test
void get_returnsFluxMap_ifSourceNull_SubscriptionTrue() {
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);
mockOperationDefinition(OperationDefinition.Operation.SUBSCRIPTION);
var collectionRequest = mock(CollectionRequest.class);
var selectionSet = mock(DataFetchingFieldSelectionSet.class);
when(environment.getSelectionSet()).thenReturn(selectionSet);
var executionStepInfo = mockExecutionStepInfoWithResultPath("bbb", "bbb");
lenient().when(requestFactory.createCollectionRequest(eq(executionStepInfo), eq(selectionSet))).thenReturn(collectionRequest);
Map<String, Object> data = new HashMap<>();
data.put("aa", new String[] { "a", "b" });
when(backendLoader.loadMany(any(CollectionRequest.class), any(RequestContext.class))).thenReturn(Flux.just(data));
mockGraphQlFieldDefinition(Map.of());
var result = ((Flux<?>) backendDataFetcher.get(environment)).blockFirst();
assertThat(result, CoreMatchers.is(notNullValue()));
assertTrue(result instanceof Map);
assertThat(((Map<?, ?>) result).get("aa"), is(data.get("aa")));
verify(requestFactory).createCollectionRequest(any(ExecutionStepInfo.class), any(DataFetchingFieldSelectionSet.class));
verify(backendLoader).loadMany(any(CollectionRequest.class), any(RequestContext.class));
}
use of org.dotwebstack.framework.core.model.ObjectField in project dotwebstack-framework by dotwebstack.
the class AggregateHelperTest method isAggregate_returnsFalse_forNonAggregateField.
@Test
void isAggregate_returnsFalse_forNonAggregateField() {
ObjectField objectField = mock(ObjectField.class);
when(objectField.getAggregationOf()).thenReturn(null);
assertThat(isAggregate(objectField), is(false));
}
use of org.dotwebstack.framework.core.model.ObjectField in project dotwebstack-framework by dotwebstack.
the class AggregateHelperTest method isAggregate_returnsTrue_forAggregateField.
@Test
void isAggregate_returnsTrue_forAggregateField() {
ObjectField objectField = mock(ObjectField.class);
when(objectField.getAggregationOf()).thenReturn("testAggregate");
assertThat(isAggregate(objectField), is(true));
}
Aggregations