TestDocumentsSearchDoc.kt 1.85 KB
Newer Older
1 2
package org.memobase

3 4
import io.mockk.every
import io.mockk.mockk
5 6
import java.io.File
import java.nio.charset.Charset
7
import org.assertj.core.api.Assertions.assertThat
8 9
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
10
import org.memobase.helpers.ElasticSearchWrapper
11
import org.memobase.helpers.JSON
12
import org.memobase.model.DocumentsSearchDoc
13 14 15
import org.memobase.model.FacetContainer
import org.memobase.model.LanguageContainer
import org.memobase.model.LanguageContainer.Companion
16 17 18 19 20 21 22 23

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestDocumentsSearchDoc {
    private val dataPath = "src/test/resources/data/documents"
    private fun readFile(fileName: String): String {
        return File("$dataPath/$fileName").readText(Charset.defaultCharset())
    }

24 25 26 27

    private val elasticSearchWrapperMocked = run {
        val internal = mockk<ElasticSearchWrapper>()
        every { internal.getRecordSetName("") } returns LanguageContainer.EMPTY
28 29 30
        every { internal.getExtraInstitutionsFromRecordSet("", "access") } returns emptyList()
        every { internal.getExtraInstitutionsFromRecordSet("", "original") } returns emptyList()
        every { internal.getExtraInstitutionsFromRecordSet("", "master") } returns emptyList()
31 32 33 34

        internal
    }

35
    private val transformer =
36 37 38 39 40
        DocumentsSearchDocBuilder(
            TestUtilities.translationMappers,
            elasticSearchWrapperMocked,
            TestUtilities.mediaUrl
        )
41 42 43 44 45

    @Test
    fun `test minimal record required`() {
        val input = JSON.parse(readFile("minimal_record_required.json"))
        val mappedInput = JSON.unpack(input)
46 47
        val output = transformer.transform(
            "TestIdentifier",
48 49
            mappedInput
        )
50
        assertThat(output.toJson())
51
            .isEqualTo(
52
                DocumentsSearchDoc.DEFAULT.toJson()
53
            )
54 55
    }
}