|
|
|
@ -16,6 +16,9 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.ejb.access; |
|
|
|
package org.springframework.ejb.access; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.easymock.EasyMock.*; |
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
import java.rmi.ConnectException; |
|
|
|
import java.rmi.ConnectException; |
|
|
|
import java.rmi.RemoteException; |
|
|
|
import java.rmi.RemoteException; |
|
|
|
|
|
|
|
|
|
|
|
@ -25,9 +28,7 @@ import javax.ejb.EJBObject; |
|
|
|
import javax.naming.Context; |
|
|
|
import javax.naming.Context; |
|
|
|
import javax.naming.NamingException; |
|
|
|
import javax.naming.NamingException; |
|
|
|
|
|
|
|
|
|
|
|
import junit.framework.TestCase; |
|
|
|
import org.junit.Test; |
|
|
|
import org.easymock.MockControl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
import org.springframework.jndi.JndiTemplate; |
|
|
|
import org.springframework.jndi.JndiTemplate; |
|
|
|
import org.springframework.remoting.RemoteAccessException; |
|
|
|
import org.springframework.remoting.RemoteAccessException; |
|
|
|
@ -35,35 +36,31 @@ import org.springframework.remoting.RemoteAccessException; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @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) |
|
|
|
String jndiName, RemoteInterface ejbInstance, int createCount, int lookupCount, int closeCount) |
|
|
|
throws Exception { |
|
|
|
throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
MockControl homeControl = MockControl.createControl(SlsbHome.class); |
|
|
|
final SlsbHome mockHome = createMock(SlsbHome.class); |
|
|
|
final SlsbHome mockHome = (SlsbHome) homeControl.getMock(); |
|
|
|
expect(mockHome.create()).andReturn(ejbInstance).times(createCount); |
|
|
|
mockHome.create(); |
|
|
|
replay(mockHome); |
|
|
|
homeControl.setReturnValue(ejbInstance, createCount); |
|
|
|
|
|
|
|
homeControl.replay(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MockControl ctxControl = MockControl.createControl(Context.class); |
|
|
|
final Context mockCtx = createMock(Context.class); |
|
|
|
final Context mockCtx = (Context) ctxControl.getMock(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mockCtx.lookup("java:comp/env/" + jndiName); |
|
|
|
expect(mockCtx.lookup("java:comp/env/" + jndiName)).andReturn(mockHome).times(lookupCount); |
|
|
|
ctxControl.setReturnValue(mockHome, lookupCount); |
|
|
|
|
|
|
|
mockCtx.close(); |
|
|
|
mockCtx.close(); |
|
|
|
ctxControl.setVoidCallable(closeCount); |
|
|
|
expectLastCall().times(closeCount); |
|
|
|
ctxControl.replay(); |
|
|
|
replay(mockCtx); |
|
|
|
|
|
|
|
|
|
|
|
return ctxControl; |
|
|
|
return mockCtx; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private SimpleRemoteSlsbInvokerInterceptor configuredInterceptor( |
|
|
|
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(); |
|
|
|
SimpleRemoteSlsbInvokerInterceptor si = createInterceptor(); |
|
|
|
si.setJndiTemplate(new JndiTemplate() { |
|
|
|
si.setJndiTemplate(new JndiTemplate() { |
|
|
|
protected Context createInitialContext() { |
|
|
|
protected Context createInitialContext() { |
|
|
|
@ -80,7 +77,7 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
return new SimpleRemoteSlsbInvokerInterceptor(); |
|
|
|
return new SimpleRemoteSlsbInvokerInterceptor(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Object configuredProxy(SimpleRemoteSlsbInvokerInterceptor si, Class ifc) throws NamingException { |
|
|
|
protected Object configuredProxy(SimpleRemoteSlsbInvokerInterceptor si, Class<?> ifc) throws NamingException { |
|
|
|
si.afterPropertiesSet(); |
|
|
|
si.afterPropertiesSet(); |
|
|
|
ProxyFactory pf = new ProxyFactory(new Class[] {ifc}); |
|
|
|
ProxyFactory pf = new ProxyFactory(new Class[] {ifc}); |
|
|
|
pf.addAdvice(si); |
|
|
|
pf.addAdvice(si); |
|
|
|
@ -88,38 +85,38 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testPerformsLookup() throws Exception { |
|
|
|
public void testPerformsLookup() throws Exception { |
|
|
|
MockControl ejbControl = MockControl.createControl(RemoteInterface.class); |
|
|
|
RemoteInterface ejb = createMock(RemoteInterface.class); |
|
|
|
RemoteInterface ejb = (RemoteInterface) ejbControl.getMock(); |
|
|
|
replay(ejb); |
|
|
|
ejbControl.replay(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String jndiName= "foobar"; |
|
|
|
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); |
|
|
|
configuredProxy(si, RemoteInterface.class); |
|
|
|
|
|
|
|
|
|
|
|
contextControl.verify(); |
|
|
|
verify(mockContext); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testPerformsLookupWithAccessContext() throws Exception { |
|
|
|
public void testPerformsLookupWithAccessContext() throws Exception { |
|
|
|
MockControl ejbControl = MockControl.createControl(RemoteInterface.class); |
|
|
|
RemoteInterface ejb = createMock(RemoteInterface.class); |
|
|
|
RemoteInterface ejb = (RemoteInterface) ejbControl.getMock(); |
|
|
|
expect(ejb.targetMethod()).andReturn(null); |
|
|
|
ejb.targetMethod(); |
|
|
|
replay(ejb); |
|
|
|
ejbControl.setReturnValue(null); |
|
|
|
|
|
|
|
ejbControl.replay(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String jndiName= "foobar"; |
|
|
|
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); |
|
|
|
si.setExposeAccessContext(true); |
|
|
|
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class); |
|
|
|
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class); |
|
|
|
assertNull(target.targetMethod()); |
|
|
|
assertNull(target.targetMethod()); |
|
|
|
|
|
|
|
|
|
|
|
contextControl.verify(); |
|
|
|
verify(mockContext); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupFailure() throws Exception { |
|
|
|
public void testLookupFailure() throws Exception { |
|
|
|
final NamingException nex = new NamingException(); |
|
|
|
final NamingException nex = new NamingException(); |
|
|
|
final String jndiName = "foobar"; |
|
|
|
final String jndiName = "foobar"; |
|
|
|
@ -144,31 +141,32 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstance() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstance() throws Exception { |
|
|
|
doTestInvokesMethodOnEjbInstance(true, true); |
|
|
|
doTestInvokesMethodOnEjbInstance(true, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithLazyLookup() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithLazyLookup() throws Exception { |
|
|
|
doTestInvokesMethodOnEjbInstance(false, true); |
|
|
|
doTestInvokesMethodOnEjbInstance(false, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithLazyLookupAndNoCache() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithLazyLookupAndNoCache() throws Exception { |
|
|
|
doTestInvokesMethodOnEjbInstance(false, false); |
|
|
|
doTestInvokesMethodOnEjbInstance(false, false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithNoCache() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithNoCache() throws Exception { |
|
|
|
doTestInvokesMethodOnEjbInstance(true, false); |
|
|
|
doTestInvokesMethodOnEjbInstance(true, false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doTestInvokesMethodOnEjbInstance(boolean lookupHomeOnStartup, boolean cacheHome) throws Exception { |
|
|
|
private void doTestInvokesMethodOnEjbInstance(boolean lookupHomeOnStartup, boolean cacheHome) throws Exception { |
|
|
|
Object retVal = new Object(); |
|
|
|
Object retVal = new Object(); |
|
|
|
MockControl ejbControl = MockControl.createControl(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = createMock(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock(); |
|
|
|
expect(ejb.targetMethod()).andReturn(retVal).times(2); |
|
|
|
ejb.targetMethod(); |
|
|
|
|
|
|
|
ejbControl.setReturnValue(retVal, 2); |
|
|
|
|
|
|
|
ejb.remove(); |
|
|
|
ejb.remove(); |
|
|
|
ejbControl.setVoidCallable(2); |
|
|
|
replay(ejb); |
|
|
|
ejbControl.replay(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int lookupCount = 1; |
|
|
|
int lookupCount = 1; |
|
|
|
if (!cacheHome) { |
|
|
|
if (!cacheHome) { |
|
|
|
@ -179,9 +177,9 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final String jndiName= "foobar"; |
|
|
|
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.setLookupHomeOnStartup(lookupHomeOnStartup); |
|
|
|
si.setCacheHome(cacheHome); |
|
|
|
si.setCacheHome(cacheHome); |
|
|
|
|
|
|
|
|
|
|
|
@ -189,46 +187,40 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
assertTrue(target.targetMethod() == retVal); |
|
|
|
assertTrue(target.targetMethod() == retVal); |
|
|
|
assertTrue(target.targetMethod() == retVal); |
|
|
|
assertTrue(target.targetMethod() == retVal); |
|
|
|
|
|
|
|
|
|
|
|
contextControl.verify(); |
|
|
|
verify(mockContext, ejb); |
|
|
|
ejbControl.verify(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithHomeInterface() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithHomeInterface() throws Exception { |
|
|
|
Object retVal = new Object(); |
|
|
|
Object retVal = new Object(); |
|
|
|
MockControl ejbControl = MockControl.createControl(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = createMock(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock(); |
|
|
|
expect(ejb.targetMethod()).andReturn(retVal); |
|
|
|
ejb.targetMethod(); |
|
|
|
|
|
|
|
ejbControl.setReturnValue(retVal, 1); |
|
|
|
|
|
|
|
ejb.remove(); |
|
|
|
ejb.remove(); |
|
|
|
ejbControl.setVoidCallable(1); |
|
|
|
replay(ejb); |
|
|
|
ejbControl.replay(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String jndiName= "foobar"; |
|
|
|
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); |
|
|
|
si.setHomeInterface(SlsbHome.class); |
|
|
|
|
|
|
|
|
|
|
|
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class); |
|
|
|
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class); |
|
|
|
assertTrue(target.targetMethod() == retVal); |
|
|
|
assertTrue(target.targetMethod() == retVal); |
|
|
|
|
|
|
|
|
|
|
|
contextControl.verify(); |
|
|
|
verify(mockContext, ejb); |
|
|
|
ejbControl.verify(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithRemoteException() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithRemoteException() throws Exception { |
|
|
|
MockControl ejbControl = MockControl.createControl(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = createMock(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock(); |
|
|
|
expect(ejb.targetMethod()).andThrow(new RemoteException()); |
|
|
|
ejb.targetMethod(); |
|
|
|
|
|
|
|
ejbControl.setThrowable(new RemoteException(), 1); |
|
|
|
|
|
|
|
ejb.remove(); |
|
|
|
ejb.remove(); |
|
|
|
ejbControl.setVoidCallable(1); |
|
|
|
replay(ejb); |
|
|
|
ejbControl.replay(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String jndiName= "foobar"; |
|
|
|
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); |
|
|
|
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class); |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -239,22 +231,25 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
// expected
|
|
|
|
// expected
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
contextControl.verify(); |
|
|
|
verify(mockContext, ejb); |
|
|
|
ejbControl.verify(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh() throws Exception { |
|
|
|
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(true, true); |
|
|
|
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(true, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndLazyLookup() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndLazyLookup() throws Exception { |
|
|
|
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(false, true); |
|
|
|
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(false, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndLazyLookupAndNoCache() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndLazyLookupAndNoCache() throws Exception { |
|
|
|
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(false, false); |
|
|
|
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(false, false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndNoCache() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndNoCache() throws Exception { |
|
|
|
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(true, false); |
|
|
|
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(true, false); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -262,13 +257,11 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
private void doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh( |
|
|
|
private void doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh( |
|
|
|
boolean lookupHomeOnStartup, boolean cacheHome) throws Exception { |
|
|
|
boolean lookupHomeOnStartup, boolean cacheHome) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
MockControl ejbControl = MockControl.createControl(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = createMock(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock(); |
|
|
|
expect(ejb.targetMethod()).andThrow(new ConnectException("")).times(2); |
|
|
|
ejb.targetMethod(); |
|
|
|
|
|
|
|
ejbControl.setThrowable(new ConnectException(""), 2); |
|
|
|
|
|
|
|
ejb.remove(); |
|
|
|
ejb.remove(); |
|
|
|
ejbControl.setVoidCallable(2); |
|
|
|
expectLastCall().times(2); |
|
|
|
ejbControl.replay(); |
|
|
|
replay(ejb); |
|
|
|
|
|
|
|
|
|
|
|
int lookupCount = 2; |
|
|
|
int lookupCount = 2; |
|
|
|
if (!cacheHome) { |
|
|
|
if (!cacheHome) { |
|
|
|
@ -279,9 +272,9 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final String jndiName= "foobar"; |
|
|
|
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.setRefreshHomeOnConnectFailure(true); |
|
|
|
si.setLookupHomeOnStartup(lookupHomeOnStartup); |
|
|
|
si.setLookupHomeOnStartup(lookupHomeOnStartup); |
|
|
|
si.setCacheHome(cacheHome); |
|
|
|
si.setCacheHome(cacheHome); |
|
|
|
@ -295,45 +288,39 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
// expected
|
|
|
|
// expected
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
contextControl.verify(); |
|
|
|
verify(mockContext, ejb); |
|
|
|
ejbControl.verify(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithBusinessInterface() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithBusinessInterface() throws Exception { |
|
|
|
Object retVal = new Object(); |
|
|
|
Object retVal = new Object(); |
|
|
|
MockControl ejbControl = MockControl.createControl(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = createMock(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock(); |
|
|
|
expect(ejb.targetMethod()).andReturn(retVal); |
|
|
|
ejb.targetMethod(); |
|
|
|
|
|
|
|
ejbControl.setReturnValue(retVal, 1); |
|
|
|
|
|
|
|
ejb.remove(); |
|
|
|
ejb.remove(); |
|
|
|
ejbControl.setVoidCallable(1); |
|
|
|
replay(ejb); |
|
|
|
ejbControl.replay(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String jndiName= "foobar"; |
|
|
|
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); |
|
|
|
BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class); |
|
|
|
assertTrue(target.targetMethod() == retVal); |
|
|
|
assertTrue(target.targetMethod() == retVal); |
|
|
|
|
|
|
|
|
|
|
|
contextControl.verify(); |
|
|
|
verify(mockContext, ejb); |
|
|
|
ejbControl.verify(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException() throws Exception { |
|
|
|
public void testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException() throws Exception { |
|
|
|
MockControl ejbControl = MockControl.createControl(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = createMock(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock(); |
|
|
|
expect(ejb.targetMethod()).andThrow(new RemoteException()); |
|
|
|
ejb.targetMethod(); |
|
|
|
|
|
|
|
ejbControl.setThrowable(new RemoteException(), 1); |
|
|
|
|
|
|
|
ejb.remove(); |
|
|
|
ejb.remove(); |
|
|
|
ejbControl.setVoidCallable(1); |
|
|
|
replay(ejb); |
|
|
|
ejbControl.replay(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String jndiName= "foobar"; |
|
|
|
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); |
|
|
|
BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class); |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -344,31 +331,29 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
// expected
|
|
|
|
// expected
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
contextControl.verify(); |
|
|
|
verify(mockContext, ejb); |
|
|
|
ejbControl.verify(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testApplicationException() throws Exception { |
|
|
|
public void testApplicationException() throws Exception { |
|
|
|
doTestException(new ApplicationException()); |
|
|
|
doTestException(new ApplicationException()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testRemoteException() throws Exception { |
|
|
|
public void testRemoteException() throws Exception { |
|
|
|
doTestException(new RemoteException()); |
|
|
|
doTestException(new RemoteException()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doTestException(Exception expected) throws Exception { |
|
|
|
private void doTestException(Exception expected) throws Exception { |
|
|
|
MockControl ejbControl = MockControl.createControl(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = createMock(RemoteInterface.class); |
|
|
|
final RemoteInterface ejb = (RemoteInterface) ejbControl.getMock(); |
|
|
|
expect(ejb.targetMethod()).andThrow(expected); |
|
|
|
ejb.targetMethod(); |
|
|
|
|
|
|
|
ejbControl.setThrowable(expected); |
|
|
|
|
|
|
|
ejb.remove(); |
|
|
|
ejb.remove(); |
|
|
|
ejbControl.setVoidCallable(1); |
|
|
|
replay(ejb); |
|
|
|
ejbControl.replay(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String jndiName= "foobar"; |
|
|
|
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); |
|
|
|
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class); |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -379,8 +364,7 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
assertTrue(thrown == expected); |
|
|
|
assertTrue(thrown == expected); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
contextControl.verify(); |
|
|
|
verify(mockContext, ejb); |
|
|
|
ejbControl.verify(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -406,7 +390,8 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected class ApplicationException extends Exception { |
|
|
|
@SuppressWarnings("serial") |
|
|
|
|
|
|
|
protected class ApplicationException extends Exception { |
|
|
|
|
|
|
|
|
|
|
|
public ApplicationException() { |
|
|
|
public ApplicationException() { |
|
|
|
super("appException"); |
|
|
|
super("appException"); |