46 lines
2.3 KiB
Kotlin
46 lines
2.3 KiB
Kotlin
package solutions.bitbadger.documents.kotlinx.tests.integration
|
|
|
|
import solutions.bitbadger.documents.*
|
|
import solutions.bitbadger.documents.kotlinx.extensions.*
|
|
import solutions.bitbadger.documents.kotlinx.tests.TEST_TABLE
|
|
import kotlin.test.assertFalse
|
|
import kotlin.test.assertTrue
|
|
|
|
/**
|
|
* Integration tests for the `Definition` object / `ensure*` connection extension functions
|
|
*/
|
|
object DefinitionFunctions {
|
|
|
|
fun ensureTable(db: ThrowawayDatabase) {
|
|
assertFalse(db.dbObjectExists("ensured"), "The 'ensured' table should not exist")
|
|
assertFalse(db.dbObjectExists("idx_ensured_key"), "The PK index for the 'ensured' table should not exist")
|
|
db.conn.ensureTable("ensured")
|
|
assertTrue(db.dbObjectExists("ensured"), "The 'ensured' table should exist")
|
|
assertTrue(db.dbObjectExists("idx_ensured_key"), "The PK index for the 'ensured' table should now exist")
|
|
}
|
|
|
|
fun ensureFieldIndex(db: ThrowawayDatabase) {
|
|
assertFalse(db.dbObjectExists("idx_${TEST_TABLE}_test"), "The test index should not exist")
|
|
db.conn.ensureFieldIndex(TEST_TABLE, "test", listOf("id", "category"))
|
|
assertTrue(db.dbObjectExists("idx_${TEST_TABLE}_test"), "The test index should now exist")
|
|
}
|
|
|
|
fun ensureDocumentIndexFull(db: ThrowawayDatabase) {
|
|
assertFalse(db.dbObjectExists("doc_table"), "The 'doc_table' table should not exist")
|
|
db.conn.ensureTable("doc_table")
|
|
assertTrue(db.dbObjectExists("doc_table"), "The 'doc_table' table should exist")
|
|
assertFalse(db.dbObjectExists("idx_doc_table_document"), "The document index should not exist")
|
|
db.conn.ensureDocumentIndex("doc_table", DocumentIndex.FULL)
|
|
assertTrue(db.dbObjectExists("idx_doc_table_document"), "The document index should exist")
|
|
}
|
|
|
|
fun ensureDocumentIndexOptimized(db: ThrowawayDatabase) {
|
|
assertFalse(db.dbObjectExists("doc_table"), "The 'doc_table' table should not exist")
|
|
db.conn.ensureTable("doc_table")
|
|
assertTrue(db.dbObjectExists("doc_table"), "The 'doc_table' table should exist")
|
|
assertFalse(db.dbObjectExists("idx_doc_table_document"), "The document index should not exist")
|
|
db.conn.ensureDocumentIndex("doc_table", DocumentIndex.OPTIMIZED)
|
|
assertTrue(db.dbObjectExists("idx_doc_table_document"), "The document index should exist")
|
|
}
|
|
}
|