Test.kt 2.41 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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * 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 org.memobase

import com.beust.klaxon.Klaxon
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.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource

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

    @Test
Jonas Waeber's avatar
Jonas Waeber committed
45
46
    fun `test institution transform`() {
        val service = Service("test1.yml")
Jonas Waeber's avatar
Jonas Waeber committed
47
48
49
50
51
52
        val testDriver = TopologyTestDriver(service.topology, service.settings.kafkaStreamsSettings)
        val factory = ConsumerRecordFactory(
            StringSerializer(), StringSerializer()
        )
        testDriver.pipeInput(
            factory.create(
Jonas Waeber's avatar
Jonas Waeber committed
53
                service.settings.inputTopic, "", readFile("1/input.json")
Jonas Waeber's avatar
Jonas Waeber committed
54
55
56
57
58
59
60
61
62
63
            )
        )

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

        assertThat(record.value())
Jonas Waeber's avatar
Jonas Waeber committed
64
            .isEqualTo(readFile("1/output.nt"))
Jonas Waeber's avatar
Jonas Waeber committed
65

Jonas Waeber's avatar
Jonas Waeber committed
66
67
68
        assertThat(record.key())
            .isEqualTo("")
    }
Jonas Waeber's avatar
Jonas Waeber committed
69
}