Search in sources :

Example 1 with SimpleNamingContext

use of org.springframework.tests.mock.jndi.SimpleNamingContext in project spring-framework by spring-projects.

the class JndiPropertySourceTests method nameBoundWithPrefix.

@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"));
}
Also used : SimpleNamingContext(org.springframework.tests.mock.jndi.SimpleNamingContext) Test(org.junit.Test)

Example 2 with SimpleNamingContext

use of org.springframework.tests.mock.jndi.SimpleNamingContext in project spring-framework by spring-projects.

the class JndiPropertySourceTests method nameBoundWithoutPrefix.

@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"));
}
Also used : SimpleNamingContext(org.springframework.tests.mock.jndi.SimpleNamingContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SimpleNamingContext (org.springframework.tests.mock.jndi.SimpleNamingContext)2