use of org.dotwebstack.framework.backend.postgres.model.PostgresObjectType 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.backend.postgres.model.PostgresObjectType 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.backend.postgres.model.PostgresObjectType 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.PostgresObjectType 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" + ")"));
}
use of org.dotwebstack.framework.backend.postgres.model.PostgresObjectType in project dotwebstack-framework by dotwebstack.
the class JoinHelperTest method createJoinConditions_returnsListCondition.
@Test
void createJoinConditions_returnsListCondition() {
var context = new Context();
context.setFields(Map.of("arg", mock(ContextField.class)));
var contextCriteria = ContextCriteria.builder().name("test").context(context).values(Map.of("arg", "val")).build();
Table<Record> junctionTable = findTable("table1", contextCriteria);
Table<Record> referencedTable = findTable("table2", contextCriteria);
JoinColumn joinColumn = mock(JoinColumn.class);
when(joinColumn.getName()).thenReturn("arg");
List<JoinColumn> joinColumns = List.of(joinColumn);
when(joinColumn.getReferencedField()).thenReturn("any");
PostgresObjectType objectType = mock(PostgresObjectType.class);
PostgresObjectField field = mock(PostgresObjectField.class);
when(field.getColumn()).thenReturn("arg");
when(objectType.getField(any(String.class))).thenReturn(field);
var result = createJoinConditions(junctionTable, referencedTable, joinColumns, objectType);
assertThat(result, notNullValue());
assertThat(result.toString(), is("\"table1_test_ctx({0})\".\"arg\" = \"table2_test_ctx({0})\".\"arg\""));
}
Aggregations