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

3
import ch.memobase.mapping.MapperParsers
Jonas Waeber's avatar
Jonas Waeber committed
4
import ch.memobase.mapping.fields.ConstantField
5
6
import ch.memobase.mapping.fields.FieldParsers
import ch.memobase.mapping.fields.LanguageField
Jonas Waeber's avatar
Jonas Waeber committed
7
import ch.memobase.mapping.mappers.ConstantFieldMapper
8
import ch.memobase.mapping.mappers.LanguageFieldMapper
Jonas Waeber's avatar
Jonas Waeber committed
9
import ch.memobase.mapping.mappers.SkosConceptFieldMapper
Jonas Waeber's avatar
Jonas Waeber committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import com.beust.klaxon.Klaxon
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
                .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
41
    }
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

    @Test
    fun `test language field mapper`() {
        val field = FieldParsers.parseAnnotationField(
                mapOf(
                        Pair("key", mapOf(
                                Pair("de", "DirectField1"),
                                Pair("fr", "DirectField2"),
                                Pair("it", "DirectField3")
                        ))
                ).entries.first()
        )
        val mapper = LanguageFieldMapper(field as LanguageField)
        val values = klaxon.toJsonString(mapper)
        val parsed = klaxon.parse<LanguageFieldMapper>(values)
        assertThat(parsed)
                .isEqualTo(mapper)
    }
Jonas Waeber's avatar
Jonas Waeber committed
60
}