polishing .aop tests

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@497 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Chris Beams 2008-12-20 22:30:29 +00:00
parent ff0db70a9a
commit f94aed847f
35 changed files with 166 additions and 232 deletions

View File

@ -42,8 +42,6 @@ import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor; import org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.AopConfigException; import org.springframework.aop.framework.AopConfigException;
import org.springframework.aop.framework.DefaultLockable;
import org.springframework.aop.framework.Lockable;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor; import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
@ -56,6 +54,8 @@ import org.springframework.util.ObjectUtils;
import test.aspect.PerTargetAspect; import test.aspect.PerTargetAspect;
import test.aspect.TwoAdviceAspect; import test.aspect.TwoAdviceAspect;
import test.mixin.DefaultLockable;
import test.mixin.Lockable;
/** /**
* Abstract tests for AspectJAdvisorFactory. * Abstract tests for AspectJAdvisorFactory.
@ -1025,6 +1025,8 @@ interface Modifiable {
} }
class NotLockable { class NotLockable {
private int intValue; private int intValue;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,7 @@ import org.springframework.beans.TestBean;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class AopProxyUtilsTests { public final class AopProxyUtilsTests {
@Test @Test
public void testCompleteProxiedInterfacesWorksWithNull() { public void testCompleteProxiedInterfacesWorksWithNull() {
@ -124,7 +124,7 @@ public class AopProxyUtilsTests {
assertEquals(Comparable.class, userInterfaces[1]); assertEquals(Comparable.class, userInterfaces[1]);
} }
@Test @Test(expected=IllegalArgumentException.class)
public void testProxiedUserInterfacesWithNoInterface() { public void testProxiedUserInterfacesWithNoInterface() {
Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[0], Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[0],
new InvocationHandler() { new InvocationHandler() {
@ -132,13 +132,7 @@ public class AopProxyUtilsTests {
return null; return null;
} }
}); });
try { AopProxyUtils.proxiedUserInterfaces(proxy);
AopProxyUtils.proxiedUserInterfaces(proxy);
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException ex) {
// expected
}
} }
} }

View File

@ -1,34 +0,0 @@
/*
* Copyright 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.framework;
import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
/**
* Simple before advice example that we can use for counting checks.
*
* @author Rod Johnson
*/
public class CountingBeforeAdvice extends MethodCounter implements MethodBeforeAdvice {
public void before(Method m, Object[] args, Object target) throws Throwable {
count(m);
}
}

View File

@ -1,43 +0,0 @@
/*
* Copyright 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.framework;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.beans.TestBean;
/**
* Used to test ExposeInvocationInterceptor.
* @author Rod Johnson
*/
public abstract class ExposedInvocationTestBean extends TestBean {
public String getName() {
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
assertions(invocation);
return super.getName();
}
public void absquatulate() {
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
assertions(invocation);
super.absquatulate();
}
protected abstract void assertions(MethodInvocation invocation);
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import org.springframework.util.StopWatch;
* @author Chris Beams * @author Chris Beams
* @since 2.0 * @since 2.0
*/ */
public class IntroductionBenchmarkTests { public final class IntroductionBenchmarkTests {
private static final int EXPECTED_COMPARE = 13; private static final int EXPECTED_COMPARE = 13;

View File

@ -1,31 +0,0 @@
/*
* Copyright 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.framework;
import junit.framework.TestCase;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.beans.ITestBean;
public class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean {
protected void assertions(MethodInvocation invocation) {
TestCase.assertTrue(invocation.getThis() == this);
TestCase.assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass()));
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,7 +32,7 @@ import org.springframework.beans.TestBean;
* @author Chris Beams * @author Chris Beams
* @since 14.03.2003 * @since 14.03.2003
*/ */
public class MethodInvocationTests { public final class MethodInvocationTests {
@Test @Test
public void testValidInvocation() throws Throwable { public void testValidInvocation() throws Throwable {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,14 +27,19 @@ import org.springframework.core.io.ClassPathResource;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams
* @since 03.09.2004 * @since 03.09.2004
*/ */
public class PrototypeTargetTests { public final class PrototypeTargetTests {
private static final Class<?> CLASS = PrototypeTargetTests.class;
private static final String CLASSNAME = CLASS.getSimpleName();
private static final ClassPathResource CONTEXT = new ClassPathResource(CLASSNAME + "-context.xml", CLASS);
@Test @Test
public void testPrototypeProxyWithPrototypeTarget() { public void testPrototypeProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0; TestBeanImpl.constructionCount = 0;
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("prototypeTarget.xml", getClass())); XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
TestBean tb = (TestBean) xbf.getBean("testBeanPrototype"); TestBean tb = (TestBean) xbf.getBean("testBeanPrototype");
tb.doSomething(); tb.doSomething();
@ -47,7 +52,7 @@ public class PrototypeTargetTests {
@Test @Test
public void testSingletonProxyWithPrototypeTarget() { public void testSingletonProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0; TestBeanImpl.constructionCount = 0;
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("prototypeTarget.xml", getClass())); XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
TestBean tb = (TestBean) xbf.getBean("testBeanSingleton"); TestBean tb = (TestBean) xbf.getBean("testBeanSingleton");
tb.doSomething(); tb.doSomething();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,19 +20,26 @@ package org.springframework.aop.framework;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.Advisor; import org.springframework.aop.Advisor;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.interceptor.DebugInterceptor; import org.springframework.aop.interceptor.DebugInterceptor;
import org.springframework.aop.interceptor.NopInterceptor;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.DefaultIntroductionAdvisor; import org.springframework.aop.support.DefaultIntroductionAdvisor;
import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
import org.springframework.beans.IOther; import org.springframework.beans.IOther;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import test.advice.MethodCounter;
import test.interceptor.NopInterceptor;
import test.util.TimeStamped;
/** /**
* Also tests AdvisedSupport and ProxyCreatorSupport superclasses. * Also tests AdvisedSupport and ProxyCreatorSupport superclasses.
* *
@ -41,7 +48,7 @@ import org.springframework.beans.TestBean;
* @author Chris Beams * @author Chris Beams
* @since 14.05.2003 * @since 14.05.2003
*/ */
public class ProxyFactoryTests { public final class ProxyFactoryTests {
@Test @Test
public void testIndexOfMethods() { public void testIndexOfMethods() {
@ -311,3 +318,42 @@ public class ProxyFactoryTests {
} }
} }
/**
* Simple before advice example that we can use for counting checks.
*
* @author Rod Johnson
*/
@SuppressWarnings("serial")
class CountingBeforeAdvice extends MethodCounter implements MethodBeforeAdvice {
public void before(Method m, Object[] args, Object target) throws Throwable {
count(m);
}
}
@SuppressWarnings("serial")
class TimestampIntroductionInterceptor extends DelegatingIntroductionInterceptor
implements TimeStamped {
private long ts;
public TimestampIntroductionInterceptor() {
}
public TimestampIntroductionInterceptor(long ts) {
this.ts = ts;
}
public void setTime(long ts) {
this.ts = ts;
}
public long getTimeStamp() {
return ts;
}
}

View File

@ -1,41 +0,0 @@
/*
* Copyright 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.framework;
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
public class TimestampIntroductionInterceptor extends DelegatingIntroductionInterceptor
implements TimeStamped {
private long ts;
public TimestampIntroductionInterceptor() {
}
public TimestampIntroductionInterceptor(long ts) {
this.ts = ts;
}
public void setTime(long ts) {
this.ts = ts;
}
public long getTimeStamp() {
return ts;
}
}

View File

@ -34,7 +34,8 @@ import org.aopalliance.intercept.MethodInvocation;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.ThrowsAdvice; import org.springframework.aop.ThrowsAdvice;
import org.springframework.aop.framework.MethodCounter;
import test.advice.MethodCounter;
/** /**
* Unit tests for {@link ThrowsAdviceInterceptor} * Unit tests for {@link ThrowsAdviceInterceptor}
@ -42,7 +43,7 @@ import org.springframework.aop.framework.MethodCounter;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class ThrowsAdviceInterceptorTests { public final class ThrowsAdviceInterceptorTests {
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)
public void testNoHandlerMethods() { public void testNoHandlerMethods() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ import org.springframework.util.SerializationTestUtils;
* @author Chris Beams * @author Chris Beams
* @since 06.04.2004 * @since 06.04.2004
*/ */
public class ConcurrencyThrottleInterceptorTests { public final class ConcurrencyThrottleInterceptorTests {
protected static final Log logger = LogFactory.getLog(ConcurrencyThrottleInterceptorTests.class); protected static final Log logger = LogFactory.getLog(ConcurrencyThrottleInterceptorTests.class);

View File

@ -31,7 +31,7 @@ import org.junit.Test;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class CustomizableTraceInterceptorTests { public final class CustomizableTraceInterceptorTests {
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)
public void testSetEmptyEnterMessage() { public void testSetEmptyEnterMessage() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,7 +28,7 @@ import org.springframework.beans.factory.NamedBean;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class ExposeBeanNameAdvisorsTests { public final class ExposeBeanNameAdvisorsTests {
private class RequiresBeanNameBoundTestBean extends TestBean { private class RequiresBeanNameBoundTestBean extends TestBean {
private final String beanName; private final String beanName;

View File

@ -6,7 +6,7 @@
--> -->
<beans> <beans>
<bean id="nopInterceptor" class="org.springframework.aop.interceptor.NopInterceptor"/> <bean id="nopInterceptor" class="test.interceptor.NopInterceptor"/>
<bean id="exposeInvocation" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"> <bean id="exposeInvocation" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="targetClass"> <property name="targetClass">
@ -19,7 +19,7 @@
<bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean"> <bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target"> <property name="target">
<bean class="org.springframework.aop.framework.InvocationCheckExposedInvocationTestBean" /> <bean class="org.springframework.aop.interceptor.InvocationCheckExposedInvocationTestBean" />
</property> </property>
<property name="interceptorNames"> <property name="interceptorNames">
<value>exposeInvocation,countingBeforeAdvice,nopInterceptor</value> <value>exposeInvocation,countingBeforeAdvice,nopInterceptor</value>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,23 +17,30 @@
package org.springframework.aop.interceptor; package org.springframework.aop.interceptor;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import junit.framework.TestCase;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
/** /**
* Non-XML tests are in AbstractAopProxyTests * Non-XML tests are in AbstractAopProxyTests
*
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class ExposeInvocationInterceptorTests { public class ExposeInvocationInterceptorTests {
private static final Class<?> CLASS = ExposeInvocationInterceptorTests.class;
private static final ClassPathResource CONTEXT =
new ClassPathResource(CLASS.getSimpleName() + "-context.xml", CLASS);
@Test @Test
public void testXmlConfig() { public void testXmlConfig() {
XmlBeanFactory bf = new XmlBeanFactory( XmlBeanFactory bf = new XmlBeanFactory(CONTEXT);
new ClassPathResource("org/springframework/aop/interceptor/exposeInvocation.xml"));
ITestBean tb = (ITestBean) bf.getBean("proxy"); ITestBean tb = (ITestBean) bf.getBean("proxy");
String name= "tony"; String name= "tony";
tb.setName(name); tb.setName(name);
@ -42,3 +49,30 @@ public class ExposeInvocationInterceptorTests {
} }
} }
abstract class ExposedInvocationTestBean extends TestBean {
public String getName() {
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
assertions(invocation);
return super.getName();
}
public void absquatulate() {
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
assertions(invocation);
super.absquatulate();
}
protected abstract void assertions(MethodInvocation invocation);
}
class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean {
protected void assertions(MethodInvocation invocation) {
TestCase.assertTrue(invocation.getThis() == this);
TestCase.assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass()));
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import org.junit.Test;
* @author Rick Evans * @author Rick Evans
* @author Chris Beams * @author Chris Beams
*/ */
public class PerformanceMonitorInterceptorTests { public final class PerformanceMonitorInterceptorTests {
@Test @Test
public void testSuffixAndPrefixAssignment() { public void testSuffixAndPrefixAssignment() {
@ -57,14 +57,12 @@ public class PerformanceMonitorInterceptorTests {
expect(mi.proceed()).andReturn(null); expect(mi.proceed()).andReturn(null);
log.trace(isA(String.class)); log.trace(isA(String.class));
replay(mi); replay(mi, log);
replay(log);
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true); PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
interceptor.invokeUnderTrace(mi, log); interceptor.invokeUnderTrace(mi, log);
verify(log); verify(mi, log);
verify(mi);
} }
@Test @Test
@ -78,8 +76,7 @@ public class PerformanceMonitorInterceptorTests {
expect(mi.proceed()).andThrow(new IllegalArgumentException()); expect(mi.proceed()).andThrow(new IllegalArgumentException());
log.trace(isA(String.class)); log.trace(isA(String.class));
replay(mi); replay(mi, log);
replay(log);
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true); PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
try { try {
@ -89,8 +86,7 @@ public class PerformanceMonitorInterceptorTests {
catch (IllegalArgumentException expected) { catch (IllegalArgumentException expected) {
} }
verify(log); verify(mi, log);
verify(mi);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -46,14 +46,12 @@ public final class SimpleTraceInterceptorTests {
expect(mi.proceed()).andReturn(null); expect(mi.proceed()).andReturn(null);
log.trace(isA(String.class)); log.trace(isA(String.class));
replay(log); replay(mi, log);
replay(mi);
SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true); SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
interceptor.invokeUnderTrace(mi, log); interceptor.invokeUnderTrace(mi, log);
verify(log); verify(mi, log);
verify(mi);
} }
public void testExceptionPathStillLogsCorrectly() throws Throwable { public void testExceptionPathStillLogsCorrectly() throws Throwable {
@ -69,8 +67,7 @@ public final class SimpleTraceInterceptorTests {
expect(mi.proceed()).andThrow(exception); expect(mi.proceed()).andThrow(exception);
log.trace(isA(String.class)); log.trace(isA(String.class));
replay(log); replay(mi, log);
replay(mi);
final SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true); final SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
@ -80,8 +77,7 @@ public final class SimpleTraceInterceptorTests {
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
} }
verify(log); verify(mi, log);
verify(mi);
} }
} }

View File

@ -25,11 +25,12 @@ import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher; import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut; import org.springframework.aop.Pointcut;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor; import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.aop.interceptor.NopInterceptor;
import org.springframework.aop.target.EmptyTargetSource; import org.springframework.aop.target.EmptyTargetSource;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;
import test.interceptor.NopInterceptor;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams

View File

@ -21,10 +21,11 @@ import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.Pointcut; import org.springframework.aop.Pointcut;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.interceptor.NopInterceptor;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import test.interceptor.NopInterceptor;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams

View File

@ -26,8 +26,6 @@ import org.junit.Test;
import org.springframework.aop.IntroductionAdvisor; import org.springframework.aop.IntroductionAdvisor;
import org.springframework.aop.IntroductionInterceptor; import org.springframework.aop.IntroductionInterceptor;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.framework.TimeStamped;
import org.springframework.aop.interceptor.SerializableNopInterceptor;
import org.springframework.beans.INestedTestBean; import org.springframework.beans.INestedTestBean;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.NestedTestBean; import org.springframework.beans.NestedTestBean;
@ -36,6 +34,9 @@ import org.springframework.beans.SerializablePerson;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;
import test.interceptor.SerializableNopInterceptor;
import test.util.TimeStamped;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams

View File

@ -22,12 +22,13 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.interceptor.NopInterceptor;
import org.springframework.aop.interceptor.SerializableNopInterceptor;
import org.springframework.beans.Person; import org.springframework.beans.Person;
import org.springframework.beans.SerializablePerson; import org.springframework.beans.SerializablePerson;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;
import test.interceptor.NopInterceptor;
import test.interceptor.SerializableNopInterceptor;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams

View File

@ -20,8 +20,6 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.interceptor.NopInterceptor;
import org.springframework.aop.interceptor.SerializableNopInterceptor;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.Person; import org.springframework.beans.Person;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
@ -30,6 +28,9 @@ import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;
import test.interceptor.NopInterceptor;
import test.interceptor.SerializableNopInterceptor;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams

View File

@ -9,7 +9,7 @@
<property name="age"><value>666</value></property> <property name="age"><value>666</value></property>
</bean> </bean>
<bean id="nopInterceptor" class="org.springframework.aop.interceptor.SerializableNopInterceptor"/> <bean id="nopInterceptor" class="test.interceptor.SerializableNopInterceptor"/>
<bean id="settersAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <bean id="settersAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice"><ref local="nopInterceptor"/></property> <property name="advice"><ref local="nopInterceptor"/></property>

View File

@ -23,7 +23,6 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.interceptor.SerializableNopInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.Person; import org.springframework.beans.Person;
import org.springframework.beans.SerializablePerson; import org.springframework.beans.SerializablePerson;
@ -32,6 +31,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;
import test.beans.SideEffectBean; import test.beans.SideEffectBean;
import test.interceptor.SerializableNopInterceptor;
/** /**

View File

@ -16,7 +16,7 @@
<property name="targetBeanName"><value>prototypeTest</value></property> <property name="targetBeanName"><value>prototypeTest</value></property>
</bean> </bean>
<bean id="debugInterceptor" class="org.springframework.aop.interceptor.NopInterceptor" /> <bean id="debugInterceptor" class="test.interceptor.NopInterceptor" />
<bean id="singleton" class="org.springframework.aop.framework.ProxyFactoryBean"> <bean id="singleton" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="interceptorNames"><value>debugInterceptor,test</value></property> <property name="interceptorNames"><value>debugInterceptor,test</value></property>

View File

@ -11,7 +11,7 @@
<property name="targetBeanName"><value>prototypeTest</value></property> <property name="targetBeanName"><value>prototypeTest</value></property>
</bean> </bean>
<bean id="debugInterceptor" class="org.springframework.aop.interceptor.NopInterceptor" /> <bean id="debugInterceptor" class="test.interceptor.NopInterceptor" />
<!-- <!--
We want to invoke the getStatsMixin method on our ThreadLocal invoker We want to invoke the getStatsMixin method on our ThreadLocal invoker

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,21 +14,23 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.aop.framework; package test.advice;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
/** /**
* Useful abstract superclass for counting advices etc. * Abstract superclass for counting advices etc.
* *
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams
*/ */
@SuppressWarnings("serial")
public class MethodCounter implements Serializable { public class MethodCounter implements Serializable {
/** Method name --> count, does not understand overloading */ /** Method name --> count, does not understand overloading */
private HashMap map = new HashMap(); private HashMap<String, Integer> map = new HashMap<String, Integer>();
private int allCount; private int allCount;
@ -37,14 +39,14 @@ public class MethodCounter implements Serializable {
} }
protected void count(String methodName) { protected void count(String methodName) {
Integer i = (Integer) map.get(methodName); Integer i = map.get(methodName);
i = (i != null) ? new Integer(i.intValue() + 1) : new Integer(1); i = (i != null) ? new Integer(i.intValue() + 1) : new Integer(1);
map.put(methodName, i); map.put(methodName, i);
++allCount; ++allCount;
} }
public int getCalls(String methodName) { public int getCalls(String methodName) {
Integer i = (Integer) map.get(methodName); Integer i = map.get(methodName);
return (i != null ? i.intValue() : 0); return (i != null ? i.intValue() : 0);
} }

View File

@ -1,6 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.aop.interceptor; package test.interceptor;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,17 +14,20 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.aop.interceptor; package test.interceptor;
import java.io.Serializable; import java.io.Serializable;
/** /**
* Subclass of NopInterceptor that is serializable and * Subclass of NopInterceptor that is serializable and
* can be used to test proxy serialization. * can be used to test proxy serialization.
* *
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams
*/ */
@SuppressWarnings("serial")
public class SerializableNopInterceptor extends NopInterceptor implements Serializable { public class SerializableNopInterceptor extends NopInterceptor implements Serializable {
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.aop.framework; package test.mixin;
/** /**
* Simple implementation of Lockable interface for use in mixins. * Simple implementation of Lockable interface for use in mixins.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.aop.framework; package test.mixin;
/** /**

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.aop.framework; package test.util;
/** /**
* This interface can be implemented by cacheable objects or cache entries, * This interface can be implemented by cacheable objects or cache entries,