use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class LocalStatelessSessionProxyFactoryBeanTests method testCreateException.
@Test
public void testCreateException() throws Exception {
final String jndiName = "foo";
final CreateException cex = new CreateException();
final MyHome home = mock(MyHome.class);
given(home.create()).willThrow(cex);
JndiTemplate jt = new JndiTemplate() {
@Override
public Object lookup(String name) throws NamingException {
// parameterize
assertTrue(name.equals(jndiName));
return home;
}
};
LocalStatelessSessionProxyFactoryBean fb = new LocalStatelessSessionProxyFactoryBean();
fb.setJndiName(jndiName);
// no java:comp/env prefix
fb.setResourceRef(false);
fb.setBusinessInterface(MyBusinessMethods.class);
assertEquals(fb.getBusinessInterface(), MyBusinessMethods.class);
fb.setJndiTemplate(jt);
// Need lifecycle methods
fb.afterPropertiesSet();
MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
assertTrue(Proxy.isProxyClass(mbm.getClass()));
try {
mbm.getValue();
fail("Should have failed to create EJB");
} catch (EjbAccessException ex) {
assertSame(cex, ex.getCause());
}
}
Aggregations