Initial Development #1

Merged
danieljsummers merged 88 commits from v1-rc into main 2025-04-16 01:29:20 +00:00
23 changed files with 820 additions and 321 deletions
Showing only changes of commit ecf71de1c4 - Show all commits

View File

@ -43,13 +43,13 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.codehaus.groovy</groupId> <groupId>org.apache.groovy</groupId>
<artifactId>groovy-test</artifactId> <artifactId>groovy-test</artifactId>
<version>${groovy.version}</version> <version>${groovy.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.codehaus.groovy</groupId> <groupId>org.apache.groovy</groupId>
<artifactId>groovy-test-junit5</artifactId> <artifactId>groovy-test-junit5</artifactId>
<version>${groovy.version}</version> <version>${groovy.version}</version>
<scope>test</scope> <scope>test</scope>
@ -131,7 +131,10 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version> <version>2.22.2</version>
<configuration> <configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine> <argLine>
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
</argLine>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -6,7 +6,7 @@ import solutions.bitbadger.documents.AutoId
//import solutions.bitbadger.documents.DocumentException //import solutions.bitbadger.documents.DocumentException
import solutions.bitbadger.documents.groovy.support.* import solutions.bitbadger.documents.groovy.support.*
import static groovy.test.GroovyAssert.* import static org.junit.jupiter.api.Assertions.*
/** /**
* Unit tests for the `AutoId` enum * Unit tests for the `AutoId` enum
@ -17,21 +17,21 @@ class AutoIdTest {
@Test @Test
@DisplayName('Generates a UUID string') @DisplayName('Generates a UUID string')
void generateUUID() { void generateUUID() {
assertEquals('The UUID should have been a 32-character string', 32, AutoId.generateUUID().length()) assertEquals 32, AutoId.generateUUID().length(), 'The UUID should have been a 32-character string'
} }
@Test @Test
@DisplayName('Generates a random hex character string of an even length') @DisplayName('Generates a random hex character string of an even length')
void generateRandomStringEven() { void generateRandomStringEven() {
def result = AutoId.generateRandomString 8 def result = AutoId.generateRandomString 8
assertEquals("There should have been 8 characters in $result", 8, result.length()) assertEquals 8, result.length(), "There should have been 8 characters in $result"
} }
@Test @Test
@DisplayName('Generates a random hex character string of an odd length') @DisplayName('Generates a random hex character string of an odd length')
void generateRandomStringOdd() { void generateRandomStringOdd() {
def result = AutoId.generateRandomString 11 def result = AutoId.generateRandomString 11
assertEquals("There should have been 11 characters in $result", 11, result.length()) assertEquals 11, result.length(), "There should have been 11 characters in $result"
} }
@Test @Test
@ -39,7 +39,7 @@ class AutoIdTest {
void generateRandomStringIsRandom() { void generateRandomStringIsRandom() {
def result1 = AutoId.generateRandomString 16 def result1 = AutoId.generateRandomString 16
def result2 = AutoId.generateRandomString 16 def result2 = AutoId.generateRandomString 16
assertNotEquals('There should have been 2 different strings generated', result1, result2) assertNotEquals result1, result2, 'There should have been 2 different strings generated'
} }
// TODO: resolve java.base open issue // TODO: resolve java.base open issue
@ -59,63 +59,63 @@ class AutoIdTest {
@Test @Test
@DisplayName('needsAutoId returns false if disabled') @DisplayName('needsAutoId returns false if disabled')
void needsAutoIdFalseIfDisabled() { void needsAutoIdFalseIfDisabled() {
assertFalse('Disabled Auto ID should always return false', AutoId.needsAutoId(AutoId.DISABLED, '', '')) assertFalse AutoId.needsAutoId(AutoId.DISABLED, '', ''), 'Disabled Auto ID should always return false'
} }
@Test @Test
@DisplayName('needsAutoId returns true for Number strategy and byte ID of 0') @DisplayName('needsAutoId returns true for Number strategy and byte ID of 0')
void needsAutoIdTrueForByteWithZero() { void needsAutoIdTrueForByteWithZero() {
assertTrue('Number Auto ID with 0 should return true', assertTrue(AutoId.needsAutoId(AutoId.NUMBER, new ByteIdClass((byte) 0), 'id'),
AutoId.needsAutoId(AutoId.NUMBER, new ByteIdClass((byte) 0), 'id')) 'Number Auto ID with 0 should return true')
} }
@Test @Test
@DisplayName('needsAutoId returns false for Number strategy and byte ID of non-0') @DisplayName('needsAutoId returns false for Number strategy and byte ID of non-0')
void needsAutoIdFalseForByteWithNonZero() { void needsAutoIdFalseForByteWithNonZero() {
assertFalse('Number Auto ID with 77 should return false', assertFalse(AutoId.needsAutoId(AutoId.NUMBER, new ByteIdClass((byte) 77), 'id'),
AutoId.needsAutoId(AutoId.NUMBER, new ByteIdClass((byte) 77), 'id')) 'Number Auto ID with 77 should return false')
} }
@Test @Test
@DisplayName('needsAutoId returns true for Number strategy and short ID of 0') @DisplayName('needsAutoId returns true for Number strategy and short ID of 0')
void needsAutoIdTrueForShortWithZero() { void needsAutoIdTrueForShortWithZero() {
assertTrue('Number Auto ID with 0 should return true', assertTrue(AutoId.needsAutoId(AutoId.NUMBER, new ShortIdClass((short) 0), 'id'),
AutoId.needsAutoId(AutoId.NUMBER, new ShortIdClass((short) 0), 'id')) 'Number Auto ID with 0 should return true')
} }
@Test @Test
@DisplayName('needsAutoId returns false for Number strategy and short ID of non-0') @DisplayName('needsAutoId returns false for Number strategy and short ID of non-0')
void needsAutoIdFalseForShortWithNonZero() { void needsAutoIdFalseForShortWithNonZero() {
assertFalse('Number Auto ID with 31 should return false', assertFalse(AutoId.needsAutoId(AutoId.NUMBER, new ShortIdClass((short) 31), 'id'),
AutoId.needsAutoId(AutoId.NUMBER, new ShortIdClass((short) 31), 'id')) 'Number Auto ID with 31 should return false')
} }
@Test @Test
@DisplayName('needsAutoId returns true for Number strategy and int ID of 0') @DisplayName('needsAutoId returns true for Number strategy and int ID of 0')
void needsAutoIdTrueForIntWithZero() { void needsAutoIdTrueForIntWithZero() {
assertTrue('Number Auto ID with 0 should return true', assertTrue(AutoId.needsAutoId(AutoId.NUMBER, new IntIdClass(0), 'id'),
AutoId.needsAutoId(AutoId.NUMBER, new IntIdClass(0), 'id')) 'Number Auto ID with 0 should return true')
} }
@Test @Test
@DisplayName('needsAutoId returns false for Number strategy and int ID of non-0') @DisplayName('needsAutoId returns false for Number strategy and int ID of non-0')
void needsAutoIdFalseForIntWithNonZero() { void needsAutoIdFalseForIntWithNonZero() {
assertFalse('Number Auto ID with 6 should return false', assertFalse(AutoId.needsAutoId(AutoId.NUMBER, new IntIdClass(6), 'id'),
AutoId.needsAutoId(AutoId.NUMBER, new IntIdClass(6), 'id')) 'Number Auto ID with 6 should return false')
} }
@Test @Test
@DisplayName('needsAutoId returns true for Number strategy and long ID of 0') @DisplayName('needsAutoId returns true for Number strategy and long ID of 0')
void needsAutoIdTrueForLongWithZero() { void needsAutoIdTrueForLongWithZero() {
assertTrue('Number Auto ID with 0 should return true', assertTrue(AutoId.needsAutoId(AutoId.NUMBER, new LongIdClass(0L), 'id'),
AutoId.needsAutoId(AutoId.NUMBER, new LongIdClass(0L), 'id')) 'Number Auto ID with 0 should return true')
} }
@Test @Test
@DisplayName('needsAutoId returns false for Number strategy and long ID of non-0') @DisplayName('needsAutoId returns false for Number strategy and long ID of non-0')
void needsAutoIdFalseForLongWithNonZero() { void needsAutoIdFalseForLongWithNonZero() {
assertFalse('Number Auto ID with 2 should return false', assertFalse(AutoId.needsAutoId(AutoId.NUMBER, new LongIdClass(2L), 'id'),
AutoId.needsAutoId(AutoId.NUMBER, new LongIdClass(2L), 'id')) 'Number Auto ID with 2 should return false')
} }
// TODO: resolve java.base open issue // TODO: resolve java.base open issue
@ -128,15 +128,15 @@ class AutoIdTest {
@Test @Test
@DisplayName('needsAutoId returns true for UUID strategy and blank ID') @DisplayName('needsAutoId returns true for UUID strategy and blank ID')
void needsAutoIdTrueForUUIDWithBlank() { void needsAutoIdTrueForUUIDWithBlank() {
assertTrue('UUID Auto ID with blank should return true', assertTrue(AutoId.needsAutoId(AutoId.UUID, new StringIdClass(''), 'id'),
AutoId.needsAutoId(AutoId.UUID, new StringIdClass(''), 'id')) 'UUID Auto ID with blank should return true')
} }
@Test @Test
@DisplayName('needsAutoId returns false for UUID strategy and non-blank ID') @DisplayName('needsAutoId returns false for UUID strategy and non-blank ID')
void needsAutoIdFalseForUUIDNotBlank() { void needsAutoIdFalseForUUIDNotBlank() {
assertFalse('UUID Auto ID with non-blank should return false', assertFalse(AutoId.needsAutoId(AutoId.UUID, new StringIdClass('howdy'), 'id'),
AutoId.needsAutoId(AutoId.UUID, new StringIdClass('howdy'), 'id')) 'UUID Auto ID with non-blank should return false')
} }
// TODO: resolve java.base open issue // TODO: resolve java.base open issue
@ -149,22 +149,22 @@ class AutoIdTest {
@Test @Test
@DisplayName('needsAutoId returns true for Random String strategy and blank ID') @DisplayName('needsAutoId returns true for Random String strategy and blank ID')
void needsAutoIdTrueForRandomWithBlank() { void needsAutoIdTrueForRandomWithBlank() {
assertTrue('Random String Auto ID with blank should return true', assertTrue(AutoId.needsAutoId(AutoId.RANDOM_STRING, new StringIdClass(''), 'id'),
AutoId.needsAutoId(AutoId.RANDOM_STRING, new StringIdClass(''), 'id')) 'Random String Auto ID with blank should return true')
} }
@Test @Test
@DisplayName('needsAutoId returns false for Random String strategy and non-blank ID') @DisplayName('needsAutoId returns false for Random String strategy and non-blank ID')
void needsAutoIdFalseForRandomNotBlank() { void needsAutoIdFalseForRandomNotBlank() {
assertFalse('Random String Auto ID with non-blank should return false', assertFalse(AutoId.needsAutoId(AutoId.RANDOM_STRING, new StringIdClass('full'), 'id'),
AutoId.needsAutoId(AutoId.RANDOM_STRING, new StringIdClass('full'), 'id')) 'Random String Auto ID with non-blank should return false')
} }
// TODO: resolve java.base open issue // TODO: resolve java.base open issue
// @Test // @Test
// @DisplayName('needsAutoId fails for Random String strategy and non-string ID') // @DisplayName('needsAutoId fails for Random String strategy and non-string ID')
// void needsAutoIdFailsForRandomNonString() { // void needsAutoIdFailsForRandomNonString() {
// assertThrows(DocumentException.class) { // assertThrows(DocumentException) {
// AutoId.needsAutoId(AutoId.RANDOM_STRING, new ShortIdClass((short) 55), 'id') // AutoId.needsAutoId(AutoId.RANDOM_STRING, new ShortIdClass((short) 55), 'id')
// } // }
// } // }

View File

@ -7,7 +7,7 @@ import solutions.bitbadger.documents.Configuration
import solutions.bitbadger.documents.Dialect import solutions.bitbadger.documents.Dialect
//import solutions.bitbadger.documents.DocumentException //import solutions.bitbadger.documents.DocumentException
import static groovy.test.GroovyAssert.* import static org.junit.jupiter.api.Assertions.*
/** /**
* Unit tests for the `Configuration` object * Unit tests for the `Configuration` object
@ -18,19 +18,19 @@ class ConfigurationTest {
@Test @Test
@DisplayName('Default ID field is "id"') @DisplayName('Default ID field is "id"')
void defaultIdField() { void defaultIdField() {
assertEquals('Default ID field incorrect', 'id', Configuration.idField) assertEquals 'id', Configuration.idField, 'Default ID field incorrect'
} }
@Test @Test
@DisplayName('Default Auto ID strategy is DISABLED') @DisplayName('Default Auto ID strategy is DISABLED')
void defaultAutoId() { void defaultAutoId() {
assertEquals('Default Auto ID strategy should be DISABLED', AutoId.DISABLED, Configuration.autoIdStrategy) assertEquals AutoId.DISABLED, Configuration.autoIdStrategy, 'Default Auto ID strategy should be DISABLED'
} }
@Test @Test
@DisplayName('Default ID string length should be 16') @DisplayName('Default ID string length should be 16')
void defaultIdStringLength() { void defaultIdStringLength() {
assertEquals('Default ID string length should be 16', 16, Configuration.idStringLength) assertEquals 16, Configuration.idStringLength, 'Default ID string length should be 16'
} }
@Test @Test
@ -40,7 +40,7 @@ class ConfigurationTest {
// TODO: uncomment once java.base open issue resolved // TODO: uncomment once java.base open issue resolved
//assertThrows(DocumentException) { Configuration.dialect() } //assertThrows(DocumentException) { Configuration.dialect() }
Configuration.connectionString = 'jdbc:postgresql:db' Configuration.connectionString = 'jdbc:postgresql:db'
assertEquals(Dialect.POSTGRESQL, Configuration.dialect()) assertEquals Dialect.POSTGRESQL, Configuration.dialect()
} finally { } finally {
Configuration.connectionString = null Configuration.connectionString = null
} }

View File

@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test
import solutions.bitbadger.documents.Dialect import solutions.bitbadger.documents.Dialect
import solutions.bitbadger.documents.DocumentException import solutions.bitbadger.documents.DocumentException
import static groovy.test.GroovyAssert.* import static org.junit.jupiter.api.Assertions.*
/** /**
* Unit tests for the `Dialect` enum * Unit tests for the `Dialect` enum
@ -16,27 +16,27 @@ class DialectTest {
@Test @Test
@DisplayName('deriveFromConnectionString derives PostgreSQL correctly') @DisplayName('deriveFromConnectionString derives PostgreSQL correctly')
void derivesPostgres() { void derivesPostgres() {
assertEquals('Dialect should have been PostgreSQL', Dialect.POSTGRESQL, assertEquals(Dialect.POSTGRESQL, Dialect.deriveFromConnectionString('jdbc:postgresql:db'),
Dialect.deriveFromConnectionString('jdbc:postgresql:db')) 'Dialect should have been PostgreSQL')
} }
@Test @Test
@DisplayName('deriveFromConnectionString derives SQLite correctly') @DisplayName('deriveFromConnectionString derives SQLite correctly')
void derivesSQLite() { void derivesSQLite() {
assertEquals('Dialect should have been SQLite', Dialect.SQLITE, assertEquals(Dialect.SQLITE, Dialect.deriveFromConnectionString('jdbc:sqlite:memory'),
Dialect.deriveFromConnectionString('jdbc:sqlite:memory')) 'Dialect should have been SQLite')
} }
@Test @Test
@DisplayName('deriveFromConnectionString fails when the connection string is unknown') @DisplayName('deriveFromConnectionString fails when the connection string is unknown')
void deriveFailsWhenUnknown() { void deriveFailsWhenUnknown() {
try { try {
Dialect.deriveFromConnectionString('SQL Server') Dialect.deriveFromConnectionString 'SQL Server'
fail('Dialect derivation should have failed') fail 'Dialect derivation should have failed'
} catch (DocumentException ex) { } catch (DocumentException ex) {
assertNotNull 'The exception message should not have been null', ex.message assertNotNull ex.message, 'The exception message should not have been null'
assertTrue('The connection string should have been in the exception message', assertTrue(ex.message.contains('[SQL Server]'),
ex.message.contains('[SQL Server]')) 'The connection string should have been in the exception message')
} }
} }
} }

View File

@ -4,7 +4,7 @@ import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import solutions.bitbadger.documents.DocumentIndex import solutions.bitbadger.documents.DocumentIndex
import static groovy.test.GroovyAssert.* import static org.junit.jupiter.api.Assertions.assertEquals
/** /**
* Unit tests for the `DocumentIndex` enum * Unit tests for the `DocumentIndex` enum
@ -15,12 +15,12 @@ class DocumentIndexTest {
@Test @Test
@DisplayName('FULL uses proper SQL') @DisplayName('FULL uses proper SQL')
void fullSQL() { void fullSQL() {
assertEquals('The SQL for Full is incorrect', '', DocumentIndex.FULL.sql) assertEquals '', DocumentIndex.FULL.sql, 'The SQL for Full is incorrect'
} }
@Test @Test
@DisplayName('OPTIMIZED uses proper SQL') @DisplayName('OPTIMIZED uses proper SQL')
void optimizedSQL() { void optimizedSQL() {
assertEquals('The SQL for Optimized is incorrect', ' jsonb_path_ops', DocumentIndex.OPTIMIZED.sql) assertEquals ' jsonb_path_ops', DocumentIndex.OPTIMIZED.sql, 'The SQL for Optimized is incorrect'
} }
} }

View File

@ -4,7 +4,7 @@ import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import solutions.bitbadger.documents.FieldMatch import solutions.bitbadger.documents.FieldMatch
import static groovy.test.GroovyAssert.assertEquals import static org.junit.jupiter.api.Assertions.assertEquals
/** /**
* Unit tests for the `FieldMatch` enum * Unit tests for the `FieldMatch` enum
@ -15,12 +15,12 @@ class FieldMatchTest {
@Test @Test
@DisplayName('ANY uses proper SQL') @DisplayName('ANY uses proper SQL')
void anySQL() { void anySQL() {
assertEquals('ANY should use OR', 'OR', FieldMatch.ANY.sql) assertEquals 'OR', FieldMatch.ANY.sql, 'ANY should use OR'
} }
@Test @Test
@DisplayName('ALL uses proper SQL') @DisplayName('ALL uses proper SQL')
void allSQL() { void allSQL() {
assertEquals('ALL should use AND', 'AND', FieldMatch.ALL.sql) assertEquals 'AND', FieldMatch.ALL.sql, 'ALL should use AND'
} }
} }

View File

@ -10,7 +10,7 @@ import solutions.bitbadger.documents.FieldFormat
import solutions.bitbadger.documents.Op import solutions.bitbadger.documents.Op
import solutions.bitbadger.documents.support.ForceDialect import solutions.bitbadger.documents.support.ForceDialect
import static groovy.test.GroovyAssert.* import static org.junit.jupiter.api.Assertions.*
/** /**
* Unit tests for the `Field` class * Unit tests for the `Field` class
@ -38,264 +38,275 @@ class FieldTest {
@Test @Test
@DisplayName('withParameterName works with colon prefix') @DisplayName('withParameterName works with colon prefix')
void withParamNameColon() { void withParamNameColon() {
def field = Field.equal('abc', '22').withQualifier('me') def field = Field.equal('abc', '22').withQualifier 'me'
def withParam = field.withParameterName(':test') def withParam = field.withParameterName ':test'
assertNotSame('A new Field instance should have been created', field, withParam) assertNotSame field, withParam, 'A new Field instance should have been created'
assertEquals('Name should have been preserved', field.name, withParam.name) assertEquals field.name, withParam.name, 'Name should have been preserved'
assertEquals('Comparison should have been preserved', field.comparison, withParam.comparison) assertEquals field.comparison, withParam.comparison, 'Comparison should have been preserved'
assertEquals('Parameter name not set correctly', ':test', withParam.parameterName) assertEquals ':test', withParam.parameterName, 'Parameter name not set correctly'
assertEquals('Qualifier should have been preserved', field.qualifier, withParam.qualifier) assertEquals field.qualifier, withParam.qualifier, 'Qualifier should have been preserved'
} }
@Test @Test
@DisplayName('withParameterName works with at-sign prefix') @DisplayName('withParameterName works with at-sign prefix')
void withParamNameAtSign() { void withParamNameAtSign() {
def field = Field.equal('def', '44') def field = Field.equal 'def', '44'
def withParam = field.withParameterName('@unit') def withParam = field.withParameterName '@unit'
assertNotSame('A new Field instance should have been created', field, withParam) assertNotSame field, withParam, 'A new Field instance should have been created'
assertEquals('Name should have been preserved', field.name, withParam.name) assertEquals field.name, withParam.name, 'Name should have been preserved'
assertEquals('Comparison should have been preserved', field.comparison, withParam.comparison) assertEquals field.comparison, withParam.comparison, 'Comparison should have been preserved'
assertEquals('Parameter name not set correctly', '@unit', withParam.parameterName) assertEquals '@unit', withParam.parameterName, 'Parameter name not set correctly'
assertEquals('Qualifier should have been preserved', field.qualifier, withParam.qualifier) assertEquals field.qualifier, withParam.qualifier, 'Qualifier should have been preserved'
} }
@Test @Test
@DisplayName('withQualifier sets qualifier correctly') @DisplayName('withQualifier sets qualifier correctly')
void withQualifier() { void withQualifier() {
def field = Field.equal('j', 'k') def field = Field.equal 'j', 'k'
def withQual = field.withQualifier('test') def withQual = field.withQualifier 'test'
assertNotSame('A new Field instance should have been created', field, withQual) assertNotSame field, withQual, 'A new Field instance should have been created'
assertEquals('Name should have been preserved', field.name, withQual.name) assertEquals field.name, withQual.name, 'Name should have been preserved'
assertEquals('Comparison should have been preserved', field.comparison, withQual.comparison) assertEquals field.comparison, withQual.comparison, 'Comparison should have been preserved'
assertEquals('Parameter Name should have been preserved', field.parameterName, withQual.parameterName) assertEquals field.parameterName, withQual.parameterName, 'Parameter Name should have been preserved'
assertEquals('Qualifier not set correctly', 'test', withQual.qualifier) assertEquals 'test', withQual.qualifier, 'Qualifier not set correctly'
} }
@Test @Test
@DisplayName('path generates for simple unqualified PostgreSQL field') @DisplayName('path generates for simple unqualified PostgreSQL field')
void pathPostgresSimpleUnqualified() { void pathPostgresSimpleUnqualified() {
assertEquals('Path not correct', "data->>'SomethingCool'", assertEquals("data->>'SomethingCool'",
Field.greaterOrEqual('SomethingCool', 18).path(Dialect.POSTGRESQL, FieldFormat.SQL)) Field.greaterOrEqual('SomethingCool', 18).path(Dialect.POSTGRESQL, FieldFormat.SQL), 'Path not correct')
} }
@Test @Test
@DisplayName('path generates for simple qualified PostgreSQL field') @DisplayName('path generates for simple qualified PostgreSQL field')
void pathPostgresSimpleQualified() { void pathPostgresSimpleQualified() {
assertEquals('Path not correct', "this.data->>'SomethingElse'", assertEquals("this.data->>'SomethingElse'",
Field.less('SomethingElse', 9).withQualifier('this').path(Dialect.POSTGRESQL, FieldFormat.SQL)) Field.less('SomethingElse', 9).withQualifier('this').path(Dialect.POSTGRESQL, FieldFormat.SQL),
'Path not correct')
} }
@Test @Test
@DisplayName('path generates for nested unqualified PostgreSQL field') @DisplayName('path generates for nested unqualified PostgreSQL field')
void pathPostgresNestedUnqualified() { void pathPostgresNestedUnqualified() {
assertEquals('Path not correct', "data#>>'{My,Nested,Field}'", assertEquals("data#>>'{My,Nested,Field}'",
Field.equal('My.Nested.Field', 'howdy').path(Dialect.POSTGRESQL, FieldFormat.SQL)) Field.equal('My.Nested.Field', 'howdy').path(Dialect.POSTGRESQL, FieldFormat.SQL), 'Path not correct')
} }
@Test @Test
@DisplayName('path generates for nested qualified PostgreSQL field') @DisplayName('path generates for nested qualified PostgreSQL field')
void pathPostgresNestedQualified() { void pathPostgresNestedQualified() {
assertEquals('Path not correct', "bird.data#>>'{Nest,Away}'", assertEquals("bird.data#>>'{Nest,Away}'",
Field.equal('Nest.Away', 'doc').withQualifier('bird').path(Dialect.POSTGRESQL, FieldFormat.SQL)) Field.equal('Nest.Away', 'doc').withQualifier('bird').path(Dialect.POSTGRESQL, FieldFormat.SQL),
'Path not correct')
} }
@Test @Test
@DisplayName('path generates for simple unqualified SQLite field') @DisplayName('path generates for simple unqualified SQLite field')
void pathSQLiteSimpleUnqualified() { void pathSQLiteSimpleUnqualified() {
assertEquals('Path not correct', "data->>'SomethingCool'", assertEquals("data->>'SomethingCool'",
Field.greaterOrEqual('SomethingCool', 18).path(Dialect.SQLITE, FieldFormat.SQL)) Field.greaterOrEqual('SomethingCool', 18).path(Dialect.SQLITE, FieldFormat.SQL), 'Path not correct')
} }
@Test @Test
@DisplayName('path generates for simple qualified SQLite field') @DisplayName('path generates for simple qualified SQLite field')
void pathSQLiteSimpleQualified() { void pathSQLiteSimpleQualified() {
assertEquals('Path not correct', "this.data->>'SomethingElse'", assertEquals("this.data->>'SomethingElse'",
Field.less('SomethingElse', 9).withQualifier('this').path(Dialect.SQLITE, FieldFormat.SQL)) Field.less('SomethingElse', 9).withQualifier('this').path(Dialect.SQLITE, FieldFormat.SQL),
'Path not correct')
} }
@Test @Test
@DisplayName('path generates for nested unqualified SQLite field') @DisplayName('path generates for nested unqualified SQLite field')
void pathSQLiteNestedUnqualified() { void pathSQLiteNestedUnqualified() {
assertEquals('Path not correct', "data->'My'->'Nested'->>'Field'", assertEquals("data->'My'->'Nested'->>'Field'",
Field.equal('My.Nested.Field', 'howdy').path(Dialect.SQLITE, FieldFormat.SQL)) Field.equal('My.Nested.Field', 'howdy').path(Dialect.SQLITE, FieldFormat.SQL), 'Path not correct')
} }
@Test @Test
@DisplayName('path generates for nested qualified SQLite field') @DisplayName('path generates for nested qualified SQLite field')
void pathSQLiteNestedQualified() { void pathSQLiteNestedQualified() {
assertEquals('Path not correct', "bird.data->'Nest'->>'Away'", assertEquals("bird.data->'Nest'->>'Away'",
Field.equal('Nest.Away', 'doc').withQualifier('bird').path(Dialect.SQLITE, FieldFormat.SQL)) Field.equal('Nest.Away', 'doc').withQualifier('bird').path(Dialect.SQLITE, FieldFormat.SQL),
'Path not correct')
} }
@Test @Test
@DisplayName('toWhere generates for exists w/o qualifier | PostgreSQL') @DisplayName('toWhere generates for exists w/o qualifier | PostgreSQL')
void toWhereExistsNoQualPostgres() { void toWhereExistsNoQualPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', "data->>'that_field' IS NOT NULL", assertEquals("data->>'that_field' IS NOT NULL", Field.exists('that_field').toWhere(),
Field.exists('that_field').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for exists w/o qualifier | SQLite') @DisplayName('toWhere generates for exists w/o qualifier | SQLite')
void toWhereExistsNoQualSQLite() { void toWhereExistsNoQualSQLite() {
ForceDialect.sqlite() ForceDialect.sqlite()
assertEquals('Field WHERE clause not generated correctly', "data->>'that_field' IS NOT NULL", assertEquals("data->>'that_field' IS NOT NULL", Field.exists('that_field').toWhere(),
Field.exists('that_field').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for not-exists w/o qualifier | PostgreSQL') @DisplayName('toWhere generates for not-exists w/o qualifier | PostgreSQL')
void toWhereNotExistsNoQualPostgres() { void toWhereNotExistsNoQualPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', "data->>'a_field' IS NULL", assertEquals("data->>'a_field' IS NULL", Field.notExists('a_field').toWhere(),
Field.notExists('a_field').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for not-exists w/o qualifier | SQLite') @DisplayName('toWhere generates for not-exists w/o qualifier | SQLite')
void toWhereNotExistsNoQualSQLite() { void toWhereNotExistsNoQualSQLite() {
ForceDialect.sqlite() ForceDialect.sqlite()
assertEquals('Field WHERE clause not generated correctly', "data->>'a_field' IS NULL", assertEquals("data->>'a_field' IS NULL", Field.notExists('a_field').toWhere(),
Field.notExists('a_field').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for BETWEEN w/o qualifier, numeric range | PostgreSQL') @DisplayName('toWhere generates for BETWEEN w/o qualifier, numeric range | PostgreSQL')
void toWhereBetweenNoQualNumericPostgres() { void toWhereBetweenNoQualNumericPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', assertEquals("(data->>'age')::numeric BETWEEN @agemin AND @agemax",
"(data->>'age')::numeric BETWEEN @agemin AND @agemax", Field.between('age', 13, 17, '@age').toWhere()) Field.between('age', 13, 17, '@age').toWhere(), 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for BETWEEN w/o qualifier, alphanumeric range | PostgreSQL') @DisplayName('toWhere generates for BETWEEN w/o qualifier, alphanumeric range | PostgreSQL')
void toWhereBetweenNoQualAlphaPostgres() { void toWhereBetweenNoQualAlphaPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', "data->>'city' BETWEEN :citymin AND :citymax", assertEquals("data->>'city' BETWEEN :citymin AND :citymax",
Field.between('city', 'Atlanta', 'Chicago', ':city').toWhere()) Field.between('city', 'Atlanta', 'Chicago', ':city').toWhere(),
'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for BETWEEN w/o qualifier | SQLite') @DisplayName('toWhere generates for BETWEEN w/o qualifier | SQLite')
void toWhereBetweenNoQualSQLite() { void toWhereBetweenNoQualSQLite() {
ForceDialect.sqlite() ForceDialect.sqlite()
assertEquals('Field WHERE clause not generated correctly', "data->>'age' BETWEEN @agemin AND @agemax", assertEquals("data->>'age' BETWEEN @agemin AND @agemax", Field.between('age', 13, 17, '@age').toWhere(),
Field.between('age', 13, 17, '@age').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for BETWEEN w/ qualifier, numeric range | PostgreSQL') @DisplayName('toWhere generates for BETWEEN w/ qualifier, numeric range | PostgreSQL')
void toWhereBetweenQualNumericPostgres() { void toWhereBetweenQualNumericPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', assertEquals("(test.data->>'age')::numeric BETWEEN @agemin AND @agemax",
"(test.data->>'age')::numeric BETWEEN @agemin AND @agemax", Field.between('age', 13, 17, '@age').withQualifier('test').toWhere(),
Field.between('age', 13, 17, '@age').withQualifier('test').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for BETWEEN w/ qualifier, alphanumeric range | PostgreSQL') @DisplayName('toWhere generates for BETWEEN w/ qualifier, alphanumeric range | PostgreSQL')
void toWhereBetweenQualAlphaPostgres() { void toWhereBetweenQualAlphaPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', "unit.data->>'city' BETWEEN :citymin AND :citymax", assertEquals("unit.data->>'city' BETWEEN :citymin AND :citymax",
Field.between('city', 'Atlanta', 'Chicago', ':city').withQualifier('unit').toWhere()) Field.between('city', 'Atlanta', 'Chicago', ':city').withQualifier('unit').toWhere(),
'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for BETWEEN w/ qualifier | SQLite') @DisplayName('toWhere generates for BETWEEN w/ qualifier | SQLite')
void toWhereBetweenQualSQLite() { void toWhereBetweenQualSQLite() {
ForceDialect.sqlite() ForceDialect.sqlite()
assertEquals('Field WHERE clause not generated correctly', "my.data->>'age' BETWEEN @agemin AND @agemax", assertEquals("my.data->>'age' BETWEEN @agemin AND @agemax",
Field.between('age', 13, 17, '@age').withQualifier('my').toWhere()) Field.between('age', 13, 17, '@age').withQualifier('my').toWhere(),
'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for IN/any, numeric values | PostgreSQL') @DisplayName('toWhere generates for IN/any, numeric values | PostgreSQL')
void toWhereAnyNumericPostgres() { void toWhereAnyNumericPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', assertEquals("(data->>'even')::numeric IN (:nbr_0, :nbr_1, :nbr_2)",
"(data->>'even')::numeric IN (:nbr_0, :nbr_1, :nbr_2)", Field.any('even', List.of(2, 4, 6), ':nbr').toWhere(), 'Field WHERE clause not generated correctly')
Field.any('even', List.of(2, 4, 6), ':nbr').toWhere())
} }
@Test @Test
@DisplayName('toWhere generates for IN/any, alphanumeric values | PostgreSQL') @DisplayName('toWhere generates for IN/any, alphanumeric values | PostgreSQL')
void toWhereAnyAlphaPostgres() { void toWhereAnyAlphaPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', "data->>'test' IN (:city_0, :city_1)", assertEquals("data->>'test' IN (:city_0, :city_1)",
Field.any('test', List.of('Atlanta', 'Chicago'), ':city').toWhere()) Field.any('test', List.of('Atlanta', 'Chicago'), ':city').toWhere(),
'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for IN/any | SQLite') @DisplayName('toWhere generates for IN/any | SQLite')
void toWhereAnySQLite() { void toWhereAnySQLite() {
ForceDialect.sqlite() ForceDialect.sqlite()
assertEquals('Field WHERE clause not generated correctly', "data->>'test' IN (:city_0, :city_1)", assertEquals("data->>'test' IN (:city_0, :city_1)",
Field.any('test', List.of('Atlanta', 'Chicago'), ':city').toWhere()) Field.any('test', List.of('Atlanta', 'Chicago'), ':city').toWhere(),
'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for inArray | PostgreSQL') @DisplayName('toWhere generates for inArray | PostgreSQL')
void toWhereInArrayPostgres() { void toWhereInArrayPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', "data->'even' ??| ARRAY[:it_0, :it_1, :it_2, :it_3]", assertEquals("data->'even' ??| ARRAY[:it_0, :it_1, :it_2, :it_3]",
Field.inArray('even', 'tbl', List.of(2, 4, 6, 8), ':it').toWhere()) Field.inArray('even', 'tbl', List.of(2, 4, 6, 8), ':it').toWhere(),
'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for inArray | SQLite') @DisplayName('toWhere generates for inArray | SQLite')
void toWhereInArraySQLite() { void toWhereInArraySQLite() {
ForceDialect.sqlite() ForceDialect.sqlite()
assertEquals('Field WHERE clause not generated correctly', assertEquals("EXISTS (SELECT 1 FROM json_each(tbl.data, '\$.test') WHERE value IN (:city_0, :city_1))",
"EXISTS (SELECT 1 FROM json_each(tbl.data, '\$.test') WHERE value IN (:city_0, :city_1))", Field.inArray('test', 'tbl', List.of('Atlanta', 'Chicago'), ':city').toWhere(),
Field.inArray('test', 'tbl', List.of('Atlanta', 'Chicago'), ':city').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for others w/o qualifier | PostgreSQL') @DisplayName('toWhere generates for others w/o qualifier | PostgreSQL')
void toWhereOtherNoQualPostgres() { void toWhereOtherNoQualPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', "data->>'some_field' = :value", assertEquals("data->>'some_field' = :value", Field.equal('some_field', '', ':value').toWhere(),
Field.equal('some_field', '', ':value').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates for others w/o qualifier | SQLite') @DisplayName('toWhere generates for others w/o qualifier | SQLite')
void toWhereOtherNoQualSQLite() { void toWhereOtherNoQualSQLite() {
ForceDialect.sqlite() ForceDialect.sqlite()
assertEquals('Field WHERE clause not generated correctly', "data->>'some_field' = :value", assertEquals("data->>'some_field' = :value", Field.equal('some_field', '', ':value').toWhere(),
Field.equal('some_field', '', ':value').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates no-parameter w/ qualifier | PostgreSQL') @DisplayName('toWhere generates no-parameter w/ qualifier | PostgreSQL')
void toWhereNoParamWithQualPostgres() { void toWhereNoParamWithQualPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', "test.data->>'no_field' IS NOT NULL", assertEquals("test.data->>'no_field' IS NOT NULL", Field.exists('no_field').withQualifier('test').toWhere(),
Field.exists('no_field').withQualifier('test').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates no-parameter w/ qualifier | SQLite') @DisplayName('toWhere generates no-parameter w/ qualifier | SQLite')
void toWhereNoParamWithQualSQLite() { void toWhereNoParamWithQualSQLite() {
ForceDialect.sqlite() ForceDialect.sqlite()
assertEquals('Field WHERE clause not generated correctly', "test.data->>'no_field' IS NOT NULL", assertEquals("test.data->>'no_field' IS NOT NULL", Field.exists('no_field').withQualifier('test').toWhere(),
Field.exists('no_field').withQualifier('test').toWhere()) 'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates parameter w/ qualifier | PostgreSQL') @DisplayName('toWhere generates parameter w/ qualifier | PostgreSQL')
void toWhereParamWithQualPostgres() { void toWhereParamWithQualPostgres() {
ForceDialect.postgres() ForceDialect.postgres()
assertEquals('Field WHERE clause not generated correctly', "(q.data->>'le_field')::numeric <= :it", assertEquals("(q.data->>'le_field')::numeric <= :it",
Field.lessOrEqual('le_field', 18, ':it').withQualifier('q').toWhere()) Field.lessOrEqual('le_field', 18, ':it').withQualifier('q').toWhere(),
'Field WHERE clause not generated correctly')
} }
@Test @Test
@DisplayName('toWhere generates parameter w/ qualifier | SQLite') @DisplayName('toWhere generates parameter w/ qualifier | SQLite')
void toWhereParamWithQualSQLite() { void toWhereParamWithQualSQLite() {
ForceDialect.sqlite() ForceDialect.sqlite()
assertEquals('Field WHERE clause not generated correctly', "q.data->>'le_field' <= :it", assertEquals("q.data->>'le_field' <= :it",
Field.lessOrEqual('le_field', 18, ':it').withQualifier('q').toWhere()) Field.lessOrEqual('le_field', 18, ':it').withQualifier('q').toWhere(),
'Field WHERE clause not generated correctly')
} }
// ~~~ STATIC CONSTRUCTOR TESTS ~~~ // ~~~ STATIC CONSTRUCTOR TESTS ~~~
@ -303,236 +314,236 @@ class FieldTest {
@Test @Test
@DisplayName('equal constructs a field w/o parameter name') @DisplayName('equal constructs a field w/o parameter name')
void equalCtor() { void equalCtor() {
def field = Field.equal('Test', 14) def field = Field.equal 'Test', 14
assertEquals('Field name not filled correctly', 'Test', field.name) assertEquals 'Test', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.EQUAL, field.comparison.op) assertEquals Op.EQUAL, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 14, field.comparison.value) assertEquals 14, field.comparison.value, 'Field comparison value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('equal constructs a field w/ parameter name') @DisplayName('equal constructs a field w/ parameter name')
void equalParameterCtor() { void equalParameterCtor() {
def field = Field.equal('Test', 14, ':w') def field = Field.equal 'Test', 14, ':w'
assertEquals('Field name not filled correctly', 'Test', field.name) assertEquals 'Test', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.EQUAL, field.comparison.op) assertEquals Op.EQUAL, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 14, field.comparison.value) assertEquals 14, field.comparison.value, 'Field comparison value not filled correctly'
assertEquals('Field parameter name not filled correctly', ':w', field.parameterName) assertEquals ':w', field.parameterName, 'Field parameter name not filled correctly'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('greater constructs a field w/o parameter name') @DisplayName('greater constructs a field w/o parameter name')
void greaterCtor() { void greaterCtor() {
def field = Field.greater('Great', 'night') def field = Field.greater 'Great', 'night'
assertEquals('Field name not filled correctly', 'Great', field.name) assertEquals 'Great', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.GREATER, field.comparison.op) assertEquals Op.GREATER, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 'night', field.comparison.value) assertEquals 'night', field.comparison.value, 'Field comparison value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('greater constructs a field w/ parameter name') @DisplayName('greater constructs a field w/ parameter name')
void greaterParameterCtor() { void greaterParameterCtor() {
def field = Field.greater('Great', 'night', ':yeah') def field = Field.greater 'Great', 'night', ':yeah'
assertEquals('Field name not filled correctly', 'Great', field.name) assertEquals 'Great', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.GREATER, field.comparison.op) assertEquals Op.GREATER, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 'night', field.comparison.value) assertEquals 'night', field.comparison.value, 'Field comparison value not filled correctly'
assertEquals('Field parameter name not filled correctly', ':yeah', field.parameterName) assertEquals('Field parameter name not filled correctly', ':yeah', field.parameterName)
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('greaterOrEqual constructs a field w/o parameter name') @DisplayName('greaterOrEqual constructs a field w/o parameter name')
void greaterOrEqualCtor() { void greaterOrEqualCtor() {
def field = Field.greaterOrEqual('Nice', 88L) def field = Field.greaterOrEqual 'Nice', 88L
assertEquals('Field name not filled correctly', 'Nice', field.name) assertEquals 'Nice', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.GREATER_OR_EQUAL, field.comparison.op) assertEquals Op.GREATER_OR_EQUAL, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 88L, field.comparison.value) assertEquals 88L, field.comparison.value, 'Field comparison value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('greaterOrEqual constructs a field w/ parameter name') @DisplayName('greaterOrEqual constructs a field w/ parameter name')
void greaterOrEqualParameterCtor() { void greaterOrEqualParameterCtor() {
def field = Field.greaterOrEqual('Nice', 88L, ':nice') def field = Field.greaterOrEqual 'Nice', 88L, ':nice'
assertEquals('Field name not filled correctly', 'Nice', field.name) assertEquals 'Nice', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.GREATER_OR_EQUAL, field.comparison.op) assertEquals Op.GREATER_OR_EQUAL, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 88L, field.comparison.value) assertEquals 88L, field.comparison.value, 'Field comparison value not filled correctly'
assertEquals('Field parameter name not filled correctly', ':nice', field.parameterName) assertEquals ':nice', field.parameterName, 'Field parameter name not filled correctly'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('less constructs a field w/o parameter name') @DisplayName('less constructs a field w/o parameter name')
void lessCtor() { void lessCtor() {
def field = Field.less('Lesser', 'seven') def field = Field.less 'Lesser', 'seven'
assertEquals('Field name not filled correctly', 'Lesser', field.name) assertEquals 'Lesser', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.LESS, field.comparison.op) assertEquals Op.LESS, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 'seven', field.comparison.value) assertEquals 'seven', field.comparison.value, 'Field comparison value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('less constructs a field w/ parameter name') @DisplayName('less constructs a field w/ parameter name')
void lessParameterCtor() { void lessParameterCtor() {
def field = Field.less('Lesser', 'seven', ':max') def field = Field.less 'Lesser', 'seven', ':max'
assertEquals('Field name not filled correctly', 'Lesser', field.name) assertEquals 'Lesser', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.LESS, field.comparison.op) assertEquals Op.LESS, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 'seven', field.comparison.value) assertEquals 'seven', field.comparison.value, 'Field comparison value not filled correctly'
assertEquals('Field parameter name not filled correctly', ':max', field.parameterName) assertEquals ':max', field.parameterName, 'Field parameter name not filled correctly'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('lessOrEqual constructs a field w/o parameter name') @DisplayName('lessOrEqual constructs a field w/o parameter name')
void lessOrEqualCtor() { void lessOrEqualCtor() {
def field = Field.lessOrEqual('Nobody', 'KNOWS') def field = Field.lessOrEqual 'Nobody', 'KNOWS'
assertEquals('Field name not filled correctly', 'Nobody', field.name) assertEquals 'Nobody', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.LESS_OR_EQUAL, field.comparison.op) assertEquals Op.LESS_OR_EQUAL, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 'KNOWS', field.comparison.value) assertEquals 'KNOWS', field.comparison.value, 'Field comparison value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('lessOrEqual constructs a field w/ parameter name') @DisplayName('lessOrEqual constructs a field w/ parameter name')
void lessOrEqualParameterCtor() { void lessOrEqualParameterCtor() {
def field = Field.lessOrEqual('Nobody', 'KNOWS', ':nope') def field = Field.lessOrEqual 'Nobody', 'KNOWS', ':nope'
assertEquals('Field name not filled correctly', 'Nobody', field.name) assertEquals 'Nobody', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.LESS_OR_EQUAL, field.comparison.op) assertEquals Op.LESS_OR_EQUAL, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 'KNOWS', field.comparison.value) assertEquals 'KNOWS', field.comparison.value, 'Field comparison value not filled correctly'
assertEquals('Field parameter name not filled correctly', ':nope', field.parameterName) assertEquals ':nope', field.parameterName, 'Field parameter name not filled correctly'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('notEqual constructs a field w/o parameter name') @DisplayName('notEqual constructs a field w/o parameter name')
void notEqualCtor() { void notEqualCtor() {
def field = Field.notEqual('Park', 'here') def field = Field.notEqual 'Park', 'here'
assertEquals('Field name not filled correctly', 'Park', field.name) assertEquals 'Park', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.NOT_EQUAL, field.comparison.op) assertEquals Op.NOT_EQUAL, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 'here', field.comparison.value) assertEquals 'here', field.comparison.value, 'Field comparison value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('notEqual constructs a field w/ parameter name') @DisplayName('notEqual constructs a field w/ parameter name')
void notEqualParameterCtor() { void notEqualParameterCtor() {
def field = Field.notEqual('Park', 'here', ':now') def field = Field.notEqual 'Park', 'here', ':now'
assertEquals('Field name not filled correctly', 'Park', field.name) assertEquals 'Park', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.NOT_EQUAL, field.comparison.op) assertEquals Op.NOT_EQUAL, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', 'here', field.comparison.value) assertEquals 'here', field.comparison.value, 'Field comparison value not filled correctly'
assertEquals('Field parameter name not filled correctly', ':now', field.parameterName) assertEquals ':now', field.parameterName, 'Field parameter name not filled correctly'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('between constructs a field w/o parameter name') @DisplayName('between constructs a field w/o parameter name')
void betweenCtor() { void betweenCtor() {
def field = Field.between('Age', 18, 49) def field = Field.between 'Age', 18, 49
assertEquals('Field name not filled correctly', 'Age', field.name) assertEquals 'Age', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.BETWEEN, field.comparison.op) assertEquals Op.BETWEEN, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison min value not filled correctly', 18, field.comparison.value.first) assertEquals 18, field.comparison.value.first, 'Field comparison min value not filled correctly'
assertEquals('Field comparison max value not filled correctly', 49, field.comparison.value.second, ) assertEquals 49, field.comparison.value.second, 'Field comparison max value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('between constructs a field w/ parameter name') @DisplayName('between constructs a field w/ parameter name')
void betweenParameterCtor() { void betweenParameterCtor() {
def field = Field.between('Age', 18, 49, ':limit') def field = Field.between 'Age', 18, 49, ':limit'
assertEquals('Field name not filled correctly', 'Age', field.name) assertEquals 'Age', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.BETWEEN, field.comparison.op) assertEquals Op.BETWEEN, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison min value not filled correctly', 18, field.comparison.value.first) assertEquals 18, field.comparison.value.first, 'Field comparison min value not filled correctly'
assertEquals('Field comparison max value not filled correctly', 49, field.comparison.value.second) assertEquals 49, field.comparison.value.second, 'Field comparison max value not filled correctly'
assertEquals('Field parameter name not filled correctly', ':limit', field.parameterName) assertEquals ':limit', field.parameterName, 'Field parameter name not filled correctly'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('any constructs a field w/o parameter name') @DisplayName('any constructs a field w/o parameter name')
void anyCtor() { void anyCtor() {
def field = Field.any('Here', List.of(8, 16, 32)) def field = Field.any 'Here', List.of(8, 16, 32)
assertEquals('Field name not filled correctly', 'Here', field.name) assertEquals 'Here', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.IN, field.comparison.op) assertEquals Op.IN, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', List.of(8, 16, 32), field.comparison.value) assertEquals List.of(8, 16, 32), field.comparison.value, 'Field comparison value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('any constructs a field w/ parameter name') @DisplayName('any constructs a field w/ parameter name')
void anyParameterCtor() { void anyParameterCtor() {
def field = Field.any('Here', List.of(8, 16, 32), ':list') def field = Field.any 'Here', List.of(8, 16, 32), ':list'
assertEquals('Field name not filled correctly', 'Here', field.name) assertEquals 'Here', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.IN, field.comparison.op) assertEquals Op.IN, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', List.of(8, 16, 32), field.comparison.value) assertEquals List.of(8, 16, 32), field.comparison.value, 'Field comparison value not filled correctly'
assertEquals('Field parameter name not filled correctly', ':list', field.parameterName) assertEquals ':list', field.parameterName, 'Field parameter name not filled correctly'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('inArray constructs a field w/o parameter name') @DisplayName('inArray constructs a field w/o parameter name')
void inArrayCtor() { void inArrayCtor() {
def field = Field.inArray('ArrayField', 'table', List.of('z')) def field = Field.inArray 'ArrayField', 'table', List.of('z')
assertEquals('Field name not filled correctly', 'ArrayField', field.name) assertEquals 'ArrayField', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.IN_ARRAY, field.comparison.op) assertEquals Op.IN_ARRAY, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison table not filled correctly', 'table', field.comparison.value.first) assertEquals 'table', field.comparison.value.first, 'Field comparison table not filled correctly'
assertEquals('Field comparison values not filled correctly', List.of('z'), field.comparison.value.second) assertEquals List.of('z'), field.comparison.value.second, 'Field comparison values not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('inArray constructs a field w/ parameter name') @DisplayName('inArray constructs a field w/ parameter name')
void inArrayParameterCtor() { void inArrayParameterCtor() {
def field = Field.inArray('ArrayField', 'table', List.of('z'), ':a') def field = Field.inArray 'ArrayField', 'table', List.of('z'), ':a'
assertEquals('Field name not filled correctly', 'ArrayField', field.name) assertEquals 'ArrayField', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.IN_ARRAY, field.comparison.op) assertEquals Op.IN_ARRAY, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison table not filled correctly', 'table', field.comparison.value.first) assertEquals 'table', field.comparison.value.first, 'Field comparison table not filled correctly'
assertEquals('Field comparison values not filled correctly', List.of('z'), field.comparison.value.second) assertEquals List.of('z'), field.comparison.value.second, 'Field comparison values not filled correctly'
assertEquals('Field parameter name not filled correctly', ':a', field.parameterName) assertEquals ':a', field.parameterName, 'Field parameter name not filled correctly'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('exists constructs a field') @DisplayName('exists constructs a field')
void existsCtor() { void existsCtor() {
def field = Field.exists 'Groovy' def field = Field.exists 'Groovy'
assertEquals('Field name not filled correctly', 'Groovy', field.name) assertEquals 'Groovy', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.EXISTS, field.comparison.op) assertEquals Op.EXISTS, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', '', field.comparison.value) assertEquals '', field.comparison.value, 'Field comparison value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('notExists constructs a field') @DisplayName('notExists constructs a field')
void notExistsCtor() { void notExistsCtor() {
def field = Field.notExists 'Groovy' def field = Field.notExists 'Groovy'
assertEquals('Field name not filled correctly', 'Groovy', field.name) assertEquals 'Groovy', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.NOT_EXISTS, field.comparison.op) assertEquals Op.NOT_EXISTS, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', '', field.comparison.value) assertEquals '', field.comparison.value, 'Field comparison value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
@Test @Test
@DisplayName('named constructs a field') @DisplayName('named constructs a field')
void namedCtor() { void namedCtor() {
def field = Field.named('Tacos') def field = Field.named 'Tacos'
assertEquals('Field name not filled correctly', 'Tacos', field.name) assertEquals 'Tacos', field.name, 'Field name not filled correctly'
assertEquals('Field comparison operation not filled correctly', Op.EQUAL, field.comparison.op) assertEquals Op.EQUAL, field.comparison.op, 'Field comparison operation not filled correctly'
assertEquals('Field comparison value not filled correctly', '', field.comparison.value) assertEquals '', field.comparison.value, 'Field comparison value not filled correctly'
assertNull('The parameter name should have been null', field.parameterName) assertNull field.parameterName, 'The parameter name should have been null'
assertNull('The qualifier should have been null', field.qualifier) assertNull field.qualifier, 'The qualifier should have been null'
} }
// TODO: fix java.base open issue // TODO: fix java.base open issue
@ -545,56 +556,60 @@ class FieldTest {
@Test @Test
@DisplayName('nameToPath creates a simple PostgreSQL SQL name') @DisplayName('nameToPath creates a simple PostgreSQL SQL name')
void nameToPathPostgresSimpleSQL() { void nameToPathPostgresSimpleSQL() {
assertEquals('Path not constructed correctly', "data->>'Simple'", assertEquals("data->>'Simple'", Field.nameToPath('Simple', Dialect.POSTGRESQL, FieldFormat.SQL),
Field.nameToPath('Simple', Dialect.POSTGRESQL, FieldFormat.SQL)) 'Path not constructed correctly')
} }
@Test @Test
@DisplayName('nameToPath creates a simple SQLite SQL name') @DisplayName('nameToPath creates a simple SQLite SQL name')
void nameToPathSQLiteSimpleSQL() { void nameToPathSQLiteSimpleSQL() {
assertEquals('Path not constructed correctly', "data->>'Simple'", assertEquals("data->>'Simple'", Field.nameToPath('Simple', Dialect.SQLITE, FieldFormat.SQL),
Field.nameToPath('Simple', Dialect.SQLITE, FieldFormat.SQL)) 'Path not constructed correctly')
} }
@Test @Test
@DisplayName('nameToPath creates a nested PostgreSQL SQL name') @DisplayName('nameToPath creates a nested PostgreSQL SQL name')
void nameToPathPostgresNestedSQL() { void nameToPathPostgresNestedSQL() {
assertEquals('Path not constructed correctly', "data#>>'{A,Long,Path,to,the,Property}'", assertEquals("data#>>'{A,Long,Path,to,the,Property}'",
Field.nameToPath('A.Long.Path.to.the.Property', Dialect.POSTGRESQL, FieldFormat.SQL)) Field.nameToPath('A.Long.Path.to.the.Property', Dialect.POSTGRESQL, FieldFormat.SQL),
'Path not constructed correctly')
} }
@Test @Test
@DisplayName('nameToPath creates a nested SQLite SQL name') @DisplayName('nameToPath creates a nested SQLite SQL name')
void nameToPathSQLiteNestedSQL() { void nameToPathSQLiteNestedSQL() {
assertEquals('Path not constructed correctly', "data->'A'->'Long'->'Path'->'to'->'the'->>'Property'", assertEquals("data->'A'->'Long'->'Path'->'to'->'the'->>'Property'",
Field.nameToPath('A.Long.Path.to.the.Property', Dialect.SQLITE, FieldFormat.SQL)) Field.nameToPath('A.Long.Path.to.the.Property', Dialect.SQLITE, FieldFormat.SQL),
'Path not constructed correctly')
} }
@Test @Test
@DisplayName('nameToPath creates a simple PostgreSQL JSON name') @DisplayName('nameToPath creates a simple PostgreSQL JSON name')
void nameToPathPostgresSimpleJSON() { void nameToPathPostgresSimpleJSON() {
assertEquals('Path not constructed correctly', "data->'Simple'", assertEquals("data->'Simple'", Field.nameToPath('Simple', Dialect.POSTGRESQL, FieldFormat.JSON),
Field.nameToPath('Simple', Dialect.POSTGRESQL, FieldFormat.JSON)) 'Path not constructed correctly')
} }
@Test @Test
@DisplayName('nameToPath creates a simple SQLite JSON name') @DisplayName('nameToPath creates a simple SQLite JSON name')
void nameToPathSQLiteSimpleJSON() { void nameToPathSQLiteSimpleJSON() {
assertEquals('Path not constructed correctly', "data->'Simple'", assertEquals("data->'Simple'", Field.nameToPath('Simple', Dialect.SQLITE, FieldFormat.JSON),
Field.nameToPath('Simple', Dialect.SQLITE, FieldFormat.JSON)) 'Path not constructed correctly')
} }
@Test @Test
@DisplayName('nameToPath creates a nested PostgreSQL JSON name') @DisplayName('nameToPath creates a nested PostgreSQL JSON name')
void nameToPathPostgresNestedJSON() { void nameToPathPostgresNestedJSON() {
assertEquals('Path not constructed correctly', "data#>'{A,Long,Path,to,the,Property}'", assertEquals("data#>'{A,Long,Path,to,the,Property}'",
Field.nameToPath('A.Long.Path.to.the.Property', Dialect.POSTGRESQL, FieldFormat.JSON)) Field.nameToPath('A.Long.Path.to.the.Property', Dialect.POSTGRESQL, FieldFormat.JSON),
'Path not constructed correctly')
} }
@Test @Test
@DisplayName('nameToPath creates a nested SQLite JSON name') @DisplayName('nameToPath creates a nested SQLite JSON name')
void nameToPathSQLiteNestedJSON() { void nameToPathSQLiteNestedJSON() {
assertEquals('Path not constructed correctly', "data->'A'->'Long'->'Path'->'to'->'the'->'Property'", assertEquals("data->'A'->'Long'->'Path'->'to'->'the'->'Property'",
Field.nameToPath('A.Long.Path.to.the.Property', Dialect.SQLITE, FieldFormat.JSON)) Field.nameToPath('A.Long.Path.to.the.Property', Dialect.SQLITE, FieldFormat.JSON),
'Path not constructed correctly')
} }
} }

View File

@ -4,7 +4,7 @@ import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import solutions.bitbadger.documents.Op import solutions.bitbadger.documents.Op
import static groovy.test.GroovyAssert.* import static org.junit.jupiter.api.Assertions.assertEquals
/** /**
* Unit tests for the `Op` enum * Unit tests for the `Op` enum
@ -15,66 +15,66 @@ class OpTest {
@Test @Test
@DisplayName('EQUAL uses proper SQL') @DisplayName('EQUAL uses proper SQL')
void equalSQL() { void equalSQL() {
assertEquals('The SQL for equal is incorrect', '=', Op.EQUAL.sql) assertEquals '=', Op.EQUAL.sql, 'The SQL for equal is incorrect'
} }
@Test @Test
@DisplayName('GREATER uses proper SQL') @DisplayName('GREATER uses proper SQL')
void greaterSQL() { void greaterSQL() {
assertEquals('The SQL for greater is incorrect', '>', Op.GREATER.sql) assertEquals '>', Op.GREATER.sql, 'The SQL for greater is incorrect'
} }
@Test @Test
@DisplayName('GREATER_OR_EQUAL uses proper SQL') @DisplayName('GREATER_OR_EQUAL uses proper SQL')
void greaterOrEqualSQL() { void greaterOrEqualSQL() {
assertEquals('The SQL for greater-or-equal is incorrect', '>=', Op.GREATER_OR_EQUAL.sql) assertEquals '>=', Op.GREATER_OR_EQUAL.sql, 'The SQL for greater-or-equal is incorrect'
} }
@Test @Test
@DisplayName('LESS uses proper SQL') @DisplayName('LESS uses proper SQL')
void lessSQL() { void lessSQL() {
assertEquals('The SQL for less is incorrect', '<', Op.LESS.sql) assertEquals '<', Op.LESS.sql, 'The SQL for less is incorrect'
} }
@Test @Test
@DisplayName('LESS_OR_EQUAL uses proper SQL') @DisplayName('LESS_OR_EQUAL uses proper SQL')
void lessOrEqualSQL() { void lessOrEqualSQL() {
assertEquals('The SQL for less-or-equal is incorrect', '<=', Op.LESS_OR_EQUAL.sql) assertEquals '<=', Op.LESS_OR_EQUAL.sql, 'The SQL for less-or-equal is incorrect'
} }
@Test @Test
@DisplayName('NOT_EQUAL uses proper SQL') @DisplayName('NOT_EQUAL uses proper SQL')
void notEqualSQL() { void notEqualSQL() {
assertEquals('The SQL for not-equal is incorrect', '<>', Op.NOT_EQUAL.sql) assertEquals '<>', Op.NOT_EQUAL.sql, 'The SQL for not-equal is incorrect'
} }
@Test @Test
@DisplayName('BETWEEN uses proper SQL') @DisplayName('BETWEEN uses proper SQL')
void betweenSQL() { void betweenSQL() {
assertEquals('The SQL for between is incorrect', 'BETWEEN', Op.BETWEEN.sql) assertEquals 'BETWEEN', Op.BETWEEN.sql, 'The SQL for between is incorrect'
} }
@Test @Test
@DisplayName('IN uses proper SQL') @DisplayName('IN uses proper SQL')
void inSQL() { void inSQL() {
assertEquals('The SQL for in is incorrect', 'IN', Op.IN.sql) assertEquals 'IN', Op.IN.sql, 'The SQL for in is incorrect'
} }
@Test @Test
@DisplayName('IN_ARRAY uses proper SQL') @DisplayName('IN_ARRAY uses proper SQL')
void inArraySQL() { void inArraySQL() {
assertEquals('The SQL for in-array is incorrect', '??|', Op.IN_ARRAY.sql) assertEquals '??|', Op.IN_ARRAY.sql, 'The SQL for in-array is incorrect'
} }
@Test @Test
@DisplayName('EXISTS uses proper SQL') @DisplayName('EXISTS uses proper SQL')
void existsSQL() { void existsSQL() {
assertEquals('The SQL for exists is incorrect', 'IS NOT NULL', Op.EXISTS.sql) assertEquals 'IS NOT NULL', Op.EXISTS.sql, 'The SQL for exists is incorrect'
} }
@Test @Test
@DisplayName('NOT_EXISTS uses proper SQL') @DisplayName('NOT_EXISTS uses proper SQL')
void notExistsSQL() { void notExistsSQL() {
assertEquals('The SQL for not-exists is incorrect', 'IS NULL', Op.NOT_EXISTS.sql) assertEquals 'IS NULL', Op.NOT_EXISTS.sql, 'The SQL for not-exists is incorrect'
} }
} }

View File

@ -3,7 +3,9 @@ package solutions.bitbadger.documents.groovy
import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import solutions.bitbadger.documents.ParameterName import solutions.bitbadger.documents.ParameterName
import static groovy.test.GroovyAssert.assertEquals
import static org.junit.jupiter.api.Assertions.assertEquals
/** /**
* Unit tests for the `ParameterName` class * Unit tests for the `ParameterName` class
*/ */
@ -14,17 +16,17 @@ class ParameterNameTest {
@DisplayName('derive works when given existing names') @DisplayName('derive works when given existing names')
void withExisting() { void withExisting() {
def names = new ParameterName() def names = new ParameterName()
assertEquals('Name should have been :taco', ':taco', names.derive(':taco')) assertEquals ':taco', names.derive(':taco'), 'Name should have been :taco'
assertEquals('Counter should not have advanced for named field', ':field0', names.derive(null)) assertEquals ':field0', names.derive(null), 'Counter should not have advanced for named field'
} }
@Test @Test
@DisplayName('derive works when given all anonymous fields') @DisplayName('derive works when given all anonymous fields')
void allAnonymous() { void allAnonymous() {
def names = new ParameterName() def names = new ParameterName()
assertEquals('Anonymous field name should have been returned', ':field0', names.derive(null)) assertEquals ':field0', names.derive(null), 'Anonymous field name should have been returned'
assertEquals('Counter should have advanced from previous call', ':field1', names.derive(null)) assertEquals ':field1', names.derive(null), 'Counter should have advanced from previous call'
assertEquals('Counter should have advanced from previous call', ':field2', names.derive(null)) assertEquals ':field2', names.derive(null), 'Counter should have advanced from previous call'
assertEquals('Counter should have advanced from previous call', ':field3', names.derive(null)) assertEquals ':field3', names.derive(null), 'Counter should have advanced from previous call'
} }
} }

View File

@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test
import solutions.bitbadger.documents.Parameter import solutions.bitbadger.documents.Parameter
import solutions.bitbadger.documents.ParameterType import solutions.bitbadger.documents.ParameterType
import static groovy.test.GroovyAssert.* import static org.junit.jupiter.api.Assertions.*
/** /**
* Unit tests for the `Parameter` class * Unit tests for the `Parameter` class
@ -15,27 +15,27 @@ import static groovy.test.GroovyAssert.*
class ParameterTest { class ParameterTest {
@Test @Test
@DisplayName("Construction with colon-prefixed name") @DisplayName('Construction with colon-prefixed name')
void ctorWithColon() { void ctorWithColon() {
def p = new Parameter(":test", ParameterType.STRING, "ABC") def p = new Parameter(':test', ParameterType.STRING, 'ABC')
assertEquals("Parameter name was incorrect", ":test", p.name) assertEquals ':test', p.name, 'Parameter name was incorrect'
assertEquals("Parameter type was incorrect", ParameterType.STRING, p.type) assertEquals ParameterType.STRING, p.type, 'Parameter type was incorrect'
assertEquals("Parameter value was incorrect", "ABC", p.value) assertEquals 'ABC', p.value, 'Parameter value was incorrect'
} }
@Test @Test
@DisplayName("Construction with at-sign-prefixed name") @DisplayName('Construction with at-sign-prefixed name')
void ctorWithAtSign() { void ctorWithAtSign() {
def p = new Parameter("@yo", ParameterType.NUMBER, null) def p = new Parameter('@yo', ParameterType.NUMBER, null)
assertEquals("Parameter name was incorrect", "@yo", p.name) assertEquals '@yo', p.name, 'Parameter name was incorrect'
assertEquals("Parameter type was incorrect", ParameterType.NUMBER, p.type) assertEquals ParameterType.NUMBER, p.type, 'Parameter type was incorrect'
assertNull("Parameter value was incorrect", p.value) assertNull p.value, 'Parameter value was incorrect'
} }
// TODO: resolve java.base open issue // TODO: resolve java.base open issue
// @Test // @Test
// @DisplayName("Construction fails with incorrect prefix") // @DisplayName('Construction fails with incorrect prefix')
// void ctorFailsForPrefix() { // void ctorFailsForPrefix() {
// assertThrows(DocumentException) { new Parameter("it", ParameterType.JSON, "") } // assertThrows(DocumentException) { new Parameter('it', ParameterType.JSON, '') }
// } // }
} }

View File

@ -0,0 +1,122 @@
package solutions.bitbadger.documents.groovy.jvm
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
//import solutions.bitbadger.documents.DocumentException
import solutions.bitbadger.documents.Field
import solutions.bitbadger.documents.Parameter
import solutions.bitbadger.documents.ParameterType
import solutions.bitbadger.documents.jvm.Parameters
import solutions.bitbadger.documents.support.ForceDialect
import static groovy.test.GroovyAssert.*
/**
* Unit tests for the `Parameters` object
*/
@DisplayName('JVM | Groovy | Parameters')
class ParametersTest {
/**
* Reset the dialect
*/
@AfterEach
void cleanUp() {
ForceDialect.none()
}
@Test
@DisplayName('nameFields works with no changes')
void nameFieldsNoChange() {
def fields = List.of(Field.equal('a', '', ':test'), Field.exists('q'), Field.equal('b', '', ':me'))
def named = Parameters.nameFields(fields).toList()
assertEquals('There should have been 3 fields in the list', fields.size(), named.size())
assertSame('The first field should be the same', fields[0], named[0])
assertSame('The second field should be the same', fields[1], named[1])
assertSame('The third field should be the same', fields[2], named[2])
}
@Test
@DisplayName('nameFields works when changing fields')
void nameFieldsChange() {
def fields = List.of(Field.equal('a', ''), Field.equal('e', '', ':hi'), Field.equal('b', ''),
Field.notExists('z'))
def named = Parameters.nameFields(fields).toList()
assertEquals('There should have been 4 fields in the list', fields.size(), named.size())
assertNotSame('The first field should not be the same', fields[0], named[0])
assertEquals('First parameter name incorrect', ':field0', named[0].parameterName)
assertSame('The second field should be the same', fields[1], named[1])
assertNotSame('The third field should not be the same', fields[2], named[2])
assertEquals('Third parameter name incorrect', ':field1', named[2].parameterName)
assertSame('The fourth field should be the same', fields[3], named[3])
}
@Test
@DisplayName('replaceNamesInQuery replaces successfully')
void replaceNamesInQuery() {
def parameters = List.of(new Parameter(':data', ParameterType.JSON, '{}'),
new Parameter(':data_ext', ParameterType.STRING, ''))
def query = 'SELECT data, data_ext FROM tbl WHERE data = :data AND data_ext = :data_ext AND more_data = :data'
assertEquals('Parameters not replaced correctly',
'SELECT data, data_ext FROM tbl WHERE data = ? AND data_ext = ? AND more_data = ?',
Parameters.replaceNamesInQuery(query, parameters))
}
@Test
@DisplayName('fieldNames generates a single parameter (PostgreSQL)')
void fieldNamesSinglePostgres() {
ForceDialect.postgres()
def nameParams = Parameters.fieldNames(List.of('test')).toList()
assertEquals('There should be one name parameter', 1, nameParams.size())
assertEquals('The parameter name is incorrect', ':name', nameParams[0].name)
assertEquals('The parameter type is incorrect', ParameterType.STRING, nameParams[0].type)
assertEquals('The parameter value is incorrect', '{test}', nameParams[0].value)
}
@Test
@DisplayName('fieldNames generates multiple parameters (PostgreSQL)')
void fieldNamesMultiplePostgres() {
ForceDialect.postgres()
def nameParams = Parameters.fieldNames(List.of('test', 'this', 'today')).toList()
assertEquals('There should be one name parameter', 1, nameParams.size())
assertEquals('The parameter name is incorrect', ':name', nameParams[0].name)
assertEquals('The parameter type is incorrect', ParameterType.STRING, nameParams[0].type)
assertEquals('The parameter value is incorrect', '{test,this,today}', nameParams[0].value)
}
@Test
@DisplayName('fieldNames generates a single parameter (SQLite)')
void fieldNamesSingleSQLite() {
ForceDialect.sqlite()
def nameParams = Parameters.fieldNames(List.of('test')).toList()
assertEquals('There should be one name parameter', 1, nameParams.size())
assertEquals('The parameter name is incorrect', ':name0', nameParams[0].name)
assertEquals('The parameter type is incorrect', ParameterType.STRING, nameParams[0].type)
assertEquals('The parameter value is incorrect', 'test', nameParams[0].value)
}
@Test
@DisplayName('fieldNames generates multiple parameters (SQLite)')
void fieldNamesMultipleSQLite() {
ForceDialect.sqlite()
def nameParams = Parameters.fieldNames(List.of('test', 'this', 'today')).toList()
assertEquals('There should be one name parameter', 3, nameParams.size())
assertEquals('The first parameter name is incorrect', ':name0', nameParams[0].name)
assertEquals('The first parameter type is incorrect', ParameterType.STRING, nameParams[0].type)
assertEquals('The first parameter value is incorrect', 'test', nameParams[0].value)
assertEquals('The second parameter name is incorrect', ':name1', nameParams[1].name)
assertEquals('The second parameter type is incorrect', ParameterType.STRING, nameParams[1].type)
assertEquals('The second parameter value is incorrect', 'this', nameParams[1].value)
assertEquals('The third parameter name is incorrect', ':name2', nameParams[2].name)
assertEquals('The third parameter type is incorrect', ParameterType.STRING, nameParams[2].type)
assertEquals('The third parameter value is incorrect', 'today', nameParams[2].value)
}
// TODO: resolve java.base open issue
// @Test
// @DisplayName('fieldNames fails if dialect not set')
// void fieldNamesFails() {
// assertThrows(DocumentException) { Parameters.fieldNames(List.of()) }
// }
}

View File

@ -0,0 +1,53 @@
package solutions.bitbadger.documents.groovy.jvm.integration.common
import solutions.bitbadger.documents.Field
import solutions.bitbadger.documents.groovy.support.JsonDocument
import solutions.bitbadger.documents.support.ThrowawayDatabase
import static solutions.bitbadger.documents.extensions.ConnExt.*
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE
import static groovy.test.GroovyAssert.*
class CountFunctions {
static void all(ThrowawayDatabase db) {
JsonDocument.load(db)
assertEquals('There should have been 5 documents in the table', 5L, countAll(db.conn, TEST_TABLE))
}
static void byFieldsNumeric(ThrowawayDatabase db) {
JsonDocument.load(db)
assertEquals('There should have been 3 matching documents', 3L,
countByFields(db.conn, TEST_TABLE, List.of(Field.between('numValue', 10, 20))))
}
static void byFieldsAlpha(ThrowawayDatabase db) {
JsonDocument.load(db)
assertEquals('There should have been 1 matching document', 1L,
countByFields(db.conn, TEST_TABLE, List.of(Field.between('value', 'aardvark', 'apple'))))
}
static void byContainsMatch(ThrowawayDatabase db) {
JsonDocument.load(db)
assertEquals('There should have been 2 matching documents', 2L,
countByContains(db.conn, TEST_TABLE, Map.of('value', 'purple')))
}
static void byContainsNoMatch(ThrowawayDatabase db) {
JsonDocument.load(db)
assertEquals('There should have been no matching documents', 0L,
countByContains(db.conn, TEST_TABLE, Map.of('value', 'magenta')))
}
static void byJsonPathMatch(ThrowawayDatabase db) {
JsonDocument.load(db)
assertEquals('There should have been 2 matching documents', 2L,
countByJsonPath(db.conn, TEST_TABLE, '$.numValue ? (@ < 5)'))
}
static void byJsonPathNoMatch(ThrowawayDatabase db) {
JsonDocument.load(db)
assertEquals('There should have been no matching documents', 0L,
countByJsonPath(db.conn, TEST_TABLE, '$.numValue ? (@ > 100)'))
}
}

View File

@ -0,0 +1,25 @@
package solutions.bitbadger.documents.groovy.jvm.integration.postgresql
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import solutions.bitbadger.documents.groovy.jvm.integration.common.CountFunctions
import solutions.bitbadger.documents.jvm.integration.postgresql.PgDB
/**
* PostgreSQL integration tests for the `Count` object / `count*` connection extension functions
*/
@DisplayName("JVM | Groovy | PostgreSQL: Count")
class CountIT {
@Test
@DisplayName("all counts all documents")
void all() {
PgDB db = new PgDB()
try {
CountFunctions.all(db)
} finally {
db.close()
}
}
}

View File

@ -0,0 +1,33 @@
package solutions.bitbadger.documents.groovy.support
import solutions.bitbadger.documents.jvm.Document
import solutions.bitbadger.documents.support.ThrowawayDatabase
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE
class JsonDocument {
String id
String value
int numValue
SubDocument sub
JsonDocument(String id, String value = "", int numValue = 0, SubDocument sub = null) {
this.id = id
this.value = value
this.numValue = numValue
this.sub = sub
}
private static final List<JsonDocument> testDocuments = List.of(
new JsonDocument("one", "FIRST!", 0),
new JsonDocument("two", "another", 10, new SubDocument("green", "blue")),
new JsonDocument("three", "", 4),
new JsonDocument("four", "purple", 17, new SubDocument("green", "red")),
new JsonDocument("five", "purple", 18))
static void load(ThrowawayDatabase db, String tableName = TEST_TABLE) {
for (doc in testDocuments) {
Document.insert(tableName, doc, db.conn)
}
}
}

View File

@ -0,0 +1,11 @@
package solutions.bitbadger.documents.groovy.support
class SubDocument {
String foo
String bar
SubDocument(String foo, String bar) {
this.foo = foo
this.bar = bar
}
}

View File

@ -4,6 +4,7 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import solutions.bitbadger.documents.* import solutions.bitbadger.documents.*
import solutions.bitbadger.documents.support.ForceDialect
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertNotSame import kotlin.test.assertNotSame
@ -20,7 +21,7 @@ class ParametersTest {
*/ */
@AfterEach @AfterEach
fun cleanUp() { fun cleanUp() {
Configuration.connectionString = null ForceDialect.none()
} }
@Test @Test
@ -65,7 +66,7 @@ class ParametersTest {
@Test @Test
@DisplayName("fieldNames generates a single parameter (PostgreSQL)") @DisplayName("fieldNames generates a single parameter (PostgreSQL)")
fun fieldNamesSinglePostgres() { fun fieldNamesSinglePostgres() {
Configuration.connectionString = ":postgresql:" ForceDialect.postgres()
val nameParams = Parameters.fieldNames(listOf("test")).toList() val nameParams = Parameters.fieldNames(listOf("test")).toList()
assertEquals(1, nameParams.size, "There should be one name parameter") assertEquals(1, nameParams.size, "There should be one name parameter")
assertEquals(":name", nameParams[0].name, "The parameter name is incorrect") assertEquals(":name", nameParams[0].name, "The parameter name is incorrect")
@ -76,7 +77,7 @@ class ParametersTest {
@Test @Test
@DisplayName("fieldNames generates multiple parameters (PostgreSQL)") @DisplayName("fieldNames generates multiple parameters (PostgreSQL)")
fun fieldNamesMultiplePostgres() { fun fieldNamesMultiplePostgres() {
Configuration.connectionString = ":postgresql:" ForceDialect.postgres()
val nameParams = Parameters.fieldNames(listOf("test", "this", "today")).toList() val nameParams = Parameters.fieldNames(listOf("test", "this", "today")).toList()
assertEquals(1, nameParams.size, "There should be one name parameter") assertEquals(1, nameParams.size, "There should be one name parameter")
assertEquals(":name", nameParams[0].name, "The parameter name is incorrect") assertEquals(":name", nameParams[0].name, "The parameter name is incorrect")
@ -87,7 +88,7 @@ class ParametersTest {
@Test @Test
@DisplayName("fieldNames generates a single parameter (SQLite)") @DisplayName("fieldNames generates a single parameter (SQLite)")
fun fieldNamesSingleSQLite() { fun fieldNamesSingleSQLite() {
Configuration.connectionString = ":sqlite:" ForceDialect.sqlite()
val nameParams = Parameters.fieldNames(listOf("test")).toList() val nameParams = Parameters.fieldNames(listOf("test")).toList()
assertEquals(1, nameParams.size, "There should be one name parameter") assertEquals(1, nameParams.size, "There should be one name parameter")
assertEquals(":name0", nameParams[0].name, "The parameter name is incorrect") assertEquals(":name0", nameParams[0].name, "The parameter name is incorrect")
@ -98,7 +99,7 @@ class ParametersTest {
@Test @Test
@DisplayName("fieldNames generates multiple parameters (SQLite)") @DisplayName("fieldNames generates multiple parameters (SQLite)")
fun fieldNamesMultipleSQLite() { fun fieldNamesMultipleSQLite() {
Configuration.connectionString = ":sqlite:" ForceDialect.sqlite()
val nameParams = Parameters.fieldNames(listOf("test", "this", "today")).toList() val nameParams = Parameters.fieldNames(listOf("test", "this", "today")).toList()
assertEquals(3, nameParams.size, "There should be one name parameter") assertEquals(3, nameParams.size, "There should be one name parameter")
assertEquals(":name0", nameParams[0].name, "The first parameter name is incorrect") assertEquals(":name0", nameParams[0].name, "The first parameter name is incorrect")

View File

@ -7,7 +7,7 @@ import kotlin.test.Test
/** /**
* PostgreSQL integration tests for the `Count` object / `count*` connection extension functions * PostgreSQL integration tests for the `Count` object / `count*` connection extension functions
*/ */
@DisplayName("Java | Kotlin | PostgreSQL: Count") @DisplayName("JVM | Kotlin | PostgreSQL: Count")
class CountIT { class CountIT {
@Test @Test

View File

@ -9,7 +9,7 @@ import kotlin.test.Test
/** /**
* SQLite integration tests for the `Count` object / `count*` connection extension functions * SQLite integration tests for the `Count` object / `count*` connection extension functions
*/ */
@DisplayName("Java | Kotlin | SQLite: Count") @DisplayName("JVM | Kotlin | SQLite: Count")
class CountIT { class CountIT {
@Test @Test

View File

@ -0,0 +1,103 @@
package solutions.bitbadger.documents.scala.jvm
import org.junit.jupiter.api.{AfterEach, DisplayName, Test}
import org.junit.jupiter.api.Assertions.*
import solutions.bitbadger.documents.{DocumentException, Field, Parameter, ParameterType}
import solutions.bitbadger.documents.jvm.Parameters
import solutions.bitbadger.documents.support.ForceDialect
import scala.jdk.CollectionConverters.*
@DisplayName("JVM | Scala | Parameters")
class ParametersTest {
/**
* Reset the dialect
*/
@AfterEach
def cleanUp(): Unit =
ForceDialect.none()
@Test
@DisplayName("nameFields works with no changes")
def nameFieldsNoChange(): Unit =
val fields = Field.equal("a", "", ":test") :: Field.exists("q") :: Field.equal("b", "", ":me") :: Nil
val named = Parameters.nameFields(fields.asJava).asScala.toList
assertEquals(fields.size, named.size, "There should have been 3 fields in the list")
assertSame(fields.head, named.head, "The first field should be the same")
assertSame(fields(1), named(1), "The second field should be the same")
assertSame(fields(2), named(2), "The third field should be the same")
@Test
@DisplayName("nameFields works when changing fields")
def nameFieldsChange(): Unit =
val fields = Field.equal("a", "") :: Field.equal("e", "", ":hi") :: Field.equal("b", "") ::
Field.notExists("z") :: Nil
val named = Parameters.nameFields(fields.asJava).asScala.toList
assertEquals(fields.size, named.size, "There should have been 4 fields in the list")
assertNotSame(fields.head, named.head, "The first field should not be the same")
assertEquals(":field0", named.head.getParameterName, "First parameter name incorrect")
assertSame(fields(1), named(1), "The second field should be the same")
assertNotSame(fields(2), named(2), "The third field should not be the same")
assertEquals(":field1", named(2).getParameterName, "Third parameter name incorrect")
assertSame(fields(3), named(3), "The fourth field should be the same")
@Test
@DisplayName("replaceNamesInQuery replaces successfully")
def replaceNamesInQuery(): Unit =
val parameters =
(Parameter(":data", ParameterType.JSON, "{}") :: Parameter(":data_ext", ParameterType.STRING, "") :: Nil).asJava
val query = "SELECT data, data_ext FROM tbl WHERE data = :data AND data_ext = :data_ext AND more_data = :data"
assertEquals("SELECT data, data_ext FROM tbl WHERE data = ? AND data_ext = ? AND more_data = ?",
Parameters.replaceNamesInQuery(query, parameters), "Parameters not replaced correctly")
@Test
@DisplayName("fieldNames generates a single parameter (PostgreSQL)")
def fieldNamesSinglePostgres(): Unit =
ForceDialect.postgres()
val nameParams = Parameters.fieldNames(("test" :: Nil).asJava).asScala.toList
assertEquals(1, nameParams.size, "There should be one name parameter")
assertEquals(":name", nameParams.head.getName, "The parameter name is incorrect")
assertEquals(ParameterType.STRING, nameParams.head.getType, "The parameter type is incorrect")
assertEquals("{test}", nameParams.head.getValue, "The parameter value is incorrect")
@Test
@DisplayName("fieldNames generates multiple parameters (PostgreSQL)")
def fieldNamesMultiplePostgres(): Unit =
ForceDialect.postgres()
val nameParams = Parameters.fieldNames(("test" :: "this" :: "today" :: Nil).asJava).asScala.toList
assertEquals(1, nameParams.size, "There should be one name parameter")
assertEquals(":name", nameParams.head.getName, "The parameter name is incorrect")
assertEquals(ParameterType.STRING, nameParams.head.getType, "The parameter type is incorrect")
assertEquals("{test,this,today}", nameParams.head.getValue, "The parameter value is incorrect")
@Test
@DisplayName("fieldNames generates a single parameter (SQLite)")
def fieldNamesSingleSQLite(): Unit =
ForceDialect.sqlite()
val nameParams = Parameters.fieldNames(("test" :: Nil).asJava).asScala.toList
assertEquals(1, nameParams.size, "There should be one name parameter")
assertEquals(":name0", nameParams.head.getName, "The parameter name is incorrect")
assertEquals(ParameterType.STRING, nameParams.head.getType, "The parameter type is incorrect")
assertEquals("test", nameParams.head.getValue, "The parameter value is incorrect")
@Test
@DisplayName("fieldNames generates multiple parameters (SQLite)")
def fieldNamesMultipleSQLite(): Unit =
ForceDialect.sqlite()
val nameParams = Parameters.fieldNames(("test" :: "this" :: "today" :: Nil).asJava).asScala.toList
assertEquals(3, nameParams.size, "There should be one name parameter")
assertEquals(":name0", nameParams.head.getName, "The first parameter name is incorrect")
assertEquals(ParameterType.STRING, nameParams.head.getType, "The first parameter type is incorrect")
assertEquals("test", nameParams.head.getValue, "The first parameter value is incorrect")
assertEquals(":name1", nameParams(1).getName, "The second parameter name is incorrect")
assertEquals(ParameterType.STRING, nameParams(1).getType, "The second parameter type is incorrect")
assertEquals("this", nameParams(1).getValue, "The second parameter value is incorrect")
assertEquals(":name2", nameParams(2).getName, "The third parameter name is incorrect")
assertEquals(ParameterType.STRING, nameParams(2).getType, "The third parameter type is incorrect")
assertEquals("today", nameParams(2).getValue, "The third parameter value is incorrect")
@Test
@DisplayName("fieldNames fails if dialect not set")
def fieldNamesFails(): Unit =
assertThrows(classOf[DocumentException], () => Parameters.fieldNames(List().asJava))
}

View File

@ -0,0 +1,47 @@
package solutions.bitbadger.documents.scala.jvm.integration.common
import org.junit.jupiter.api.Assertions.*
import solutions.bitbadger.documents.Field
import solutions.bitbadger.documents.extensions.ConnExt.*
import solutions.bitbadger.documents.scala.support.JsonDocument
import solutions.bitbadger.documents.support.ThrowawayDatabase
import solutions.bitbadger.documents.support.TypesKt.TEST_TABLE
import scala.jdk.CollectionConverters.*
object CountFunctions {
def all(db: ThrowawayDatabase): Unit =
JsonDocument.load(db)
assertEquals(5L, countAll(db.getConn, TEST_TABLE), "There should have been 5 documents in the table")
def byFieldsNumeric(db: ThrowawayDatabase): Unit =
JsonDocument.load(db)
assertEquals(3L, countByFields(db.getConn, TEST_TABLE, (Field.between("numValue", 10, 20) :: Nil).asJava),
"There should have been 3 matching documents")
def byFieldsAlpha(db: ThrowawayDatabase): Unit =
JsonDocument.load(db)
assertEquals(1L, countByFields(db.getConn, TEST_TABLE, (Field.between("value", "aardvark", "apple") :: Nil).asJava),
"There should have been 1 matching document")
def byContainsMatch(db: ThrowawayDatabase): Unit =
JsonDocument.load(db)
assertEquals(2L, countByContains(db.getConn, TEST_TABLE, Map.Map1("value", "purple")),
"There should have been 2 matching documents")
def byContainsNoMatch(db: ThrowawayDatabase): Unit =
JsonDocument.load(db)
assertEquals(0L, countByContains(db.getConn, TEST_TABLE, Map.Map1("value", "magenta")),
"There should have been no matching documents")
def byJsonPathMatch(db: ThrowawayDatabase): Unit =
JsonDocument.load(db)
assertEquals(2L, countByJsonPath(db.getConn, TEST_TABLE, "$.numValue ? (@ < 5)"),
"There should have been 2 matching documents")
def byJsonPathNoMatch(db: ThrowawayDatabase): Unit =
JsonDocument.load(db)
assertEquals(0L, countByJsonPath(db.getConn, TEST_TABLE, "$.numValue ? (@ > 100)"),
"There should have been no matching documents")
}

View File

@ -0,0 +1,46 @@
package solutions.bitbadger.documents.scala.jvm.integration.postgresql
import org.junit.jupiter.api.{DisplayName, Test}
import solutions.bitbadger.documents.jvm.integration.postgresql.PgDB
import solutions.bitbadger.documents.scala.jvm.integration.common.CountFunctions
import scala.util.Using
@DisplayName("JVM | Scala | PostgreSQL: Count")
class CountIT {
@Test
@DisplayName("all counts all documents")
def all(): Unit =
Using(PgDB()) { db => CountFunctions.all(db) }
@Test
@DisplayName("byFields counts documents by a numeric value")
def byFieldsNumeric(): Unit =
Using(PgDB()) { db => CountFunctions.byFieldsNumeric(db) }
@Test
@DisplayName("byFields counts documents by a alphanumeric value")
def byFieldsAlpha(): Unit =
Using(PgDB()) { db => CountFunctions.byFieldsAlpha(db) }
@Test
@DisplayName("byContains counts documents when matches are found")
def byContainsMatch(): Unit =
Using(PgDB()) { db => CountFunctions.byContainsMatch(db) }
@Test
@DisplayName("byContains counts documents when no matches are found")
def byContainsNoMatch(): Unit =
Using(PgDB()) { db => CountFunctions.byContainsNoMatch(db) }
@Test
@DisplayName("byJsonPath counts documents when matches are found")
def byJsonPathMatch(): Unit =
Using(PgDB()) { db => CountFunctions.byJsonPathMatch(db) }
@Test
@DisplayName("byJsonPath counts documents when no matches are found")
def byJsonPathNoMatch(): Unit =
Using(PgDB()) { db => CountFunctions.byJsonPathNoMatch(db) }
}

View File

@ -0,0 +1,38 @@
package solutions.bitbadger.documents.scala.jvm.integration.sqlite
import org.junit.jupiter.api.{DisplayName, Test}
import solutions.bitbadger.documents.jvm.integration.sqlite.SQLiteDB
import solutions.bitbadger.documents.scala.jvm.integration.common.CountFunctions
import org.junit.jupiter.api.Assertions.assertThrows
import solutions.bitbadger.documents.DocumentException
import scala.util.Using
@DisplayName("JVM | Scala | SQLite: Count")
class CountIT {
@Test
@DisplayName("all counts all documents")
def all(): Unit =
Using(SQLiteDB()) { db => CountFunctions.all(db) }
@Test
@DisplayName("byFields counts documents by a numeric value")
def byFieldsNumeric(): Unit =
Using(SQLiteDB()) { db => CountFunctions.byFieldsNumeric(db) }
@Test
@DisplayName("byFields counts documents by a alphanumeric value")
def byFieldsAlpha(): Unit =
Using(SQLiteDB()) { db => CountFunctions.byFieldsAlpha(db) }
@Test
@DisplayName("byContains fails")
def byContainsMatch(): Unit =
Using(SQLiteDB()) { db => assertThrows(classOf[DocumentException], () => CountFunctions.byContainsMatch(db)) }
@Test
@DisplayName("byJsonPath fails")
def byJsonPathMatch(): Unit =
Using(SQLiteDB()) { db => assertThrows(classOf[DocumentException], () => CountFunctions.byJsonPathMatch(db)) }
}

View File

@ -43,7 +43,7 @@
<kotlin.version>2.1.10</kotlin.version> <kotlin.version>2.1.10</kotlin.version>
<serialization.version>1.8.0</serialization.version> <serialization.version>1.8.0</serialization.version>
<scala.version>3.5.2</scala.version> <scala.version>3.5.2</scala.version>
<groovy.version>3.0.24</groovy.version> <groovy.version>4.0.26</groovy.version>
<sqlite.version>3.46.1.2</sqlite.version> <sqlite.version>3.46.1.2</sqlite.version>
<postgresql.version>42.7.5</postgresql.version> <postgresql.version>42.7.5</postgresql.version>
</properties> </properties>