Search in sources :

Example 11 with RequestContext

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

the class PostgresBackendLoaderTest method loadSingle_returnsMonoObject.

@Test
void loadSingle_returnsMonoObject() {
    Map<String, Object> source = new HashMap<>();
    source.put("a", "bbb");
    RequestContext requestContext = RequestContext.builder().objectField(mock(ObjectField.class)).source(source).build();
    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);
    ObjectRequest objectRequest = initObjectRequest();
    var res = backendLoader.loadSingle(objectRequest, 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) ObjectRequest(org.dotwebstack.framework.core.query.model.ObjectRequest) DatabaseClient(org.springframework.r2dbc.core.DatabaseClient) HashMap(java.util.HashMap) FetchSpec(org.springframework.r2dbc.core.FetchSpec) PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField) ObjectField(org.dotwebstack.framework.core.model.ObjectField) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RequestContext(org.dotwebstack.framework.core.query.model.RequestContext) 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