forked from grails/grails-core
/
GrailsPlaceholderConfigurerSpec.groovy
74 lines (65 loc) · 2.69 KB
/
GrailsPlaceholderConfigurerSpec.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
package org.codehaus.groovy.grails.commons.cfg
import org.codehaus.groovy.grails.commons.DefaultGrailsApplication
import org.springframework.context.groovy.GroovyBeanDefinitionReader
import spock.lang.Issue
import spock.lang.Specification
/**
* @author Graeme Rocher
*/
class GrailsPlaceholderConfigurerSpec extends Specification {
void "Test that property placeholder configuration works for simple properties"() {
when:"A bean is defined with a placeholder"
def application = new DefaultGrailsApplication()
application.config.foo.bar="test"
def bb = new GroovyBeanDefinitionReader()
bb.beans {
addBeanFactoryPostProcessor(new GrailsPlaceholderConfigurer(application))
testBean(TestBean) {
name = '${foo.bar}'
}
}
def applicationContext = bb.createApplicationContext()
def bean = applicationContext.getBean(TestBean)
then:"The placeholder is replaced"
bean.name == "test"
}
@Issue('GRAILS-9490')
void "Test that property placeholder configuration doesn't throw an error if invalid placeholders are configured"() {
when:"A bean is defined with a placeholder"
def application = new DefaultGrailsApplication()
application.config.bar.foo="test"
application.config.more.stuff='another ${place.holder}'
def bb = new GroovyBeanDefinitionReader()
bb.beans {
addBeanFactoryPostProcessor(new GrailsPlaceholderConfigurer(application))
testBean(TestBean) {
name = '${foo.bar}'
}
}
def applicationContext = bb.createApplicationContext()
def bean = applicationContext.getBean(TestBean)
then:"The placeholder is replaced"
bean.name == '${foo.bar}'
}
void "Test that property placeholder configuration works for simple properties with a custom placeholder prefix"() {
when:"A bean is defined with a placeholder"
def application = new DefaultGrailsApplication()
application.config.foo.bar="test"
application.config.grails.spring.placeholder.prefix='£{'
application.setConfig(application.config)
def bb = new GroovyBeanDefinitionReader()
bb.beans {
addBeanFactoryPostProcessor(new GrailsPlaceholderConfigurer(application))
testBean(TestBean) {
name = '£{foo.bar}'
}
}
def applicationContext = bb.createApplicationContext()
def bean = applicationContext.getBean(TestBean)
then:"The placeholder is replaced"
bean.name == "test"
}
}
class TestBean {
String name
}