Initial Development #1
@ -25,6 +25,10 @@
|
|||||||
<url>https://git.bitbadger.solutions/bit-badger/solutions.bitbadger.documents</url>
|
<url>https://git.bitbadger.solutions/bit-badger/solutions.bitbadger.documents</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<jackson.version>2.18.2</jackson.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>solutions.bitbadger.documents</groupId>
|
<groupId>solutions.bitbadger.documents</groupId>
|
||||||
@ -34,6 +38,12 @@
|
|||||||
<systemPath>${project.basedir}/../common/target/common-4.0.0-alpha1-SNAPSHOT.jar</systemPath>
|
<systemPath>${project.basedir}/../common/target/common-4.0.0-alpha1-SNAPSHOT.jar</systemPath>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -65,8 +75,8 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sourceDirs>
|
<sourceDirs>
|
||||||
<sourceDir>${project.basedir}/src/test/java</sourceDir>
|
|
||||||
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
|
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
|
||||||
|
<sourceDir>${project.basedir}/src/test/java</sourceDir>
|
||||||
</sourceDirs>
|
</sourceDirs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
18
src/java/src/test/kotlin/JacksonDocumentSerializer.kt
Normal file
18
src/java/src/test/kotlin/JacksonDocumentSerializer.kt
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package solutions.bitbadger.documents.java
|
||||||
|
|
||||||
|
import solutions.bitbadger.documents.common.DocumentSerializer
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JSON serializer using Jackson's default options
|
||||||
|
*/
|
||||||
|
class JacksonDocumentSerializer : DocumentSerializer {
|
||||||
|
|
||||||
|
val mapper = ObjectMapper()
|
||||||
|
|
||||||
|
override fun <TDoc> serialize(document: TDoc) =
|
||||||
|
mapper.writeValueAsString(document)
|
||||||
|
|
||||||
|
override fun <TDoc> deserialize(json: String, clazz: Class<TDoc>) =
|
||||||
|
mapper.readValue(json, clazz)
|
||||||
|
}
|
@ -7,13 +7,20 @@ import solutions.bitbadger.documents.java.insert
|
|||||||
const val TEST_TABLE = "test_table"
|
const val TEST_TABLE = "test_table"
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class NumIdDocument(val key: Int, val text: String)
|
data class NumIdDocument(val key: Int, val text: String) {
|
||||||
|
constructor() : this(0, "")
|
||||||
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class SubDocument(val foo: String, val bar: String)
|
data class SubDocument(val foo: String, val bar: String) {
|
||||||
|
constructor() : this("", "")
|
||||||
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ArrayDocument(val id: String, val values: List<String>) {
|
data class ArrayDocument(val id: String, val values: List<String>) {
|
||||||
|
|
||||||
|
constructor() : this("", listOf())
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/** A set of documents used for integration tests */
|
/** A set of documents used for integration tests */
|
||||||
val testDocuments = listOf(
|
val testDocuments = listOf(
|
||||||
@ -26,6 +33,9 @@ data class ArrayDocument(val id: String, val values: List<String>) {
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class JsonDocument(val id: String, val value: String = "", val numValue: Int = 0, val sub: SubDocument? = null) {
|
data class JsonDocument(val id: String, val value: String = "", val numValue: Int = 0, val sub: SubDocument? = null) {
|
||||||
|
|
||||||
|
constructor() : this("")
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/** Documents to use for testing */
|
/** Documents to use for testing */
|
||||||
private val testDocuments = listOf(
|
private val testDocuments = listOf(
|
||||||
|
@ -13,6 +13,7 @@ class PgDB : ThrowawayDatabase {
|
|||||||
private var dbName = ""
|
private var dbName = ""
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
DocumentConfig.serializer = JacksonDocumentSerializer()
|
||||||
dbName = "throwaway_${AutoId.generateRandomString(8)}"
|
dbName = "throwaway_${AutoId.generateRandomString(8)}"
|
||||||
Configuration.connectionString = connString("postgres")
|
Configuration.connectionString = connString("postgres")
|
||||||
Configuration.dbConn().use {
|
Configuration.dbConn().use {
|
||||||
|
@ -14,6 +14,7 @@ class SQLiteDB : ThrowawayDatabase {
|
|||||||
private var dbName = ""
|
private var dbName = ""
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
DocumentConfig.serializer = JacksonDocumentSerializer()
|
||||||
dbName = "test-db-${AutoId.generateRandomString(8)}.db"
|
dbName = "test-db-${AutoId.generateRandomString(8)}.db"
|
||||||
Configuration.connectionString = "jdbc:sqlite:$dbName"
|
Configuration.connectionString = "jdbc:sqlite:$dbName"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user