Finish KotlinX Json tests
This commit is contained in:
parent
f2dd740933
commit
e3a8c10eae
@ -1,9 +1,6 @@
|
||||
package solutions.bitbadger.documents.kotlinx.tests.integration
|
||||
|
||||
import solutions.bitbadger.documents.*
|
||||
import solutions.bitbadger.documents.java.extensions.countAll
|
||||
import solutions.bitbadger.documents.java.extensions.insert
|
||||
import solutions.bitbadger.documents.java.extensions.writeCustomJsonArray
|
||||
import solutions.bitbadger.documents.kotlinx.Results
|
||||
import solutions.bitbadger.documents.kotlinx.extensions.*
|
||||
import solutions.bitbadger.documents.kotlinx.tests.ArrayDocument
|
||||
@ -46,7 +43,7 @@ object CustomFunctions {
|
||||
fun jsonArraySingle(db: ThrowawayDatabase) {
|
||||
db.conn.insert(TEST_TABLE, ArrayDocument("one", listOf("2", "3")))
|
||||
assertEquals(
|
||||
JsonFunctions.maybeJsonB("[{\"id\":\"one\",\"values\":[\"2\",\"3\"]}]"),
|
||||
JsonFunctions.maybeJsonB("""[{"id":"one","values":["2","3"]}]"""),
|
||||
db.conn.customJsonArray(FindQuery.all(TEST_TABLE), listOf(), Results::jsonFromData),
|
||||
"A single document list was not represented correctly"
|
||||
)
|
||||
@ -55,9 +52,8 @@ object CustomFunctions {
|
||||
fun jsonArrayMany(db: ThrowawayDatabase) {
|
||||
ArrayDocument.testDocuments.forEach { db.conn.insert(TEST_TABLE, it) }
|
||||
assertEquals(
|
||||
JsonFunctions.maybeJsonB("[{\"id\":\"first\",\"values\":[\"a\",\"b\",\"c\"]},"
|
||||
+ "{\"id\":\"second\",\"values\":[\"c\",\"d\",\"e\"]},"
|
||||
+ "{\"id\":\"third\",\"values\":[\"x\",\"y\",\"z\"]}]"),
|
||||
JsonFunctions.maybeJsonB("""[{"id":"first","values":["a","b","c"]},"""
|
||||
+ """{"id":"second","values":["c","d","e"]},{"id":"third","values":["x","y","z"]}]"""),
|
||||
db.conn.customJsonArray(FindQuery.all(TEST_TABLE) + orderBy(listOf(Field.named("id"))), listOf(),
|
||||
Results::jsonFromData),
|
||||
"A multiple document list was not represented correctly"
|
||||
|
@ -121,7 +121,7 @@ object JsonFunctions {
|
||||
Configuration.idField = "key"
|
||||
try {
|
||||
db.conn.insert(TEST_TABLE, NumIdDocument(18, "howdy"))
|
||||
checkByIdString(db.conn.jsonById(TEST_TABLE, 18))
|
||||
checkByIdNumber(db.conn.jsonById(TEST_TABLE, 18))
|
||||
} finally {
|
||||
Configuration.idField = "id"
|
||||
}
|
||||
|
@ -8,16 +8,11 @@ import solutions.bitbadger.documents.kotlinx.tests.TEST_TABLE
|
||||
/**
|
||||
* A wrapper for a throwaway PostgreSQL database
|
||||
*/
|
||||
class PgDB : ThrowawayDatabase {
|
||||
|
||||
private var dbName = ""
|
||||
class PgDB : ThrowawayDatabase() {
|
||||
|
||||
init {
|
||||
dbName = "throwaway_${AutoId.generateRandomString(8)}"
|
||||
Configuration.connectionString = connString("postgres")
|
||||
Configuration.dbConn().use {
|
||||
it.customNonQuery("CREATE DATABASE $dbName")
|
||||
}
|
||||
Configuration.dbConn().use { it.customNonQuery("CREATE DATABASE $dbName") }
|
||||
Configuration.connectionString = connString(dbName)
|
||||
}
|
||||
|
||||
@ -30,9 +25,7 @@ class PgDB : ThrowawayDatabase {
|
||||
override fun close() {
|
||||
conn.close()
|
||||
Configuration.connectionString = connString("postgres")
|
||||
Configuration.dbConn().use {
|
||||
it.customNonQuery("DROP DATABASE $dbName")
|
||||
}
|
||||
Configuration.dbConn().use { it.customNonQuery("DROP DATABASE $dbName") }
|
||||
Configuration.connectionString = null
|
||||
}
|
||||
|
||||
|
@ -9,12 +9,9 @@ import java.io.File
|
||||
/**
|
||||
* A wrapper for a throwaway SQLite database
|
||||
*/
|
||||
class SQLiteDB : ThrowawayDatabase {
|
||||
|
||||
private var dbName = ""
|
||||
class SQLiteDB : ThrowawayDatabase() {
|
||||
|
||||
init {
|
||||
dbName = "test-db-${AutoId.generateRandomString(8)}.db"
|
||||
Configuration.connectionString = "jdbc:sqlite:$dbName"
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,18 @@
|
||||
package solutions.bitbadger.documents.kotlinx.tests.integration
|
||||
|
||||
import solutions.bitbadger.documents.AutoId
|
||||
import java.sql.Connection
|
||||
|
||||
/**
|
||||
* Common interface for PostgreSQL and SQLite throwaway databases
|
||||
*/
|
||||
interface ThrowawayDatabase : AutoCloseable {
|
||||
abstract class ThrowawayDatabase : AutoCloseable {
|
||||
|
||||
/** The name of the throwaway database */
|
||||
protected val dbName = "throwaway_${AutoId.generateRandomString(8)}"
|
||||
|
||||
/** The database connection for the throwaway database */
|
||||
val conn: Connection
|
||||
abstract val conn: Connection
|
||||
|
||||
/**
|
||||
* Determine if a database object exists
|
||||
@ -16,5 +20,5 @@ interface ThrowawayDatabase : AutoCloseable {
|
||||
* @param name The name of the object whose existence should be checked
|
||||
* @return True if the object exists, false if not
|
||||
*/
|
||||
fun dbObjectExists(name: String): Boolean
|
||||
abstract fun dbObjectExists(name: String): Boolean
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user