In order to mitigate against the brute force attacks against Gitlab accounts, we are moving to all edu-ID Logins. We would like to remind you to link your account with your edu-id. Login will be possible only by edu-ID after November 30, 2021. Here you can find the instructions for linking your account.

If you don't have a SWITCH edu-ID, you can create one with this guide here

kind regards

IntegrationTest.kt 4.16 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
/*
 * 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/>.
 */
Jonas Waeber's avatar
Jonas Waeber committed
18
package org.memobase
Jonas Waeber's avatar
Jonas Waeber committed
19

20
import io.mockk.every
21
import io.mockk.mockk
22
23
24
import java.io.File
import java.nio.charset.Charset
import java.util.stream.Stream
Jonas Waeber's avatar
Jonas Waeber committed
25
26
27
28
29
30
31
import org.apache.kafka.common.serialization.StringDeserializer
import org.apache.kafka.common.serialization.StringSerializer
import org.apache.kafka.streams.TopologyTestDriver
import org.apache.kafka.streams.test.ConsumerRecordFactory
import org.apache.logging.log4j.LogManager
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.TestInstance
32
import org.junit.jupiter.api.assertAll
Jonas Waeber's avatar
Jonas Waeber committed
33
34
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
35
import org.memobase.helpers.ElasticSearchWrapper
36
import org.memobase.model.FacetContainer
37
import org.memobase.model.FacetContainer.Companion
38
import org.memobase.model.LanguageContainer
39
import org.memobase.params.TestParam
Jonas Waeber's avatar
Jonas Waeber committed
40
41

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
42
class IntegrationTest {
Jonas Waeber's avatar
Jonas Waeber committed
43
44
45
46
47
48
49
    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())
    }

50
51
52
53
54
55
56
    private val elasticSearchWrapperMocked = run {
        val internal = mockk<ElasticSearchWrapper>()
        every { internal.getRecordSetName("soz-004") } returns LanguageContainer.placeholder("soz-004")
        every { internal.getInstitutionName("soz") } returns FacetContainer.placeholder("soz")
        internal
    }

Jonas Waeber's avatar
Jonas Waeber committed
57
58
59
    @ParameterizedTest
    @MethodSource("testParams")
    fun `integration tests`(params: TestParam) {
60
61
        val settings = App.createSettings("kafkaTest1.yml")

62
63
        every { elasticSearchWrapperMocked.countNumberOfDocuments("") } returns 123
        every { elasticSearchWrapperMocked.getDocumentTypesFromRecords("", "") } returns listOf(
64
65
66
67
            FacetContainer(
                LanguageContainer(listOf("Foto"), listOf("Foto"), listOf("Foto"), emptyList()), "Foto", emptyList()
            )
        )
68
69
70


        val topology =
71
            KafkaTopology(settings, TestUtilities.translationMappers, elasticSearchWrapperMocked)
72
        val testDriver = TopologyTestDriver(topology.build(), settings.kafkaStreamsSettings)
Jonas Waeber's avatar
Jonas Waeber committed
73
        val factory = ConsumerRecordFactory(
74
            StringSerializer(), StringSerializer()
Jonas Waeber's avatar
Jonas Waeber committed
75
76
        )
        testDriver.pipeInput(
77
78
79
            factory.create(
                settings.inputTopic, params.inputKey, readFile("${params.count}/input.json")
            )
Jonas Waeber's avatar
Jonas Waeber committed
80
81
82
        )

        val record = testDriver.readOutput(
83
84
85
            settings.outputTopic,
            StringDeserializer(),
            StringDeserializer()
Jonas Waeber's avatar
Jonas Waeber committed
86
87
        )

88
89
90
91
92
93
94
        assertAll("",
            {
                assertThat(record.value())
                    .isEqualTo(readFile("${params.count}/output.json"))
            },
            { assertThat(record.key()).isEqualTo(params.outputKey) }
        )
Jonas Waeber's avatar
Jonas Waeber committed
95
96
97
    }

    private fun testParams() = Stream.of(
98
99
100
101
        TestParam(
            "test-1",
            1,
            "kafkaTest1.yml",
102
103
            "https://memobase.ch/record/fad-001-DON3196",
            "fad-001-DON3196"
104
105
106
107
108
        ),
        TestParam(
            "test-2",
            2,
            "kafkaTest1.yml",
109
            "Burgerbib-Krebser-208576",
110
111
112
113
114
115
            "Burgerbib-Krebser-208576"
        ),
        TestParam(
            "test-3",
            3,
            "kafkaTest1.yml",
116
            "LS-film-162354",
117
118
            "LS-film-162354"
        )
Jonas Waeber's avatar
Jonas Waeber committed
119
120
    )
}