pom updates, move integration tests to test dir
This commit is contained in:
41
src/test/kotlin/integration/sqlite/CountIT.kt
Normal file
41
src/test/kotlin/integration/sqlite/CountIT.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package solutions.bitbadger.documents.integration.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import solutions.bitbadger.documents.DocumentException
|
||||
import solutions.bitbadger.documents.integration.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) }
|
||||
}
|
||||
}
|
||||
47
src/test/kotlin/integration/sqlite/CustomIT.kt
Normal file
47
src/test/kotlin/integration/sqlite/CustomIT.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
package solutions.bitbadger.documents.integration.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import solutions.bitbadger.documents.integration.common.Custom
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `Custom` object / `custom*` connection extension functions
|
||||
*/
|
||||
@DisplayName("SQLite - Custom")
|
||||
class CustomIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("list succeeds with empty list")
|
||||
fun listEmpty() =
|
||||
SQLiteDB().use(Custom::listEmpty)
|
||||
|
||||
@Test
|
||||
@DisplayName("list succeeds with a non-empty list")
|
||||
fun listAll() =
|
||||
SQLiteDB().use(Custom::listAll)
|
||||
|
||||
@Test
|
||||
@DisplayName("single succeeds when document not found")
|
||||
fun singleNone() =
|
||||
SQLiteDB().use(Custom::singleNone)
|
||||
|
||||
@Test
|
||||
@DisplayName("single succeeds when a document is found")
|
||||
fun singleOne() =
|
||||
SQLiteDB().use(Custom::singleOne)
|
||||
|
||||
@Test
|
||||
@DisplayName("nonQuery makes changes")
|
||||
fun nonQueryChanges() =
|
||||
SQLiteDB().use(Custom::nonQueryChanges)
|
||||
|
||||
@Test
|
||||
@DisplayName("nonQuery makes no changes when where clause matches nothing")
|
||||
fun nonQueryNoChanges() =
|
||||
SQLiteDB().use(Custom::nonQueryNoChanges)
|
||||
|
||||
@Test
|
||||
@DisplayName("scalar succeeds")
|
||||
fun scalar() =
|
||||
SQLiteDB().use(Custom::scalar)
|
||||
}
|
||||
36
src/test/kotlin/integration/sqlite/DefinitionIT.kt
Normal file
36
src/test/kotlin/integration/sqlite/DefinitionIT.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package solutions.bitbadger.documents.integration.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import solutions.bitbadger.documents.*
|
||||
import solutions.bitbadger.documents.integration.common.Definition
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `Definition` object / `ensure*` connection extension functions
|
||||
*/
|
||||
@DisplayName("SQLite - Definition")
|
||||
class DefinitionIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("ensureTable creates table and index")
|
||||
fun ensureTable() =
|
||||
SQLiteDB().use(Definition::ensureTable)
|
||||
|
||||
@Test
|
||||
@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) }
|
||||
}
|
||||
}
|
||||
46
src/test/kotlin/integration/sqlite/DeleteIT.kt
Normal file
46
src/test/kotlin/integration/sqlite/DeleteIT.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package solutions.bitbadger.documents.integration.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import solutions.bitbadger.documents.DocumentException
|
||||
import solutions.bitbadger.documents.integration.common.Delete
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `Delete` object / `deleteBy*` connection extension functions
|
||||
*/
|
||||
@DisplayName("SQLite - Delete")
|
||||
class DeleteIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("byId deletes a matching ID")
|
||||
fun byIdMatch() =
|
||||
SQLiteDB().use(Delete::byIdMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byId succeeds when no ID matches")
|
||||
fun byIdNoMatch() =
|
||||
SQLiteDB().use(Delete::byIdNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields deletes matching documents")
|
||||
fun byFieldsMatch() =
|
||||
SQLiteDB().use(Delete::byFieldsMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields succeeds when no documents match")
|
||||
fun byFieldsNoMatch() =
|
||||
SQLiteDB().use(Delete::byFieldsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains fails")
|
||||
fun byContainsFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Delete::byContainsMatch) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath fails")
|
||||
fun byJsonPathFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Delete::byJsonPathMatch) }
|
||||
}
|
||||
}
|
||||
57
src/test/kotlin/integration/sqlite/DocumentIT.kt
Normal file
57
src/test/kotlin/integration/sqlite/DocumentIT.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package solutions.bitbadger.documents.integration.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import solutions.bitbadger.documents.integration.common.Document
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `Document` object / `insert`, `save`, `update` connection extension functions
|
||||
*/
|
||||
@DisplayName("SQLite - Document")
|
||||
class DocumentIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("insert works with default values")
|
||||
fun insertDefault() =
|
||||
SQLiteDB().use(Document::insertDefault)
|
||||
|
||||
@Test
|
||||
@DisplayName("insert fails with duplicate key")
|
||||
fun insertDupe() =
|
||||
SQLiteDB().use(Document::insertDupe)
|
||||
|
||||
@Test
|
||||
@DisplayName("insert succeeds with numeric auto IDs")
|
||||
fun insertNumAutoId() =
|
||||
SQLiteDB().use(Document::insertNumAutoId)
|
||||
|
||||
@Test
|
||||
@DisplayName("insert succeeds with UUID auto ID")
|
||||
fun insertUUIDAutoId() =
|
||||
SQLiteDB().use(Document::insertUUIDAutoId)
|
||||
|
||||
@Test
|
||||
@DisplayName("insert succeeds with random string auto ID")
|
||||
fun insertStringAutoId() =
|
||||
SQLiteDB().use(Document::insertStringAutoId)
|
||||
|
||||
@Test
|
||||
@DisplayName("save updates an existing document")
|
||||
fun saveMatch() =
|
||||
SQLiteDB().use(Document::saveMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("save inserts a new document")
|
||||
fun saveNoMatch() =
|
||||
SQLiteDB().use(Document::saveNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("update replaces an existing document")
|
||||
fun updateMatch() =
|
||||
SQLiteDB().use(Document::updateMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("update succeeds when no document exists")
|
||||
fun updateNoMatch() =
|
||||
SQLiteDB().use(Document::updateNoMatch)
|
||||
}
|
||||
46
src/test/kotlin/integration/sqlite/ExistsIT.kt
Normal file
46
src/test/kotlin/integration/sqlite/ExistsIT.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package solutions.bitbadger.documents.integration.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import solutions.bitbadger.documents.DocumentException
|
||||
import solutions.bitbadger.documents.integration.common.Exists
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `Exists` object / `existsBy*` connection extension functions
|
||||
*/
|
||||
@DisplayName("SQLite - Exists")
|
||||
class ExistsIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("byId returns true when a document matches the ID")
|
||||
fun byIdMatch() =
|
||||
SQLiteDB().use(Exists::byIdMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byId returns false when no document matches the ID")
|
||||
fun byIdNoMatch() =
|
||||
SQLiteDB().use(Exists::byIdNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields returns true when documents match")
|
||||
fun byFieldsMatch() =
|
||||
SQLiteDB().use(Exists::byFieldsMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields returns false when no documents match")
|
||||
fun byFieldsNoMatch() =
|
||||
SQLiteDB().use(Exists::byFieldsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains fails")
|
||||
fun byContainsFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Exists::byContainsMatch) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath fails")
|
||||
fun byJsonPathFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Exists::byJsonPathMatch) }
|
||||
}
|
||||
}
|
||||
128
src/test/kotlin/integration/sqlite/FindIT.kt
Normal file
128
src/test/kotlin/integration/sqlite/FindIT.kt
Normal file
@@ -0,0 +1,128 @@
|
||||
package solutions.bitbadger.documents.integration.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import solutions.bitbadger.documents.DocumentException
|
||||
import solutions.bitbadger.documents.integration.common.Find
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `Find` object / `find*` connection extension functions
|
||||
*/
|
||||
@DisplayName("SQLite - Find")
|
||||
class FindIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("all retrieves all documents")
|
||||
fun allDefault() =
|
||||
SQLiteDB().use(Find::allDefault)
|
||||
|
||||
@Test
|
||||
@DisplayName("all sorts data ascending")
|
||||
fun allAscending() =
|
||||
SQLiteDB().use(Find::allAscending)
|
||||
|
||||
@Test
|
||||
@DisplayName("all sorts data descending")
|
||||
fun allDescending() =
|
||||
SQLiteDB().use(Find::allDescending)
|
||||
|
||||
@Test
|
||||
@DisplayName("all sorts data numerically")
|
||||
fun allNumOrder() =
|
||||
SQLiteDB().use(Find::allNumOrder)
|
||||
|
||||
@Test
|
||||
@DisplayName("all succeeds with an empty table")
|
||||
fun allEmpty() =
|
||||
SQLiteDB().use(Find::allEmpty)
|
||||
|
||||
@Test
|
||||
@DisplayName("byId retrieves a document via a string ID")
|
||||
fun byIdString() =
|
||||
SQLiteDB().use(Find::byIdString)
|
||||
|
||||
@Test
|
||||
@DisplayName("byId retrieves a document via a numeric ID")
|
||||
fun byIdNumber() =
|
||||
SQLiteDB().use(Find::byIdNumber)
|
||||
|
||||
@Test
|
||||
@DisplayName("byId returns null when a matching ID is not found")
|
||||
fun byIdNotFound() =
|
||||
SQLiteDB().use(Find::byIdNotFound)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields retrieves matching documents")
|
||||
fun byFieldsMatch() =
|
||||
SQLiteDB().use(Find::byFieldsMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields retrieves ordered matching documents")
|
||||
fun byFieldsMatchOrdered() =
|
||||
SQLiteDB().use(Find::byFieldsMatchOrdered)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields retrieves matching documents with a numeric IN clause")
|
||||
fun byFieldsMatchNumIn() =
|
||||
SQLiteDB().use(Find::byFieldsMatchNumIn)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields succeeds when no documents match")
|
||||
fun byFieldsNoMatch() =
|
||||
SQLiteDB().use(Find::byFieldsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields retrieves matching documents with an IN_ARRAY comparison")
|
||||
fun byFieldsMatchInArray() =
|
||||
SQLiteDB().use(Find::byFieldsMatchInArray)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields succeeds when no documents match an IN_ARRAY comparison")
|
||||
fun byFieldsNoMatchInArray() =
|
||||
SQLiteDB().use(Find::byFieldsNoMatchInArray)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains fails")
|
||||
fun byContainsFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Find::byContainsMatch) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath fails")
|
||||
fun byJsonPathFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Find::byJsonPathMatch) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("firstByFields retrieves a matching document")
|
||||
fun firstByFieldsMatchOne() =
|
||||
SQLiteDB().use(Find::firstByFieldsMatchOne)
|
||||
|
||||
@Test
|
||||
@DisplayName("firstByFields retrieves a matching document among many")
|
||||
fun firstByFieldsMatchMany() =
|
||||
SQLiteDB().use(Find::firstByFieldsMatchMany)
|
||||
|
||||
@Test
|
||||
@DisplayName("firstByFields retrieves a matching document among many (ordered)")
|
||||
fun firstByFieldsMatchOrdered() =
|
||||
SQLiteDB().use(Find::firstByFieldsMatchOrdered)
|
||||
|
||||
@Test
|
||||
@DisplayName("firstByFields returns null when no document matches")
|
||||
fun firstByFieldsNoMatch() =
|
||||
SQLiteDB().use(Find::firstByFieldsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("firstByContains fails")
|
||||
fun firstByContainsFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Find::firstByContainsMatchOne) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("firstByJsonPath fails")
|
||||
fun firstByJsonPathFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Find::firstByJsonPathMatchOne) }
|
||||
}
|
||||
}
|
||||
46
src/test/kotlin/integration/sqlite/PatchIT.kt
Normal file
46
src/test/kotlin/integration/sqlite/PatchIT.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package solutions.bitbadger.documents.integration.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import solutions.bitbadger.documents.DocumentException
|
||||
import solutions.bitbadger.documents.integration.common.Patch
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `Patch` object / `patchBy*` connection extension functions
|
||||
*/
|
||||
@DisplayName("SQLite - Patch")
|
||||
class PatchIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("byId patches an existing document")
|
||||
fun byIdMatch() =
|
||||
SQLiteDB().use(Patch::byIdMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byId succeeds for a non-existent document")
|
||||
fun byIdNoMatch() =
|
||||
SQLiteDB().use(Patch::byIdNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields patches matching document")
|
||||
fun byFieldsMatch() =
|
||||
SQLiteDB().use(Patch::byFieldsMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields succeeds when no documents match")
|
||||
fun byFieldsNoMatch() =
|
||||
SQLiteDB().use(Patch::byFieldsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains fails")
|
||||
fun byContainsFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Patch::byContainsMatch) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath fails")
|
||||
fun byJsonPathFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Patch::byJsonPathMatch) }
|
||||
}
|
||||
}
|
||||
56
src/test/kotlin/integration/sqlite/RemoveFieldsIT.kt
Normal file
56
src/test/kotlin/integration/sqlite/RemoveFieldsIT.kt
Normal file
@@ -0,0 +1,56 @@
|
||||
package solutions.bitbadger.documents.integration.sqlite
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import solutions.bitbadger.documents.DocumentException
|
||||
import solutions.bitbadger.documents.integration.common.RemoveFields
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `RemoveFields` object / `removeFieldsBy*` connection extension functions
|
||||
*/
|
||||
@DisplayName("SQLite - RemoveFields")
|
||||
class RemoveFieldsIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("byId removes fields from an existing document")
|
||||
fun byIdMatchFields() =
|
||||
SQLiteDB().use(RemoveFields::byIdMatchFields)
|
||||
|
||||
@Test
|
||||
@DisplayName("byId succeeds when fields do not exist on an existing document")
|
||||
fun byIdMatchNoFields() =
|
||||
SQLiteDB().use(RemoveFields::byIdMatchNoFields)
|
||||
|
||||
@Test
|
||||
@DisplayName("byId succeeds when no document exists")
|
||||
fun byIdNoMatch() =
|
||||
SQLiteDB().use(RemoveFields::byIdNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields removes fields from matching documents")
|
||||
fun byFieldsMatchFields() =
|
||||
SQLiteDB().use(RemoveFields::byFieldsMatchFields)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields succeeds when fields do not exist on matching documents")
|
||||
fun byFieldsMatchNoFields() =
|
||||
SQLiteDB().use(RemoveFields::byFieldsMatchNoFields)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields succeeds when no matching documents exist")
|
||||
fun byFieldsNoMatch() =
|
||||
SQLiteDB().use(RemoveFields::byFieldsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains fails")
|
||||
fun byContainsFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(RemoveFields::byContainsMatchFields) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath fails")
|
||||
fun byJsonPathFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(RemoveFields::byJsonPathMatchFields) }
|
||||
}
|
||||
}
|
||||
34
src/test/kotlin/integration/sqlite/SQLiteDB.kt
Normal file
34
src/test/kotlin/integration/sqlite/SQLiteDB.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package solutions.bitbadger.documents.integration.sqlite
|
||||
|
||||
import solutions.bitbadger.documents.*
|
||||
import solutions.bitbadger.documents.integration.TEST_TABLE
|
||||
import solutions.bitbadger.documents.integration.ThrowawayDatabase
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* A wrapper for a throwaway SQLite database
|
||||
*/
|
||||
class SQLiteDB : ThrowawayDatabase {
|
||||
|
||||
private var dbName = ""
|
||||
|
||||
init {
|
||||
dbName = "test-db-${AutoId.generateRandomString(8)}.db"
|
||||
Configuration.connectionString = "jdbc:sqlite:$dbName"
|
||||
}
|
||||
|
||||
override val conn = Configuration.dbConn()
|
||||
|
||||
init {
|
||||
conn.ensureTable(TEST_TABLE)
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
conn.close()
|
||||
File(dbName).delete()
|
||||
}
|
||||
|
||||
override fun dbObjectExists(name: String) =
|
||||
conn.customScalar("SELECT EXISTS (SELECT 1 FROM sqlite_master WHERE name = :name) AS it",
|
||||
listOf(Parameter(":name", ParameterType.STRING, name)), Results::toExists)
|
||||
}
|
||||
Reference in New Issue
Block a user