Search in sources :

Example 1 with RequestContext

use of org.dotwebstack.framework.core.query.model.RequestContext 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();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CoreMatchers(org.hamcrest.CoreMatchers) BeforeEach(org.junit.jupiter.api.BeforeEach) CollectionBatchRequest(org.dotwebstack.framework.core.query.model.CollectionBatchRequest) Mock(org.mockito.Mock) RequestContext(org.dotwebstack.framework.core.query.model.RequestContext) HashMap(java.util.HashMap) FieldRequest(org.dotwebstack.framework.core.query.model.FieldRequest) Disabled(org.junit.jupiter.api.Disabled) DatabaseClient(org.springframework.r2dbc.core.DatabaseClient) ContextField(org.dotwebstack.framework.core.model.ContextField) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) PostgresObjectType(org.dotwebstack.framework.backend.postgres.model.PostgresObjectType) Context(org.dotwebstack.framework.core.model.Context) Mockito.when(org.mockito.Mockito.when) CollectionRequest(org.dotwebstack.framework.core.query.model.CollectionRequest) ObjectRequest(org.dotwebstack.framework.core.query.model.ObjectRequest) FetchSpec(org.springframework.r2dbc.core.FetchSpec) JoinCriteria(org.dotwebstack.framework.core.query.model.JoinCriteria) PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) ObjectField(org.dotwebstack.framework.core.model.ObjectField) ContextCriteria(org.dotwebstack.framework.core.query.model.ContextCriteria) JoinTable(org.dotwebstack.framework.backend.postgres.model.JoinTable) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) CollectionRequest(org.dotwebstack.framework.core.query.model.CollectionRequest) FetchSpec(org.springframework.r2dbc.core.FetchSpec) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ObjectRequest(org.dotwebstack.framework.core.query.model.ObjectRequest) DatabaseClient(org.springframework.r2dbc.core.DatabaseClient) PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField) ObjectField(org.dotwebstack.framework.core.model.ObjectField) RequestContext(org.dotwebstack.framework.core.query.model.RequestContext) Test(org.junit.jupiter.api.Test)

Example 2 with RequestContext

use of org.dotwebstack.framework.core.query.model.RequestContext in project dotwebstack-framework by dotwebstack.

the class PostgresBackendLoaderTest method batchLoadMany_returnsFluxObject.

@Test
@Disabled("fix me")
void batchLoadMany_returnsFluxObject() {
    FetchSpec fetchSpec = mock(FetchSpec.class);
    when(fetchSpec.all()).thenReturn(Flux.just(Map.of("@@@", "ccc")));
    DatabaseClient.GenericExecuteSpec spec = mock(DatabaseClient.GenericExecuteSpec.class);
    when(spec.fetch()).thenReturn(fetchSpec);
    when(databaseClient.sql(anyString())).thenReturn(spec);
    PostgresObjectField objectFieldMock = mock(PostgresObjectField.class);
    when(objectFieldMock.getJoinTable()).thenReturn(mock(JoinTable.class));
    Map<String, Object> source = new HashMap<>();
    source.put("a", "bbb");
    RequestContext requestContext = RequestContext.builder().objectField(objectFieldMock).source(source).build();
    ObjectRequest objectRequest = initObjectRequest();
    CollectionRequest collectionRequest = CollectionRequest.builder().objectRequest(objectRequest).sortCriterias(List.of()).build();
    CollectionBatchRequest request = CollectionBatchRequest.builder().collectionRequest(collectionRequest).joinCriteria(JoinCriteria.builder().build()).build();
    var res = backendLoader.batchLoadMany(request, requestContext);
    assertThat(res, CoreMatchers.is(notNullValue()));
}
Also used : CollectionRequest(org.dotwebstack.framework.core.query.model.CollectionRequest) FetchSpec(org.springframework.r2dbc.core.FetchSpec) HashMap(java.util.HashMap) CollectionBatchRequest(org.dotwebstack.framework.core.query.model.CollectionBatchRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ObjectRequest(org.dotwebstack.framework.core.query.model.ObjectRequest) DatabaseClient(org.springframework.r2dbc.core.DatabaseClient) PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField) RequestContext(org.dotwebstack.framework.core.query.model.RequestContext) JoinTable(org.dotwebstack.framework.backend.postgres.model.JoinTable) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with RequestContext

use of org.dotwebstack.framework.core.query.model.RequestContext in project dotwebstack-framework by dotwebstack.

the class PagingBuilderTest method build_noLimitAddition_forMissingOffset.

@Test
void build_noLimitAddition_forMissingOffset() {
    RequestContext context = RequestContext.builder().source(Map.of(OFFSET_KEY, 1)).build();
    testNoLimitAddition(context);
}
Also used : RequestContext(org.dotwebstack.framework.core.query.model.RequestContext) Test(org.junit.jupiter.api.Test)

Example 4 with RequestContext

use of org.dotwebstack.framework.core.query.model.RequestContext in project dotwebstack-framework by dotwebstack.

the class PagingBuilderTest method build_noLimitAddition_forNullSource.

@Test
void build_noLimitAddition_forNullSource() {
    RequestContext context = RequestContext.builder().source(null).build();
    testNoLimitAddition(context);
}
Also used : RequestContext(org.dotwebstack.framework.core.query.model.RequestContext) Test(org.junit.jupiter.api.Test)

Example 5 with RequestContext

use of org.dotwebstack.framework.core.query.model.RequestContext 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));
}
Also used : CollectionRequest(org.dotwebstack.framework.core.query.model.CollectionRequest) HashMap(java.util.HashMap) DataFetchingFieldSelectionSet(graphql.schema.DataFetchingFieldSelectionSet) GroupedFlux(reactor.core.publisher.GroupedFlux) KeyGroupedFlux(org.dotwebstack.framework.core.datafetchers.KeyGroupedFlux) Flux(reactor.core.publisher.Flux) Field(graphql.language.Field) ObjectField(org.dotwebstack.framework.core.model.ObjectField) MergedField(graphql.execution.MergedField) Field(graphql.language.Field) ExecutionStepInfo(graphql.execution.ExecutionStepInfo) ObjectField(org.dotwebstack.framework.core.model.ObjectField) GraphQLObjectType.newObject(graphql.schema.GraphQLObjectType.newObject) RequestContext(org.dotwebstack.framework.core.query.model.RequestContext) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

RequestContext (org.dotwebstack.framework.core.query.model.RequestContext)11 Test (org.junit.jupiter.api.Test)11 HashMap (java.util.HashMap)7 CollectionRequest (org.dotwebstack.framework.core.query.model.CollectionRequest)6 ObjectField (org.dotwebstack.framework.core.model.ObjectField)5 ObjectRequest (org.dotwebstack.framework.core.query.model.ObjectRequest)5 Map (java.util.Map)4 PostgresObjectField (org.dotwebstack.framework.backend.postgres.model.PostgresObjectField)4 ExecutionStepInfo (graphql.execution.ExecutionStepInfo)3 DataFetchingFieldSelectionSet (graphql.schema.DataFetchingFieldSelectionSet)3 GraphQLObjectType.newObject (graphql.schema.GraphQLObjectType.newObject)3 List (java.util.List)3 JoinTable (org.dotwebstack.framework.backend.postgres.model.JoinTable)3 CollectionBatchRequest (org.dotwebstack.framework.core.query.model.CollectionBatchRequest)3 Disabled (org.junit.jupiter.api.Disabled)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 MergedField (graphql.execution.MergedField)2 Field (graphql.language.Field)2 Collections (java.util.Collections)2 CompletableFuture (java.util.concurrent.CompletableFuture)2