use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.
the class JndiObjectFactoryBeanTests method testLookupWithDefaultObjectAndExpectedTypeConversionViaBeanFactory.
@Test
public void testLookupWithDefaultObjectAndExpectedTypeConversionViaBeanFactory() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", ""));
jof.setJndiName("myFoo");
jof.setExpectedType(Integer.class);
jof.setDefaultObject("5");
jof.setBeanFactory(new DefaultListableBeanFactory());
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 testLookupWithExpectedTypeAndNoMatch.
@Test
public void testLookupWithExpectedTypeAndNoMatch() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", new Object()));
jof.setJndiName("foo");
jof.setExpectedType(String.class);
assertThatExceptionOfType(NamingException.class).isThrownBy(jof::afterPropertiesSet).withMessageContaining("java.lang.String");
}
use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.
the class JndiObjectFactoryBeanTests method testLookupWithProxyInterface.
@Test
public void testLookupWithProxyInterface() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
TestBean tb = new TestBean();
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", tb));
jof.setJndiName("foo");
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 testLookupWithExpectedTypeAndMatch.
@Test
public void testLookupWithExpectedTypeAndMatch() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
String s = "";
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", s));
jof.setJndiName("foo");
jof.setExpectedType(String.class);
jof.afterPropertiesSet();
assertThat(jof.getObject() == s).isTrue();
}
use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.
the class PersistenceInjectionTests method testSinglePersistenceUnitFromJndi.
@Test
public void testSinglePersistenceUnitFromJndi() {
Map<String, String> persistenceUnits = new HashMap<>();
persistenceUnits.put("Person", "pu1");
ExpectedLookupTemplate jt = new ExpectedLookupTemplate();
jt.addObject("java:comp/env/pu1", mockEmf);
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
PersistenceAnnotationBeanPostProcessor bpp = new PersistenceAnnotationBeanPostProcessor();
bpp.setPersistenceUnits(persistenceUnits);
bpp.setJndiTemplate(jt);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition(DefaultPublicPersistenceUnitSetter.class.getName(), new RootBeanDefinition(DefaultPublicPersistenceUnitSetter.class));
bf.registerBeanDefinition(DefaultPublicPersistenceUnitSetterNamedPerson.class.getName(), new RootBeanDefinition(DefaultPublicPersistenceUnitSetterNamedPerson.class));
DefaultPublicPersistenceUnitSetter bean = (DefaultPublicPersistenceUnitSetter) bf.getBean(DefaultPublicPersistenceUnitSetter.class.getName());
DefaultPublicPersistenceUnitSetterNamedPerson bean2 = (DefaultPublicPersistenceUnitSetterNamedPerson) bf.getBean(DefaultPublicPersistenceUnitSetterNamedPerson.class.getName());
assertThat(bean.emf).isSameAs(mockEmf);
assertThat(bean2.emf).isSameAs(mockEmf);
}
Aggregations