11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2016 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3030 * Unit tests for {@link JndiPropertySource}.
3131 *
3232 * @author Chris Beams
33+ * @author Juergen Hoeller
3334 * @since 3.1
3435 */
3536public class JndiPropertySourceTests {
@@ -56,7 +57,7 @@ protected Context createInitialContext() throws NamingException {
5657 jndiLocator .setJndiTemplate (jndiTemplate );
5758
5859 JndiPropertySource ps = new JndiPropertySource ("jndiProperties" , jndiLocator );
59- assertThat (( String ) ps .getProperty ("p1" ), equalTo ("v1" ));
60+ assertThat (ps .getProperty ("p1" ), equalTo ("v1" ));
6061 }
6162
6263 @ Test
@@ -75,7 +76,36 @@ protected Context createInitialContext() throws NamingException {
7576 jndiLocator .setJndiTemplate (jndiTemplate );
7677
7778 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" ));
79109 }
80110
81111}
0 commit comments