@Test public void nonExistentProperty() { JndiPropertySource ps = new JndiPropertySource("jndiProperties"); assertThat(ps.getProperty("bogus"), nullValue()); }
@Nullable public Object getProperty(String name) { if (getSource().isResourceRef() && name.indexOf(':') != -1) {
propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)); if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) { propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)); if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) { propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
@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")); }
propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)); if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) { propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
@Nullable public Object getProperty(String name) { if (getSource().isResourceRef() && name.indexOf(':') != -1) {
@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()); }
propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)); if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) { propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
@Nullable public Object getProperty(String name) { if (getSource().isResourceRef() && name.indexOf(':') != -1) {
@Test public void nameBoundWithPrefix() { final SimpleNamingContext context = new SimpleNamingContext(); context.bind("java:comp/env/p1", "v1"); JndiTemplate jndiTemplate = new JndiTemplate() { @Override protected Context createInitialContext() throws NamingException { return context; } }; JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); jndiLocator.setResourceRef(true); jndiLocator.setJndiTemplate(jndiTemplate); JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator); assertThat(ps.getProperty("p1"), equalTo("v1")); }
propertySources.addLast(new StubPropertySource(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)); if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) { propertySources.addLast(new JndiPropertySource(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME));
@Test public void nameBoundWithoutPrefix() { final SimpleNamingContext context = new SimpleNamingContext(); context.bind("p1", "v1"); JndiTemplate jndiTemplate = new JndiTemplate() { @Override protected Context createInitialContext() throws NamingException { return context; } }; JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); jndiLocator.setResourceRef(true); jndiLocator.setJndiTemplate(jndiTemplate); JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator); assertThat(ps.getProperty("p1"), equalTo("v1")); }
propertySources.addLast(new StubPropertySource(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)); if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) { propertySources.addLast(new JndiPropertySource(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME));