package solutions.bitbadger.documents.integration.common import solutions.bitbadger.documents.* import solutions.bitbadger.documents.common.Field import solutions.bitbadger.documents.integration.JsonDocument import solutions.bitbadger.documents.integration.TEST_TABLE import solutions.bitbadger.documents.integration.ThrowawayDatabase 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("numValue", 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, "$.numValue ? (@ < 5)"), "There should have been 2 matching documents" ) } fun byJsonPathNoMatch(db: ThrowawayDatabase) { JsonDocument.load(db) assertEquals( 0L, db.conn.countByJsonPath(TEST_TABLE, "$.numValue ? (@ > 100)"), "There should have been no matching documents" ) } }