use of org.dotwebstack.framework.backend.postgres.model.PostgresObjectField 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.backend.postgres.model.PostgresObjectField in project dotwebstack-framework by dotwebstack.
the class PostgresBackendModuleTest method assertColumnPrefixFields.
private void assertColumnPrefixFields(PostgresObjectType beer, String fieldName, String columnPrefix) {
PostgresObjectField location = beer.getField(fieldName);
assertThat(location, notNullValue());
assertThat(location.getTargetType(), notNullValue());
assertThat(beer.getField(fieldName).getTargetType().getField("street"), notNullValue());
assertThat(((PostgresObjectField) beer.getField(fieldName).getTargetType().getField("street")).getColumn(), is(columnPrefix.concat("street")));
assertThat(beer.getField(fieldName).getTargetType().getField("housenumber"), notNullValue());
assertThat(((PostgresObjectField) beer.getField(fieldName).getTargetType().getField("housenumber")).getColumn(), is(columnPrefix.concat("housenumber")));
assertThat(beer.getField(fieldName).getTargetType().getField("city"), notNullValue());
assertThat(((PostgresObjectField) beer.getField(fieldName).getTargetType().getField("city")).getColumn(), is("ownprefix_city"));
}
use of org.dotwebstack.framework.backend.postgres.model.PostgresObjectField in project dotwebstack-framework by dotwebstack.
the class SortBuilderTest method createNestedFieldPath.
private List<ObjectField> createNestedFieldPath() {
PostgresObjectField objectField = new PostgresObjectField();
objectField.setName("fieldTwo");
PostgresObjectField nestedObjectField = new PostgresObjectField();
nestedObjectField.setName("nestedField");
return List.of(objectField, nestedObjectField);
}
use of org.dotwebstack.framework.backend.postgres.model.PostgresObjectField in project dotwebstack-framework by dotwebstack.
the class BatchQueryBuilderTest method build_throwsException_whileMissingJoinConfiguration.
@Test
void build_throwsException_whileMissingJoinConfiguration() {
var table = DSL.table("beers");
var dataQuery = DSL.select(DSL.asterisk()).from(table).getQuery();
var objectField = new PostgresObjectField();
objectField.setName("testField");
var joinConfiguration = JoinConfiguration.builder().objectField(objectField).objectType(new PostgresObjectType()).targetType(new PostgresObjectType()).build();
var builder = batchQueryBuilder.table(table).dataQuery(dataQuery).joinConfiguration(joinConfiguration).joinKeys(Set.of(Map.of("identifier", "id-1")));
var thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown.getMessage(), equalTo("Object field 'testField' has no relation configuration!"));
}
use of org.dotwebstack.framework.backend.postgres.model.PostgresObjectField in project dotwebstack-framework by dotwebstack.
the class FilterConditionBuilderTest method build_returnsCondition_forFieldPathWithMultipleItems.
@Test
void build_returnsCondition_forFieldPathWithMultipleItems() {
var childObjectType = new PostgresObjectType();
childObjectType.setTable("child_v");
childObjectType.setFields(Map.of("child_id", new PostgresObjectField()));
var joinColumns = new ArrayList<JoinColumn>();
var joinColumn = new JoinColumn();
joinColumn.setName("parent_id");
joinColumn.setReferencedColumn("child_id");
joinColumns.add(joinColumn);
var parentField = new PostgresObjectField();
parentField.setJoinColumns(joinColumns);
parentField.setObjectType(new PostgresObjectType());
parentField.setTargetType(childObjectType);
var childField = new PostgresObjectField();
childField.setColumn("child_column");
Map<String, Object> values = Map.of("eq", "foo");
var filterCriteria = ObjectFieldFilterCriteria.builder().filterType(FilterType.EXACT).fieldPath(List.of(parentField, childField)).value(values).build();
var condition = build(filterCriteria);
assertThat(condition, notNullValue());
assertThat(condition.toString(), equalTo("exists (\n" + " select 1\n" + " from \"child_v\" \"x1\"\n" + " where (\n" + " \"x1\".\"parent_id\" = \"x1\".\"child_id\"\n" + " and \"x1\".\"child_column\" = 'foo'\n" + " )\n" + ")"));
}
Aggregations