WIP on count impl; reworking comparisons
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package solutions.bitbadger.documents
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.sql.Connection
|
||||
|
||||
/** The test table name to use for integration tests */
|
||||
const val TEST_TABLE = "test_table"
|
||||
|
||||
69
src/integration-test/kotlin/common/Count.kt
Normal file
69
src/integration-test/kotlin/common/Count.kt
Normal file
@@ -0,0 +1,69 @@
|
||||
package solutions.bitbadger.documents.common
|
||||
|
||||
import solutions.bitbadger.documents.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
/**
|
||||
* Integration tests for the `Count` object
|
||||
*/
|
||||
object Count {
|
||||
|
||||
fun all(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(5L, db.conn.countAll(TEST_TABLE), "There should have been 5 documents in the table")
|
||||
}
|
||||
|
||||
fun byFieldsNumeric(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(
|
||||
3L,
|
||||
db.conn.countByFields(TEST_TABLE, listOf(Field.between("num_value", 10, 20))),
|
||||
"There should have been 3 matching documents"
|
||||
)
|
||||
}
|
||||
|
||||
fun byFieldsAlpha(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(
|
||||
1L,
|
||||
db.conn.countByFields(TEST_TABLE, listOf(Field.between("value", "aardvark", "apple"))),
|
||||
"There should have been 1 matching document"
|
||||
)
|
||||
}
|
||||
|
||||
fun byContainsMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(
|
||||
2L,
|
||||
db.conn.countByContains(TEST_TABLE, mapOf("value" to "purple")),
|
||||
"There should have been 2 matching documents"
|
||||
)
|
||||
}
|
||||
|
||||
fun byContainsNoMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(
|
||||
0L,
|
||||
db.conn.countByContains(TEST_TABLE, mapOf("value" to "magenta")),
|
||||
"There should have been no matching documents"
|
||||
)
|
||||
}
|
||||
|
||||
fun byJsonPathMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(
|
||||
2L,
|
||||
db.conn.countByJsonPath(TEST_TABLE, "$.num_value ? (@ < 5)"),
|
||||
"There should have been 2 matching documents"
|
||||
)
|
||||
}
|
||||
|
||||
fun byJsonPathNoMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(
|
||||
0L,
|
||||
db.conn.countByJsonPath(TEST_TABLE, "$.num_value ? (@ > 100)"),
|
||||
"There should have been no matching documents"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
package solutions.bitbadger.documents.common
|
||||
|
||||
import solutions.bitbadger.documents.TEST_TABLE
|
||||
import solutions.bitbadger.documents.ThrowawayDatabase
|
||||
import solutions.bitbadger.documents.ensureFieldIndex
|
||||
import solutions.bitbadger.documents.ensureTable
|
||||
import solutions.bitbadger.documents.*
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@@ -25,4 +22,22 @@ object Definition {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
47
src/integration-test/kotlin/postgresql/CountIT.kt
Normal file
47
src/integration-test/kotlin/postgresql/CountIT.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
package solutions.bitbadger.documents.postgresql
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import solutions.bitbadger.documents.common.Count
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* PostgreSQL integration tests for the `Count` object / `count*` connection extension functions
|
||||
*/
|
||||
@DisplayName("PostgreSQL - Count")
|
||||
class CountIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("all counts all documents")
|
||||
fun all() =
|
||||
PgDB().use(Count::all)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields counts documents by a numeric value")
|
||||
fun byFieldsNumeric() =
|
||||
PgDB().use(Count::byFieldsNumeric)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields counts documents by a alphanumeric value")
|
||||
fun byFieldsAlpha() =
|
||||
PgDB().use(Count::byFieldsAlpha)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains counts documents when matches are found")
|
||||
fun byContainsMatch() =
|
||||
PgDB().use(Count::byContainsMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains counts documents when no matches are found")
|
||||
fun byContainsNoMatch() =
|
||||
PgDB().use(Count::byContainsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath counts documents when matches are found")
|
||||
fun byJsonPathMatch() =
|
||||
PgDB().use(Count::byJsonPathMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath counts documents when no matches are found")
|
||||
fun byJsonPathNoMatch() =
|
||||
PgDB().use(Count::byJsonPathNoMatch)
|
||||
}
|
||||
@@ -19,4 +19,14 @@ class DefinitionIT {
|
||||
@DisplayName("ensureFieldIndex creates an index")
|
||||
fun ensureFieldIndex() =
|
||||
PgDB().use(Definition::ensureFieldIndex)
|
||||
|
||||
@Test
|
||||
@DisplayName("ensureDocumentIndex creates a full index")
|
||||
fun ensureDocumentIndexFull() =
|
||||
PgDB().use(Definition::ensureDocumentIndexFull)
|
||||
|
||||
@Test
|
||||
@DisplayName("ensureDocumentIndex creates an optimized index")
|
||||
fun ensureDocumentIndexOptimized() =
|
||||
PgDB().use(Definition::ensureDocumentIndexOptimized)
|
||||
}
|
||||
|
||||
41
src/integration-test/kotlin/sqlite/CountIT.kt
Normal file
41
src/integration-test/kotlin/sqlite/CountIT.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package solutions.bitbadger.documents.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import solutions.bitbadger.documents.DocumentException
|
||||
import solutions.bitbadger.documents.common.Count
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `Count` object / `count*` connection extension functions
|
||||
*/
|
||||
@DisplayName("SQLite - Count")
|
||||
class CountIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("all counts all documents")
|
||||
fun all() =
|
||||
SQLiteDB().use(Count::all)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields counts documents by a numeric value")
|
||||
fun byFieldsNumeric() =
|
||||
SQLiteDB().use(Count::byFieldsNumeric)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields counts documents by a alphanumeric value")
|
||||
fun byFieldsAlpha() =
|
||||
SQLiteDB().use(Count::byFieldsAlpha)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains fails")
|
||||
fun byContainsMatch() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Count::byContainsMatch) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath fails")
|
||||
fun byJsonPathMatch() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Count::byJsonPathMatch) }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
package solutions.bitbadger.documents.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import solutions.bitbadger.documents.*
|
||||
import solutions.bitbadger.documents.common.Definition
|
||||
import java.sql.Connection
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `Definition` object / `ensure*` connection extension functions
|
||||
@@ -23,4 +21,16 @@ class DefinitionIT {
|
||||
@DisplayName("ensureFieldIndex creates an index")
|
||||
fun ensureFieldIndex() =
|
||||
SQLiteDB().use(Definition::ensureFieldIndex)
|
||||
|
||||
@Test
|
||||
@DisplayName("ensureDocumentIndex fails for full index")
|
||||
fun ensureDocumentIndexFull() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Definition::ensureDocumentIndexFull) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ensureDocumentIndex fails for optimized index")
|
||||
fun ensureDocumentIndexOptimized() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Definition::ensureDocumentIndexOptimized) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package solutions.bitbadger.documents.sqlite
|
||||
|
||||
import solutions.bitbadger.documents.*
|
||||
import java.io.File
|
||||
import java.sql.Connection
|
||||
|
||||
/**
|
||||
* A wrapper for a throwaway SQLite database
|
||||
|
||||
Reference in New Issue
Block a user