Search in sources :

Example 16 with JndiTemplate

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());
    }
}
Also used : JndiTemplate(org.springframework.jndi.JndiTemplate) CreateException(javax.ejb.CreateException) Test(org.junit.Test)

Aggregations

JndiTemplate (org.springframework.jndi.JndiTemplate)16 Test (org.junit.Test)12 CreateException (javax.ejb.CreateException)3 Context (javax.naming.Context)3 NamingException (javax.naming.NamingException)3 RemoteException (java.rmi.RemoteException)2 JndiDestinationResolver (org.springframework.jms.support.destination.JndiDestinationResolver)1 RemoteAccessException (org.springframework.remoting.RemoteAccessException)1