Add delete functions
This commit is contained in:
66
src/integration-test/kotlin/common/Delete.kt
Normal file
66
src/integration-test/kotlin/common/Delete.kt
Normal file
@@ -0,0 +1,66 @@
|
||||
package solutions.bitbadger.documents.common
|
||||
|
||||
import solutions.bitbadger.documents.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
/**
|
||||
* Integration tests for the `Delete` object
|
||||
*/
|
||||
object Delete {
|
||||
|
||||
fun byIdMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table")
|
||||
db.conn.deleteById(TEST_TABLE, "four")
|
||||
assertEquals(4, db.conn.countAll(TEST_TABLE), "There should now be 4 documents in the table")
|
||||
}
|
||||
|
||||
fun byIdNoMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table")
|
||||
db.conn.deleteById(TEST_TABLE, "negative four")
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should still be 5 documents in the table")
|
||||
}
|
||||
|
||||
fun byFieldsMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table")
|
||||
db.conn.deleteByFields(TEST_TABLE, listOf(Field.notEqual("value", "purple")))
|
||||
assertEquals(2, db.conn.countAll(TEST_TABLE), "There should now be 2 documents in the table")
|
||||
}
|
||||
|
||||
fun byFieldsNoMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table")
|
||||
db.conn.deleteByFields(TEST_TABLE, listOf(Field.equal("value", "crimson")))
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should still be 5 documents in the table")
|
||||
}
|
||||
|
||||
fun byContainsMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table")
|
||||
db.conn.deleteByContains(TEST_TABLE, mapOf("value" to "purple"))
|
||||
assertEquals(3, db.conn.countAll(TEST_TABLE), "There should now be 3 documents in the table")
|
||||
}
|
||||
|
||||
fun byContainsNoMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table")
|
||||
db.conn.deleteByContains(TEST_TABLE, mapOf("target" to "acquired"))
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should still be 5 documents in the table")
|
||||
}
|
||||
|
||||
fun byJsonPathMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table")
|
||||
db.conn.deleteByJsonPath(TEST_TABLE, "$.value ? (@ == \"purple\")")
|
||||
assertEquals(3, db.conn.countAll(TEST_TABLE), "There should now be 3 documents in the table")
|
||||
}
|
||||
|
||||
fun byJsonPathNoMatch(db: ThrowawayDatabase) {
|
||||
JsonDocument.load(db)
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table")
|
||||
db.conn.deleteByJsonPath(TEST_TABLE, "$.numValue ? (@ > 100)")
|
||||
assertEquals(5, db.conn.countAll(TEST_TABLE), "There should still be 5 documents in the table")
|
||||
}
|
||||
}
|
||||
49
src/integration-test/kotlin/postgresql/DeleteIT.kt
Normal file
49
src/integration-test/kotlin/postgresql/DeleteIT.kt
Normal file
@@ -0,0 +1,49 @@
|
||||
package solutions.bitbadger.documents.postgresql
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import solutions.bitbadger.documents.common.Delete
|
||||
import kotlin.test.Test
|
||||
|
||||
@DisplayName("PostgreSQL - Delete")
|
||||
class DeleteIT {
|
||||
|
||||
@Test
|
||||
@DisplayName("byId deletes a matching ID")
|
||||
fun byIdMatch() =
|
||||
PgDB().use(Delete::byIdMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byId succeeds when no ID matches")
|
||||
fun byIdNoMatch() =
|
||||
PgDB().use(Delete::byIdNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields deletes matching documents")
|
||||
fun byFieldsMatch() =
|
||||
PgDB().use(Delete::byFieldsMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byFields succeeds when no documents match")
|
||||
fun byFieldsNoMatch() =
|
||||
PgDB().use(Delete::byFieldsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains deletes matching documents")
|
||||
fun byContainsMatch() =
|
||||
PgDB().use(Delete::byContainsMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byContains succeeds when no documents match")
|
||||
fun byContainsNoMatch() =
|
||||
PgDB().use(Delete::byContainsNoMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath deletes matching documents")
|
||||
fun byJsonPathMatch() =
|
||||
PgDB().use(Delete::byJsonPathMatch)
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath succeeds when no documents match")
|
||||
fun byJsonPathNoMatch() =
|
||||
PgDB().use(Delete::byJsonPathNoMatch)
|
||||
}
|
||||
43
src/integration-test/kotlin/sqlite/DeleteIT.kt
Normal file
43
src/integration-test/kotlin/sqlite/DeleteIT.kt
Normal file
@@ -0,0 +1,43 @@
|
||||
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.Delete
|
||||
import kotlin.test.Test
|
||||
|
||||
@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 byContainsMatch() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Delete::byContainsMatch) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("byJsonPath fails")
|
||||
fun byJsonPathMatch() {
|
||||
assertThrows<DocumentException> { SQLiteDB().use(Delete::byJsonPathMatch) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user