Search in sources :

Example 1 with PostgresObjectField

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()));
}
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 2 with PostgresObjectField

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"));
}
Also used : PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField)

Example 3 with PostgresObjectField

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);
}
Also used : PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField)

Example 4 with PostgresObjectField

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!"));
}
Also used : PostgresObjectType(org.dotwebstack.framework.backend.postgres.model.PostgresObjectType) PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField) Test(org.junit.jupiter.api.Test)

Example 5 with PostgresObjectField

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" + ")"));
}
Also used : PostgresObjectType(org.dotwebstack.framework.backend.postgres.model.PostgresObjectType) JoinColumn(org.dotwebstack.framework.backend.postgres.model.JoinColumn) PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

PostgresObjectField (org.dotwebstack.framework.backend.postgres.model.PostgresObjectField)8 Test (org.junit.jupiter.api.Test)4 PostgresObjectType (org.dotwebstack.framework.backend.postgres.model.PostgresObjectType)3 JoinColumn (org.dotwebstack.framework.backend.postgres.model.JoinColumn)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JoinTable (org.dotwebstack.framework.backend.postgres.model.JoinTable)1 Context (org.dotwebstack.framework.core.model.Context)1 CollectionBatchRequest (org.dotwebstack.framework.core.query.model.CollectionBatchRequest)1 CollectionRequest (org.dotwebstack.framework.core.query.model.CollectionRequest)1 ObjectRequest (org.dotwebstack.framework.core.query.model.ObjectRequest)1 RequestContext (org.dotwebstack.framework.core.query.model.RequestContext)1 Record (org.jooq.Record)1 Disabled (org.junit.jupiter.api.Disabled)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 DatabaseClient (org.springframework.r2dbc.core.DatabaseClient)1 FetchSpec (org.springframework.r2dbc.core.FetchSpec)1