TestLocalTransformLoader.kt 3.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
   Copyright 2020 Jonas Waeber

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package ch.memobase

import ch.memobase.configs.LocalTransformsLoader
19
import ch.memobase.reporting.ReportStatus
20
import java.io.File
21
import org.apache.logging.log4j.LogManager
22
23
24
25
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
26
import org.junit.jupiter.api.assertAll
27
28
29
30


@TestInstance(PER_CLASS)
class TestLocalTransformLoader {
31
32
33
34
35
36
37
38
    private val log = LogManager.getLogger(this::class.java)

    private fun readYml(fileName: String): ByteArray {
        return File("src/test/resources/local/$fileName.yml").readBytes()
    }

    @Test
    fun `test empty local transform`() {
Jonas Waeber's avatar
Jonas Waeber committed
39
        val localTransformsLoader = LocalTransformsLoader(byteArrayOf(), "test")
40
41
42
43
44
45
46
        val report = localTransformsLoader.parse("key")
        assertThat(report.status)
            .isEqualTo(ReportStatus.ignored)
    }

    @Test
    fun `test yml parse error`() {
Jonas Waeber's avatar
Jonas Waeber committed
47
        val localTransformsLoader = LocalTransformsLoader(readYml("invalid"), "test")
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        val report = localTransformsLoader.parse("key")
        assertAll(
            "",
            {
                assertThat(report.status)
                    .isEqualTo(ReportStatus.fatal)
            },
            {
                assertThat(report.message)
                    .isEqualTo(
                        "[Local Transform] YamlParserError: Cannot construct instance of `ch.memobase.model.LocalTransform` " +
                                "(although at least one Creator exists): no String-argument constructor/factory method " +
                                "to deserialize from String value ('bla bla bla')\n" +
                                " at [Source: (ByteArrayInputStream); line: 1, column: 1]"
                    )
            }
        )
    }

    @Test
    fun `test valid input`() {
Jonas Waeber's avatar
Jonas Waeber committed
69
        val localTransformsLoader = LocalTransformsLoader(readYml("valid"), "test")
70
71
72
73
74
75
76
77
78
79
80
81
82
83
        val report = localTransformsLoader.parse("key")
        assertAll(
            "",
            {
                assertThat(report.status)
                    .isEqualTo(ReportStatus.success)
            },
            {
                assertThat(report.message)
                    .isEqualTo("")
            }
        )
    }

84
    @Test
85
    fun `test invalid entity splitter input`() {
Jonas Waeber's avatar
Jonas Waeber committed
86
        val localTransformsLoader = LocalTransformsLoader(readYml("invalidEntitySplitter"), "test")
87
88
89
90
91
92
93
94
95
96
97
98
        val report = localTransformsLoader.parse("key")
        assertAll(
            "",
            {
                assertThat(report.status)
                    .isEqualTo(ReportStatus.fatal)
            },
            {
                assertThat(report.message)
                    .isEqualTo("[Local Transform] ValidationError: Property 'type' should have format 'prefix:ClassName', but was 'ricoPerson' instead.")
            }
        )
99
100
    }
}