TestFieldMapperSerde.kt 1.29 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1
2
package ch.memobase.test

Jonas Waeber's avatar
Jonas Waeber committed
3
4
import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.mappers.ConstantFieldMapper
Jonas Waeber's avatar
Jonas Waeber committed
5
import ch.memobase.mapping.mappers.SkosConceptFieldMapper
Jonas Waeber's avatar
Jonas Waeber committed
6
import com.beust.klaxon.Klaxon
Jonas Waeber's avatar
Jonas Waeber committed
7
import mapping.MapperParsers
Jonas Waeber's avatar
Jonas Waeber committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestFieldMapperSerde {

    private val klaxon = Klaxon()

    @Test
    fun `test constant field mapper serialization`() {
        val json = klaxon.toJsonString(ConstantFieldMapper(ConstantField("key", "value")))
        val parsed = klaxon.parse<ConstantFieldMapper>(json)
        assertThat(parsed)
Jonas Waeber's avatar
Jonas Waeber committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
                .isNotNull
                .isEqualTo(ConstantFieldMapper(ConstantField("key", "value")))
    }

    @Test
    fun `test skos concept field mapper`() {
        val mappers = MapperParsers.buildSkosConceptMappers(
                "subject", mapOf(
                Pair("prefLabel", "TestField"),
                Pair("note", mapOf(Pair("const", "ConstValue")))
        )
        )[0]
        val values = klaxon.toJsonString(mappers)
        val parsed = klaxon.parse<SkosConceptFieldMapper>(values)
        assertThat(parsed)
                .isEqualTo(mappers)
Jonas Waeber's avatar
Jonas Waeber committed
38
39
    }
}