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 @@ + + org.junit.jupiter + junit-jupiter + 5.11.1 + test + org.jetbrains.kotlin kotlin-test-junit5 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") + } +}