-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfiguratorTest.groovy
executable file
·95 lines (79 loc) · 2.12 KB
/
ConfiguratorTest.groovy
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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class ConfiguratorTest extends GroovyTestCase {
def configurator
void setUp() {
configurator = new Configurator()
}
void testParseFile() {
def configFile = new File("temp.config")
configFile.write("x = 1")
def config = configurator.parseFile(configFile)
assert config.x == 1 : "x != 1"
}
void testSetProperty() {
def config = configurator.parse("x=1")
assert config.x == 1 : "x != 1"
}
void testGetProperty() {
def config = configurator.parse("x=1; y=x")
assert config.y == 1 : "y != 1"
}
void testSubstitution() {
def config = configurator.parse('x=1; y=${x}')
assert config.y == 1 : "y != 1"
}
void testGrouping() {
def configurator = new Configurator()
def config = configurator.parse('''
a {
b {
c=1
}
}
y=a.b.c
''')
assert config.y == 1 : "y != 1"
}
void testScoping() {
def config = configurator.parse('''
a {
b=1
c {
d=b
e=a.b
}
}
y=a.c.e
''')
assert config.y == 1 : "y != 1"
}
void testMethodCall() {
configurator.parse('println 1')
}
void testMissingProperty() {
try {
configurator.parse('a=b')
assert false : "Exception not thrown."
} catch(e) {
}
}
void testMissingMethod() {
try {
configurator.parse('a()')
assert false : "Exception not thrown."
} catch(e) {
}
}
void testFlatten() {
def config = configurator.parse('x=1; a { b=1 }')
def props = new java.util.Properties()
configurator.flatten("", configurator.binding.root, props)
assert props.getProperty("x") == '1' : "props.x != '1'"
assert props.getProperty("a.b") == '1' : "props.a.b != '1'"
}
void testToProperties() {
configurator.parse('x=1; a { b=1 }')
def props = configurator.toProperties()
assert props.getProperty("x") == '1' : "props.x != '1'"
assert props.getProperty("a.b") == '1' : "props.a.b != '1'"
}
}