Search in sources :

Example 41 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class DataTypeTest method toDatabase.

@ParameterizedTest
@MethodSource("parametersForToDatabase")
<T> void toDatabase(DataType<T> dataType, T input, Object expected) {
    if (input != null) {
        when(db.dialect()).thenReturn(new AnsiDialect());
    }
    Object actual = dataType.toDatabase(db, input);
    assertThat(actual, is(expected));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 42 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class DataTypeTest method toDatabaseLocalDateTime.

@ParameterizedTest
@MethodSource("timeZones")
void toDatabaseLocalDateTime(String jvmTimeZone) {
    try (UncheckedAutoCloseable ignored = withTimeZone(jvmTimeZone)) {
        LocalDateTime input = RandomValues.randomLocalDateTime();
        Timestamp expected = Timestamp.valueOf(input);
        when(db.dialect()).thenReturn(new AnsiDialect());
        Object result = DataType.LOCAL_DATE_TIME.toDatabase(db, input);
        assertThat(result, is(expected));
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) RandomValues.randomLocalDateTime(com.cadenzauk.core.RandomValues.randomLocalDateTime) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) Timestamp(java.sql.Timestamp) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 43 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class EmbeddedTest method embeddedInProjection.

@Test
void embeddedInProjection() {
    Database database = testDatabase(new AnsiDialect());
    database.from(PartRow.class).select(PartRow::purchasePrice, "pp").comma(PartRow::retailPrice, "rp").comma(column(PartRow::purchasePrice).dot(MoneyAmount::currency), "pc").comma(column(PartRow::retailPrice).dot(MoneyAmount::currency), "rc").where(PartRow::partId).isEqualTo(4L).optional(sqlExecutor);
    Mockito.verify(sqlExecutor).query(sql.capture(), args.capture(), any());
    assertThat(sql.getValue(), is("select PART.PURCHASE_PRICE_AMOUNT as pp_PURCHASE_PRICE_AMOUNT, " + "PART.PURCHASE_PRICE_CCY as pp_PURCHASE_PRICE_CCY, " + "PART.RETAIL_PRICE_AMOUNT as rp_RETAIL_PRICE_AMOUNT, " + "PART.RETAIL_PRICE_CCY as rp_RETAIL_PRICE_CCY, " + "PART.PURCHASE_PRICE_CCY as pc, " + "PART.RETAIL_PRICE_CCY as rc " + "from SIESTA.PART PART " + "where PART.PART_ID = ?"));
    assertThat(args.getValue(), is(toArray(4L)));
}
Also used : PartRow(com.cadenzauk.siesta.model.PartRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) MoneyAmount(com.cadenzauk.siesta.model.MoneyAmount) Test(org.junit.jupiter.api.Test) MockitoTest(com.cadenzauk.core.MockitoTest)

Example 44 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class FromTest method validateInvalidThrows.

@Test
void validateInvalidThrows() {
    Database database = testDatabase(new AnsiDialect());
    calling(() -> database.from(WidgetRow.class).join(ManufacturerRow.class, "m").on(WidgetRow::name).isEqualTo("Fred").sql()).shouldThrow(InvalidJoinException.class).withMessage(is("Joined table 'SIESTA.MANUFACTURER m' is not referenced in the ON clause."));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) InvalidJoinException(com.cadenzauk.siesta.grammar.InvalidJoinException) Test(org.junit.jupiter.api.Test)

Example 45 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class SelectExpressionTest method isNotLike.

@Test
void isNotLike() {
    Database database = testDatabase(new AnsiDialect());
    String sql = database.from(WidgetRow.class).where(WidgetRow::name).isNotLike("abc%").sql();
    assertThat(sql, is("select WIDGET.WIDGET_ID as WIDGET_WIDGET_ID, " + "WIDGET.NAME as WIDGET_NAME, " + "WIDGET.MANUFACTURER_ID as WIDGET_MANUFACTURER_ID, " + "WIDGET.DESCRIPTION as WIDGET_DESCRIPTION " + "from SIESTA.WIDGET WIDGET " + "where WIDGET.NAME not like ?"));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Test(org.junit.jupiter.api.Test)

Aggregations

AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)56 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)36 Test (org.junit.jupiter.api.Test)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 MethodSource (org.junit.jupiter.params.provider.MethodSource)24 WidgetRow (com.cadenzauk.siesta.model.WidgetRow)23 Database (com.cadenzauk.siesta.Database)16 MockitoTest (com.cadenzauk.core.MockitoTest)14 SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)10 TestDatabase (com.cadenzauk.siesta.model.TestDatabase)10 ManufacturerRow (com.cadenzauk.siesta.model.ManufacturerRow)8 UncheckedAutoCloseable (com.cadenzauk.core.lang.UncheckedAutoCloseable)5 InWhereExpectingAnd (com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd)4 Scope (com.cadenzauk.siesta.Scope)3 Timestamp (java.sql.Timestamp)3 RandomValues.randomLocalDate (com.cadenzauk.core.RandomValues.randomLocalDate)2 RandomValues.randomLocalDateTime (com.cadenzauk.core.RandomValues.randomLocalDateTime)2 InvalidJoinException (com.cadenzauk.siesta.grammar.InvalidJoinException)2 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2