1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
30
30
* Unit tests for {@link JndiPropertySource}.
31
31
*
32
32
* @author Chris Beams
33
+ * @author Juergen Hoeller
33
34
* @since 3.1
34
35
*/
35
36
public class JndiPropertySourceTests {
@@ -56,7 +57,7 @@ protected Context createInitialContext() throws NamingException {
56
57
jndiLocator .setJndiTemplate (jndiTemplate );
57
58
58
59
JndiPropertySource ps = new JndiPropertySource ("jndiProperties" , jndiLocator );
59
- assertThat (( String ) ps .getProperty ("p1" ), equalTo ("v1" ));
60
+ assertThat (ps .getProperty ("p1" ), equalTo ("v1" ));
60
61
}
61
62
62
63
@ Test
@@ -75,7 +76,36 @@ protected Context createInitialContext() throws NamingException {
75
76
jndiLocator .setJndiTemplate (jndiTemplate );
76
77
77
78
JndiPropertySource ps = new JndiPropertySource ("jndiProperties" , jndiLocator );
78
- assertThat ((String )ps .getProperty ("p1" ), equalTo ("v1" ));
79
+ assertThat (ps .getProperty ("p1" ), equalTo ("v1" ));
80
+ }
81
+
82
+ @ Test
83
+ public void propertyWithDefaultClauseInResourceRefMode () {
84
+ JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate () {
85
+ @ Override
86
+ public Object lookup (String jndiName ) throws NamingException {
87
+ throw new IllegalStateException ("Should not get called" );
88
+ }
89
+ };
90
+ jndiLocator .setResourceRef (true );
91
+
92
+ JndiPropertySource ps = new JndiPropertySource ("jndiProperties" , jndiLocator );
93
+ assertThat (ps .getProperty ("propertyKey:defaultValue" ), nullValue ());
94
+ }
95
+
96
+ @ Test
97
+ public void propertyWithColonInNonResourceRefMode () {
98
+ JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate () {
99
+ @ Override
100
+ public Object lookup (String jndiName ) throws NamingException {
101
+ assertEquals ("my:key" , jndiName );
102
+ return "my:value" ;
103
+ }
104
+ };
105
+ jndiLocator .setResourceRef (false );
106
+
107
+ JndiPropertySource ps = new JndiPropertySource ("jndiProperties" , jndiLocator );
108
+ assertThat (ps .getProperty ("my:key" ), equalTo ("my:value" ));
79
109
}
80
110
81
111
}
0 commit comments