WIP on common tests
This commit is contained in:
20
src/common/src/test/kotlin/FieldMatchTest.kt
Normal file
20
src/common/src/test/kotlin/FieldMatchTest.kt
Normal file
@@ -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
|
||||
|
||||
class FieldMatchTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("ANY uses proper SQL")
|
||||
fun any() {
|
||||
assertEquals("OR", FieldMatch.ANY.sql, "ANY should use OR")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ALL uses proper SQL")
|
||||
fun all() {
|
||||
assertEquals("AND", FieldMatch.ALL.sql, "ALL should use AND")
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,270 @@ import kotlin.test.assertNull
|
||||
class FieldTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Equal constructs a field")
|
||||
@DisplayName("equal constructs a field")
|
||||
fun equalCtor() {
|
||||
val field = Field.Equal("Test", 14)
|
||||
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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("greater constructs a field")
|
||||
fun greaterCtor() {
|
||||
val field = Field.greater("Great", "night")
|
||||
assertEquals("Great", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.GREATER, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals("night", 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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("greaterOrEqual constructs a field")
|
||||
fun greaterOrEqualCtor() {
|
||||
val field = Field.greaterOrEqual("Nice", 88L)
|
||||
assertEquals("Nice", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.GREATER_OR_EQUAL, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals(88L, 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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("less constructs a field")
|
||||
fun lessCtor() {
|
||||
val field = Field.less("Lesser", "seven")
|
||||
assertEquals("Lesser", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.LESS, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals("seven", 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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("lessOrEqual constructs a field")
|
||||
fun lessOrEqualCtor() {
|
||||
val field = Field.lessOrEqual("Nobody", "KNOWS")
|
||||
assertEquals("Nobody", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.LESS_OR_EQUAL, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals("KNOWS", 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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("notEqual constructs a field")
|
||||
fun notEqualCtor() {
|
||||
val field = Field.notEqual("Park", "here")
|
||||
assertEquals("Park", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.NOT_EQUAL, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals("here", 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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("between constructs a field")
|
||||
fun betweenCtor() {
|
||||
val field = Field.between("Age", 18, 49)
|
||||
assertEquals("Age", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.BETWEEN, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals(18, field.comparison.value.first, "Field comparison min value not filled correctly")
|
||||
assertEquals(49, field.comparison.value.second, "Field comparison max value not filled correctly")
|
||||
assertNull(field.parameterName, "The parameter name should have been null")
|
||||
assertNull(field.qualifier, "The qualifier should have been null")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("any constructs a field")
|
||||
fun inCtor() {
|
||||
val field = Field.any("Here", listOf(8, 16, 32))
|
||||
assertEquals("Here", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.IN, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals(listOf(8, 16, 32), 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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("inArray constructs a field")
|
||||
fun inArrayCtor() {
|
||||
val field = Field.inArray("ArrayField", "table", listOf("z"))
|
||||
assertEquals("ArrayField", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.IN_ARRAY, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals("table", field.comparison.value.first, "Field comparison table not filled correctly")
|
||||
assertEquals(listOf("z"), field.comparison.value.second, "Field comparison values not filled correctly")
|
||||
assertNull(field.parameterName, "The parameter name should have been null")
|
||||
assertNull(field.qualifier, "The qualifier should have been null")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("exists constructs a field")
|
||||
fun existsCtor() {
|
||||
val field = Field.exists("Groovy")
|
||||
assertEquals("Groovy", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.EXISTS, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals("", 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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("notExists constructs a field")
|
||||
fun notExistsCtor() {
|
||||
val field = Field.notExists("Groovy")
|
||||
assertEquals("Groovy", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.NOT_EXISTS, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals("", 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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("named constructs a field")
|
||||
fun namedCtor() {
|
||||
val field = Field.named("Tacos")
|
||||
assertEquals("Tacos", field.name, "Field name not filled correctly")
|
||||
assertEquals(Op.EQUAL, field.comparison.op, "Field comparison operation not filled correctly")
|
||||
assertEquals("", 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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("nameToPath creates a simple PostgreSQL SQL name")
|
||||
fun nameToPathPostgresSimpleSQL() {
|
||||
assertEquals("data->>'Simple'", Field.nameToPath("Simple", Dialect.POSTGRESQL, FieldFormat.SQL),
|
||||
"Path not constructed correctly")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("nameToPath creates a simple SQLite SQL name")
|
||||
fun nameToPathSQLiteSimpleSQL() {
|
||||
assertEquals("data->>'Simple'", Field.nameToPath("Simple", Dialect.SQLITE, FieldFormat.SQL),
|
||||
"Path not constructed correctly")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("nameToPath creates a nested PostgreSQL SQL name")
|
||||
fun nameToPathPostgresNestedSQL() {
|
||||
assertEquals("data#>>'{A,Long,Path,to,the,Property}'",
|
||||
Field.nameToPath("A.Long.Path.to.the.Property", Dialect.POSTGRESQL, FieldFormat.SQL),
|
||||
"Path not constructed correctly")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("nameToPath creates a nested SQLite SQL name")
|
||||
fun nameToPathSQLiteNestedSQL() {
|
||||
assertEquals("data->'A'->'Long'->'Path'->'to'->'the'->>'Property'",
|
||||
Field.nameToPath("A.Long.Path.to.the.Property", Dialect.SQLITE, FieldFormat.SQL),
|
||||
"Path not constructed correctly")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("nameToPath creates a simple PostgreSQL JSON name")
|
||||
fun nameToPathPostgresSimpleJSON() {
|
||||
assertEquals("data->'Simple'", Field.nameToPath("Simple", Dialect.POSTGRESQL, FieldFormat.JSON),
|
||||
"Path not constructed correctly")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("nameToPath creates a simple SQLite JSON name")
|
||||
fun nameToPathSQLiteSimpleJSON() {
|
||||
assertEquals("data->'Simple'", Field.nameToPath("Simple", Dialect.SQLITE, FieldFormat.JSON),
|
||||
"Path not constructed correctly")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("nameToPath creates a nested PostgreSQL JSON name")
|
||||
fun nameToPathPostgresNestedJSON() {
|
||||
assertEquals("data#>'{A,Long,Path,to,the,Property}'",
|
||||
Field.nameToPath("A.Long.Path.to.the.Property", Dialect.POSTGRESQL, FieldFormat.JSON),
|
||||
"Path not constructed correctly")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("nameToPath creates a nested SQLite JSON name")
|
||||
fun nameToPathSQLiteNestedJSON() {
|
||||
assertEquals("data->'A'->'Long'->'Path'->'to'->'the'->'Property'",
|
||||
Field.nameToPath("A.Long.Path.to.the.Property", Dialect.SQLITE, FieldFormat.JSON),
|
||||
"Path not constructed correctly")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("withParameterName adjusts the parameter name")
|
||||
fun withParameterName() {
|
||||
assertEquals(":name", Field.equal("Bob", "Tom").withParameterName(":name").parameterName,
|
||||
"Parameter name not filled correctly")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("withQualifier adjust the table qualifier")
|
||||
fun withQualifier() {
|
||||
assertEquals("joe", Field.equal("Bill", "Matt").withQualifier("joe").qualifier,
|
||||
"Qualifier not filled correctly")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("path generates for simple unqualified PostgreSQL field")
|
||||
fun pathPostgresSimpleUnqualified() {
|
||||
assertEquals("data->>'SomethingCool'",
|
||||
Field.greaterOrEqual("SomethingCool", 18).path(Dialect.POSTGRESQL, FieldFormat.SQL), "Path not correct")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("path generates for simple qualified PostgreSQL field")
|
||||
fun pathPostgresSimpleQualified() {
|
||||
assertEquals("this.data->>'SomethingElse'",
|
||||
Field.less("SomethingElse", 9).withQualifier("this").path(Dialect.POSTGRESQL, FieldFormat.SQL),
|
||||
"Path not correct")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("path generates for nested unqualified PostgreSQL field")
|
||||
fun pathPostgresNestedUnqualified() {
|
||||
assertEquals("data#>>'{My,Nested,Field}'",
|
||||
Field.equal("My.Nested.Field", "howdy").path(Dialect.POSTGRESQL, FieldFormat.SQL), "Path not correct")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("path generates for nested qualified PostgreSQL field")
|
||||
fun pathPostgresNestedQualified() {
|
||||
assertEquals("bird.data#>>'{Nest,Away}'",
|
||||
Field.equal("Nest.Away", "doc").withQualifier("bird").path(Dialect.POSTGRESQL, FieldFormat.SQL),
|
||||
"Path not correct")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("path generates for simple unqualified SQLite field")
|
||||
fun pathSQLiteSimpleUnqualified() {
|
||||
assertEquals("data->>'SomethingCool'",
|
||||
Field.greaterOrEqual("SomethingCool", 18).path(Dialect.SQLITE, FieldFormat.SQL), "Path not correct")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("path generates for simple qualified SQLite field")
|
||||
fun pathSQLiteSimpleQualified() {
|
||||
assertEquals("this.data->>'SomethingElse'",
|
||||
Field.less("SomethingElse", 9).withQualifier("this").path(Dialect.SQLITE, FieldFormat.SQL),
|
||||
"Path not correct")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("path generates for nested unqualified SQLite field")
|
||||
fun pathSQLiteNestedUnqualified() {
|
||||
assertEquals("data->'My'->'Nested'->>'Field'",
|
||||
Field.equal("My.Nested.Field", "howdy").path(Dialect.SQLITE, FieldFormat.SQL), "Path not correct")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("path generates for nested qualified SQLite field")
|
||||
fun pathSQLiteNestedQualified() {
|
||||
assertEquals("bird.data->'Nest'->>'Away'",
|
||||
Field.equal("Nest.Away", "doc").withQualifier("bird").path(Dialect.SQLITE, FieldFormat.SQL),
|
||||
"Path not correct")
|
||||
}
|
||||
}
|
||||
|
||||
26
src/common/src/test/kotlin/ParameterNameTest.kt
Normal file
26
src/common/src/test/kotlin/ParameterNameTest.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package solutions.bitbadger.documents.common
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ParameterNameTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("derive works when given existing names")
|
||||
fun withExisting() {
|
||||
val names = ParameterName()
|
||||
assertEquals(":taco", names.derive(":taco"), "Name should have been :taco")
|
||||
assertEquals(":field0", names.derive(null), "Counter should not have advanced for named field")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("derive works when given all anonymous fields")
|
||||
fun allAnonymous() {
|
||||
val names = ParameterName()
|
||||
assertEquals(":field0", names.derive(null), "Anonymous field name should have been returned")
|
||||
assertEquals(":field1", names.derive(null), "Counter should have advanced from previous call")
|
||||
assertEquals(":field2", names.derive(null), "Counter should have advanced from previous call")
|
||||
assertEquals(":field3", names.derive(null), "Counter should have advanced from previous call")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user