moving unit tests from .testsuite -> .aop

This commit is contained in:
Chris Beams 2008-12-12 18:08:15 +00:00
parent c563f97b90
commit 3c0015c1ec
6 changed files with 35 additions and 57 deletions

View File

@ -68,6 +68,7 @@ import org.springframework.util.StopWatch;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams
* @since 13.03.2003 * @since 13.03.2003
*/ */
public abstract class AbstractAopProxyTests { public abstract class AbstractAopProxyTests {
@ -800,7 +801,8 @@ public abstract class AbstractAopProxyTests {
target.setAge(21); target.setAge(21);
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped { @SuppressWarnings("serial")
class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped {
/** /**
* @see org.springframework.aop.framework.TimeStamped#getTimeStamp() * @see org.springframework.aop.framework.TimeStamped#getTimeStamp()
*/ */

View File

@ -16,6 +16,7 @@
package org.springframework.aop.framework; package org.springframework.aop.framework;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.Serializable; import java.io.Serializable;
@ -43,6 +44,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Rob Harrop * @author Rob Harrop
* @author Ramnivas Laddad * @author Ramnivas Laddad
* @author Chris Beams
*/ */
public class CglibProxyTests extends AbstractAopProxyTests { public class CglibProxyTests extends AbstractAopProxyTests {
@ -65,7 +67,7 @@ public class CglibProxyTests extends AbstractAopProxyTests {
@Test @Test
public void testNullConfig() { public void testNullConfig() {
try { try {
AopProxy aop = new Cglib2AopProxy(null); new Cglib2AopProxy(null);
fail("Shouldn't allow null interceptors"); fail("Shouldn't allow null interceptors");
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex) {
@ -276,7 +278,7 @@ public class CglibProxyTests extends AbstractAopProxyTests {
as.addAdvice(new NopInterceptor()); as.addAdvice(new NopInterceptor());
cglib = new Cglib2AopProxy(as); cglib = new Cglib2AopProxy(as);
ITestBean proxy2 = (ITestBean) cglib.getProxy(); assertThat(cglib.getProxy(), instanceOf(ITestBean.class));
} }
@Test @Test

View File

@ -16,11 +16,14 @@
package org.springframework.aop.framework; package org.springframework.aop.framework;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.easymock.MockControl;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor; import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
@ -31,6 +34,7 @@ import org.springframework.beans.TestBean;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams
* @since 13.03.2003 * @since 13.03.2003
*/ */
public class JdkDynamicProxyTests extends AbstractAopProxyTests { public class JdkDynamicProxyTests extends AbstractAopProxyTests {
@ -48,7 +52,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests {
public void testNullConfig() { public void testNullConfig() {
try { try {
JdkDynamicAopProxy aop = new JdkDynamicAopProxy(null); new JdkDynamicAopProxy(null);
fail("Shouldn't allow null interceptors"); fail("Shouldn't allow null interceptors");
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex) {
@ -71,27 +75,18 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests {
public void testInterceptorIsInvokedWithNoTarget() throws Throwable { public void testInterceptorIsInvokedWithNoTarget() throws Throwable {
// Test return value // Test return value
int age = 25; int age = 25;
MockControl miControl = MockControl.createControl(MethodInterceptor.class); MethodInterceptor mi = createMock(MethodInterceptor.class);
MethodInterceptor mi = (MethodInterceptor) miControl.getMock();
AdvisedSupport pc = new AdvisedSupport(new Class[] { ITestBean.class }); AdvisedSupport pc = new AdvisedSupport(new Class[] { ITestBean.class });
pc.addAdvice(mi); pc.addAdvice(mi);
AopProxy aop = createAopProxy(pc); AopProxy aop = createAopProxy(pc);
// Really would like to permit null arg:can't get exact mi expect(mi.invoke(null)).andReturn(age);
mi.invoke(null); replay(mi);
//mi.invoke(new MethodInvocationImpl(aop, null, ITestBean.class,
// ITestBean.class.getMethod("getAge", null),
// null, l, r));
//miControl.
//miControl.setReturnValue(new Integer(age));
// Have disabled strong argument checking
miControl.setDefaultReturnValue(new Integer(age));
miControl.replay();
ITestBean tb = (ITestBean) aop.getProxy(); ITestBean tb = (ITestBean) aop.getProxy();
assertTrue("correct return value", tb.getAge() == age); assertTrue("correct return value", tb.getAge() == age);
miControl.verify(); verify(mi);
} }
public void testTargetCanGetInvocationWithPrivateClass() throws Throwable { public void testTargetCanGetInvocationWithPrivateClass() throws Throwable {

View File

@ -16,18 +16,18 @@
package org.springframework.aop.framework; package org.springframework.aop.framework;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import javax.servlet.ServletException;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.aopalliance.aop.Advice; import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.ClassFilter; import org.springframework.aop.ClassFilter;
import org.springframework.aop.IntroductionAdvisor; import org.springframework.aop.IntroductionAdvisor;
import org.springframework.aop.IntroductionInterceptor; import org.springframework.aop.IntroductionInterceptor;
@ -425,16 +425,16 @@ public class ProxyFactoryBeanTests extends TestCase {
assertEquals(0, th.getCalls()); assertEquals(0, th.getCalls());
// Handler knows how to handle this exception // Handler knows how to handle this exception
expected = new ServletException(); expected = new FileNotFoundException();
try { try {
echo.echoException(1, expected); echo.echoException(1, expected);
fail(); fail();
} }
catch (ServletException ex) { catch (IOException ex) {
assertEquals(expected, ex); assertEquals(expected, ex);
} }
// One match // One match
assertEquals(1, th.getCalls("servletException")); assertEquals(1, th.getCalls("ioException"));
} }
// These two fail the whole bean factory // These two fail the whole bean factory

View File

@ -16,10 +16,10 @@
package org.springframework.aop.framework.adapter; package org.springframework.aop.framework.adapter;
import junit.framework.*; import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.aop.*; import org.springframework.aop.*;
import org.springframework.aop.support.*;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -29,13 +29,11 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
* TestCase for AdvisorAdapterRegistrationManager mechanism. * TestCase for AdvisorAdapterRegistrationManager mechanism.
* *
* @author Dmitriy Kopylenko * @author Dmitriy Kopylenko
* @author Chris Beams
*/ */
public class AdvisorAdapterRegistrationTests extends TestCase { public class AdvisorAdapterRegistrationTests {
public AdvisorAdapterRegistrationTests(String name) {
super(name);
}
@Test
public void testAdvisorAdapterRegistrationManagerNotPresentInContext() { public void testAdvisorAdapterRegistrationManagerNotPresentInContext() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withoutBPPContext.xml"); ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withoutBPPContext.xml");
ITestBean tb = (ITestBean) ctx.getBean("testBean"); ITestBean tb = (ITestBean) ctx.getBean("testBean");
@ -50,6 +48,7 @@ public class AdvisorAdapterRegistrationTests extends TestCase {
} }
} }
@Test
public void testAdvisorAdapterRegistrationManagerPresentInContext() { public void testAdvisorAdapterRegistrationManagerPresentInContext() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withBPPContext.xml"); ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withBPPContext.xml");
ITestBean tb = (ITestBean) ctx.getBean("testBean"); ITestBean tb = (ITestBean) ctx.getBean("testBean");
@ -69,13 +68,4 @@ public class AdvisorAdapterRegistrationTests extends TestCase {
return (SimpleBeforeAdviceImpl) advisor.getAdvice(); return (SimpleBeforeAdviceImpl) advisor.getAdvice();
} }
// temporary suite method to make tests work on JRockit!
// Alef knows more about this.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new AdvisorAdapterRegistrationTests("testAdvisorAdapterRegistrationManagerNotPresentInContext"));
suite.addTest(new AdvisorAdapterRegistrationTests("testAdvisorAdapterRegistrationManagerPresentInContext"));
return suite;
}
} }

View File

@ -9,29 +9,18 @@
<beans> <beans>
<!-- Simple target --> <!-- Simple target -->
<bean id="target" class="org.springframework.aop.framework.adapter.ThrowsAdviceInterceptorTests$Echo"> <bean id="target" class="org.springframework.aop.framework.Echo"/>
</bean>
<bean id="nopInterceptor" class="org.springframework.aop.interceptor.NopInterceptor"> <bean id="nopInterceptor" class="org.springframework.aop.interceptor.NopInterceptor"/>
</bean>
<bean id="countingBeforeAdvice" <bean id="countingBeforeAdvice" class="org.springframework.aop.framework.CountingBeforeAdvice" />
class="org.springframework.aop.framework.CountingBeforeAdvice"
/>
<bean id="throwsAdvice"
class="org.springframework.aop.framework.adapter.ThrowsAdviceInterceptorTests$MyThrowsHandler">
</bean>
<bean id="throwsAdvice" class="org.springframework.aop.framework.MyThrowsHandler"/>
<bean id="throwsAdvised" <bean id="throwsAdvised" class="org.springframework.aop.framework.ProxyFactoryBean">
class="org.springframework.aop.framework.ProxyFactoryBean"
>
<property name="interceptorNames"> <property name="interceptorNames">
<value>countingBeforeAdvice,nopInterceptor,throwsAdvice,target</value> <value>countingBeforeAdvice,nopInterceptor,throwsAdvice,target</value>
</property> </property>
</bean> </bean>
</beans> </beans>