TestTransform.kt 1.67 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1 2 3
package org.memobase

import com.beust.klaxon.json
4 5
import io.mockk.every
import io.mockk.mockk
6 7
import java.io.File
import java.io.FileInputStream
Jonas Waeber's avatar
Jonas Waeber committed
8 9 10
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.assertThrows
11
import org.memobase.helpers.ElasticSearchWrapper
Jonas Waeber's avatar
Jonas Waeber committed
12
import org.memobase.helpers.JSON
13
import org.memobase.model.LanguageContainer
Jonas Waeber's avatar
Jonas Waeber committed
14 15 16 17

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

18 19 20
    private val elasticSearchWrapperMocked = run {
        val internal = mockk<ElasticSearchWrapper>()
        every { internal.getRecordSetName("") } returns LanguageContainer.EMPTY
21 22 23
        every { internal.getExtraInstitutionsFromRecordSet("", "access") } returns emptyList()
        every { internal.getExtraInstitutionsFromRecordSet("", "original") } returns emptyList()
        every { internal.getExtraInstitutionsFromRecordSet("", "master") } returns emptyList()
24 25 26
        internal
    }

Jonas Waeber's avatar
Jonas Waeber committed
27
    private val dataPath = "src/test/resources/data/transformer"
28
    private val transformer = DocumentsSearchDocBuilder(TestUtilities.translationMappers, elasticSearchWrapperMocked, TestUtilities.mediaUrl)
29

Jonas Waeber's avatar
Jonas Waeber committed
30 31 32
    @Test
    fun `test missing record`() {
        val input = mapOf(Pair("", json { obj() }))
33
        assertThrows<InvalidInputException> { transformer.transform("", input) }
Jonas Waeber's avatar
Jonas Waeber committed
34 35 36 37 38
    }


    @Test
    fun `test enriched digital metadata record`() {
Jonas Waeber's avatar
Jonas Waeber committed
39 40 41
        val input = JSON.unpack(
            JSON.parse(
                FileInputStream(File("$dataPath/enrich_digital_metadata_record.json")).bufferedReader().readLines()
42
                    .reduce { acc, s -> acc + "\n" + s })
Jonas Waeber's avatar
Jonas Waeber committed
43
        )
44
        val values = transformer.transform("", input)
Jonas Waeber's avatar
Jonas Waeber committed
45 46
    }
}