Test.kt 2.43 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
/*
 * 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 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
Jonas Waeber's avatar
Jonas Waeber committed
28
29
import java.io.File
import java.nio.charset.Charset
Jonas Waeber's avatar
Jonas Waeber committed
30
31
32
33
34
35
36
37
38
39

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

Jonas Waeber's avatar
Jonas Waeber committed
40
41
    @Test
    fun `test municipalities loader`() {
42
        val result = Helpers.getMunicipalities()
Jonas Waeber's avatar
Jonas Waeber committed
43
44
45
46
47
        assertThat(result)
            .isNotNull
            .isNotEmpty
    }

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

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

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

Jonas Waeber's avatar
Jonas Waeber committed
70
71
72
        assertThat(record.key())
            .isEqualTo("")
    }
Jonas Waeber's avatar
Jonas Waeber committed
73
}