use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class SimpleRemoteSlsbInvokerInterceptorTests method testLookupFailure.
@Test
public void testLookupFailure() throws Exception {
final NamingException nex = new NamingException();
final String jndiName = "foobar";
JndiTemplate jt = new JndiTemplate() {
@Override
public Object lookup(String name) throws NamingException {
assertTrue(jndiName.equals(name));
throw nex;
}
};
SimpleRemoteSlsbInvokerInterceptor si = new SimpleRemoteSlsbInvokerInterceptor();
si.setJndiName("foobar");
// default resourceRef=false should cause this to fail, as java:/comp/env will not
// automatically be added
si.setJndiTemplate(jt);
try {
si.afterPropertiesSet();
fail("Should have failed with naming exception");
} catch (NamingException ex) {
assertTrue(ex == nex);
}
}
use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class SimpleRemoteStatelessSessionProxyFactoryBeanTests 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) {
// parameterize
assertTrue(name.equals(jndiName));
return home;
}
};
SimpleRemoteStatelessSessionProxyFactoryBean fb = new SimpleRemoteStatelessSessionProxyFactoryBean();
fb.setJndiName(jndiName);
// rely on default setting of resourceRef=false, no auto addition of java:/comp/env prefix
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 (RemoteException ex) {
// expected
}
}
use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class SimpleRemoteStatelessSessionProxyFactoryBeanTests method testInvokesMethodOnEjb3StyleBean.
@Test
public void testInvokesMethodOnEjb3StyleBean() throws Exception {
final int value = 11;
final String jndiName = "foo";
final MyEjb myEjb = mock(MyEjb.class);
given(myEjb.getValue()).willReturn(value);
JndiTemplate jt = new JndiTemplate() {
@Override
public Object lookup(String name) {
// parameterize
assertTrue(name.equals("java:comp/env/" + jndiName));
return myEjb;
}
};
SimpleRemoteStatelessSessionProxyFactoryBean fb = new SimpleRemoteStatelessSessionProxyFactoryBean();
fb.setJndiName(jndiName);
fb.setResourceRef(true);
fb.setBusinessInterface(MyBusinessMethods.class);
fb.setJndiTemplate(jt);
// Need lifecycle methods
fb.afterPropertiesSet();
MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
assertTrue(Proxy.isProxyClass(mbm.getClass()));
assertEquals("Returns expected value", value, mbm.getValue());
}
use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class SimpleRemoteStatelessSessionProxyFactoryBeanTests method testRemoteException.
@Override
@Test
public void testRemoteException() throws Exception {
final RemoteException rex = new RemoteException();
final String jndiName = "foo";
MyEjb myEjb = mock(MyEjb.class);
given(myEjb.getValue()).willThrow(rex);
// TODO might want to control this behaviour...
// Do we really want to call remove after a remote exception?
final MyHome home = mock(MyHome.class);
given(home.create()).willReturn(myEjb);
JndiTemplate jt = new JndiTemplate() {
@Override
public Object lookup(String name) {
// parameterize
assertTrue(name.equals("java:comp/env/" + jndiName));
return home;
}
};
SimpleRemoteStatelessSessionProxyFactoryBean fb = new SimpleRemoteStatelessSessionProxyFactoryBean();
fb.setJndiName(jndiName);
fb.setResourceRef(true);
fb.setBusinessInterface(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've thrown remote exception");
} catch (RemoteException ex) {
assertSame("Threw expected RemoteException", rex, ex);
}
verify(myEjb).remove();
}
use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class SimpleRemoteStatelessSessionProxyFactoryBeanTests method testNoBusinessInterfaceSpecified.
@Test
public void testNoBusinessInterfaceSpecified() throws Exception {
// Will do JNDI lookup to get home but won't call create
// Could actually try to figure out interface from create?
final String jndiName = "foo";
final MyHome home = mock(MyHome.class);
JndiTemplate jt = new JndiTemplate() {
@Override
public Object lookup(String name) throws NamingException {
// parameterize
assertTrue(name.equals(jndiName));
return home;
}
};
SimpleRemoteStatelessSessionProxyFactoryBean fb = new SimpleRemoteStatelessSessionProxyFactoryBean();
fb.setJndiName(jndiName);
// rely on default setting of resourceRef=false, no auto addition of java:/comp/env prefix
// Don't set business interface
fb.setJndiTemplate(jt);
// Check it's a singleton
assertTrue(fb.isSingleton());
try {
fb.afterPropertiesSet();
fail("Should have failed to create EJB");
} catch (IllegalArgumentException ex) {
// TODO more appropriate exception?
assertTrue(ex.getMessage().indexOf("businessInterface") != 1);
}
// Expect no methods on home
verifyZeroInteractions(home);
}
Aggregations