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 SimpleRemoteSlsbInvokerInterceptorTests method configuredInterceptor.
private SimpleRemoteSlsbInvokerInterceptor configuredInterceptor(final Context mockCtx, String jndiName) throws Exception {
SimpleRemoteSlsbInvokerInterceptor si = createInterceptor();
si.setJndiTemplate(new JndiTemplate() {
@Override
protected Context createInitialContext() {
return mockCtx;
}
});
si.setResourceRef(true);
si.setJndiName(jndiName);
return si;
}
use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class SimpleRemoteStatelessSessionProxyFactoryBeanTests 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) {
// 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()));
assertEquals("Returns expected value", value, mbm.getValue());
verify(myEjb).remove();
}
use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class SimpleRemoteStatelessSessionProxyFactoryBeanTests method testCreateExceptionWithLocalBusinessInterface.
@Test
public void testCreateExceptionWithLocalBusinessInterface() 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(MyLocalBusinessMethods.class);
assertEquals(fb.getBusinessInterface(), MyLocalBusinessMethods.class);
fb.setJndiTemplate(jt);
// Need lifecycle methods
fb.afterPropertiesSet();
MyLocalBusinessMethods mbm = (MyLocalBusinessMethods) fb.getObject();
assertTrue(Proxy.isProxyClass(mbm.getClass()));
try {
mbm.getValue();
fail("Should have failed to create EJB");
} catch (RemoteAccessException ex) {
assertTrue(ex.getCause() == cex);
}
}
use of org.springframework.jndi.JndiTemplate in project spring-framework by spring-projects.
the class LocalSlsbInvokerInterceptorTests method configuredInterceptor.
protected LocalSlsbInvokerInterceptor configuredInterceptor(final Context mockCtx, final String jndiName) throws Exception {
LocalSlsbInvokerInterceptor si = new LocalSlsbInvokerInterceptor();
si.setJndiTemplate(new JndiTemplate() {
@Override
protected Context createInitialContext() throws NamingException {
return mockCtx;
}
});
si.setJndiName(jndiName);
si.setResourceRef(true);
si.afterPropertiesSet();
return si;
}
Aggregations