/
EachPropertyInterfaceSpec.groovy
54 lines (44 loc) · 1.57 KB
/
EachPropertyInterfaceSpec.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
package io.micronaut.inject.foreach
import io.micronaut.context.ApplicationContext
import io.micronaut.inject.qualifiers.Qualifiers
import spock.lang.Specification
class EachPropertyInterfaceSpec extends Specification {
void "test @EachProperty on interface"() {
given:
def context = ApplicationContext.run(
"foo.bar.one.host": 'host1',
"foo.bar.one.port": '9999',
"foo.bar.two.host": 'host2',
"foo.bar.two.port": '8888'
)
when:
def one = context.getBean(InterfaceConfig, Qualifiers.byName("one"))
def two = context.getBean(InterfaceConfig, Qualifiers.byName("two"))
then:
one.host == 'host1'
one.port == 9999
two.host == 'host2'
two.port == 8888
cleanup:
context.close()
}
void "test @EachProperty on interface with nested @ConfigurationProperties"() {
given:
def context = ApplicationContext.run(
"foo.bar[0].address.host": 'host1',
"foo.bar[0].address.port": '9999',
"foo.bar[1].address.host": 'host2',
"foo.bar[1].address.port": '8888'
)
when:
def one = context.getBean(InterfaceAggregatorConfig, Qualifiers.byName("0"))
def two = context.getBean(InterfaceAggregatorConfig, Qualifiers.byName("1"))
then:
one.address.host == 'host1'
one.address.port == 9999
two.address.host == 'host2'
two.address.port == 8888
cleanup:
context.close()
}
}