|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -30,6 +30,7 @@ import static org.junit.Assert.*; |
|
|
|
* Unit tests for {@link JndiPropertySource}. |
|
|
|
* Unit tests for {@link JndiPropertySource}. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Chris Beams |
|
|
|
* @author Chris Beams |
|
|
|
|
|
|
|
* @author Juergen Hoeller |
|
|
|
* @since 3.1 |
|
|
|
* @since 3.1 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class JndiPropertySourceTests { |
|
|
|
public class JndiPropertySourceTests { |
|
|
|
@ -56,7 +57,7 @@ public class JndiPropertySourceTests { |
|
|
|
jndiLocator.setJndiTemplate(jndiTemplate); |
|
|
|
jndiLocator.setJndiTemplate(jndiTemplate); |
|
|
|
|
|
|
|
|
|
|
|
JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator); |
|
|
|
JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator); |
|
|
|
assertThat((String)ps.getProperty("p1"), equalTo("v1")); |
|
|
|
assertThat(ps.getProperty("p1"), equalTo("v1")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -75,7 +76,36 @@ public class JndiPropertySourceTests { |
|
|
|
jndiLocator.setJndiTemplate(jndiTemplate); |
|
|
|
jndiLocator.setJndiTemplate(jndiTemplate); |
|
|
|
|
|
|
|
|
|
|
|
JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator); |
|
|
|
JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator); |
|
|
|
assertThat((String)ps.getProperty("p1"), equalTo("v1")); |
|
|
|
assertThat(ps.getProperty("p1"), equalTo("v1")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void propertyWithDefaultClauseInResourceRefMode() { |
|
|
|
|
|
|
|
JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Object lookup(String jndiName) throws NamingException { |
|
|
|
|
|
|
|
throw new IllegalStateException("Should not get called"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
jndiLocator.setResourceRef(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator); |
|
|
|
|
|
|
|
assertThat(ps.getProperty("propertyKey:defaultValue"), nullValue()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void propertyWithColonInNonResourceRefMode() { |
|
|
|
|
|
|
|
JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Object lookup(String jndiName) throws NamingException { |
|
|
|
|
|
|
|
assertEquals("my:key", jndiName); |
|
|
|
|
|
|
|
return "my:value"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
jndiLocator.setResourceRef(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator); |
|
|
|
|
|
|
|
assertThat(ps.getProperty("my:key"), equalTo("my:value")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|