use of javax.naming.Context in project spring-framework by spring-projects.
the class SimpleRemoteSlsbInvokerInterceptorTests method testInvokesMethodOnEjbInstanceWithBusinessInterface.
@Test
public void testInvokesMethodOnEjbInstanceWithBusinessInterface() throws Exception {
Object retVal = new Object();
final RemoteInterface ejb = mock(RemoteInterface.class);
given(ejb.targetMethod()).willReturn(retVal);
final String jndiName = "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class);
assertTrue(target.targetMethod() == retVal);
verify(mockContext).close();
verify(ejb).remove();
}
use of javax.naming.Context in project spring-framework by spring-projects.
the class SimpleRemoteSlsbInvokerInterceptorTests method testInvokesMethodOnEjbInstanceWithHomeInterface.
@Test
public void testInvokesMethodOnEjbInstanceWithHomeInterface() throws Exception {
Object retVal = new Object();
final RemoteInterface ejb = mock(RemoteInterface.class);
given(ejb.targetMethod()).willReturn(retVal);
final String jndiName = "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
si.setHomeInterface(SlsbHome.class);
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
assertTrue(target.targetMethod() == retVal);
verify(mockContext).close();
verify(ejb).remove();
}
use of javax.naming.Context in project spring-framework by spring-projects.
the class SimpleRemoteSlsbInvokerInterceptorTests method testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException.
@Test
public void testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException() throws Exception {
final RemoteInterface ejb = mock(RemoteInterface.class);
given(ejb.targetMethod()).willThrow(new RemoteException());
final String jndiName = "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class);
try {
target.targetMethod();
fail("Should have thrown RemoteAccessException");
} catch (RemoteAccessException ex) {
// expected
}
verify(mockContext).close();
verify(ejb).remove();
}
use of javax.naming.Context in project spring-framework by spring-projects.
the class JndiTemplateTests method testLookupReturnsNull.
@Test
public void testLookupReturnsNull() throws Exception {
String name = "foo";
final Context context = mock(Context.class);
given(context.lookup(name)).willReturn(null);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
try {
jt.lookup(name);
fail("Should have thrown NamingException");
} catch (NameNotFoundException ex) {
// Ok
}
verify(context).close();
}
use of javax.naming.Context in project spring-framework by spring-projects.
the class JndiTemplateTests method testLookupSucceeds.
@Test
public void testLookupSucceeds() throws Exception {
Object o = new Object();
String name = "foo";
final Context context = mock(Context.class);
given(context.lookup(name)).willReturn(o);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
Object o2 = jt.lookup(name);
assertEquals(o, o2);
verify(context).close();
}
Aggregations