Search in sources :

Example 1 with ObjectRequest

use of org.dotwebstack.framework.core.query.model.ObjectRequest 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 ObjectRequest

use of org.dotwebstack.framework.core.query.model.ObjectRequest 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 ObjectRequest

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

the class PostgresBackendLoaderTest method initObjectRequest.

private ObjectRequest initObjectRequest() {
    PostgresObjectType objectType = mock(PostgresObjectType.class);
    when(objectType.getTable()).thenReturn("anyTable");
    Map<String, Object> mapValues = Map.of("a", "bbb");
    ContextCriteria contextCriteria = mock(ContextCriteria.class);
    Context context = mock(Context.class);
    when(context.getFields()).thenReturn(Map.of("a", mock(ContextField.class)));
    when(contextCriteria.getContext()).thenReturn(context);
    when(contextCriteria.getValues()).thenReturn(mapValues);
    when(contextCriteria.getName()).thenReturn("Brewery");
    Map<FieldRequest, ObjectRequest> objectFields = Map.of();
    return ObjectRequest.builder().objectType(objectType).objectFields(objectFields).contextCriteria(contextCriteria).build();
}
Also used : RequestContext(org.dotwebstack.framework.core.query.model.RequestContext) Context(org.dotwebstack.framework.core.model.Context) ObjectRequest(org.dotwebstack.framework.core.query.model.ObjectRequest) PostgresObjectType(org.dotwebstack.framework.backend.postgres.model.PostgresObjectType) FieldRequest(org.dotwebstack.framework.core.query.model.FieldRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ContextCriteria(org.dotwebstack.framework.core.query.model.ContextCriteria)

Example 4 with ObjectRequest

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

the class QueryTest method initObjectRequest.

private ObjectRequest initObjectRequest() {
    PostgresObjectType objectType = mock(PostgresObjectType.class);
    when(objectType.getTable()).thenReturn("anyTable");
    Map<FieldRequest, ObjectRequest> objectFields = Map.of();
    return ObjectRequest.builder().objectType(objectType).objectFields(objectFields).build();
}
Also used : ObjectRequest(org.dotwebstack.framework.core.query.model.ObjectRequest) PostgresObjectType(org.dotwebstack.framework.backend.postgres.model.PostgresObjectType) FieldRequest(org.dotwebstack.framework.core.query.model.FieldRequest)

Example 5 with ObjectRequest

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

the class SelectBuilderTest method build_returnsSelectQuery_forObjectRequestWithPresenceColumn.

@Test
void build_returnsSelectQuery_forObjectRequestWithPresenceColumn() {
    ObjectRequest objectRequest = getObjectRequestWithNestedObject("age_column");
    var result = selectBuilder.build(objectRequest);
    assertThat(result, notNullValue());
    assertThat(result.toString(), equalTo("select\n" + "  \"x1\".\"name_column\" as \"x2\",\n" + "  \"x1\".\"soldPerYear_column\" as \"x3\",\n" + "  \"x1\".\"identifier_column\" as \"x4\",\n" + "  (\"x1\".\"age_column\" is not null) as \"x5\",\n" + "  \"x1\".\"age_column\" as \"x6\"\n" + "from \"beer\" as \"x1\"\n" + "where \"x1\".\"identifier_column\" = 'id-1'"));
}
Also used : AggregateObjectRequest(org.dotwebstack.framework.core.query.model.AggregateObjectRequest) ObjectRequest(org.dotwebstack.framework.core.query.model.ObjectRequest) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectRequest (org.dotwebstack.framework.core.query.model.ObjectRequest)13 Test (org.junit.jupiter.api.Test)9 RequestContext (org.dotwebstack.framework.core.query.model.RequestContext)6 HashMap (java.util.HashMap)5 ObjectField (org.dotwebstack.framework.core.model.ObjectField)5 PostgresObjectField (org.dotwebstack.framework.backend.postgres.model.PostgresObjectField)4 PostgresObjectType (org.dotwebstack.framework.backend.postgres.model.PostgresObjectType)4 CollectionRequest (org.dotwebstack.framework.core.query.model.CollectionRequest)4 FieldRequest (org.dotwebstack.framework.core.query.model.FieldRequest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Map (java.util.Map)3 JoinTable (org.dotwebstack.framework.backend.postgres.model.JoinTable)3 Context (org.dotwebstack.framework.core.model.Context)3 AggregateObjectRequest (org.dotwebstack.framework.core.query.model.AggregateObjectRequest)3 CollectionBatchRequest (org.dotwebstack.framework.core.query.model.CollectionBatchRequest)3 ContextCriteria (org.dotwebstack.framework.core.query.model.ContextCriteria)3 Disabled (org.junit.jupiter.api.Disabled)3 DatabaseClient (org.springframework.r2dbc.core.DatabaseClient)3 Collections (java.util.Collections)2 List (java.util.List)2