Add exists functions
This commit is contained in:
63
src/integration-test/kotlin/common/Exists.kt
Normal file
63
src/integration-test/kotlin/common/Exists.kt
Normal file
@@ -0,0 +1,63 @@
|
||||
package solutions.bitbadger.documents.common
|
||||
|
||||
import solutions.bitbadger.documents.*
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* Integration tests for the `Exists` object
|
||||
*/
|
||||
object Exists {
|
||||
|
||||
fun byIdMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertTrue("The document with ID \"three\" should exist") { db.conn.existsById(TEST_TABLE, "three") }
|
||||
}
|
||||
|
||||
fun byIdNoMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertFalse("The document with ID \"seven\" should not exist") { db.conn.existsById(TEST_TABLE, "seven") }
|
||||
}
|
||||
|
||||
fun byFieldsMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertTrue("Matching documents should have been found") {
|
||||
db.conn.existsByFields(TEST_TABLE, listOf(Field.equal("numValue", 10)))
|
||||
}
|
||||
}
|
||||
|
||||
fun byFieldsNoMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertFalse("No matching documents should have been found") {
|
||||
db.conn.existsByFields(TEST_TABLE, listOf(Field.equal("nothing", "none")))
|
||||
}
|
||||
}
|
||||
|
||||
fun byContainsMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertTrue("Matching documents should have been found") {
|
||||
db.conn.existsByContains(TEST_TABLE, mapOf("value" to "purple"))
|
||||
}
|
||||
}
|
||||
|
||||
fun byContainsNoMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertFalse("Matching documents should not have been found") {
|
||||
db.conn.existsByContains(TEST_TABLE, mapOf("value" to "violet"))
|
||||
}
|
||||
}
|
||||
|
||||
fun byJsonPathMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertTrue("Matching documents should have been found") {
|
||||
db.conn.existsByJsonPath(TEST_TABLE, "$.numValue ? (@ == 10)")
|
||||
}
|
||||
}
|
||||
|
||||
fun byJsonPathNoMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertFalse("Matching documents should not have been found") {
|
||||
db.conn.existsByJsonPath(TEST_TABLE, "$.numValue ? (@ == 10.1)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ import org.junit.jupiter.api.DisplayName
|
||||
import solutions.bitbadger.documents.common.Delete
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* PostgreSQL integration tests for the `Delete` object / `deleteBy*` connection extension functions
|
||||
*/
|
||||
@DisplayName("PostgreSQL - Delete")
|
||||
class DeleteIT {
|
||||
|
||||
|
||||
52
src/integration-test/kotlin/postgresql/ExistsIT.kt
Normal file
52
src/integration-test/kotlin/postgresql/ExistsIT.kt
Normal file
@@ -0,0 +1,52 @@
|
||||
package solutions.bitbadger.documents.postgresql
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import solutions.bitbadger.documents.common.Exists
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* PostgreSQL integration tests for the `Exists` object / `existsBy*` connection extension functions
|
||||
*/
|
||||
@DisplayName("PostgreSQL - Exists")
|
||||
class ExistsIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("byId returns true when a document matches the ID")
|
||||
fun byIdMatch() =
|
||||
PgDB().use(Exists::byIdMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byId returns false when no document matches the ID")
|
||||
fun byIdNoMatch() =
|
||||
PgDB().use(Exists::byIdNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields returns true when documents match")
|
||||
fun byFieldsMatch() =
|
||||
PgDB().use(Exists::byFieldsMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields returns false when no documents match")
|
||||
fun byFieldsNoMatch() =
|
||||
PgDB().use(Exists::byFieldsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains returns true when documents match")
|
||||
fun byContainsMatch() =
|
||||
PgDB().use(Exists::byContainsMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains returns false when no documents match")
|
||||
fun byContainsNoMatch() =
|
||||
PgDB().use(Exists::byContainsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath returns true when documents match")
|
||||
fun byJsonPathMatch() =
|
||||
PgDB().use(Exists::byJsonPathMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath returns false when no documents match")
|
||||
fun byJsonPathNoMatch() =
|
||||
PgDB().use(Exists::byJsonPathNoMatch)
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import solutions.bitbadger.documents.DocumentException
|
||||
import solutions.bitbadger.documents.common.Delete
|
||||
import kotlin.test.Test
|
||||
|
||||
/**
|
||||
* SQLite integration tests for the `Delete` object / `deleteBy*` connection extension functions
|
||||
*/
|
||||
@DisplayName("SQLite - Delete")
|
||||
class DeleteIT {
|
||||
|
||||
@@ -31,13 +34,13 @@ class DeleteIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains fails")
|
||||
fun byContainsMatch() {
|
||||
fun byContainsFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Delete::byContainsMatch) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath fails")
|
||||
fun byJsonPathMatch() {
|
||||
fun byJsonPathFails() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Delete::byJsonPathMatch) }
|
||||
}
|
||||
}
|
||||
|
||||
46
src/integration-test/kotlin/sqlite/ExistsIT.kt
Normal file
46
src/integration-test/kotlin/sqlite/ExistsIT.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
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.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) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user