use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class LocalSlsbInvokerInterceptorTests 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;
}
};
LocalSlsbInvokerInterceptor si = new LocalSlsbInvokerInterceptor();
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 LocalStatelessSessionProxyFactoryBeanTests 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("java:comp/env/" + jndiName));
return home;
}
};
LocalStatelessSessionProxyFactoryBean fb = new LocalStatelessSessionProxyFactoryBean();
fb.setJndiName(jndiName);
fb.setResourceRef(true);
// 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);
}
use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class LocalStatelessSessionProxyFactoryBeanTests 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) throws NamingException {
// parameterize
assertTrue(name.equals("java:comp/env/" + jndiName));
return myEjb;
}
};
LocalStatelessSessionProxyFactoryBean fb = new LocalStatelessSessionProxyFactoryBean();
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()));
assertTrue(mbm.getValue() == value);
}
use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class LocalStatelessSessionProxyFactoryBeanTests method testInvokesMethod.
@Test
public void testInvokesMethod() throws Exception {
final int value = 11;
final String jndiName = "foo";
MyEjb myEjb = mock(MyEjb.class);
given(myEjb.getValue()).willReturn(value);
final MyHome home = mock(MyHome.class);
given(home.create()).willReturn(myEjb);
JndiTemplate jt = new JndiTemplate() {
@Override
public Object lookup(String name) throws NamingException {
// parameterize
assertTrue(name.equals("java:comp/env/" + jndiName));
return home;
}
};
LocalStatelessSessionProxyFactoryBean fb = new LocalStatelessSessionProxyFactoryBean();
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()));
assertTrue(mbm.getValue() == value);
verify(myEjb).remove();
}
use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class JmsTemplateTests method createTemplate.
private JmsTemplate createTemplate() {
JmsTemplate template = new JmsTemplate();
JndiDestinationResolver destMan = new JndiDestinationResolver();
destMan.setJndiTemplate(new JndiTemplate() {
@Override
protected Context createInitialContext() {
return jndiContext;
}
});
template.setDestinationResolver(destMan);
template.setSessionTransacted(useTransactedTemplate());
return template;
}
Aggregations