Initial Development #1
1
.idea/encodings.xml
generated
1
.idea/encodings.xml
generated
@ -5,6 +5,7 @@
|
|||||||
<file url="file://$PROJECT_DIR$/src/jvm/src/main/resources" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/src/jvm/src/main/resources" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/src/kotlin/src/main/kotlin" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/src/kotlin/src/main/kotlin" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/src/kotlin/src/main/resources" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/src/kotlin/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/src/main/kotlin" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/src/main/kotlin" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/src/sqlite/src/main/kotlin" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/src/sqlite/src/main/kotlin" charset="UTF-8" />
|
||||||
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/src/jvm/jvm.iml" filepath="$PROJECT_DIR$/src/jvm/jvm.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
2
pom.xml
2
pom.xml
@ -7,7 +7,7 @@
|
|||||||
<groupId>solutions.bitbadger</groupId>
|
<groupId>solutions.bitbadger</groupId>
|
||||||
<artifactId>documents</artifactId>
|
<artifactId>documents</artifactId>
|
||||||
<version>4.0.0-alpha1-SNAPSHOT</version>
|
<version>4.0.0-alpha1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>${project.groupId}:${project.artifactId}</name>
|
<name>${project.groupId}:${project.artifactId}</name>
|
||||||
<description>Expose a document store interface for PostgreSQL and SQLite</description>
|
<description>Expose a document store interface for PostgreSQL and SQLite</description>
|
||||||
|
8
src/jvm/jvm.iml
Normal file
8
src/jvm/jvm.iml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module version="4">
|
||||||
|
<component name="AdditionalModuleElements">
|
||||||
|
<content url="file://$MODULE_DIR$" dumb="true">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/scala" isTestSource="true" />
|
||||||
|
</content>
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -36,6 +36,18 @@
|
|||||||
<version>${jackson.version}</version>
|
<version>${jackson.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.scalatest</groupId>
|
||||||
|
<artifactId>scalatest_3</artifactId>
|
||||||
|
<version>3.2.9</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
|
<artifactId>groovy-test-junit5</artifactId>
|
||||||
|
<version>3.0.24</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -68,15 +80,69 @@
|
|||||||
<sourceDirs>
|
<sourceDirs>
|
||||||
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
|
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
|
||||||
<sourceDir>${project.basedir}/src/test/java</sourceDir>
|
<sourceDir>${project.basedir}/src/test/java</sourceDir>
|
||||||
|
<sourceDir>${project.basedir}/src/test/scala</sourceDir>
|
||||||
</sourceDirs>
|
</sourceDirs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>net.alchim31.maven</groupId>
|
||||||
|
<artifactId>scala-maven-plugin</artifactId>
|
||||||
|
<version>4.9.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>testCompile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.gmaven</groupId>
|
||||||
|
<artifactId>gmaven-plugin</artifactId>
|
||||||
|
<version>1.5</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<configuration>
|
||||||
|
<providerSelection>2.0</providerSelection>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>generateTestStubs</goal>
|
||||||
|
<goal>testCompile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.22.2</version>
|
<version>2.22.2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.scalatest</groupId>
|
||||||
|
<artifactId>scalatest-maven-plugin</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
<configuration>
|
||||||
|
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
|
||||||
|
<junitxml>.</junitxml>
|
||||||
|
<filereports>WDF TestSuite.txt</filereports>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>test</id>
|
||||||
|
<goals>
|
||||||
|
<goal>test</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-failsafe-plugin</artifactId>
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
<version>2.22.2</version>
|
<version>2.22.2</version>
|
||||||
@ -92,6 +158,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${java.version}</source>
|
<source>${java.version}</source>
|
||||||
<target>${java.version}</target>
|
<target>${java.version}</target>
|
||||||
|
@ -0,0 +1,166 @@
|
|||||||
|
package solutions.bitbadger.documents.groovy
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import solutions.bitbadger.documents.AutoId
|
||||||
|
import solutions.bitbadger.documents.DocumentException
|
||||||
|
import solutions.bitbadger.documents.groovy.support.*
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for the `AutoId` enum
|
||||||
|
*/
|
||||||
|
@DisplayName('JVM | Groovy | AutoId')
|
||||||
|
class AutoIdTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('Generates a UUID string')
|
||||||
|
void generateUUID() {
|
||||||
|
assertEquals(32, AutoId.generateUUID().length(), 'The UUID should have been a 32-character string')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('Generates a random hex character string of an even length')
|
||||||
|
void generateRandomStringEven() {
|
||||||
|
def result = AutoId.generateRandomString 8
|
||||||
|
assertEquals(8, result.length(), "There should have been 8 characters in $result")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('Generates a random hex character string of an odd length')
|
||||||
|
void generateRandomStringOdd() {
|
||||||
|
def result = AutoId.generateRandomString 11
|
||||||
|
assertEquals(11, result.length(), "There should have been 11 characters in $result")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('Generates different random hex character strings')
|
||||||
|
void generateRandomStringIsRandom() {
|
||||||
|
def result1 = AutoId.generateRandomString 16
|
||||||
|
def result2 = AutoId.generateRandomString 16
|
||||||
|
assertNotEquals(result1, result2, 'There should have been 2 different strings generated')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId fails for null document')
|
||||||
|
void needsAutoIdFailsForNullDocument() {
|
||||||
|
assertThrows(DocumentException.class) { AutoId.needsAutoId(AutoId.DISABLED, null, 'id') }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId fails for missing ID property')
|
||||||
|
void needsAutoIdFailsForMissingId() {
|
||||||
|
assertThrows(DocumentException.class) { AutoId.needsAutoId(AutoId.UUID, new IntIdClass(0), 'Id') }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns false if disabled')
|
||||||
|
void needsAutoIdFalseIfDisabled() {
|
||||||
|
assertFalse(AutoId.needsAutoId(AutoId.DISABLED, '', ''), 'Disabled Auto ID should always return false')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns true for Number strategy and byte ID of 0')
|
||||||
|
void needsAutoIdTrueForByteWithZero() {
|
||||||
|
assertTrue(AutoId.needsAutoId(AutoId.NUMBER, new ByteIdClass((byte) 0), 'id'),
|
||||||
|
'Number Auto ID with 0 should return true')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns false for Number strategy and byte ID of non-0')
|
||||||
|
void needsAutoIdFalseForByteWithNonZero() {
|
||||||
|
assertFalse(AutoId.needsAutoId(AutoId.NUMBER, new ByteIdClass((byte) 77), 'id'),
|
||||||
|
'Number Auto ID with 77 should return false')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns true for Number strategy and short ID of 0')
|
||||||
|
void needsAutoIdTrueForShortWithZero() {
|
||||||
|
assertTrue(AutoId.needsAutoId(AutoId.NUMBER, new ShortIdClass((short) 0), 'id'),
|
||||||
|
'Number Auto ID with 0 should return true')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns false for Number strategy and short ID of non-0')
|
||||||
|
void needsAutoIdFalseForShortWithNonZero() {
|
||||||
|
assertFalse(AutoId.needsAutoId(AutoId.NUMBER, new ShortIdClass((short) 31), 'id'),
|
||||||
|
'Number Auto ID with 31 should return false')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns true for Number strategy and int ID of 0')
|
||||||
|
void needsAutoIdTrueForIntWithZero() {
|
||||||
|
assertTrue(AutoId.needsAutoId(AutoId.NUMBER, new IntIdClass(0), 'id'),
|
||||||
|
'Number Auto ID with 0 should return true')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns false for Number strategy and int ID of non-0')
|
||||||
|
void needsAutoIdFalseForIntWithNonZero() {
|
||||||
|
assertFalse(AutoId.needsAutoId(AutoId.NUMBER, new IntIdClass(6), 'id'),
|
||||||
|
'Number Auto ID with 6 should return false')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns true for Number strategy and long ID of 0')
|
||||||
|
void needsAutoIdTrueForLongWithZero() {
|
||||||
|
assertTrue(AutoId.needsAutoId(AutoId.NUMBER, new LongIdClass(0L), 'id'),
|
||||||
|
'Number Auto ID with 0 should return true')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns false for Number strategy and long ID of non-0')
|
||||||
|
void needsAutoIdFalseForLongWithNonZero() {
|
||||||
|
assertFalse(AutoId.needsAutoId(AutoId.NUMBER, new LongIdClass(2L), 'id'),
|
||||||
|
'Number Auto ID with 2 should return false')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId fails for Number strategy and non-number ID')
|
||||||
|
void needsAutoIdFailsForNumberWithStringId() {
|
||||||
|
assertThrows(DocumentException.class) { AutoId.needsAutoId(AutoId.NUMBER, new StringIdClass(''), 'id') }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns true for UUID strategy and blank ID')
|
||||||
|
void needsAutoIdTrueForUUIDWithBlank() {
|
||||||
|
assertTrue(AutoId.needsAutoId(AutoId.UUID, new StringIdClass(''), 'id'),
|
||||||
|
'UUID Auto ID with blank should return true')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns false for UUID strategy and non-blank ID')
|
||||||
|
void needsAutoIdFalseForUUIDNotBlank() {
|
||||||
|
assertFalse(AutoId.needsAutoId(AutoId.UUID, new StringIdClass('howdy'), 'id'),
|
||||||
|
'UUID Auto ID with non-blank should return false')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId fails for UUID strategy and non-string ID')
|
||||||
|
void needsAutoIdFailsForUUIDNonString() {
|
||||||
|
assertThrows(DocumentException.class) { AutoId.needsAutoId(AutoId.UUID, new IntIdClass(5), 'id') }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns true for Random String strategy and blank ID')
|
||||||
|
void needsAutoIdTrueForRandomWithBlank() {
|
||||||
|
assertTrue(AutoId.needsAutoId(AutoId.RANDOM_STRING, new StringIdClass(''), 'id'),
|
||||||
|
'Random String Auto ID with blank should return true')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId returns false for Random String strategy and non-blank ID')
|
||||||
|
void needsAutoIdFalseForRandomNotBlank() {
|
||||||
|
assertFalse(AutoId.needsAutoId(AutoId.RANDOM_STRING, new StringIdClass('full'), 'id'),
|
||||||
|
'Random String Auto ID with non-blank should return false')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName('needsAutoId fails for Random String strategy and non-string ID')
|
||||||
|
void needsAutoIdFailsForRandomNonString() {
|
||||||
|
assertThrows(DocumentException.class) {
|
||||||
|
AutoId.needsAutoId(AutoId.RANDOM_STRING, new ShortIdClass((short) 55), 'id')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package solutions.bitbadger.documents.groovy
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import solutions.bitbadger.documents.FieldMatch
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for the `FieldMatch` enum
|
||||||
|
*/
|
||||||
|
@DisplayName("JVM | Groovy | FieldMatch")
|
||||||
|
class FieldMatchTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("ANY uses proper SQL")
|
||||||
|
void anySQL() {
|
||||||
|
assertEquals("OR", FieldMatch.ANY.sql, "ANY should use OR")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("ALL uses proper SQL")
|
||||||
|
void allSQL() {
|
||||||
|
assertEquals("AND", FieldMatch.ALL.sql, "ALL should use AND")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package solutions.bitbadger.documents.groovy.support
|
||||||
|
|
||||||
|
class ByteIdClass {
|
||||||
|
byte id
|
||||||
|
|
||||||
|
ByteIdClass(byte id) {
|
||||||
|
this.id = id
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package solutions.bitbadger.documents.groovy.support
|
||||||
|
|
||||||
|
class IntIdClass {
|
||||||
|
int id
|
||||||
|
|
||||||
|
IntIdClass(int id) {
|
||||||
|
this.id = id
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package solutions.bitbadger.documents.groovy.support
|
||||||
|
|
||||||
|
class LongIdClass {
|
||||||
|
long id
|
||||||
|
|
||||||
|
LongIdClass(long id) {
|
||||||
|
this.id = id
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package solutions.bitbadger.documents.groovy.support
|
||||||
|
|
||||||
|
class ShortIdClass {
|
||||||
|
short id
|
||||||
|
|
||||||
|
ShortIdClass(short id) {
|
||||||
|
this.id = id
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package solutions.bitbadger.documents.groovy.support
|
||||||
|
|
||||||
|
class StringIdClass {
|
||||||
|
String id
|
||||||
|
|
||||||
|
StringIdClass(String id) {
|
||||||
|
this.id = id
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package solutions.bitbadger.documents.scala
|
||||||
|
|
||||||
|
import org.scalatest.funspec.AnyFunSpec
|
||||||
|
import solutions.bitbadger.documents.FieldMatch
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for the `FieldMatch` enum
|
||||||
|
*/
|
||||||
|
class FieldMatchTest extends AnyFunSpec {
|
||||||
|
|
||||||
|
describe("sql") {
|
||||||
|
describe("ANY") {
|
||||||
|
it("should use OR") {
|
||||||
|
assert("OR" == FieldMatch.ANY.getSql)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
describe("ALL") {
|
||||||
|
it("should use AND") {
|
||||||
|
assert("AND" == FieldMatch.ALL.getSql)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user