Search in sources :

Example 1 with Context

use of org.dotwebstack.framework.core.model.Context 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 2 with Context

use of org.dotwebstack.framework.core.model.Context 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\""));
}
Also used : Context(org.dotwebstack.framework.core.model.Context) JoinColumn(org.dotwebstack.framework.backend.postgres.model.JoinColumn) PostgresObjectType(org.dotwebstack.framework.backend.postgres.model.PostgresObjectType) PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField) Record(org.jooq.Record) Test(org.junit.jupiter.api.Test)

Aggregations

PostgresObjectType (org.dotwebstack.framework.backend.postgres.model.PostgresObjectType)2 Context (org.dotwebstack.framework.core.model.Context)2 JoinColumn (org.dotwebstack.framework.backend.postgres.model.JoinColumn)1 PostgresObjectField (org.dotwebstack.framework.backend.postgres.model.PostgresObjectField)1 ContextCriteria (org.dotwebstack.framework.core.query.model.ContextCriteria)1 FieldRequest (org.dotwebstack.framework.core.query.model.FieldRequest)1 ObjectRequest (org.dotwebstack.framework.core.query.model.ObjectRequest)1 RequestContext (org.dotwebstack.framework.core.query.model.RequestContext)1 Record (org.jooq.Record)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1