TestTransform.kt 1.18 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1
2
3
4
5
6
7
8
9
package org.memobase

import com.beust.klaxon.json
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.assertThrows
import org.memobase.helpers.JSON
import java.io.File
import java.io.FileInputStream
10
import org.memobase.helpers.DocumentTypeMapper
Jonas Waeber's avatar
Jonas Waeber committed
11
12
13
14
15
16

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

    private val dataPath = "src/test/resources/data/transformer"

17
18
19
    private val documentTypeMapper = DocumentTypeMapper("src/test/resources/configs/document-type-labels.csv")
    private val transformer = DocumentsSearchDocBuilder(documentTypeMapper, "https://media.memobase.k8s.unibas.ch/memo/")

Jonas Waeber's avatar
Jonas Waeber committed
20
21
22
    @Test
    fun `test missing record`() {
        val input = mapOf(Pair("", json { obj() }))
23
        assertThrows<InvalidInputException> { transformer.transform(input) }
Jonas Waeber's avatar
Jonas Waeber committed
24
25
26
27
28
    }


    @Test
    fun `test enriched digital metadata record`() {
Jonas Waeber's avatar
Jonas Waeber committed
29
30
31
        val input = JSON.unpack(
            JSON.parse(
                FileInputStream(File("$dataPath/enrich_digital_metadata_record.json")).bufferedReader().readLines()
32
                    .reduce { acc, s -> acc + "\n" + s })
Jonas Waeber's avatar
Jonas Waeber committed
33
        )
34
        val values = transformer.transform(input)
Jonas Waeber's avatar
Jonas Waeber committed
35
36
    }
}