Skip to content

Commit

Permalink
Migrate tests from DynaTest to JUnit5
Browse files Browse the repository at this point in the history
  • Loading branch information
mvysny committed Jan 31, 2025
1 parent 066296e commit 7bd955a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/test/kotlin/com/github/vokorm/Databases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ fun clearDb() {
TypeMappingEntity.deleteAll()
}

private val isX86_64: Boolean get() = System.getProperty("os.arch") == "amd64"

@DynaTestDsl
private fun DynaNodeGroup.usingDockerizedMSSQL() {
check(DockerClientFactory.instance().isDockerAvailable()) { "Docker not available" }
Expand Down
90 changes: 90 additions & 0 deletions src/test/kotlin/com/github/vokorm/MssqlDatabaseTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.github.vokorm

import com.gitlab.mvysny.jdbiorm.JdbiOrm
import com.gitlab.mvysny.jdbiorm.quirks.DatabaseVariant
import org.junit.jupiter.api.*
import org.testcontainers.containers.MSSQLServerContainer
import kotlin.test.expect

class MssqlDatabaseTest {
companion object {
private lateinit var container: MSSQLServerContainer<*>
@BeforeAll @JvmStatic
fun setup() {
assumeDockerAvailable()
Assumptions.assumeTrue(isX86_64) { "MSSQL is only available on amd64: https://hub.docker.com/_/microsoft-mssql-server/ " }

container =
MSSQLServerContainer("mcr.microsoft.com/mssql/server:${DatabaseVersions.mssql}")
container.start()
hikari {
minimumIdle = 0
maximumPoolSize = 30
jdbcUrl = container.jdbcUrl
username = container.username
password = container.password
}
db {
// otherwise the CREATE FULLTEXT CATALOG would fail: Cannot use full-text search in master, tempdb, or model database.
ddl("CREATE DATABASE foo")
ddl("USE foo")
ddl("CREATE FULLTEXT CATALOG AdvWksDocFTCat")

ddl(
"""create table Test (
id bigint primary key IDENTITY(1,1) not null,
name varchar(400) not null,
age integer not null,
dateOfBirth datetime,
created datetime NULL,
modified datetime NULL,
alive bit,
maritalStatus varchar(200)
)"""
)
// unfortunately the default Docker image doesn't support the FULLTEXT index:
// https://stackoverflow.com/questions/60489784/installing-mssql-server-express-using-docker-with-full-text-search-support
// just skip the tests for now
/*
ddl("CREATE UNIQUE INDEX ui_ukDoc ON Test(name);")
ddl("""CREATE FULLTEXT INDEX ON Test
(
Test --Full-text index column name
TYPE COLUMN name --Name of column that contains file type information
Language 2057 --2057 is the LCID for British English
)
KEY INDEX ui_ukDoc ON AdvWksDocFTCat --Unique index
WITH CHANGE_TRACKING AUTO --Population type; """)
*/

ddl("""create table EntityWithAliasedId(myid bigint primary key IDENTITY(1,1) not null, name varchar(400) not null)""")
ddl("""create table NaturalPerson(id varchar(10) primary key not null, name varchar(400) not null, bytes binary(16) not null)""")
ddl("""create table LogRecord(id uniqueidentifier primary key not null, text varchar(400) not null)""")
ddl("""create table TypeMappingEntity(id bigint primary key IDENTITY(1,1) not null, enumTest varchar(10))""")
}
}

@AfterAll @JvmStatic
fun teardown() {
JdbiOrm.destroy()
if (this::container.isInitialized) {
container.stop()
}
}
}

@BeforeEach @AfterEach fun purgeDb() { clearDb() }

@Test fun `expect MSSQL variant`() {
expect(DatabaseVariant.MSSQL) {
db {
DatabaseVariant.from(handle)
}
}
}

// unfortunately the default Docker image doesn't support the FULLTEXT index:
// https://stackoverflow.com/questions/60489784/installing-mssql-server-express-using-docker-with-full-text-search-support
@Nested
inner class AllDatabaseTests : AbstractDatabaseTests(DatabaseInfo(DatabaseVariant.MSSQL, supportsFullText = false))
}
2 changes: 2 additions & 0 deletions src/test/kotlin/com/github/vokorm/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import java.time.Instant
import java.util.Date
import kotlin.test.expect

val isX86_64: Boolean get() = System.getProperty("os.arch") == "amd64"

val gson: Gson = GsonBuilder().registerJavaTimeAdapters().create()

private fun GsonBuilder.registerJavaTimeAdapters(): GsonBuilder = apply {
Expand Down

0 comments on commit 7bd955a

Please sign in to comment.