TestXsltTransform.kt 2.39 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
/*
 * xml-data-transform
 * Copyright (C) 2019  Memobase
 *
 * 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 java.io.File
import java.io.FileInputStream
import java.nio.charset.Charset
import java.nio.file.Paths
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
import org.junit.jupiter.api.assertAll
Jonas Waeber's avatar
Jonas Waeber committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import org.memobase.testing.EmbeddedSftpServer
import java.io.InputStream
import java.util.Properties

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

    private fun createInputStream(fileName: String): InputStream {
        return File("$resourcePath/$fileName").inputStream()
    }

    @Test
Jonas Waeber's avatar
Jonas Waeber committed
47
    fun `test old memobase xslt transform`() {
Jonas Waeber's avatar
Jonas Waeber committed
48
49
50
51
52
53
        val props = Properties()
        props.setProperty("xsltFilePath", "${resourcePath}/test_transform/test-transformer.xslt")
        props.setProperty("identifierFieldName", "identifierMain")
        props.setProperty("recordTag", "record")
        val transformer = XMLTransformer(props)
        val result = transformer.applyXSLT("", createInputStream("test_transform/test-transformer.xml"))
Jonas Waeber's avatar
Jonas Waeber committed
54
55
56
57
58
59
60
61
62
63
64
65
        assertAll("assert old memobase xslt transformation.",
            {
                assertThat(result.key)
                    .isEqualTo("ADG-102683")
            },
            {
                assertThat(result.value.output.toString())
                    .isEqualTo(readFile("test_transform/output.json"))
            }
        )


Jonas Waeber's avatar
Jonas Waeber committed
66
67
    }
}