Tests.kt 2.38 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * record-parser
 * Copyright (C) 2019  Memobase
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
package org.memobase

Jonas Waeber's avatar
Jonas Waeber committed
20
import com.beust.klaxon.Klaxon
Jonas Waeber's avatar
Jonas Waeber committed
21
import org.apache.logging.log4j.LogManager
Jonas Waeber's avatar
Jonas Waeber committed
22
import org.junit.jupiter.api.Test
Jonas Waeber's avatar
Jonas Waeber committed
23
import org.junit.jupiter.api.TestInstance
Jonas Waeber's avatar
Jonas Waeber committed
24
25
import org.memobase.builder.ResourceBuilder
import org.memobase.mapping.MappingConfig
Jonas Waeber's avatar
Jonas Waeber committed
26
import java.io.File
Jonas Waeber's avatar
Jonas Waeber committed
27
import java.io.FileOutputStream
Jonas Waeber's avatar
Jonas Waeber committed
28
import java.nio.charset.Charset
Jonas Waeber's avatar
Jonas Waeber committed
29
30
import java.nio.file.Files
import java.nio.file.Paths
Jonas Waeber's avatar
Jonas Waeber committed
31
32
33
34
35
36
37
38
39

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class Tests {
    private val log = LogManager.getLogger("TestLogger")

    private val resourcePath = "src/test/resources/data"
    private fun readFile(fileName: String): String {
        return File("$resourcePath/$fileName").readText(Charset.defaultCharset())
    }
Jonas Waeber's avatar
Jonas Waeber committed
40
41
42

    @Test
    fun `test mapping config parser`() {
Jonas Waeber's avatar
Jonas Waeber committed
43
44
        val config =
            MappingConfig("src/test/resources/multifileconfig")
Jonas Waeber's avatar
Jonas Waeber committed
45
46
47
48
49
50
        var count = 0
        Files.list(Paths.get("src/test/resources/data")).forEach { path ->
            val text = Files.newBufferedReader(path).readText()
            val values = Klaxon().parse<Map<String, String>>(text)
            val resourceBuilder = ResourceBuilder(
                config.uriField,
51
                config.recordType,
Jonas Waeber's avatar
Jonas Waeber committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
                config.recordFieldMappers,
                config.physicalObjectFieldMappers,
                values!!,
                "BAZ",
                "BAZ-B_MEI"
            )
            val string = resourceBuilder.write()


            string.forEach { s ->
                count += 1
                FileOutputStream("src/test/resources/output/data$count.json").bufferedWriter(Charset.defaultCharset()).use {
                    it.write(s)
                }
            }
        }

Jonas Waeber's avatar
Jonas Waeber committed
69
70

    }
Jonas Waeber's avatar
Jonas Waeber committed
71
}