use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.
the class JndiObjectFactoryBeanTests method testLookupWithProxyInterfaceAndDefaultObject.
@Test
public void testLookupWithProxyInterfaceAndDefaultObject() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
TestBean tb = new TestBean();
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", tb));
jof.setJndiName("myFoo");
jof.setProxyInterface(ITestBean.class);
jof.setDefaultObject(Boolean.TRUE);
assertThatIllegalArgumentException().isThrownBy(jof::afterPropertiesSet);
}
use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.
the class JndiObjectFactoryBeanTests method testLookupWithDefaultObject.
@Test
public void testLookupWithDefaultObject() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", ""));
jof.setJndiName("myFoo");
jof.setExpectedType(String.class);
jof.setDefaultObject("myString");
jof.afterPropertiesSet();
assertThat(jof.getObject()).isEqualTo("myString");
}
use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.
the class JndiObjectFactoryBeanTests method testLookupWithDefaultObjectAndExpectedTypeConversion.
@Test
public void testLookupWithDefaultObjectAndExpectedTypeConversion() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", ""));
jof.setJndiName("myFoo");
jof.setExpectedType(Integer.class);
jof.setDefaultObject("5");
jof.afterPropertiesSet();
assertThat(jof.getObject()).isEqualTo(5);
}
use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.
the class JndiObjectFactoryBeanTests method testLookupWithProxyInterfaceAndExpectedTypeAndMatch.
@Test
public void testLookupWithProxyInterfaceAndExpectedTypeAndMatch() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
TestBean tb = new TestBean();
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", tb));
jof.setJndiName("foo");
jof.setExpectedType(TestBean.class);
jof.setProxyInterface(ITestBean.class);
jof.afterPropertiesSet();
boolean condition = jof.getObject() instanceof ITestBean;
assertThat(condition).isTrue();
ITestBean proxy = (ITestBean) jof.getObject();
assertThat(tb.getAge()).isEqualTo(0);
proxy.setAge(99);
assertThat(tb.getAge()).isEqualTo(99);
}
use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.
the class JndiObjectFactoryBeanTests method testLookupWithFullNameAndResourceRefFalse.
@Test
public void testLookupWithFullNameAndResourceRefFalse() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
Object o = new Object();
jof.setJndiTemplate(new ExpectedLookupTemplate("java:comp/env/foo", o));
jof.setJndiName("java:comp/env/foo");
jof.setResourceRef(false);
jof.afterPropertiesSet();
assertThat(jof.getObject() == o).isTrue();
}
Aggregations