Search in sources :

Example 31 with Database

use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.

the class TableBuilderTest method schemaFromAnnotation.

@Test
void schemaFromAnnotation() {
    Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
    Table<SchemaInAnnotation> result = database.table(SchemaInAnnotation.class);
    assertThat(result.qualifiedName(), is("ANNOTATION_SCHEMA.SCHEMA_IN_ANNOTATION"));
}
Also used : Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 32 with Database

use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.

the class TableBuilderTest method givenAnnotationWithoutSchemaButSchemaOnParentThenParentIsUsed.

@Test
void givenAnnotationWithoutSchemaButSchemaOnParentThenParentIsUsed() {
    Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
    Table<NameInAnnotationAndSchemaInParentAnnotation> result = database.table(NameInAnnotationAndSchemaInParentAnnotation.class);
    assertThat(result.qualifiedName(), is("ANNOTATION_SCHEMA.DERIVED_NAME_IN_ANNOTATION"));
}
Also used : Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 33 with Database

use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.

the class TableBuilderTest method schemaFromBuilder.

@Test
void schemaFromBuilder() {
    Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(SchemaInAnnotation.class, t -> t.schema("BUILDER_SCHEMA")).build();
    Table<SchemaInAnnotation> result = database.table(SchemaInAnnotation.class);
    assertThat(result.qualifiedName(), is("BUILDER_SCHEMA.SCHEMA_IN_ANNOTATION"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Embedded(javax.persistence.Embedded) ZonedDateTime(java.time.ZonedDateTime) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) AttributeOverride(javax.persistence.AttributeOverride) BigDecimal(java.math.BigDecimal) Alias(com.cadenzauk.siesta.Alias) EmbeddedId(javax.persistence.EmbeddedId) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Database(com.cadenzauk.siesta.Database) Id(javax.persistence.Id) Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 34 with Database

use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.

the class TableBuilderTest method schemaFromParentAnnotation.

@Test
void schemaFromParentAnnotation() {
    Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").build();
    Table<SchemaInParentAnnotation> result = database.table(SchemaInParentAnnotation.class);
    assertThat(result.qualifiedName(), is("ANNOTATION_SCHEMA.SCHEMA_IN_PARENT_ANNOTATION"));
}
Also used : Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Example 35 with Database

use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.

the class TableBuilderTest method notInsertableFromBuilder.

@Test
void notInsertableFromBuilder() {
    Database database = Database.newBuilder().defaultSchema("DEFAULT_SCHEMA").table(NoAnnotations.class, t -> t.column(NoAnnotations::updateTime, c -> c.insertable(false))).build();
    String insertSql = database.table(NoAnnotations.class).columns().flatMap(Column::insertColumnSql).collect(joining(", "));
    assertThat(database.table(NoAnnotations.class).column(NoAnnotations::id).insertable(), is(true));
    assertThat(database.table(NoAnnotations.class).column(NoAnnotations::name).insertable(), is(true));
    assertThat(database.table(NoAnnotations.class).column(NoAnnotations::updateTime).insertable(), is(false));
    assertThat(database.table(NoAnnotations.class).column(NoAnnotations::insertTime).insertable(), is(true));
    assertThat(insertSql, is("ID, NAME, INSERT_TIME"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Embedded(javax.persistence.Embedded) ZonedDateTime(java.time.ZonedDateTime) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) AttributeOverride(javax.persistence.AttributeOverride) BigDecimal(java.math.BigDecimal) Alias(com.cadenzauk.siesta.Alias) EmbeddedId(javax.persistence.EmbeddedId) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Database(com.cadenzauk.siesta.Database) Id(javax.persistence.Id) Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test)

Aggregations

Database (com.cadenzauk.siesta.Database)57 Test (org.junit.jupiter.api.Test)41 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 ZonedDateTime (java.time.ZonedDateTime)17 Optional (java.util.Optional)17 AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)16 Alias (com.cadenzauk.siesta.Alias)15 BigDecimal (java.math.BigDecimal)14 Collectors.joining (java.util.stream.Collectors.joining)14 AttributeOverride (javax.persistence.AttributeOverride)14 Embedded (javax.persistence.Embedded)14 EmbeddedId (javax.persistence.EmbeddedId)14 Id (javax.persistence.Id)14 CoreMatchers.is (org.hamcrest.CoreMatchers.is)14 SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)13 WidgetRow (com.cadenzauk.siesta.model.WidgetRow)7 MockitoTest (com.cadenzauk.core.MockitoTest)5