Search in sources :

Example 36 with WidgetRow

use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.

the class SelectProjectionTest method projectIntoObject.

@Test
void projectIntoObject() {
    Database database = TestDatabase.testDatabase(new AnsiDialect());
    database.from(WidgetRow.class, "w").join(ManufacturerRow.class, "m").on(ManufacturerRow::manufacturerId).isEqualTo(WidgetRow::manufacturerId).selectInto(WidgetViewRow.class, "v").with(WidgetRow::widgetId).as(WidgetViewRow::widgetId).with(WidgetRow::name).as(WidgetViewRow::widgetName).with(WidgetRow::description).as(WidgetViewRow::description).with(WidgetRow::manufacturerId).as(WidgetViewRow::manufacturerId).with(ManufacturerRow::name).as(WidgetViewRow::manufacturerName).list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
    assertThat(sql.getValue(), is("select w.WIDGET_ID as v_WIDGET_ID, " + "w.NAME as v_WIDGET_NAME, " + "w.DESCRIPTION as v_DESCRIPTION, " + "w.MANUFACTURER_ID as v_MANUFACTURER_ID, " + "m.NAME as v_MANUFACTURER_NAME " + "from SIESTA.WIDGET w " + "join SIESTA.MANUFACTURER m on m.MANUFACTURER_ID = w.MANUFACTURER_ID"));
    assertThat(args.getValue(), arrayWithSize(0));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) ManufacturerRow(com.cadenzauk.siesta.model.ManufacturerRow) TestDatabase(com.cadenzauk.siesta.model.TestDatabase) WidgetViewRow(com.cadenzauk.siesta.model.WidgetViewRow) Test(org.junit.jupiter.api.Test) MockitoTest(com.cadenzauk.core.MockitoTest)

Example 37 with WidgetRow

use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.

the class SelectProjectionTest method projectColumns.

@Test
void projectColumns() {
    Database database = TestDatabase.testDatabase(new AnsiDialect());
    Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
    database.from(w).select(WidgetRow::name, "n1").comma(WidgetRow::description, "d1").comma(WidgetRow::manufacturerId, "m1").comma("w", WidgetRow::name, "n2").comma("w", WidgetRow::description, "d2").comma("w", WidgetRow::manufacturerId, "m2").comma(w, WidgetRow::name, "n3").comma(w, WidgetRow::description, "d3").comma(w, WidgetRow::manufacturerId, "m3").where(WidgetRow::name).isEqualTo("Bob").list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
    assertThat(sql.getValue(), is("select " + "w.NAME as n1, w.DESCRIPTION as d1, w.MANUFACTURER_ID as m1, " + "w.NAME as n2, w.DESCRIPTION as d2, w.MANUFACTURER_ID as m2, " + "w.NAME as n3, w.DESCRIPTION as d3, w.MANUFACTURER_ID as m3 " + "from SIESTA.WIDGET w " + "where w.NAME = ?"));
    assertThat(args.getValue(), arrayWithSize(1));
    assertThat(args.getValue()[0], is("Bob"));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase(com.cadenzauk.siesta.model.TestDatabase) Test(org.junit.jupiter.api.Test) MockitoTest(com.cadenzauk.core.MockitoTest)

Aggregations

WidgetRow (com.cadenzauk.siesta.model.WidgetRow)37 Test (org.junit.jupiter.api.Test)32 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)26 AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 MockitoTest (com.cadenzauk.core.MockitoTest)9 ManufacturerRow (com.cadenzauk.siesta.model.ManufacturerRow)8 TestDatabase (com.cadenzauk.siesta.model.TestDatabase)8 Database (com.cadenzauk.siesta.Database)7 Tuple2 (com.cadenzauk.core.tuple.Tuple2)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)5 Tuple3 (com.cadenzauk.core.tuple.Tuple3)2 TypedExpression.column (com.cadenzauk.siesta.grammar.expression.TypedExpression.column)2 WidgetViewRow (com.cadenzauk.siesta.model.WidgetViewRow)2 Optional (java.util.Optional)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.is (org.hamcrest.Matchers.is)2 RandomValues (com.cadenzauk.core.RandomValues)1 Tuple5 (com.cadenzauk.core.tuple.Tuple5)1 DatabaseIntegrationTest (com.cadenzauk.siesta.DatabaseIntegrationTest)1