From 359e09bd5299c8bf0537b31bf2c0d4e6c95c6772 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" <daniel@bitbadger.solutions> Date: Thu, 13 Feb 2025 17:56:59 -0500 Subject: [PATCH] WIP on tests for common module --- src/common/pom.xml | 6 ++ src/common/src/main/kotlin/Op.kt | 2 +- src/common/src/test/kotlin/AutoIdTest.kt | 17 ++++++ src/common/src/test/kotlin/FieldTest.kt | 20 +++++++ src/common/src/test/kotlin/OpTest.kt | 74 ++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 src/common/src/test/kotlin/AutoIdTest.kt create mode 100644 src/common/src/test/kotlin/FieldTest.kt create mode 100644 src/common/src/test/kotlin/OpTest.kt diff --git a/src/common/pom.xml b/src/common/pom.xml index 2bc4cdc..110ad24 100644 --- a/src/common/pom.xml +++ b/src/common/pom.xml @@ -66,6 +66,12 @@ </build> <dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>5.11.1</version> + <scope>test</scope> + </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-test-junit5</artifactId> diff --git a/src/common/src/main/kotlin/Op.kt b/src/common/src/main/kotlin/Op.kt index 0fbf185..89f6139 100644 --- a/src/common/src/main/kotlin/Op.kt +++ b/src/common/src/main/kotlin/Op.kt @@ -3,7 +3,7 @@ package solutions.bitbadger.documents.common /** * A comparison operator used for fields */ -enum class Op(sql: String) { +enum class Op(val sql: String) { /** Compare using equality */ EQUAL("="), /** Compare using greater-than */ diff --git a/src/common/src/test/kotlin/AutoIdTest.kt b/src/common/src/test/kotlin/AutoIdTest.kt new file mode 100644 index 0000000..9552a81 --- /dev/null +++ b/src/common/src/test/kotlin/AutoIdTest.kt @@ -0,0 +1,17 @@ +package solutions.bitbadger.documents.common + +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +class AutoIdTest { + + @Test + @DisplayName("Generates a UUID string") + fun testGenerateUUID() { + val generated = AutoId.generateUUID() + assertNotNull(generated, "The UUID string should not have been null") + assertEquals(32, generated.length, "The UUID should have been a 32-character string") + } +} \ No newline at end of file diff --git a/src/common/src/test/kotlin/FieldTest.kt b/src/common/src/test/kotlin/FieldTest.kt new file mode 100644 index 0000000..9a74bae --- /dev/null +++ b/src/common/src/test/kotlin/FieldTest.kt @@ -0,0 +1,20 @@ +package solutions.bitbadger.documents.common + +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +class FieldTest { + + @Test + @DisplayName("Equal constructs a field") + fun equalCtor() { + val field = Field.Equal("Test", 14) + assertEquals("Test", field.name, "Field name not filled correctly") + assertEquals(Op.EQUAL, field.comparison.op, "Field comparison operation not filled correctly") + assertEquals(14, field.comparison.value, "Field comparison value not filled correctly") + assertNull(field.parameterName, "The parameter name should have been null") + assertNull(field.qualifier, "The qualifier should have been null") + } +} diff --git a/src/common/src/test/kotlin/OpTest.kt b/src/common/src/test/kotlin/OpTest.kt new file mode 100644 index 0000000..6656928 --- /dev/null +++ b/src/common/src/test/kotlin/OpTest.kt @@ -0,0 +1,74 @@ +package solutions.bitbadger.documents.common + +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class OpTest { + + @Test + @DisplayName("EQUAL uses proper SQL") + fun equalSQL() { + assertEquals("=", Op.EQUAL.sql, "The SQL for equal is incorrect") + } + + @Test + @DisplayName("GREATER uses proper SQL") + fun greaterSQL() { + assertEquals(">", Op.GREATER.sql, "The SQL for greater is incorrect") + } + + @Test + @DisplayName("GREATER_OR_EQUAL uses proper SQL") + fun greaterOrEqualSQL() { + assertEquals(">=", Op.GREATER_OR_EQUAL.sql, "The SQL for greater-or-equal is incorrect") + } + + @Test + @DisplayName("LESS uses proper SQL") + fun lessSQL() { + assertEquals("<", Op.LESS.sql, "The SQL for less is incorrect") + } + + @Test + @DisplayName("LESS_OR_EQUAL uses proper SQL") + fun lessOrEqualSQL() { + assertEquals("<=", Op.LESS_OR_EQUAL.sql, "The SQL for less-or-equal is incorrect") + } + + @Test + @DisplayName("NOT_EQUAL uses proper SQL") + fun notEqualSQL() { + assertEquals("<>", Op.NOT_EQUAL.sql, "The SQL for not-equal is incorrect") + } + + @Test + @DisplayName("BETWEEN uses proper SQL") + fun betweenSQL() { + assertEquals("BETWEEN", Op.BETWEEN.sql, "The SQL for between is incorrect") + } + + @Test + @DisplayName("IN uses proper SQL") + fun inSQL() { + assertEquals("IN", Op.IN.sql, "The SQL for in is incorrect") + } + + @Test + @DisplayName("IN_ARRAY uses proper SQL") + fun inArraySQL() { + assertEquals("?|", Op.IN_ARRAY.sql, "The SQL for in-array is incorrect") + } + + @Test + @DisplayName("EXISTS uses proper SQL") + fun existsSQL() { + assertEquals("IS NOT NULL", Op.EXISTS.sql, "The SQL for exists is incorrect") + } + + @Test + @DisplayName("NOT_EXISTS uses proper SQL") + fun notExistsSQL() { + assertEquals("IS NULL", Op.NOT_EXISTS.sql, "The SQL for not-exists is incorrect") + } +}