Browse Source

polishing .aop tests

conversation
Chris Beams 16 years ago
parent
commit
0f4ab0a987
  1. 6
      org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java
  2. 14
      org.springframework.aop/src/test/java/org/springframework/aop/framework/AopProxyUtilsTests.java
  3. 34
      org.springframework.aop/src/test/java/org/springframework/aop/framework/CountingBeforeAdvice.java
  4. 43
      org.springframework.aop/src/test/java/org/springframework/aop/framework/ExposedInvocationTestBean.java
  5. 4
      org.springframework.aop/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java
  6. 31
      org.springframework.aop/src/test/java/org/springframework/aop/framework/InvocationCheckExposedInvocationTestBean.java
  7. 4
      org.springframework.aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java
  8. 0
      org.springframework.aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests-context.xml
  9. 13
      org.springframework.aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java
  10. 52
      org.springframework.aop/src/test/java/org/springframework/aop/framework/ProxyFactoryTests.java
  11. 41
      org.springframework.aop/src/test/java/org/springframework/aop/framework/TimestampIntroductionInterceptor.java
  12. 5
      org.springframework.aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java
  13. 4
      org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java
  14. 2
      org.springframework.aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java
  15. 2
      org.springframework.aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java
  16. 4
      org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisorsTests.java
  17. 4
      org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests-context.xml
  18. 40
      org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java
  19. 16
      org.springframework.aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java
  20. 14
      org.springframework.aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java
  21. 3
      org.springframework.aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java
  22. 3
      org.springframework.aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java
  23. 5
      org.springframework.aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java
  24. 5
      org.springframework.aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java
  25. 5
      org.springframework.aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java
  26. 2
      org.springframework.aop/src/test/java/org/springframework/aop/support/regexpSetterTests.xml
  27. 2
      org.springframework.aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java
  28. 2
      org.springframework.aop/src/test/java/org/springframework/aop/target/prototypeTests.xml
  29. 2
      org.springframework.aop/src/test/java/org/springframework/aop/target/threadLocalTests.xml
  30. 14
      org.springframework.aop/src/test/java/test/advice/MethodCounter.java
  31. 5
      org.springframework.aop/src/test/java/test/interceptor/NopInterceptor.java
  32. 7
      org.springframework.aop/src/test/java/test/interceptor/SerializableNopInterceptor.java
  33. 4
      org.springframework.aop/src/test/java/test/mixin/DefaultLockable.java
  34. 4
      org.springframework.aop/src/test/java/test/mixin/Lockable.java
  35. 2
      org.springframework.aop/src/test/java/test/util/TimeStamped.java

6
org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java

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

14
org.springframework.aop/src/test/java/org/springframework/aop/framework/AopProxyUtilsTests.java

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

34
org.springframework.aop/src/test/java/org/springframework/aop/framework/CountingBeforeAdvice.java

@ -1,34 +0,0 @@ @@ -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);
}
}

43
org.springframework.aop/src/test/java/org/springframework/aop/framework/ExposedInvocationTestBean.java

@ -1,43 +0,0 @@ @@ -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);
}

4
org.springframework.aop/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import org.springframework.util.StopWatch; @@ -31,7 +31,7 @@ import org.springframework.util.StopWatch;
* @author Chris Beams
* @since 2.0
*/
public class IntroductionBenchmarkTests {
public final class IntroductionBenchmarkTests {
private static final int EXPECTED_COMPARE = 13;

31
org.springframework.aop/src/test/java/org/springframework/aop/framework/InvocationCheckExposedInvocationTestBean.java

@ -1,31 +0,0 @@ @@ -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()));
}
}

4
org.springframework.aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -32,7 +32,7 @@ import org.springframework.beans.TestBean; @@ -32,7 +32,7 @@ import org.springframework.beans.TestBean;
* @author Chris Beams
* @since 14.03.2003
*/
public class MethodInvocationTests {
public final class MethodInvocationTests {
@Test
public void testValidInvocation() throws Throwable {

0
org.springframework.aop/src/test/java/org/springframework/aop/framework/prototypeTarget.xml → org.springframework.aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests-context.xml

13
org.springframework.aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -27,14 +27,19 @@ import org.springframework.core.io.ClassPathResource; @@ -27,14 +27,19 @@ import org.springframework.core.io.ClassPathResource;
/**
* @author Juergen Hoeller
* @author Chris Beams
* @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
public void testPrototypeProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0;
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("prototypeTarget.xml", getClass()));
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
for (int i = 0; i < 10; i++) {
TestBean tb = (TestBean) xbf.getBean("testBeanPrototype");
tb.doSomething();
@ -47,7 +52,7 @@ public class PrototypeTargetTests { @@ -47,7 +52,7 @@ public class PrototypeTargetTests {
@Test
public void testSingletonProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0;
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("prototypeTarget.xml", getClass()));
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
for (int i = 0; i < 10; i++) {
TestBean tb = (TestBean) xbf.getBean("testBeanSingleton");
tb.doSomething();

52
org.springframework.aop/src/test/java/org/springframework/aop/framework/ProxyFactoryTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -20,19 +20,26 @@ package org.springframework.aop.framework; @@ -20,19 +20,26 @@ package org.springframework.aop.framework;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.aop.Advisor;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.interceptor.DebugInterceptor;
import org.springframework.aop.interceptor.NopInterceptor;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.DefaultIntroductionAdvisor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
import org.springframework.beans.IOther;
import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean;
import test.advice.MethodCounter;
import test.interceptor.NopInterceptor;
import test.util.TimeStamped;
/**
* Also tests AdvisedSupport and ProxyCreatorSupport superclasses.
*
@ -41,7 +48,7 @@ import org.springframework.beans.TestBean; @@ -41,7 +48,7 @@ import org.springframework.beans.TestBean;
* @author Chris Beams
* @since 14.05.2003
*/
public class ProxyFactoryTests {
public final class ProxyFactoryTests {
@Test
public void testIndexOfMethods() {
@ -311,3 +318,42 @@ public class ProxyFactoryTests { @@ -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;
}
}

41
org.springframework.aop/src/test/java/org/springframework/aop/framework/TimestampIntroductionInterceptor.java

@ -1,41 +0,0 @@ @@ -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;
}
}

5
org.springframework.aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java

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

4
org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ import org.springframework.util.SerializationTestUtils; @@ -34,7 +34,7 @@ import org.springframework.util.SerializationTestUtils;
* @author Chris Beams
* @since 06.04.2004
*/
public class ConcurrencyThrottleInterceptorTests {
public final class ConcurrencyThrottleInterceptorTests {
protected static final Log logger = LogFactory.getLog(ConcurrencyThrottleInterceptorTests.class);

2
org.springframework.aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java

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

2
org.springframework.aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.

4
org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisorsTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -28,7 +28,7 @@ import org.springframework.beans.factory.NamedBean; @@ -28,7 +28,7 @@ import org.springframework.beans.factory.NamedBean;
* @author Rod Johnson
* @author Chris Beams
*/
public class ExposeBeanNameAdvisorsTests {
public final class ExposeBeanNameAdvisorsTests {
private class RequiresBeanNameBoundTestBean extends TestBean {
private final String beanName;

4
org.springframework.aop/src/test/java/org/springframework/aop/interceptor/exposeInvocation.xml → org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests-context.xml

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
-->
<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">
<property name="targetClass">
@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
<bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<bean class="org.springframework.aop.framework.InvocationCheckExposedInvocationTestBean" />
<bean class="org.springframework.aop.interceptor.InvocationCheckExposedInvocationTestBean" />
</property>
<property name="interceptorNames">
<value>exposeInvocation,countingBeforeAdvice,nopInterceptor</value>

40
org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -17,23 +17,30 @@ @@ -17,23 +17,30 @@
package org.springframework.aop.interceptor;
import static org.junit.Assert.assertEquals;
import junit.framework.TestCase;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
/**
* Non-XML tests are in AbstractAopProxyTests
*
* @author Rod Johnson
* @author Chris Beams
*/
public class ExposeInvocationInterceptorTests {
private static final Class<?> CLASS = ExposeInvocationInterceptorTests.class;
private static final ClassPathResource CONTEXT =
new ClassPathResource(CLASS.getSimpleName() + "-context.xml", CLASS);
@Test
public void testXmlConfig() {
XmlBeanFactory bf = new XmlBeanFactory(
new ClassPathResource("org/springframework/aop/interceptor/exposeInvocation.xml"));
XmlBeanFactory bf = new XmlBeanFactory(CONTEXT);
ITestBean tb = (ITestBean) bf.getBean("proxy");
String name= "tony";
tb.setName(name);
@ -42,3 +49,30 @@ public class ExposeInvocationInterceptorTests { @@ -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()));
}
}

16
org.springframework.aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java

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

14
org.springframework.aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -46,14 +46,12 @@ public final class SimpleTraceInterceptorTests { @@ -46,14 +46,12 @@ public final class SimpleTraceInterceptorTests {
expect(mi.proceed()).andReturn(null);
log.trace(isA(String.class));
replay(log);
replay(mi);
replay(mi, log);
SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
interceptor.invokeUnderTrace(mi, log);
verify(log);
verify(mi);
verify(mi, log);
}
public void testExceptionPathStillLogsCorrectly() throws Throwable {
@ -69,8 +67,7 @@ public final class SimpleTraceInterceptorTests { @@ -69,8 +67,7 @@ public final class SimpleTraceInterceptorTests {
expect(mi.proceed()).andThrow(exception);
log.trace(isA(String.class));
replay(log);
replay(mi);
replay(mi, log);
final SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
@ -80,8 +77,7 @@ public final class SimpleTraceInterceptorTests { @@ -80,8 +77,7 @@ public final class SimpleTraceInterceptorTests {
} catch (IllegalArgumentException expected) {
}
verify(log);
verify(mi);
verify(mi, log);
}
}

3
org.springframework.aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java

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

3
org.springframework.aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java

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

5
org.springframework.aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java

@ -26,8 +26,6 @@ import org.junit.Test; @@ -26,8 +26,6 @@ import org.junit.Test;
import org.springframework.aop.IntroductionAdvisor;
import org.springframework.aop.IntroductionInterceptor;
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.ITestBean;
import org.springframework.beans.NestedTestBean;
@ -36,6 +34,9 @@ import org.springframework.beans.SerializablePerson; @@ -36,6 +34,9 @@ import org.springframework.beans.SerializablePerson;
import org.springframework.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
import test.interceptor.SerializableNopInterceptor;
import test.util.TimeStamped;
/**
* @author Rod Johnson
* @author Chris Beams

5
org.springframework.aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java

@ -22,12 +22,13 @@ import org.junit.Before; @@ -22,12 +22,13 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
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.SerializablePerson;
import org.springframework.util.SerializationTestUtils;
import test.interceptor.NopInterceptor;
import test.interceptor.SerializableNopInterceptor;
/**
* @author Rod Johnson
* @author Chris Beams

5
org.springframework.aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java

@ -20,8 +20,6 @@ import static org.junit.Assert.assertEquals; @@ -20,8 +20,6 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
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.Person;
import org.springframework.beans.TestBean;
@ -30,6 +28,9 @@ import org.springframework.beans.factory.xml.XmlBeanFactory; @@ -30,6 +28,9 @@ import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.SerializationTestUtils;
import test.interceptor.NopInterceptor;
import test.interceptor.SerializableNopInterceptor;
/**
* @author Rod Johnson
* @author Chris Beams

2
org.springframework.aop/src/test/java/org/springframework/aop/support/regexpSetterTests.xml

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
<property name="age"><value>666</value></property>
</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">
<property name="advice"><ref local="nopInterceptor"/></property>

2
org.springframework.aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java

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

2
org.springframework.aop/src/test/java/org/springframework/aop/target/prototypeTests.xml

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
<property name="targetBeanName"><value>prototypeTest</value></property>
</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">
<property name="interceptorNames"><value>debugInterceptor,test</value></property>

2
org.springframework.aop/src/test/java/org/springframework/aop/target/threadLocalTests.xml

@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
<property name="targetBeanName"><value>prototypeTest</value></property>
</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

14
org.springframework.aop/src/test/java/org/springframework/aop/framework/MethodCounter.java → org.springframework.aop/src/test/java/test/advice/MethodCounter.java

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

5
org.springframework.aop/src/test/java/org/springframework/aop/interceptor/NopInterceptor.java → org.springframework.aop/src/test/java/test/interceptor/NopInterceptor.java

@ -1,6 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -15,7 +14,7 @@ @@ -15,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.aop.interceptor;
package test.interceptor;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

7
org.springframework.aop/src/test/java/org/springframework/aop/interceptor/SerializableNopInterceptor.java → org.springframework.aop/src/test/java/test/interceptor/SerializableNopInterceptor.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -14,17 +14,20 @@ @@ -14,17 +14,20 @@
* limitations under the License.
*/
package org.springframework.aop.interceptor;
package test.interceptor;
import java.io.Serializable;
/**
* Subclass of NopInterceptor that is serializable and
* can be used to test proxy serialization.
*
* @author Rod Johnson
* @author Chris Beams
*/
@SuppressWarnings("serial")
public class SerializableNopInterceptor extends NopInterceptor implements Serializable {
/**

4
org.springframework.aop/src/test/java/org/springframework/aop/framework/DefaultLockable.java → org.springframework.aop/src/test/java/test/mixin/DefaultLockable.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.aop.framework;
package test.mixin;
/**
* Simple implementation of Lockable interface for use in mixins.

4
org.springframework.aop/src/test/java/org/springframework/aop/framework/Lockable.java → org.springframework.aop/src/test/java/test/mixin/Lockable.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.aop.framework;
package test.mixin;
/**

2
org.springframework.aop/src/test/java/org/springframework/aop/framework/TimeStamped.java → org.springframework.aop/src/test/java/test/util/TimeStamped.java

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