Test.kt 2.82 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
21
22
23
24
25
26
27
28
29
30
31

import java.io.File
import java.nio.charset.Charset
import java.util.stream.Stream
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
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
32
import org.memobase.params.TestParam
Jonas Waeber's avatar
Jonas Waeber committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class Test {
    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())
    }

    @ParameterizedTest
    @MethodSource("testParams")
    fun `integration tests`(params: TestParam) {
        val service = Service(params.settingsFileName)
        val testDriver = TopologyTestDriver(service.topology, service.settings.kafkaStreamsSettings)
        val factory = ConsumerRecordFactory(
            StringSerializer(), StringSerializer()
        )
        testDriver.pipeInput(
            factory.create(
                service.settings.inputTopic, params.inputKey, readFile("${params.count}/input.json")
            )
        )

        val record = testDriver.readOutput(
            service.settings.outputTopic,
            StringDeserializer(),
            StringDeserializer()
        )

        assertThat(record.value())
            .isEqualTo(readFile("${params.count}/output.json"))
    }

    private fun testParams() = Stream.of(
        TestParam(
            "test-1",
            1,
            "kafkaTest1.yml",
            "key"
Jonas Waeber's avatar
Jonas Waeber committed
73
        ),
Jonas Waeber's avatar
Jonas Waeber committed
74
75
76
77
78
        TestParam(
            "test-2",
            2,
            "kafkaTest1.yml",
            "key"
Jonas Waeber's avatar
Jonas Waeber committed
79
        )/*,
80
81
82
83
84
        TestParam(
            "test-3",
            3,
            "kafkaTest1.yml",
            "key"
85
        )*/
Jonas Waeber's avatar
Jonas Waeber committed
86
87
    )
}