TestGlobalTransformLoader.kt 2.33 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.GlobalTransformsLoader
Jonas Waeber's avatar
Jonas Waeber committed
19
import ch.memobase.helpers.GlobalTransformException
20
21
22
23
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
Jonas Waeber's avatar
Jonas Waeber committed
24
import org.junit.jupiter.api.assertThrows
25
26
27

@TestInstance(PER_CLASS)
class TestGlobalTransformLoader {
Jonas Waeber's avatar
Jonas Waeber committed
28
29
30

    private val basePath = "src/test/resources/global/tests"

31
    @Test
Jonas Waeber's avatar
Jonas Waeber committed
32
    fun `test full valid global loader`() {
33
34
        val file = "src/test/resources/global/transforms.yml"
        val global = GlobalTransformsLoader(file)
Jonas Waeber's avatar
Jonas Waeber committed
35
        global.parse()
36
37
38
39
        val transforms = global.get()
        assertThat(transforms)
            .isNotEmpty
    }
Jonas Waeber's avatar
Jonas Waeber committed
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
73
74
75

    @Test
    fun `test 1 - invalid transform path 1`() {
        val file = "/test/invalid/path/transforms.yml"
        val global = GlobalTransformsLoader(file)
        assertThrows<GlobalTransformException> {
            global.parse()
        }
    }

    @Test
    fun `test 2 - missing date normalization file`() {
        val file = "$basePath/2/transforms.yml"
        val global = GlobalTransformsLoader(file)
        assertThrows<GlobalTransformException> {
            global.parse()
        }
    }

    @Test
    fun `test 3 - invalid regex pattern in date`() {
        val file = "$basePath/3/transforms.yml"
        val global = GlobalTransformsLoader(file)
        assertThrows<GlobalTransformException> {
            global.parse()
        }
    }

    @Test
    fun `test 4 - missing qualifier group in qualifier regex`() {
        val file = "$basePath/4/transforms.yml"
        val global = GlobalTransformsLoader(file)
        assertThrows<GlobalTransformException> {
            global.parse()
        }
    }
76
}