moving .ejb.access unit tests from .testsuite -> .context
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@432 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
dfce78549e
commit
bdd36aa36a
|
|
@ -16,40 +16,43 @@
|
|||
|
||||
package org.springframework.ejb.access;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import javax.ejb.CreateException;
|
||||
import javax.ejb.EJBLocalHome;
|
||||
import javax.ejb.EJBLocalObject;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.jndi.JndiTemplate;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class LocalSlsbInvokerInterceptorTests extends TestCase {
|
||||
public class LocalSlsbInvokerInterceptorTests {
|
||||
|
||||
/**
|
||||
* Test that it performs the correct lookup.
|
||||
*/
|
||||
@Test
|
||||
public void testPerformsLookup() throws Exception {
|
||||
MockControl ejbControl = MockControl.createControl(LocalInterfaceWithBusinessMethods.class);
|
||||
final LocalInterfaceWithBusinessMethods ejb = (LocalInterfaceWithBusinessMethods) ejbControl.getMock();
|
||||
ejbControl.replay();
|
||||
LocalInterfaceWithBusinessMethods ejb = createMock(LocalInterfaceWithBusinessMethods.class);
|
||||
replay(ejb);
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb);
|
||||
String jndiName= "foobar";
|
||||
Context mockContext = mockContext(jndiName, ejb);
|
||||
|
||||
LocalSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
configuredInterceptor(mockContext, jndiName);
|
||||
|
||||
contextControl.verify();
|
||||
verify(mockContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupFailure() throws Exception {
|
||||
final NamingException nex = new NamingException();
|
||||
final String jndiName= "foobar";
|
||||
|
|
@ -74,20 +77,18 @@ public class LocalSlsbInvokerInterceptorTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstance() throws Exception {
|
||||
Object retVal = new Object();
|
||||
MockControl ejbControl = MockControl.createControl(LocalInterfaceWithBusinessMethods.class);
|
||||
final LocalInterfaceWithBusinessMethods ejb = (LocalInterfaceWithBusinessMethods) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setReturnValue(retVal, 1);
|
||||
LocalInterfaceWithBusinessMethods ejb = createMock(LocalInterfaceWithBusinessMethods.class);
|
||||
expect(ejb.targetMethod()).andReturn(retVal);
|
||||
ejb.remove();
|
||||
ejbControl.setVoidCallable(1);
|
||||
ejbControl.replay();
|
||||
replay(ejb);
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb);
|
||||
String jndiName= "foobar";
|
||||
Context mockContext = mockContext(jndiName, ejb);
|
||||
|
||||
LocalSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
|
||||
ProxyFactory pf = new ProxyFactory(new Class[] { BusinessMethods.class } );
|
||||
pf.addAdvice(si);
|
||||
|
|
@ -95,24 +96,22 @@ public class LocalSlsbInvokerInterceptorTests extends TestCase {
|
|||
|
||||
assertTrue(target.targetMethod() == retVal);
|
||||
|
||||
contextControl.verify();
|
||||
ejbControl.verify();
|
||||
verify(mockContext);
|
||||
verify(ejb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithSeparateBusinessMethods() throws Exception {
|
||||
Object retVal = new Object();
|
||||
MockControl ejbControl = MockControl.createControl(LocalInterface.class);
|
||||
final LocalInterface ejb = (LocalInterface) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setReturnValue(retVal, 1);
|
||||
LocalInterface ejb = createMock(LocalInterface.class);
|
||||
expect(ejb.targetMethod()).andReturn(retVal);
|
||||
ejb.remove();
|
||||
ejbControl.setVoidCallable(1);
|
||||
ejbControl.replay();
|
||||
replay(ejb);
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb);
|
||||
String jndiName= "foobar";
|
||||
Context mockContext = mockContext(jndiName, ejb);
|
||||
|
||||
LocalSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
|
||||
ProxyFactory pf = new ProxyFactory(new Class[] { BusinessMethods.class } );
|
||||
pf.addAdvice(si);
|
||||
|
|
@ -120,21 +119,19 @@ public class LocalSlsbInvokerInterceptorTests extends TestCase {
|
|||
|
||||
assertTrue(target.targetMethod() == retVal);
|
||||
|
||||
contextControl.verify();
|
||||
ejbControl.verify();
|
||||
verify(mockContext);
|
||||
verify(ejb);
|
||||
}
|
||||
|
||||
private void testException(Exception expected) throws Exception {
|
||||
MockControl ejbControl = MockControl.createControl(LocalInterfaceWithBusinessMethods.class);
|
||||
final LocalInterfaceWithBusinessMethods ejb = (LocalInterfaceWithBusinessMethods) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setThrowable(expected);
|
||||
ejbControl.replay();
|
||||
LocalInterfaceWithBusinessMethods ejb = createMock(LocalInterfaceWithBusinessMethods.class);
|
||||
expect(ejb.targetMethod()).andThrow(expected);
|
||||
replay(ejb);
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb);
|
||||
String jndiName= "foobar";
|
||||
Context mockContext = mockContext(jndiName, ejb);
|
||||
|
||||
LocalSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
|
||||
ProxyFactory pf = new ProxyFactory(new Class[] { LocalInterfaceWithBusinessMethods.class } );
|
||||
pf.addAdvice(si);
|
||||
|
|
@ -148,38 +145,33 @@ public class LocalSlsbInvokerInterceptorTests extends TestCase {
|
|||
assertTrue(thrown == expected);
|
||||
}
|
||||
|
||||
contextControl.verify();
|
||||
ejbControl.verify();
|
||||
verify(mockContext);
|
||||
verify(ejb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplicationException() throws Exception {
|
||||
testException(new ApplicationException());
|
||||
}
|
||||
|
||||
protected MockControl contextControl(final String jndiName, final Object ejbInstance)
|
||||
protected Context mockContext(final String jndiName, final Object ejbInstance)
|
||||
throws Exception {
|
||||
|
||||
MockControl homeControl = MockControl.createControl(SlsbHome.class);
|
||||
final SlsbHome mockHome = (SlsbHome) homeControl.getMock();
|
||||
mockHome.create();
|
||||
homeControl.setReturnValue(ejbInstance, 1);
|
||||
homeControl.replay();
|
||||
final SlsbHome mockHome = createMock(SlsbHome.class);
|
||||
expect(mockHome.create()).andReturn((LocalInterface)ejbInstance);
|
||||
replay(mockHome);
|
||||
|
||||
MockControl ctxControl = MockControl.createControl(Context.class);
|
||||
final Context mockCtx = (Context) ctxControl.getMock();
|
||||
final Context mockCtx = createMock(Context.class);
|
||||
|
||||
mockCtx.lookup("java:comp/env/" + jndiName);
|
||||
ctxControl.setReturnValue(mockHome);
|
||||
expect(mockCtx.lookup("java:comp/env/" + jndiName)).andReturn(mockHome);
|
||||
mockCtx.close();
|
||||
ctxControl.setVoidCallable();
|
||||
ctxControl.replay();
|
||||
return ctxControl;
|
||||
replay(mockCtx);
|
||||
return mockCtx;
|
||||
}
|
||||
|
||||
protected LocalSlsbInvokerInterceptor configuredInterceptor(MockControl contextControl, final String jndiName)
|
||||
protected LocalSlsbInvokerInterceptor configuredInterceptor(final Context mockCtx, final String jndiName)
|
||||
throws Exception {
|
||||
|
||||
final Context mockCtx = (Context) contextControl.getMock();
|
||||
LocalSlsbInvokerInterceptor si = new LocalSlsbInvokerInterceptor();
|
||||
si.setJndiTemplate(new JndiTemplate() {
|
||||
protected Context createInitialContext() throws NamingException {
|
||||
|
|
@ -219,6 +211,7 @@ public class LocalSlsbInvokerInterceptorTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class ApplicationException extends Exception {
|
||||
|
||||
public ApplicationException() {
|
||||
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.springframework.ejb.access;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import javax.ejb.CreateException;
|
||||
|
|
@ -23,35 +26,30 @@ import javax.ejb.EJBLocalHome;
|
|||
import javax.ejb.EJBLocalObject;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.jndi.JndiTemplate;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 21.05.2003
|
||||
*/
|
||||
public class LocalStatelessSessionProxyFactoryBeanTests extends TestCase {
|
||||
public class LocalStatelessSessionProxyFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testInvokesMethod() throws Exception {
|
||||
final int value = 11;
|
||||
final String jndiName = "foo";
|
||||
|
||||
MockControl ec = MockControl.createControl(MyEjb.class);
|
||||
MyEjb myEjb = (MyEjb) ec.getMock();
|
||||
myEjb.getValue();
|
||||
ec.setReturnValue(value, 1);
|
||||
MyEjb myEjb = createMock(MyEjb.class);
|
||||
expect(myEjb.getValue()).andReturn(value);
|
||||
myEjb.remove();
|
||||
ec.setVoidCallable(1);
|
||||
ec.replay();
|
||||
replay(myEjb);
|
||||
|
||||
MockControl mc = MockControl.createControl(MyHome.class);
|
||||
final MyHome home = (MyHome) mc.getMock();
|
||||
home.create();
|
||||
mc.setReturnValue(myEjb, 1);
|
||||
mc.replay();
|
||||
final MyHome home = createMock(MyHome.class);
|
||||
expect(home.create()).andReturn(myEjb);
|
||||
replay(home);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
public Object lookup(String name) throws NamingException {
|
||||
|
|
@ -73,19 +71,18 @@ public class LocalStatelessSessionProxyFactoryBeanTests extends TestCase {
|
|||
MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
|
||||
assertTrue(Proxy.isProxyClass(mbm.getClass()));
|
||||
assertTrue(mbm.getValue() == value);
|
||||
mc.verify();
|
||||
ec.verify();
|
||||
verify(myEjb);
|
||||
verify(home);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjb3StyleBean() throws Exception {
|
||||
final int value = 11;
|
||||
final String jndiName = "foo";
|
||||
|
||||
MockControl ec = MockControl.createControl(MyEjb.class);
|
||||
final MyEjb myEjb = (MyEjb) ec.getMock();
|
||||
myEjb.getValue();
|
||||
ec.setReturnValue(value, 1);
|
||||
ec.replay();
|
||||
final MyEjb myEjb = createMock(MyEjb.class);
|
||||
expect(myEjb.getValue()).andReturn(value);
|
||||
replay(myEjb);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
public Object lookup(String name) throws NamingException {
|
||||
|
|
@ -107,18 +104,17 @@ public class LocalStatelessSessionProxyFactoryBeanTests extends TestCase {
|
|||
MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
|
||||
assertTrue(Proxy.isProxyClass(mbm.getClass()));
|
||||
assertTrue(mbm.getValue() == value);
|
||||
ec.verify();
|
||||
verify(myEjb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateException() throws Exception {
|
||||
final String jndiName = "foo";
|
||||
|
||||
final CreateException cex = new CreateException();
|
||||
MockControl mc = MockControl.createControl(MyHome.class);
|
||||
final MyHome home = (MyHome) mc.getMock();
|
||||
home.create();
|
||||
mc.setThrowable(cex);
|
||||
mc.replay();
|
||||
final MyHome home = createMock(MyHome.class);
|
||||
expect(home.create()).andThrow(cex);
|
||||
replay(home);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
public Object lookup(String name) throws NamingException {
|
||||
|
|
@ -149,17 +145,17 @@ public class LocalStatelessSessionProxyFactoryBeanTests extends TestCase {
|
|||
assertSame(cex, ex.getCause());
|
||||
}
|
||||
|
||||
mc.verify();
|
||||
verify(home);
|
||||
}
|
||||
|
||||
@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";
|
||||
|
||||
MockControl mc = MockControl.createControl(MyHome.class);
|
||||
final MyHome home = (MyHome) mc.getMock();
|
||||
mc.replay();
|
||||
final MyHome home = createMock(MyHome.class);
|
||||
replay(home);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
public Object lookup(String name) throws NamingException {
|
||||
|
|
@ -188,7 +184,7 @@ public class LocalStatelessSessionProxyFactoryBeanTests extends TestCase {
|
|||
}
|
||||
|
||||
// Expect no methods on home
|
||||
mc.verify();
|
||||
verify(home);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.springframework.ejb.access;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.rmi.ConnectException;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
|
|
@ -25,9 +28,7 @@ import javax.ejb.EJBObject;
|
|||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.jndi.JndiTemplate;
|
||||
import org.springframework.remoting.RemoteAccessException;
|
||||
|
|
@ -35,35 +36,31 @@ import org.springframework.remoting.RemoteAccessException;
|
|||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
||||
public class SimpleRemoteSlsbInvokerInterceptorTests {
|
||||
|
||||
private MockControl contextControl(
|
||||
private Context mockContext(
|
||||
String jndiName, RemoteInterface ejbInstance, int createCount, int lookupCount, int closeCount)
|
||||
throws Exception {
|
||||
|
||||
MockControl homeControl = MockControl.createControl(SlsbHome.class);
|
||||
final SlsbHome mockHome = (SlsbHome) homeControl.getMock();
|
||||
mockHome.create();
|
||||
homeControl.setReturnValue(ejbInstance, createCount);
|
||||
homeControl.replay();
|
||||
final SlsbHome mockHome = createMock(SlsbHome.class);
|
||||
expect(mockHome.create()).andReturn(ejbInstance).times(createCount);
|
||||
replay(mockHome);
|
||||
|
||||
MockControl ctxControl = MockControl.createControl(Context.class);
|
||||
final Context mockCtx = (Context) ctxControl.getMock();
|
||||
final Context mockCtx = createMock(Context.class);
|
||||
|
||||
mockCtx.lookup("java:comp/env/" + jndiName);
|
||||
ctxControl.setReturnValue(mockHome, lookupCount);
|
||||
expect(mockCtx.lookup("java:comp/env/" + jndiName)).andReturn(mockHome).times(lookupCount);
|
||||
mockCtx.close();
|
||||
ctxControl.setVoidCallable(closeCount);
|
||||
ctxControl.replay();
|
||||
expectLastCall().times(closeCount);
|
||||
replay(mockCtx);
|
||||
|
||||
return ctxControl;
|
||||
return mockCtx;
|
||||
}
|
||||
|
||||
private SimpleRemoteSlsbInvokerInterceptor configuredInterceptor(
|
||||
MockControl ctxControl, String jndiName) throws Exception {
|
||||
final Context mockCtx, String jndiName) throws Exception {
|
||||
|
||||
final Context mockCtx = (Context) ctxControl.getMock();
|
||||
SimpleRemoteSlsbInvokerInterceptor si = createInterceptor();
|
||||
si.setJndiTemplate(new JndiTemplate() {
|
||||
protected Context createInitialContext() {
|
||||
|
|
@ -80,7 +77,7 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
return new SimpleRemoteSlsbInvokerInterceptor();
|
||||
}
|
||||
|
||||
protected Object configuredProxy(SimpleRemoteSlsbInvokerInterceptor si, Class ifc) throws NamingException {
|
||||
protected Object configuredProxy(SimpleRemoteSlsbInvokerInterceptor si, Class<?> ifc) throws NamingException {
|
||||
si.afterPropertiesSet();
|
||||
ProxyFactory pf = new ProxyFactory(new Class[] {ifc});
|
||||
pf.addAdvice(si);
|
||||
|
|
@ -88,38 +85,38 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPerformsLookup() throws Exception {
|
||||
MockControl ejbControl = MockControl.createControl(RemoteInterface.class);
|
||||
RemoteInterface ejb = (RemoteInterface) ejbControl.getMock();
|
||||
ejbControl.replay();
|
||||
RemoteInterface ejb = createMock(RemoteInterface.class);
|
||||
replay(ejb);
|
||||
|
||||
String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb, 1, 1, 1);
|
||||
Context mockContext = mockContext(jndiName, ejb, 1, 1, 1);
|
||||
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
configuredProxy(si, RemoteInterface.class);
|
||||
|
||||
contextControl.verify();
|
||||
verify(mockContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerformsLookupWithAccessContext() throws Exception {
|
||||
MockControl ejbControl = MockControl.createControl(RemoteInterface.class);
|
||||
RemoteInterface ejb = (RemoteInterface) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setReturnValue(null);
|
||||
ejbControl.replay();
|
||||
RemoteInterface ejb = createMock(RemoteInterface.class);
|
||||
expect(ejb.targetMethod()).andReturn(null);
|
||||
replay(ejb);
|
||||
|
||||
String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb, 1, 1, 2);
|
||||
Context mockContext = mockContext(jndiName, ejb, 1, 1, 2);
|
||||
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
si.setExposeAccessContext(true);
|
||||
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
|
||||
assertNull(target.targetMethod());
|
||||
|
||||
contextControl.verify();
|
||||
verify(mockContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupFailure() throws Exception {
|
||||
final NamingException nex = new NamingException();
|
||||
final String jndiName = "foobar";
|
||||
|
|
@ -144,31 +141,32 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstance() throws Exception {
|
||||
doTestInvokesMethodOnEjbInstance(true, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithLazyLookup() throws Exception {
|
||||
doTestInvokesMethodOnEjbInstance(false, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithLazyLookupAndNoCache() throws Exception {
|
||||
doTestInvokesMethodOnEjbInstance(false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithNoCache() throws Exception {
|
||||
doTestInvokesMethodOnEjbInstance(true, false);
|
||||
}
|
||||
|
||||
private void doTestInvokesMethodOnEjbInstance(boolean lookupHomeOnStartup, boolean cacheHome) throws Exception {
|
||||
Object retVal = new Object();
|
||||
MockControl ejbControl = MockControl.createControl(RemoteInterface.class);
|
||||
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setReturnValue(retVal, 2);
|
||||
final RemoteInterface ejb = createMock(RemoteInterface.class);
|
||||
expect(ejb.targetMethod()).andReturn(retVal).times(2);
|
||||
ejb.remove();
|
||||
ejbControl.setVoidCallable(2);
|
||||
ejbControl.replay();
|
||||
replay(ejb);
|
||||
|
||||
int lookupCount = 1;
|
||||
if (!cacheHome) {
|
||||
|
|
@ -179,9 +177,9 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
}
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb, 2, lookupCount, lookupCount);
|
||||
Context mockContext = mockContext(jndiName, ejb, 2, lookupCount, lookupCount);
|
||||
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
si.setLookupHomeOnStartup(lookupHomeOnStartup);
|
||||
si.setCacheHome(cacheHome);
|
||||
|
||||
|
|
@ -189,46 +187,40 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
assertTrue(target.targetMethod() == retVal);
|
||||
assertTrue(target.targetMethod() == retVal);
|
||||
|
||||
contextControl.verify();
|
||||
ejbControl.verify();
|
||||
verify(mockContext, ejb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithHomeInterface() throws Exception {
|
||||
Object retVal = new Object();
|
||||
MockControl ejbControl = MockControl.createControl(RemoteInterface.class);
|
||||
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setReturnValue(retVal, 1);
|
||||
final RemoteInterface ejb = createMock(RemoteInterface.class);
|
||||
expect(ejb.targetMethod()).andReturn(retVal);
|
||||
ejb.remove();
|
||||
ejbControl.setVoidCallable(1);
|
||||
ejbControl.replay();
|
||||
replay(ejb);
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb, 1, 1, 1);
|
||||
Context mockContext = mockContext(jndiName, ejb, 1, 1, 1);
|
||||
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
si.setHomeInterface(SlsbHome.class);
|
||||
|
||||
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
|
||||
assertTrue(target.targetMethod() == retVal);
|
||||
|
||||
contextControl.verify();
|
||||
ejbControl.verify();
|
||||
verify(mockContext, ejb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithRemoteException() throws Exception {
|
||||
MockControl ejbControl = MockControl.createControl(RemoteInterface.class);
|
||||
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setThrowable(new RemoteException(), 1);
|
||||
final RemoteInterface ejb = createMock(RemoteInterface.class);
|
||||
expect(ejb.targetMethod()).andThrow(new RemoteException());
|
||||
ejb.remove();
|
||||
ejbControl.setVoidCallable(1);
|
||||
ejbControl.replay();
|
||||
replay(ejb);
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb, 1, 1, 1);
|
||||
Context mockContext = mockContext(jndiName, ejb, 1, 1, 1);
|
||||
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
|
||||
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
|
||||
try {
|
||||
|
|
@ -239,22 +231,25 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
// expected
|
||||
}
|
||||
|
||||
contextControl.verify();
|
||||
ejbControl.verify();
|
||||
verify(mockContext, ejb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh() throws Exception {
|
||||
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(true, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndLazyLookup() throws Exception {
|
||||
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(false, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndLazyLookupAndNoCache() throws Exception {
|
||||
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndNoCache() throws Exception {
|
||||
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(true, false);
|
||||
}
|
||||
|
|
@ -262,13 +257,11 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
private void doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(
|
||||
boolean lookupHomeOnStartup, boolean cacheHome) throws Exception {
|
||||
|
||||
MockControl ejbControl = MockControl.createControl(RemoteInterface.class);
|
||||
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setThrowable(new ConnectException(""), 2);
|
||||
final RemoteInterface ejb = createMock(RemoteInterface.class);
|
||||
expect(ejb.targetMethod()).andThrow(new ConnectException("")).times(2);
|
||||
ejb.remove();
|
||||
ejbControl.setVoidCallable(2);
|
||||
ejbControl.replay();
|
||||
expectLastCall().times(2);
|
||||
replay(ejb);
|
||||
|
||||
int lookupCount = 2;
|
||||
if (!cacheHome) {
|
||||
|
|
@ -279,9 +272,9 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
}
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb, 2, lookupCount, lookupCount);
|
||||
Context mockContext = mockContext(jndiName, ejb, 2, lookupCount, lookupCount);
|
||||
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
si.setRefreshHomeOnConnectFailure(true);
|
||||
si.setLookupHomeOnStartup(lookupHomeOnStartup);
|
||||
si.setCacheHome(cacheHome);
|
||||
|
|
@ -295,45 +288,39 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
// expected
|
||||
}
|
||||
|
||||
contextControl.verify();
|
||||
ejbControl.verify();
|
||||
verify(mockContext, ejb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithBusinessInterface() throws Exception {
|
||||
Object retVal = new Object();
|
||||
MockControl ejbControl = MockControl.createControl(RemoteInterface.class);
|
||||
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setReturnValue(retVal, 1);
|
||||
final RemoteInterface ejb = createMock(RemoteInterface.class);
|
||||
expect(ejb.targetMethod()).andReturn(retVal);
|
||||
ejb.remove();
|
||||
ejbControl.setVoidCallable(1);
|
||||
ejbControl.replay();
|
||||
replay(ejb);
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb, 1, 1, 1);
|
||||
Context mockContext = mockContext(jndiName, ejb, 1, 1, 1);
|
||||
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
|
||||
BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class);
|
||||
assertTrue(target.targetMethod() == retVal);
|
||||
|
||||
contextControl.verify();
|
||||
ejbControl.verify();
|
||||
verify(mockContext, ejb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException() throws Exception {
|
||||
MockControl ejbControl = MockControl.createControl(RemoteInterface.class);
|
||||
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setThrowable(new RemoteException(), 1);
|
||||
final RemoteInterface ejb = createMock(RemoteInterface.class);
|
||||
expect(ejb.targetMethod()).andThrow(new RemoteException());
|
||||
ejb.remove();
|
||||
ejbControl.setVoidCallable(1);
|
||||
ejbControl.replay();
|
||||
replay(ejb);
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb, 1, 1, 1);
|
||||
Context mockContext = mockContext(jndiName, ejb, 1, 1, 1);
|
||||
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
|
||||
BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class);
|
||||
try {
|
||||
|
|
@ -344,31 +331,29 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
// expected
|
||||
}
|
||||
|
||||
contextControl.verify();
|
||||
ejbControl.verify();
|
||||
verify(mockContext, ejb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplicationException() throws Exception {
|
||||
doTestException(new ApplicationException());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteException() throws Exception {
|
||||
doTestException(new RemoteException());
|
||||
}
|
||||
|
||||
private void doTestException(Exception expected) throws Exception {
|
||||
MockControl ejbControl = MockControl.createControl(RemoteInterface.class);
|
||||
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock();
|
||||
ejb.targetMethod();
|
||||
ejbControl.setThrowable(expected);
|
||||
final RemoteInterface ejb = createMock(RemoteInterface.class);
|
||||
expect(ejb.targetMethod()).andThrow(expected);
|
||||
ejb.remove();
|
||||
ejbControl.setVoidCallable(1);
|
||||
ejbControl.replay();
|
||||
replay(ejb);
|
||||
|
||||
final String jndiName= "foobar";
|
||||
MockControl contextControl = contextControl(jndiName, ejb, 1, 1, 1);
|
||||
Context mockContext = mockContext(jndiName, ejb, 1, 1, 1);
|
||||
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(contextControl, jndiName);
|
||||
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
|
||||
|
||||
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
|
||||
try {
|
||||
|
|
@ -379,8 +364,7 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
assertTrue(thrown == expected);
|
||||
}
|
||||
|
||||
contextControl.verify();
|
||||
ejbControl.verify();
|
||||
verify(mockContext, ejb);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -406,6 +390,7 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
protected class ApplicationException extends Exception {
|
||||
|
||||
public ApplicationException() {
|
||||
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.springframework.ejb.access;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
|
|
@ -24,8 +27,7 @@ import javax.ejb.EJBHome;
|
|||
import javax.ejb.EJBObject;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.jndi.JndiTemplate;
|
||||
import org.springframework.remoting.RemoteAccessException;
|
||||
|
||||
|
|
@ -40,30 +42,26 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
|
|||
return new SimpleRemoteStatelessSessionProxyFactoryBean();
|
||||
}
|
||||
|
||||
protected Object configuredProxy(SimpleRemoteSlsbInvokerInterceptor si, Class ifc) throws NamingException {
|
||||
protected Object configuredProxy(SimpleRemoteSlsbInvokerInterceptor si, Class<?> ifc) throws NamingException {
|
||||
SimpleRemoteStatelessSessionProxyFactoryBean fb = (SimpleRemoteStatelessSessionProxyFactoryBean) si;
|
||||
fb.setBusinessInterface(ifc);
|
||||
fb.afterPropertiesSet();
|
||||
return fb.getObject();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethod() throws Exception {
|
||||
final int value = 11;
|
||||
final String jndiName = "foo";
|
||||
|
||||
MockControl ec = MockControl.createControl(MyEjb.class);
|
||||
MyEjb myEjb = (MyEjb) ec.getMock();
|
||||
myEjb.getValue();
|
||||
ec.setReturnValue(value, 1);
|
||||
MyEjb myEjb = createMock(MyEjb.class);
|
||||
expect(myEjb.getValue()).andReturn(value);
|
||||
myEjb.remove();
|
||||
ec.setVoidCallable(1);
|
||||
ec.replay();
|
||||
replay(myEjb);
|
||||
|
||||
MockControl mc = MockControl.createControl(MyHome.class);
|
||||
final MyHome home = (MyHome) mc.getMock();
|
||||
home.create();
|
||||
mc.setReturnValue(myEjb, 1);
|
||||
mc.replay();
|
||||
final MyHome home = createMock(MyHome.class);
|
||||
expect(home.create()).andReturn(myEjb);
|
||||
replay(home);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
public Object lookup(String name) {
|
||||
|
|
@ -85,19 +83,18 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
|
|||
MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
|
||||
assertTrue(Proxy.isProxyClass(mbm.getClass()));
|
||||
assertEquals("Returns expected value", value, mbm.getValue());
|
||||
mc.verify();
|
||||
ec.verify();
|
||||
verify(myEjb);
|
||||
verify(home);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokesMethodOnEjb3StyleBean() throws Exception {
|
||||
final int value = 11;
|
||||
final String jndiName = "foo";
|
||||
|
||||
MockControl ec = MockControl.createControl(MyEjb.class);
|
||||
final MyEjb myEjb = (MyEjb) ec.getMock();
|
||||
myEjb.getValue();
|
||||
ec.setReturnValue(value, 1);
|
||||
ec.replay();
|
||||
final MyEjb myEjb = createMock(MyEjb.class);
|
||||
expect(myEjb.getValue()).andReturn(value);
|
||||
replay(myEjb);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
public Object lookup(String name) {
|
||||
|
|
@ -119,28 +116,24 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
|
|||
MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
|
||||
assertTrue(Proxy.isProxyClass(mbm.getClass()));
|
||||
assertEquals("Returns expected value", value, mbm.getValue());
|
||||
ec.verify();
|
||||
verify(myEjb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteException() throws Exception {
|
||||
final RemoteException rex = new RemoteException();
|
||||
final String jndiName = "foo";
|
||||
|
||||
MockControl ec = MockControl.createControl(MyEjb.class);
|
||||
MyEjb myEjb = (MyEjb) ec.getMock();
|
||||
myEjb.getValue();
|
||||
ec.setThrowable(rex);
|
||||
MyEjb myEjb = createMock(MyEjb.class);
|
||||
expect(myEjb.getValue()).andThrow(rex);
|
||||
// TODO might want to control this behaviour...
|
||||
// Do we really want to call remove after a remote exception?
|
||||
myEjb.remove();
|
||||
ec.setVoidCallable(1);
|
||||
ec.replay();
|
||||
replay(myEjb);
|
||||
|
||||
MockControl mc = MockControl.createControl(MyHome.class);
|
||||
final MyHome home = (MyHome) mc.getMock();
|
||||
home.create();
|
||||
mc.setReturnValue(myEjb, 1);
|
||||
mc.replay();
|
||||
final MyHome home = createMock(MyHome.class);
|
||||
expect(home.create()).andReturn(myEjb);
|
||||
replay(home);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
public Object lookup(String name) {
|
||||
|
|
@ -168,19 +161,18 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
|
|||
catch (RemoteException ex) {
|
||||
assertSame("Threw expected RemoteException", rex, ex);
|
||||
}
|
||||
mc.verify();
|
||||
ec.verify();
|
||||
verify(myEjb);
|
||||
verify(home);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateException() throws Exception {
|
||||
final String jndiName = "foo";
|
||||
|
||||
final CreateException cex = new CreateException();
|
||||
MockControl mc = MockControl.createControl(MyHome.class);
|
||||
final MyHome home = (MyHome) mc.getMock();
|
||||
home.create();
|
||||
mc.setThrowable(cex);
|
||||
mc.replay();
|
||||
final MyHome home = createMock(MyHome.class);
|
||||
expect(home.create()).andThrow(cex);
|
||||
replay(home);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
public Object lookup(String name) {
|
||||
|
|
@ -211,18 +203,17 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
|
|||
// expected
|
||||
}
|
||||
|
||||
mc.verify();
|
||||
verify(home);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateExceptionWithLocalBusinessInterface() throws Exception {
|
||||
final String jndiName = "foo";
|
||||
|
||||
final CreateException cex = new CreateException();
|
||||
MockControl mc = MockControl.createControl(MyHome.class);
|
||||
final MyHome home = (MyHome) mc.getMock();
|
||||
home.create();
|
||||
mc.setThrowable(cex);
|
||||
mc.replay();
|
||||
final MyHome home = createMock(MyHome.class);
|
||||
expect(home.create()).andThrow(cex);
|
||||
replay(home);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
public Object lookup(String name) {
|
||||
|
|
@ -253,17 +244,17 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
|
|||
assertTrue(ex.getCause() == cex);
|
||||
}
|
||||
|
||||
mc.verify();
|
||||
verify(home);
|
||||
}
|
||||
|
||||
@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";
|
||||
|
||||
MockControl mc = MockControl.createControl(MyHome.class);
|
||||
final MyHome home = (MyHome) mc.getMock();
|
||||
mc.replay();
|
||||
final MyHome home = createMock(MyHome.class);
|
||||
replay(home);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
public Object lookup(String name) throws NamingException {
|
||||
|
|
@ -292,7 +283,7 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
|
|||
}
|
||||
|
||||
// Expect no methods on home
|
||||
mc.verify();
|
||||
verify(home);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue