diff --git a/build.gradle.kts b/build.gradle.kts index 9edfa46223..fb716b30fb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -102,9 +102,10 @@ subprojects { } } - testDb("mariadb") { - port = 3000 + testDb("mariadb_v2") { dialects("mariadb") + container = "mariadb" + port = 3000 dependencies { dependency("org.mariadb.jdbc:mariadb-java-client:${Versions.mariaDB_v2}") } @@ -119,17 +120,9 @@ subprojects { } } - testDb("mariadb_v2") { - dialects("mariadb") - container = "mariadb" - port = 3000 - dependencies { - dependency("org.mariadb.jdbc:mariadb-java-client:${Versions.mariaDB_v2}") - } - } - testDb("oracle") { port = 3003 + colima = true dialects("oracle") dependencies { dependency("com.oracle.database.jdbc:ojdbc8:${Versions.oracle12}") @@ -156,6 +149,7 @@ subprojects { testDb("sqlserver") { port = 3005 + dialects("sqlserver") dependencies { dependency("com.microsoft.sqlserver:mssql-jdbc:${Versions.sqlserver}") } diff --git a/buildScripts/docker/docker-compose-oracle.yml b/buildScripts/docker/docker-compose-oracle.yml index b11df21b8d..4702a3b544 100644 --- a/buildScripts/docker/docker-compose-oracle.yml +++ b/buildScripts/docker/docker-compose-oracle.yml @@ -7,8 +7,4 @@ services: ports: - "3003:1521" environment: -# WEB_CONSOLE: "true" -# DBCA_TOTAL_MEMORY: 1024 -# PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -# USE_UTF8_IF_CHARSET_EMPTY: "true" ORACLE_PASSWORD: "Oracle18" diff --git a/buildSrc/src/main/kotlin/org/jetbrains/exposed/gradle/TestDbDsl.kt b/buildSrc/src/main/kotlin/org/jetbrains/exposed/gradle/TestDbDsl.kt index 20d365da3f..2b77c6b8ae 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/exposed/gradle/TestDbDsl.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/exposed/gradle/TestDbDsl.kt @@ -2,11 +2,15 @@ package org.jetbrains.exposed.gradle import com.avast.gradle.dockercompose.ComposeExtension import org.gradle.api.Project +import org.gradle.api.internal.tasks.testing.filter.DefaultTestFilter +import org.gradle.api.tasks.TaskProvider +import org.gradle.api.tasks.testing.AbstractTestTask import org.gradle.api.tasks.testing.Test import org.gradle.configurationcache.extensions.capitalized import org.gradle.kotlin.dsl.dependencies +import org.gradle.kotlin.dsl.environment import org.gradle.kotlin.dsl.getValue -import org.gradle.kotlin.dsl.provideDelegate +import org.gradle.kotlin.dsl.named import org.gradle.kotlin.dsl.register import java.time.Duration @@ -17,6 +21,7 @@ class TestDb(val name: String) { var port: Int? = null var container: String = name var withContainer: Boolean = true + var colima: Boolean = false internal val dependencies = mutableListOf() @@ -61,17 +66,27 @@ fun Project.testDb(name: String, block: TestDb.() -> Unit) { } } - val test by tasks - test.dependsOn(testTask) + tasks.named("test") { + delegatedTo(testTask) + } } private fun Project.configureCompose(db: TestDb) { if (rootProject.tasks.findByPath("${db.container}ComposeUp") != null) return rootProject.extensions.configure("dockerCompose") { - nested(db.name).apply { + nested(db.container).apply { environment.put("SERVICES_HOST", "127.0.0.1") environment.put("COMPOSE_CONVERT_WINDOWS_PATHS", true) + + val isArm = System.getProperty("os.arch") == "aarch64" + if (isArm && db.colima) { + val home = System.getProperty("user.home") + val DOCKER_HOST = "unix://$home/.colima/default/docker.sock" + println("Using docker host for colima: $DOCKER_HOST") + environment.put("DOCKER_HOST", DOCKER_HOST) + } + useComposeFiles.set(listOf("buildScripts/docker/docker-compose-${db.container}.yml")) removeVolumes.set(true) stopContainers.set(false) @@ -89,3 +104,26 @@ private fun Project.configureCompose(db: TestDb) { startCompose.dependsOn(startDb) stopCompose.dependsOn(stopDb) } + +/** + * Delegates the execution of tests to other tasks. + * + * @param tasks The tasks to delegate the test execution to. + * @return The modified Test object. + */ +fun Test.delegatedTo(vararg tasks: TaskProvider): Test { + // don't run tests directly, delegate to other tasks + filter { + setExcludePatterns("*") + isFailOnNoMatchingTests = false + } + finalizedBy(tasks) + // Pass --tests CLI option value into delegates + doFirst { + val testsFilter = (filter as DefaultTestFilter).commandLineIncludePatterns.toList() + tasks.forEach { + it.configure { setTestNameIncludePatterns(testsFilter) } + } + } + return this +} diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 5521ce1141..ecb19d81d7 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -18,7 +18,7 @@ Independently of how you'd like to contribute, please make sure you read and com ### Testing on Apple Silicon To run Oracle XE tests, you need to install [Colima](https://github.com/abiosoft/colima) container runtime. It will work in pair with your docker installation. ```shell -brew install +brew install colima ``` After installing, you need to start the colima daemon in arch x86_64 mode: @@ -26,14 +26,15 @@ After installing, you need to start the colima daemon in arch x86_64 mode: colima start --arch x86_64 --memory 4 --network-address ``` -Make sure that colima is used as default docker context: +The test task can automatically use colima context when needed, and it's better to use default context for other tasks. +To switch the context to default, run: ```shell -docker context list +docker context use default ``` -If not, set it as default: +Make sure that default is used as default docker context: ```shell -docker context use colima +docker context list ``` ### Code diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt index ae350d9175..7fd562c959 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt @@ -175,8 +175,8 @@ class Database private constructor( fun connect( url: String, driver: String = getDriver(url), - user: String = "root", - password: String = "Exposed_password_1!", + user: String = "", + password: String = "", setupConnection: (Connection) -> Unit = {}, databaseConfig: DatabaseConfig? = null, manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it) } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt index 29e3eba435..54657bea4e 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt @@ -152,7 +152,7 @@ object SchemaUtils { return createStatement() } - fun createIndex(index: Index) = index.createStatement() + fun createIndex(index: Index): List = index.createStatement() @Suppress("NestedBlockDepth", "ComplexMethod") private fun DataTypeProvider.dbDefaultToString(column: Column<*>, exp: Expression<*>): String { @@ -628,6 +628,13 @@ object SchemaUtils { } } + /** + * Retrieves a list of all table names in the current database. + * + * @return A list of table names as strings. + */ + fun listTables(): List = currentDialect.allTablesNames() + fun drop(vararg tables: Table, inBatch: Boolean = false) { if (tables.isEmpty()) return with(TransactionManager.current()) { diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt index 115ce24216..5503d8c44b 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt @@ -39,7 +39,9 @@ interface FieldSet { fields.forEach { if (it is CompositeColumn<*>) { unrolled.addAll(it.getRealColumns()) - } else unrolled.add(it) + } else { + unrolled.add(it) + } } return unrolled @@ -174,7 +176,9 @@ class Join( val table: ColumnSet ) : ColumnSet() { - override val columns: List> get() = joinParts.flatMapTo(table.columns.toMutableList()) { it.joinPart.columns } + override val columns: List> get() = joinParts.flatMapTo( + table.columns.toMutableList() + ) { it.joinPart.columns } internal val joinParts: MutableList = mutableListOf() @@ -245,12 +249,16 @@ class Join( val fkKeys = findKeys(this, otherTable) ?: findKeys(otherTable, this) ?: emptyList() return when { joinType != JoinType.CROSS && fkKeys.isEmpty() -> { - error("Cannot join with $otherTable as there is no matching primary key/foreign key pair and constraint missing") + error( + "Cannot join with $otherTable as there is no matching primary key/foreign key pair and constraint missing" + ) } fkKeys.any { it.second.size > 1 } -> { val references = fkKeys.joinToString(" & ") { "${it.first} -> ${it.second.joinToString()}" } - error("Cannot join with $otherTable as there is multiple primary key <-> foreign key references.\n$references") + error( + "Cannot join with $otherTable as there is multiple primary key <-> foreign key references.\n$references" + ) } else -> { @@ -286,7 +294,9 @@ class Join( val additionalConstraint: (SqlExpressionBuilder.() -> Op)? = null ) { init { - require(joinType == JoinType.CROSS || conditions.isNotEmpty() || additionalConstraint != null) { "Missing join condition on $${this.joinPart}" } + require( + joinType == JoinType.CROSS || conditions.isNotEmpty() || additionalConstraint != null + ) { "Missing join condition on $${this.joinPart}" } } fun describe(transaction: Transaction, builder: QueryBuilder) = with(builder) { @@ -341,7 +351,9 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { internal val tableNameWithoutScheme: String get() = tableName.substringAfterLast(".") // Table name may contain quotes, remove those before appending - internal val tableNameWithoutSchemeSanitized: String get() = tableNameWithoutScheme.replace("\"", "").replace("'", "") + internal val tableNameWithoutSchemeSanitized: String get() = tableNameWithoutScheme + .replace("\"", "") + .replace("'", "") private val _columns = mutableListOf>() @@ -383,7 +395,11 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { tableNameWithoutScheme.inProperCase().trim('\"', '\'') } - override fun describe(s: Transaction, queryBuilder: QueryBuilder): Unit = queryBuilder { append(s.identity(this@Table)) } + override fun describe(s: Transaction, queryBuilder: QueryBuilder): Unit = queryBuilder { + append( + s.identity(this@Table) + ) + } // Join operations @@ -408,9 +424,19 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { // Column registration /** Adds a column of the specified [type] and with the specified [name] to the table. */ - fun registerColumn(name: String, type: IColumnType): Column = Column(this, name, type).also { _columns.addColumn(it) } - - fun > registerCompositeColumn(column: T): T = column.apply { getRealColumns().forEach { _columns.addColumn(it) } } + fun registerColumn(name: String, type: IColumnType): Column = Column( + this, + name, + type + ).also { _columns.addColumn(it) } + + fun > registerCompositeColumn(column: T): T = column.apply { + getRealColumns().forEach { + _columns.addColumn( + it + ) + } + } /** * Replaces the specified [oldColumn] with the specified [newColumn] in the table. @@ -431,7 +457,9 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { // Primary keys - internal fun isCustomPKNameDefined(): Boolean = primaryKey?.let { it.name != "pk_$tableNameWithoutSchemeSanitized" } == true + internal fun isCustomPKNameDefined(): Boolean = primaryKey?.let { + it.name != "pk_$tableNameWithoutSchemeSanitized" + } == true /** * Represents a primary key composed by the specified [columns], and with the specified [name]. @@ -477,7 +505,11 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { /** Creates an [EntityID] column, with the specified [name], for storing the same objects as the specified [originalColumn]. */ fun > entityId(name: String, originalColumn: Column): Column> { val columnTypeCopy = originalColumn.columnType.cloneAsBaseType() - val answer = Column>(this, name, EntityIDColumnType(Column(originalColumn.table, name, columnTypeCopy))) + val answer = Column>( + this, + name, + EntityIDColumnType(Column(originalColumn.table, name, columnTypeCopy)) + ) _columns.addColumn(answer) return answer } @@ -551,7 +583,10 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { * @param precision Total count of significant digits in the whole number, that is, the number of digits to both sides of the decimal point. * @param scale Count of decimal digits in the fractional part. */ - fun decimal(name: String, precision: Int, scale: Int): Column = registerColumn(name, DecimalColumnType(precision, scale)) + fun decimal(name: String, precision: Int, scale: Int): Column = registerColumn( + name, + DecimalColumnType(precision, scale) + ) // Character columns @@ -562,13 +597,19 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { * Creates a character column, with the specified [name], for storing strings with the specified [length] using the specified text [collate] type. * If no collate type is specified then the database default is used. */ - fun char(name: String, length: Int, collate: String? = null): Column = registerColumn(name, CharColumnType(length, collate)) + fun char(name: String, length: Int, collate: String? = null): Column = registerColumn( + name, + CharColumnType(length, collate) + ) /** * Creates a character column, with the specified [name], for storing strings with the specified maximum [length] using the specified text [collate] type. * If no collate type is specified then the database default is used. */ - fun varchar(name: String, length: Int, collate: String? = null): Column = registerColumn(name, VarCharColumnType(length, collate)) + fun varchar(name: String, length: Int, collate: String? = null): Column = registerColumn( + name, + VarCharColumnType(length, collate) + ) /** * Creates a character column, with the specified [name], for storing strings of arbitrary length using the specified [collate] type. @@ -639,7 +680,10 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { // Enumeration columns /** Creates an enumeration column, with the specified [name], for storing enums of type [klass] by their ordinal. */ - fun > enumeration(name: String, klass: KClass): Column = registerColumn(name, EnumerationColumnType(klass)) + fun > enumeration(name: String, klass: KClass): Column = registerColumn( + name, + EnumerationColumnType(klass) + ) /** Creates an enumeration column, with the specified [name], for storing enums of type [T] by their ordinal. */ inline fun > enumeration(name: String) = enumeration(name, T::class) @@ -742,7 +786,12 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { * @param ref A column from another table which will be used as a "parent". * @see [references] */ - infix fun , S : T, C : Column> C.references(ref: Column): C = references(ref, null, null, null) + infix fun , S : T, C : Column> C.references(ref: Column): C = references( + ref, + null, + null, + null + ) /** * Create reference from a @receiver column to [ref] column with [onDelete], [onUpdate], and [fkName] options. @@ -817,7 +866,11 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { onUpdate: ReferenceOption? = null, fkName: String? = null ): Column { - val column = Column(this, name, refColumn.columnType.cloneAsBaseType()).references(refColumn, onDelete, onUpdate, fkName) + val column = Column( + this, + name, + refColumn.columnType.cloneAsBaseType() + ).references(refColumn, onDelete, onUpdate, fkName) _columns.addColumn(column) return column } @@ -982,9 +1035,13 @@ open class Table(name: String = "") : ColumnSet(), DdlAware { ) { _indices.add( Index( - columns.toList(), isUnique, customIndexName, indexType, + columns.toList(), + isUnique, + customIndexName, + indexType, filterCondition?.invoke(SqlExpressionBuilder), - functions, functions?.let { this } + functions, + functions?.let { this } ) ) } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/transactions/ThreadLocalTransactionManager.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/transactions/ThreadLocalTransactionManager.kt index 67a4934453..b3c80991a3 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/transactions/ThreadLocalTransactionManager.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/transactions/ThreadLocalTransactionManager.kt @@ -166,46 +166,45 @@ fun transaction( readOnly: Boolean = false, db: Database? = null, statement: Transaction.() -> T -): T = - keepAndRestoreTransactionRefAfterRun(db) { - val outer = TransactionManager.currentOrNull() +): T = keepAndRestoreTransactionRefAfterRun(db) { + val outer = TransactionManager.currentOrNull() - if (outer != null && (db == null || outer.db == db)) { - val outerManager = outer.db.transactionManager + if (outer != null && (db == null || outer.db == db)) { + val outerManager = outer.db.transactionManager - val transaction = outerManager.newTransaction(transactionIsolation, readOnly, outer) + val transaction = outerManager.newTransaction(transactionIsolation, readOnly, outer) + try { + transaction.statement().also { + if (outer.db.useNestedTransactions) { + transaction.commit() + } + } + } finally { + TransactionManager.resetCurrent(outerManager) + } + } else { + val existingForDb = db?.transactionManager + existingForDb?.currentOrNull()?.let { transaction -> + val currentManager = outer?.db.transactionManager try { + TransactionManager.resetCurrent(existingForDb) transaction.statement().also { - if (outer.db.useNestedTransactions) { + if (db.useNestedTransactions) { transaction.commit() } } } finally { - TransactionManager.resetCurrent(outerManager) + TransactionManager.resetCurrent(currentManager) } - } else { - val existingForDb = db?.transactionManager - existingForDb?.currentOrNull()?.let { transaction -> - val currentManager = outer?.db.transactionManager - try { - TransactionManager.resetCurrent(existingForDb) - transaction.statement().also { - if (db.useNestedTransactions) { - transaction.commit() - } - } - } finally { - TransactionManager.resetCurrent(currentManager) - } - } ?: inTopLevelTransaction( - transactionIsolation, - readOnly, - db, - null, - statement - ) - } + } ?: inTopLevelTransaction( + transactionIsolation, + readOnly, + db, + null, + statement + ) } +} fun inTopLevelTransaction( transactionIsolation: Int, @@ -249,6 +248,7 @@ fun inTopLevelTransaction( intermediateDelay += retryInterval * repetitions ThreadLocalRandom.current().nextLong(intermediateDelay, intermediateDelay + retryInterval) } + transaction.minRepetitionDelay == transaction.maxRepetitionDelay -> transaction.minRepetitionDelay else -> 0 } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/transactions/TransactionApi.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/transactions/TransactionApi.kt index 9d7bd393fd..2399a3902d 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/transactions/TransactionApi.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/transactions/TransactionApi.kt @@ -108,6 +108,10 @@ interface TransactionManager { private class TransactionManagerThreadLocal : ThreadLocal() { var isInitialized = false + override fun get(): TransactionManager { + return super.get() + } + override fun initialValue(): TransactionManager { isInitialized = true return defaultDatabase?.let { registeredDatabases.getValue(it) } ?: NotInitializedManager diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/Default.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/Default.kt index 80120c60ec..0ca8ef8aa8 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/Default.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/Default.kt @@ -1150,12 +1150,13 @@ abstract class VendorDialect( tableScheme != null -> it == table.nameInDatabaseCase() scheme.isEmpty() -> it == table.nameInDatabaseCaseUnquoted() else -> { - val sanitizedTableName = if (currentDialect is MysqlDialect) { + val sanitizedTableName = if (currentDialect is MysqlDialect || currentDialect is SQLServerDialect) { table.tableNameWithoutScheme } else { table.tableNameWithoutSchemeSanitized } - it == "$scheme.$sanitizedTableName".inProperCase() + val nameInDb = "$scheme.$sanitizedTableName".inProperCase() + it == nameInDb } } } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLServerDialect.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLServerDialect.kt index 14d242e385..637a5ad069 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLServerDialect.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLServerDialect.kt @@ -303,6 +303,8 @@ open class SQLServerDialect : VendorDialect(dialectName, SQLServerDataTypeProvid override fun createDatabase(name: String): String = "CREATE DATABASE ${name.inProperCase()}" + override fun listDatabases(): String = "SELECT name FROM sys.databases" + override fun dropDatabase(name: String) = "DROP DATABASE ${name.inProperCase()}" override fun setSchema(schema: Schema): String = "ALTER USER ${schema.authorization} WITH DEFAULT_SCHEMA = ${schema.identifier}" diff --git a/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt b/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt index e51bcc161f..0c9f1906d9 100644 --- a/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt +++ b/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt @@ -194,11 +194,9 @@ class DefaultsTest : DatabaseTestsBase() { @Test fun testDefaults01() { - println("Start test") val currentDT = CurrentDateTime val nowExpression = object : Expression() { override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder { - println("currentDialectTest = $currentDialectTest") +when (val dialect = currentDialectTest) { is OracleDialect -> "SYSDATE" is SQLServerDialect -> "GETDATE()" diff --git a/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/sqlserver/SQLServerDefaultsTest.kt b/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/sqlserver/SQLServerDefaultsTest.kt index 90fe9ac00d..af68845b7e 100644 --- a/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/sqlserver/SQLServerDefaultsTest.kt +++ b/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/sqlserver/SQLServerDefaultsTest.kt @@ -15,7 +15,6 @@ class SQLServerDefaultsTest : DatabaseTestsBase() { @Test fun testDefaultExpressionsForTemporalTable() { - fun databaseGeneratedTimestamp() = object : ExpressionWithColumnType() { override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder { +"DEFAULT" } override val columnType: IColumnType = JavaLocalDateTimeColumnType() diff --git a/exposed-jodatime/src/test/kotlin/org/jetbrains/exposed/JodaTimeDefaultsTest.kt b/exposed-jodatime/src/test/kotlin/org/jetbrains/exposed/JodaTimeDefaultsTest.kt index f28ddc9134..3853c94c19 100644 --- a/exposed-jodatime/src/test/kotlin/org/jetbrains/exposed/JodaTimeDefaultsTest.kt +++ b/exposed-jodatime/src/test/kotlin/org/jetbrains/exposed/JodaTimeDefaultsTest.kt @@ -288,7 +288,7 @@ class JodaTimeDefaultsTest : JodaTimeBaseTest() { } withTables(testDate) { - val duration: Long = 1000 + val duration: Long = 2000 val before = currentDateTime() Thread.sleep(duration) diff --git a/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfigurationTest.kt b/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfigurationTest.kt index d81a0b0777..849d5586c8 100644 --- a/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfigurationTest.kt +++ b/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfigurationTest.kt @@ -47,7 +47,10 @@ open class ExposedAutoConfigurationTest { fun `database config can be overrode by custom one`() { val expectedConfig = CustomDatabaseConfigConfiguration.expectedConfig assertSame(databaseConfig, expectedConfig) - assertEquals(expectedConfig.maxEntitiesToStoreInCachePerEntity, databaseConfig!!.maxEntitiesToStoreInCachePerEntity) + assertEquals( + expectedConfig.maxEntitiesToStoreInCachePerEntity, + databaseConfig!!.maxEntitiesToStoreInCachePerEntity + ) } @TestConfiguration @@ -120,5 +123,7 @@ open class AsyncExposedService { open fun allTestData() = TestTable.selectAll().toList() // you need to put open otherwise @Transactional is not applied since spring plugin not applied (similar to maven kotlin plugin) - open fun allTestDataAsync(): CompletableFuture> = CompletableFuture.completedFuture(TestTable.selectAll().toList()) + open fun allTestDataAsync(): CompletableFuture> = CompletableFuture.completedFuture( + TestTable.selectAll().toList() + ) } diff --git a/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/DatabaseTestsBase.kt b/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/DatabaseTestsBase.kt index dbc523a21e..fa00ec0ecb 100644 --- a/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/DatabaseTestsBase.kt +++ b/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/DatabaseTestsBase.kt @@ -61,7 +61,7 @@ abstract class DatabaseTestsBase { lateinit var testName: String fun withDb(dbSettings: TestDB, statement: Transaction.(TestDB) -> Unit) { - Assume.assumeTrue(dbSettings in TestDB.enabledDialects()) + Assume.assumeTrue(dialect == dbSettings) if (dbSettings !in registeredOnShutdown) { dbSettings.beforeConnection() @@ -104,16 +104,9 @@ abstract class DatabaseTestsBase { } fun withTables(excludeSettings: List, vararg tables: Table, statement: Transaction.(TestDB) -> Unit) { - val testDB: TestDB? = dialect as? TestDB + Assume.assumeFalse(dialect in excludeSettings) - if (testDB == null) { - Assume.assumeFalse(false) - return - } - - Assume.assumeFalse(testDB in excludeSettings) - - withDb(testDB) { + withDb(dialect) { try { SchemaUtils.drop(*tables) } catch (_: Throwable) { @@ -121,14 +114,14 @@ abstract class DatabaseTestsBase { SchemaUtils.create(*tables) try { - statement(testDB) + statement(dialect) commit() // Need commit to persist data before drop tables } finally { try { SchemaUtils.drop(*tables) commit() } catch (_: Exception) { - val database = testDB.db!! + val database = dialect.db!! inTopLevelTransaction(database.transactionManager.defaultIsolationLevel, db = database) { repetitionAttempts = 1 SchemaUtils.drop(*tables) diff --git a/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/LogDbInTestName.kt b/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/LogDbInTestName.kt new file mode 100644 index 0000000000..15906d6627 --- /dev/null +++ b/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/LogDbInTestName.kt @@ -0,0 +1,16 @@ +package org.jetbrains.exposed.sql.tests + +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +@RunWith(Parameterized::class) +abstract class LogDbInTestName { + @Parameterized.Parameter(0) + lateinit var dialect: String + + companion object { + @JvmStatic + @Parameterized.Parameters(name = "{0}") + fun data() = TestDB.enabledDialects().map { arrayOf(it.name) } + } +} diff --git a/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/TestDB.kt b/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/TestDB.kt index d15dbd8922..1dcf014c15 100644 --- a/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/TestDB.kt +++ b/exposed-tests/src/main/kotlin/org/jetbrains/exposed/sql/tests/TestDB.kt @@ -25,29 +25,37 @@ enum class TestDB( H2_MYSQL({ "jdbc:h2:mem:mysql;MODE=MySQL;DB_CLOSE_DELAY=-1" }, "org.h2.Driver", beforeConnection = { Mode::class.declaredMemberProperties.firstOrNull { it.name == "convertInsertNullToZero" }?.let { field -> val mode = Mode.getInstance("MySQL") - @Suppress("UNCHECKED_CAST") (field as KMutableProperty1).set(mode, false) + @Suppress("UNCHECKED_CAST") + (field as KMutableProperty1).set(mode, false) } }), H2_MARIADB( - { "jdbc:h2:mem:mariadb;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1" }, "org.h2.Driver", pass = "root" + { "jdbc:h2:mem:mariadb;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1" }, + "org.h2.Driver", + pass = "root" ), H2_PSQL( - { "jdbc:h2:mem:psql;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;DEFAULT_NULL_ORDERING=HIGH;DB_CLOSE_DELAY=-1" }, "org.h2.Driver" + { "jdbc:h2:mem:psql;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;DEFAULT_NULL_ORDERING=HIGH;DB_CLOSE_DELAY=-1" }, + "org.h2.Driver" ), H2_ORACLE( - { "jdbc:h2:mem:oracle;MODE=Oracle;DATABASE_TO_LOWER=TRUE;DEFAULT_NULL_ORDERING=HIGH;DB_CLOSE_DELAY=-1" }, "org.h2.Driver" + { "jdbc:h2:mem:oracle;MODE=Oracle;DATABASE_TO_LOWER=TRUE;DEFAULT_NULL_ORDERING=HIGH;DB_CLOSE_DELAY=-1" }, + "org.h2.Driver" ), H2_SQLSERVER({ "jdbc:h2:mem:sqlserver;MODE=MSSQLServer;DB_CLOSE_DELAY=-1" }, "org.h2.Driver"), SQLITE({ "jdbc:sqlite:file:test?mode=memory&cache=shared" }, "org.sqlite.JDBC"), MYSQL( connection = { "jdbc:mysql://127.0.0.1:3001/testdb?useSSL=false&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull" - }, driver = "com.mysql.jdbc.Driver" + }, + driver = "com.mysql.jdbc.Driver" + ), + POSTGRESQL( + { "jdbc:postgresql://127.0.0.1:3004/postgres?lc_messages=en_US.UTF-8" }, + "org.postgresql.Driver", + beforeConnection = { }, + afterTestFinished = { } ), - POSTGRESQL({ "jdbc:postgresql://127.0.0.1:3004/postgres?lc_messages=en_US.UTF-8" }, - "org.postgresql.Driver", - beforeConnection = { }, - afterTestFinished = { }), POSTGRESQLNG( { POSTGRESQL.connection().replace(":postgresql:", ":pgsql:") }, "com.impossibl.postgres.jdbc.PGDriver", @@ -56,8 +64,13 @@ enum class TestDB( "jdbc:oracle:thin:@127.0.0.1:3003/XEPDB1" }, beforeConnection = { Locale.setDefault(Locale.ENGLISH) - val tmp = Database.connect(ORACLE.connection(), user = "sys as sysdba", password = "Oracle18", driver = ORACLE.driver) - transaction(Connection.TRANSACTION_READ_COMMITTED, db = tmp) { + val tmp = Database.connect( + ORACLE.connection(), + user = "sys as sysdba", + password = "Oracle18", + driver = ORACLE.driver + ) + transaction(Connection.TRANSACTION_READ_COMMITTED, db = tmp) { repetitionAttempts = 1 try { exec("DROP USER ExposedTest CASCADE") @@ -79,7 +92,8 @@ enum class TestDB( MARIADB( { "jdbc:mariadb://127.0.0.1:3000/testdb" - }, "org.mariadb.jdbc.Driver" + }, + "org.mariadb.jdbc.Driver" ); var db: Database? = null @@ -95,7 +109,12 @@ enum class TestDB( companion object { val allH2TestDB = listOf(H2, H2_MYSQL, H2_PSQL, H2_MARIADB, H2_ORACLE, H2_SQLSERVER) val mySqlRelatedDB = listOf(MYSQL, MARIADB, H2_MYSQL, H2_MARIADB) + fun enabledDialects(): Set { + if (TEST_DIALECTS.isEmpty()) { + return values().toSet() + } + return values().filterTo(enumSetOf()) { it.name in TEST_DIALECTS } } } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/demo/sql/SamplesSQL.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/demo/sql/SamplesSQL.kt index c825e7baf8..b6bd555b12 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/demo/sql/SamplesSQL.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/demo/sql/SamplesSQL.kt @@ -114,20 +114,21 @@ fun main() { println("Functions and group by:") - ((Cities innerJoin Users) - .slice(Cities.name, Users.id.count()) - .selectAll() - .groupBy(Cities.name) + ( + (Cities innerJoin Users) + .slice(Cities.name, Users.id.count()) + .selectAll() + .groupBy(Cities.name) ).forEach { - val cityName = it[Cities.name] - val userCount = it[Users.id.count()] + val cityName = it[Cities.name] + val userCount = it[Users.id.count()] - if (userCount > 0) { - println("$userCount user(s) live(s) in $cityName") - } else { - println("Nobody lives in $cityName") - } + if (userCount > 0) { + println("$userCount user(s) live(s) in $cityName") + } else { + println("Nobody lives in $cityName") } + } SchemaUtils.drop(Users, Cities) } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/ConnectionPoolTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/ConnectionPoolTests.kt index 2b154bc95c..c74af6b1dc 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/ConnectionPoolTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/ConnectionPoolTests.kt @@ -11,6 +11,7 @@ import org.jetbrains.exposed.dao.id.EntityID import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils +import org.jetbrains.exposed.sql.tests.LogDbInTestName import org.jetbrains.exposed.sql.tests.TestDB import org.jetbrains.exposed.sql.tests.shared.assertEquals import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction @@ -18,7 +19,7 @@ import org.jetbrains.exposed.sql.transactions.transaction import org.junit.Assume import org.junit.Test -class ConnectionPoolTests { +class ConnectionPoolTests : LogDbInTestName() { private val hikariDataSource1 by lazy { HikariDataSource( HikariConfig().apply { diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/H2Tests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/H2Tests.kt index c54810679c..7df91e9fe2 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/H2Tests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/H2Tests.kt @@ -18,7 +18,6 @@ class H2Tests : DatabaseTestsBase() { @Test fun insertInH2() { withDb(listOf(TestDB.H2_MYSQL, TestDB.H2)) { - SchemaUtils.drop(Testing) SchemaUtils.create(Testing) Testing.insert { @@ -33,7 +32,6 @@ class H2Tests : DatabaseTestsBase() { @Test fun replaceAsInsertInH2() { withDb(listOf(TestDB.H2_MYSQL, TestDB.H2_MARIADB)) { - SchemaUtils.drop(Testing) SchemaUtils.create(Testing) Testing.replace { @@ -76,8 +74,14 @@ class H2Tests : DatabaseTestsBase() { withDb(listOf(TestDB.H2, TestDB.H2_MYSQL)) { try { SchemaUtils.createMissingTablesAndColumns(initialTable) - assertEquals("ALTER TABLE ${tableName.inProperCase()} ADD ${"id".inProperCase()} ${t.id.columnType.sqlType()}", t.id.ddl.first()) - assertEquals("ALTER TABLE ${tableName.inProperCase()} ADD CONSTRAINT pk_$tableName PRIMARY KEY (${"id".inProperCase()})", t.id.ddl[1]) + assertEquals( + "ALTER TABLE ${tableName.inProperCase()} ADD ${"id".inProperCase()} ${t.id.columnType.sqlType()}", + t.id.ddl.first() + ) + assertEquals( + "ALTER TABLE ${tableName.inProperCase()} ADD CONSTRAINT pk_$tableName PRIMARY KEY (${"id".inProperCase()})", + t.id.ddl[1] + ) assertEquals(1, currentDialectTest.tableColumns(t)[t]!!.size) SchemaUtils.createMissingTablesAndColumns(t) assertEquals(2, currentDialectTest.tableColumns(t)[t]!!.size) diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ThreadLocalManagerTest.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ThreadLocalManagerTest.kt index f0fe39c412..3215ca81e4 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ThreadLocalManagerTest.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ThreadLocalManagerTest.kt @@ -6,6 +6,7 @@ import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.exceptions.ExposedSQLException import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.tests.DatabaseTestsBase +import org.jetbrains.exposed.sql.tests.LogDbInTestName import org.jetbrains.exposed.sql.tests.TestDB import org.jetbrains.exposed.sql.tests.shared.dml.DMLTestsData import org.jetbrains.exposed.sql.transactions.TransactionManager @@ -381,7 +382,7 @@ class TransactionIsolationTest : DatabaseTestsBase() { } } -class TransactionManagerResetTest { +class TransactionManagerResetTest : LogDbInTestName() { @Test fun `test closeAndUnregister with next Database-connect works fine`() { Assume.assumeTrue(TestDB.H2 in TestDB.enabledDialects()) diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateDatabaseTest.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateDatabaseTest.kt index 0ed1c5f1b7..3e87f1bc8a 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateDatabaseTest.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateDatabaseTest.kt @@ -34,8 +34,8 @@ class CreateDatabaseTest : DatabaseTestsBase() { } @Test - fun testListDatabasesPostgres() { - withDb(TestDB.POSTGRESQL) { + fun testListDatabasesWithAutoCommit() { + withDb(listOf(TestDB.POSTGRESQL, TestDB.POSTGRESQLNG, TestDB.SQLSERVER)) { connection.autoCommit = true val dbName = "jetbrains" val initial = SchemaUtils.listDatabases() @@ -55,7 +55,7 @@ class CreateDatabaseTest : DatabaseTestsBase() { @Test fun testListDatabases() { - withDb(excludeSettings = listOf(TestDB.ORACLE, TestDB.POSTGRESQL, TestDB.POSTGRESQLNG)) { + withDb(excludeSettings = listOf(TestDB.ORACLE, TestDB.POSTGRESQL, TestDB.POSTGRESQLNG, TestDB.SQLSERVER)) { val dbName = "jetbrains" val initial = SchemaUtils.listDatabases() if (dbName in initial) { @@ -72,7 +72,7 @@ class CreateDatabaseTest : DatabaseTestsBase() { } @Test - fun testCreateAndDropDatabaseInPostgresql() { + fun testCreateAndDropDatabaseWithAutoCommit() { // PostgreSQL needs auto commit to be "ON" to allow create database statement withDb(listOf(TestDB.POSTGRESQL, TestDB.POSTGRESQLNG)) { connection.autoCommit = true diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/DMLTestData.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/DMLTestData.kt index 0aad742d12..330729e21f 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/DMLTestData.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/DMLTestData.kt @@ -51,7 +51,11 @@ object DMLTestsData { @Suppress("LongMethod") fun DatabaseTestsBase.withCitiesAndUsers( exclude: List = emptyList(), - statement: Transaction.(cities: DMLTestsData.Cities, users: DMLTestsData.Users, userData: DMLTestsData.UserData) -> Unit + statement: Transaction.( + cities: DMLTestsData.Cities, + users: DMLTestsData.Users, + userData: DMLTestsData.UserData + ) -> Unit ) { val Users = DMLTestsData.Users val UserFlags = DMLTestsData.Users.Flags diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/DeleteTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/DeleteTests.kt index 68c45ab5f5..a5fbbf9ab4 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/DeleteTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/DeleteTests.kt @@ -16,7 +16,13 @@ import org.junit.Test class DeleteTests : DatabaseTestsBase() { private val notSupportLimit by lazy { - val exclude = arrayListOf(TestDB.POSTGRESQL, TestDB.POSTGRESQLNG, TestDB.ORACLE, TestDB.H2_PSQL, TestDB.H2_ORACLE) + val exclude = arrayListOf( + TestDB.POSTGRESQL, + TestDB.POSTGRESQLNG, + TestDB.ORACLE, + TestDB.H2_PSQL, + TestDB.H2_ORACLE + ) if (!SQLiteDialect.ENABLE_UPDATE_DELETE_LIMIT) { exclude.add(TestDB.SQLITE) } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/OrderByTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/OrderByTests.kt index 1d3a6e1384..b283eca766 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/OrderByTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/OrderByTests.kt @@ -2,7 +2,6 @@ package org.jetbrains.exposed.sql.tests.shared.dml import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.tests.DatabaseTestsBase -import org.jetbrains.exposed.sql.tests.TestDB import org.jetbrains.exposed.sql.tests.currentDialectTest import org.jetbrains.exposed.sql.tests.shared.assertEquals import org.jetbrains.exposed.sql.vendors.H2Dialect @@ -39,8 +38,11 @@ class OrderByTests : DatabaseTestsBase() { assertEquals(5, r.size) val usersWithoutCities = listOf("alex", "smth") val otherUsers = listOf("eugene", "sergey", "andrey") - val expected = if (isNullFirst()) usersWithoutCities + otherUsers - else otherUsers + usersWithoutCities + val expected = if (isNullFirst()) { + usersWithoutCities + otherUsers + } else { + otherUsers + usersWithoutCities + } expected.forEachIndexed { index, e -> assertEquals(e, r[index][users.id]) } @@ -54,8 +56,11 @@ class OrderByTests : DatabaseTestsBase() { assertEquals(5, r.size) val usersWithoutCities = listOf("alex", "smth") val otherUsers = listOf("eugene", "sergey", "andrey") - val expected = if (isNullFirst()) usersWithoutCities + otherUsers - else otherUsers + usersWithoutCities + val expected = if (isNullFirst()) { + usersWithoutCities + otherUsers + } else { + otherUsers + usersWithoutCities + } expected.forEachIndexed { index, e -> assertEquals(e, r[index][users.id]) } @@ -65,7 +70,10 @@ class OrderByTests : DatabaseTestsBase() { @Test fun testOrderBy04() { withCitiesAndUsers { cities, users, _ -> - val r = (cities innerJoin users).slice(cities.name, users.id.count()).selectAll().groupBy(cities.name).orderBy(cities.name).toList() + val r = (cities innerJoin users).slice( + cities.name, + users.id.count() + ).selectAll().groupBy(cities.name).orderBy(cities.name).toList() assertEquals(2, r.size) assertEquals("Munich", r[0][cities.name]) assertEquals(2, r[0][users.id.count()]) @@ -81,8 +89,11 @@ class OrderByTests : DatabaseTestsBase() { assertEquals(5, r.size) val usersWithoutCities = listOf("alex", "smth") val otherUsers = listOf("eugene", "sergey", "andrey") - val expected = if (isNullFirst()) usersWithoutCities + otherUsers - else otherUsers + usersWithoutCities + val expected = if (isNullFirst()) { + usersWithoutCities + otherUsers + } else { + otherUsers + usersWithoutCities + } expected.forEachIndexed { index, e -> assertEquals(e, r[index][users.id]) } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/functions/MathFunctionTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/functions/MathFunctionTests.kt index a9375dd2ce..1aa9842988 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/functions/MathFunctionTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/functions/MathFunctionTests.kt @@ -68,18 +68,36 @@ class MathFunctionTests : FunctionsTestBase() { assertExpressionEqual(BigDecimal(100), PowerFunction(intLiteral(10), doubleLiteral(2.0))) if (testDb != TestDB.SQLSERVER) { assertExpressionEqual(BigDecimal("102.01"), PowerFunction(doubleLiteral(10.1), intLiteral(2))) - assertExpressionEqual(BigDecimal("102.01"), PowerFunction(decimalLiteral(BigDecimal("10.1")), intLiteral(2))) + assertExpressionEqual( + BigDecimal("102.01"), + PowerFunction(decimalLiteral(BigDecimal("10.1")), intLiteral(2)) + ) assertExpressionEqual(BigDecimal("102.01"), PowerFunction(doubleLiteral(10.1), doubleLiteral(2.0))) - assertExpressionEqual(BigDecimal("102.01"), PowerFunction(decimalLiteral(BigDecimal("10.1")), doubleLiteral(2.0))) - assertExpressionEqual(BigDecimal("324.1928515714"), PowerFunction(doubleLiteral(10.1), doubleLiteral(2.5))) - assertExpressionEqual(BigDecimal("324.1928515714"), PowerFunction(decimalLiteral(BigDecimal("10.1")), doubleLiteral(2.5))) + assertExpressionEqual( + BigDecimal("102.01"), + PowerFunction(decimalLiteral(BigDecimal("10.1")), doubleLiteral(2.0)) + ) + assertExpressionEqual( + BigDecimal("324.1928515714"), + PowerFunction(doubleLiteral(10.1), doubleLiteral(2.5)) + ) + assertExpressionEqual( + BigDecimal("324.1928515714"), + PowerFunction(decimalLiteral(BigDecimal("10.1")), doubleLiteral(2.5)) + ) } else { assertExpressionEqual(BigDecimal(102), PowerFunction(doubleLiteral(10.1), intLiteral(2))) assertExpressionEqual(BigDecimal(102), PowerFunction(decimalLiteral(BigDecimal("10.1")), intLiteral(2))) assertExpressionEqual(BigDecimal(102), PowerFunction(doubleLiteral(10.1), doubleLiteral(2.0))) - assertExpressionEqual(BigDecimal(102), PowerFunction(decimalLiteral(BigDecimal("10.1")), doubleLiteral(2.0))) + assertExpressionEqual( + BigDecimal(102), + PowerFunction(decimalLiteral(BigDecimal("10.1")), doubleLiteral(2.0)) + ) assertExpressionEqual(BigDecimal("324.2"), PowerFunction(doubleLiteral(10.1), doubleLiteral(2.5))) - assertExpressionEqual(BigDecimal("324.2"), PowerFunction(decimalLiteral(BigDecimal("10.1")), doubleLiteral(2.5))) + assertExpressionEqual( + BigDecimal("324.2"), + PowerFunction(decimalLiteral(BigDecimal("10.1")), doubleLiteral(2.5)) + ) } } } @@ -115,7 +133,7 @@ class MathFunctionTests : FunctionsTestBase() { } } TestDB.POSTGRESQL, TestDB.POSTGRESQLNG, TestDB.ORACLE -> { - // SQLite, PSQL, Oracle fail to execute sqrt with negative value + // PSQL, Oracle fail to execute sqrt with negative value expectException { assertExpressionEqual(null, SqrtFunction(intLiteral(-100))) }