Move ITs to common files, call from both DBs
- Fix PostgreSQL auto-number syntax
This commit is contained in:
48
src/integration-test/kotlin/postgresql/CustomIT.kt
Normal file
48
src/integration-test/kotlin/postgresql/CustomIT.kt
Normal file
@@ -0,0 +1,48 @@
|
||||
package solutions.bitbadger.documents.postgresql
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import solutions.bitbadger.documents.common.Custom
|
||||
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* PostgreSQL integration tests for the `Custom` object / `custom*` connection extension functions
|
||||
*/
|
||||
@DisplayName("PostgreSQL - Custom")
|
||||
class CustomIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("list succeeds with empty list")
|
||||
fun listEmpty() =
|
||||
PgDB().use { Custom.listEmpty(it.conn) }
|
||||
|
||||
@Test
|
||||
@DisplayName("list succeeds with a non-empty list")
|
||||
fun listAll() =
|
||||
PgDB().use { Custom.listAll(it.conn) }
|
||||
|
||||
@Test
|
||||
@DisplayName("single succeeds when document not found")
|
||||
fun singleNone() =
|
||||
PgDB().use { Custom.singleNone(it.conn) }
|
||||
|
||||
@Test
|
||||
@DisplayName("single succeeds when a document is found")
|
||||
fun singleOne() =
|
||||
PgDB().use { Custom.singleOne(it.conn) }
|
||||
|
||||
@Test
|
||||
@DisplayName("nonQuery makes changes")
|
||||
fun nonQueryChanges() =
|
||||
PgDB().use { Custom.nonQueryChanges(it.conn) }
|
||||
|
||||
@Test
|
||||
@DisplayName("nonQuery makes no changes when where clause matches nothing")
|
||||
fun nonQueryNoChanges() =
|
||||
PgDB().use { Custom.nonQueryNoChanges(it.conn) }
|
||||
|
||||
@Test
|
||||
@DisplayName("scalar succeeds")
|
||||
fun scalar() =
|
||||
PgDB().use { Custom.scalar(it.conn) }
|
||||
}
|
||||
27
src/integration-test/kotlin/postgresql/DocumentIT.kt
Normal file
27
src/integration-test/kotlin/postgresql/DocumentIT.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
package solutions.bitbadger.documents.postgresql
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import solutions.bitbadger.documents.common.Document
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* PostgreSQL integration tests for the `Document` object / `insert`, `save`, `update` connection extension functions
|
||||
*/
|
||||
@DisplayName("PostgreSQL - Document")
|
||||
class DocumentIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("insert works with default values")
|
||||
fun insertDefault() =
|
||||
PgDB().use { Document.insertDefault(it.conn) }
|
||||
|
||||
@Test
|
||||
@DisplayName("insert fails with duplicate key")
|
||||
fun insertDupe() =
|
||||
PgDB().use { Document.insertDupe(it.conn) }
|
||||
|
||||
@Test
|
||||
@DisplayName("insert succeeds with numeric auto IDs")
|
||||
fun insertNumAutoId() =
|
||||
PgDB().use { Document.insertNumAutoId(it.conn) }
|
||||
}
|
||||
53
src/integration-test/kotlin/postgresql/PgDB.kt
Normal file
53
src/integration-test/kotlin/postgresql/PgDB.kt
Normal file
@@ -0,0 +1,53 @@
|
||||
package solutions.bitbadger.documents.postgresql
|
||||
|
||||
import solutions.bitbadger.documents.AutoId
|
||||
import solutions.bitbadger.documents.Configuration
|
||||
import solutions.bitbadger.documents.customNonQuery
|
||||
import solutions.bitbadger.documents.ensureTable
|
||||
|
||||
/**
|
||||
* A wrapper for a throwaway PostgreSQL database
|
||||
*/
|
||||
class PgDB : AutoCloseable {
|
||||
|
||||
private var dbName = ""
|
||||
|
||||
init {
|
||||
dbName = "throwaway_${AutoId.generateRandomString(8)}"
|
||||
Configuration.connectionString = connString("postgres")
|
||||
Configuration.dbConn().use {
|
||||
it.customNonQuery("CREATE DATABASE $dbName")
|
||||
}
|
||||
Configuration.connectionString = connString(dbName)
|
||||
}
|
||||
|
||||
val conn = Configuration.dbConn()
|
||||
|
||||
init {
|
||||
conn.ensureTable(tableName)
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
conn.close()
|
||||
Configuration.connectionString = connString("postgres")
|
||||
Configuration.dbConn().use {
|
||||
it.customNonQuery("DROP DATABASE $dbName")
|
||||
}
|
||||
Configuration.connectionString = null
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
/** The table used for test documents */
|
||||
val tableName = "test_table"
|
||||
|
||||
/**
|
||||
* Create a connection string for the given database
|
||||
*
|
||||
* @param database The database to which the library should connect
|
||||
* @return The connection string for the database
|
||||
*/
|
||||
private fun connString(database: String) =
|
||||
"jdbc:postgresql://localhost/$database?user=postgres&password=postgres"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user