TestDocumentsSearchDoc.kt 2.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * search-doc-service
 * Copyright (C) 2020 Memoriav
 *
 * 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 ch.memobase
19

20
21
22
23
import ch.memobase.helpers.ElasticSearchWrapper
import ch.memobase.helpers.JsonUtility
import ch.memobase.model.DocumentsSearchDoc
import ch.memobase.model.LanguageContainer
24
25
import io.mockk.every
import io.mockk.mockk
26
27
import java.io.File
import java.nio.charset.Charset
28
import org.assertj.core.api.Assertions.assertThat
29
30
31
32
33
34
35
36
37
38
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance

@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())
    }

39
40
41
42

    private val elasticSearchWrapperMocked = run {
        val internal = mockk<ElasticSearchWrapper>()
        every { internal.getRecordSetName("") } returns LanguageContainer.EMPTY
Jonas Waeber's avatar
Jonas Waeber committed
43
44
45
        every { internal.getExtraInstitutionsFromRecordSet("", "accessInstitution") } returns emptyList()
        every { internal.getExtraInstitutionsFromRecordSet("", "originalInstitution") } returns emptyList()
        every { internal.getExtraInstitutionsFromRecordSet("", "masterInstitution") } returns emptyList()
Jonas Waeber's avatar
Jonas Waeber committed
46
        every { internal.getInstitutionNamesFromRecordSet("") } returns emptyList()
47
48
49
50

        internal
    }

51
    private val transformer =
52
53
54
55
56
        DocumentsSearchDocBuilder(
            TestUtilities.translationMappers,
            elasticSearchWrapperMocked,
            TestUtilities.mediaUrl
        )
57
58
59

    @Test
    fun `test minimal record required`() {
Jonas Waeber's avatar
Jonas Waeber committed
60
61
        val input = JsonUtility.parse(readFile("minimal_record_required.json"))
        val mappedInput = JsonUtility.unpack(input)
62
63
        val output = transformer.transform(
            "TestIdentifier",
64
65
            mappedInput
        )
66
        assertThat(output.toJson())
67
            .isEqualTo(
68
                DocumentsSearchDoc.DEFAULT.toJson()
69
            )
70
71
    }
}