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();
}
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()));
}
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();
}
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();
}
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'"));
}
Aggregations