Add Jackson serializer for tests
This commit is contained in:
parent
5f0a6e4434
commit
ee46c0bc54
@ -25,6 +25,10 @@
|
||||
<url>https://git.bitbadger.solutions/bit-badger/solutions.bitbadger.documents</url>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<jackson.version>2.18.2</jackson.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>solutions.bitbadger.documents</groupId>
|
||||
@ -34,6 +38,12 @@
|
||||
<systemPath>${project.basedir}/../common/target/common-4.0.0-alpha1-SNAPSHOT.jar</systemPath>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -65,8 +75,8 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>${project.basedir}/src/test/java</sourceDir>
|
||||
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
|
||||
<sourceDir>${project.basedir}/src/test/java</sourceDir>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</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"
|
||||
|
||||
@Serializable
|
||||
data class NumIdDocument(val key: Int, val text: String)
|
||||
data class NumIdDocument(val key: Int, val text: String) {
|
||||
constructor() : this(0, "")
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class SubDocument(val foo: String, val bar: String)
|
||||
data class SubDocument(val foo: String, val bar: String) {
|
||||
constructor() : this("", "")
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class ArrayDocument(val id: String, val values: List<String>) {
|
||||
|
||||
constructor() : this("", listOf())
|
||||
|
||||
companion object {
|
||||
/** A set of documents used for integration tests */
|
||||
val testDocuments = listOf(
|
||||
@ -26,6 +33,9 @@ data class ArrayDocument(val id: String, val values: List<String>) {
|
||||
|
||||
@Serializable
|
||||
data class JsonDocument(val id: String, val value: String = "", val numValue: Int = 0, val sub: SubDocument? = null) {
|
||||
|
||||
constructor() : this("")
|
||||
|
||||
companion object {
|
||||
/** Documents to use for testing */
|
||||
private val testDocuments = listOf(
|
||||
|
@ -13,6 +13,7 @@ class PgDB : ThrowawayDatabase {
|
||||
private var dbName = ""
|
||||
|
||||
init {
|
||||
DocumentConfig.serializer = JacksonDocumentSerializer()
|
||||
dbName = "throwaway_${AutoId.generateRandomString(8)}"
|
||||
Configuration.connectionString = connString("postgres")
|
||||
Configuration.dbConn().use {
|
||||
|
@ -14,6 +14,7 @@ class SQLiteDB : ThrowawayDatabase {
|
||||
private var dbName = ""
|
||||
|
||||
init {
|
||||
DocumentConfig.serializer = JacksonDocumentSerializer()
|
||||
dbName = "test-db-${AutoId.generateRandomString(8)}.db"
|
||||
Configuration.connectionString = "jdbc:sqlite:$dbName"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user