Remove trailing whitespace in source files
find . -type f -name "*.java" -or -name "*.aj" | \
xargs perl -p -i -e "s/[ \t]*$//g" {} \;
Issue: SPR-10127
This commit is contained in:
committed by
Chris Beams
parent
44a474a014
commit
1762157ad1
@@ -36,7 +36,7 @@ public final class AspectJAdviceParameterNameDiscoverAnnotationTests
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface MyAnnotation {}
|
||||
|
||||
|
||||
public void pjpAndAnAnnotation(ProceedingJoinPoint pjp, MyAnnotation ann) {}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -247,7 +247,7 @@ public class AspectJAdviceParameterNameDiscovererTests {
|
||||
public void testReferenceBindingWithAlternateTokenizations() {
|
||||
assertParameterNames(getMethod("onePrimitive"),"call(bar *) && somepc(foo)",new String[] {"foo"});
|
||||
assertParameterNames(getMethod("onePrimitive"),"somepc ( foo )",new String[] {"foo"});
|
||||
assertParameterNames(getMethod("onePrimitive"),"somepc( foo)",new String[] {"foo"});
|
||||
assertParameterNames(getMethod("onePrimitive"),"somepc( foo)",new String[] {"foo"});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -44,7 +44,7 @@ import test.beans.subpkg.DeepBean;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class AspectJExpressionPointcutTests {
|
||||
|
||||
|
||||
public static final String MATCH_ALL_METHODS = "execution(* *(..))";
|
||||
|
||||
private Method getAge;
|
||||
@@ -54,8 +54,8 @@ public final class AspectJExpressionPointcutTests {
|
||||
private Method setSomeNumber;
|
||||
|
||||
private Method isPostProcessed;
|
||||
|
||||
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws NoSuchMethodException {
|
||||
getAge = TestBean.class.getMethod("getAge", (Class<?>[])null);
|
||||
@@ -63,7 +63,7 @@ public final class AspectJExpressionPointcutTests {
|
||||
setSomeNumber = TestBean.class.getMethod("setSomeNumber", new Class[]{Number.class});
|
||||
isPostProcessed = TestBean.class.getMethod("isPostProcessed", (Class[]) null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchExplicit() {
|
||||
String expression = "execution(int test.beans.TestBean.getAge())";
|
||||
@@ -100,60 +100,60 @@ public final class AspectJExpressionPointcutTests {
|
||||
assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testThis() throws SecurityException, NoSuchMethodException{
|
||||
testThisOrTarget("this");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTarget() throws SecurityException, NoSuchMethodException {
|
||||
testThisOrTarget("target");
|
||||
}
|
||||
|
||||
|
||||
public static class OtherIOther implements IOther {
|
||||
|
||||
public void absquatulate() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This and target are equivalent. Really instanceof pointcuts.
|
||||
* @throws Exception
|
||||
* @param which this or target
|
||||
* @throws NoSuchMethodException
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws SecurityException
|
||||
*/
|
||||
private void testThisOrTarget(String which) throws SecurityException, NoSuchMethodException {
|
||||
String matchesTestBean = which + "(test.beans.TestBean)";
|
||||
String matchesIOther = which + "(test.beans.IOther)";
|
||||
AspectJExpressionPointcut testBeanPc = new AspectJExpressionPointcut();
|
||||
testBeanPc.setExpression(matchesTestBean);
|
||||
|
||||
|
||||
AspectJExpressionPointcut iOtherPc = new AspectJExpressionPointcut();
|
||||
iOtherPc.setExpression(matchesIOther);
|
||||
|
||||
|
||||
assertTrue(testBeanPc.matches(TestBean.class));
|
||||
assertTrue(testBeanPc.matches(getAge, TestBean.class));
|
||||
assertTrue(iOtherPc.matches(OtherIOther.class.getMethod("absquatulate", (Class<?>[])null),
|
||||
OtherIOther.class));
|
||||
|
||||
|
||||
assertFalse(testBeanPc.matches(OtherIOther.class.getMethod("absquatulate", (Class<?>[])null),
|
||||
OtherIOther.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithinRootPackage() throws SecurityException, NoSuchMethodException {
|
||||
testWithinPackage(false);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithinRootAndSubpackages() throws SecurityException, NoSuchMethodException {
|
||||
testWithinPackage(true);
|
||||
}
|
||||
|
||||
|
||||
private void testWithinPackage(boolean matchSubpackages) throws SecurityException, NoSuchMethodException {
|
||||
String withinBeansPackage = "within(test.beans.";
|
||||
// Subpackages are matched by **
|
||||
@@ -163,7 +163,7 @@ public final class AspectJExpressionPointcutTests {
|
||||
withinBeansPackage = withinBeansPackage + "*)";
|
||||
AspectJExpressionPointcut withinBeansPc = new AspectJExpressionPointcut();
|
||||
withinBeansPc.setExpression(withinBeansPackage);
|
||||
|
||||
|
||||
assertTrue(withinBeansPc.matches(TestBean.class));
|
||||
assertTrue(withinBeansPc.matches(getAge, TestBean.class));
|
||||
assertEquals(matchSubpackages, withinBeansPc.matches(DeepBean.class));
|
||||
@@ -173,7 +173,7 @@ public final class AspectJExpressionPointcutTests {
|
||||
assertFalse(withinBeansPc.matches(OtherIOther.class.getMethod("absquatulate", (Class<?>[])null),
|
||||
OtherIOther.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFriendlyErrorOnNoLocationClassMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
@@ -185,7 +185,7 @@ public final class AspectJExpressionPointcutTests {
|
||||
assertTrue(ex.getMessage().indexOf("expression") != -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFriendlyErrorOnNoLocation2ArgMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
@@ -197,7 +197,7 @@ public final class AspectJExpressionPointcutTests {
|
||||
assertTrue(ex.getMessage().indexOf("expression") != -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFriendlyErrorOnNoLocation3ArgMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
@@ -210,7 +210,7 @@ public final class AspectJExpressionPointcutTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchWithArgs() throws Exception {
|
||||
String expression = "execution(void test.beans.TestBean.setSomeNumber(Number)) && args(Double)";
|
||||
@@ -329,19 +329,19 @@ public final class AspectJExpressionPointcutTests {
|
||||
@Test
|
||||
public void testAndSubstitution() {
|
||||
Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
|
||||
PointcutExpression expr =
|
||||
PointcutExpression expr =
|
||||
((AspectJExpressionPointcut) pc).getPointcutExpression();
|
||||
assertEquals("execution(* *(..)) && args(String)",expr.getPointcutExpression());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMultipleAndSubstitutions() {
|
||||
Pointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)");
|
||||
PointcutExpression expr =
|
||||
PointcutExpression expr =
|
||||
((AspectJExpressionPointcut) pc).getPointcutExpression();
|
||||
assertEquals("execution(* *(..)) && args(String) && this(Object)",expr.getPointcutExpression());
|
||||
assertEquals("execution(* *(..)) && args(String) && this(Object)",expr.getPointcutExpression());
|
||||
}
|
||||
|
||||
|
||||
private Pointcut getPointcut(String expression) {
|
||||
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
||||
pointcut.setExpression(expression);
|
||||
|
||||
@@ -34,8 +34,8 @@ public final class BeanNamePointcutMatchingTests {
|
||||
public void testMatchingPointcuts() {
|
||||
assertMatch("someName", "bean(someName)");
|
||||
|
||||
// Spring bean names are less restrictive compared to AspectJ names (methods, types etc.)
|
||||
// MVC Controller-kind
|
||||
// Spring bean names are less restrictive compared to AspectJ names (methods, types etc.)
|
||||
// MVC Controller-kind
|
||||
assertMatch("someName/someOtherName", "bean(someName/someOtherName)");
|
||||
assertMatch("someName/foo/someOtherName", "bean(someName/*/someOtherName)");
|
||||
assertMatch("someName/foo/bar/someOtherName", "bean(someName/*/someOtherName)");
|
||||
@@ -58,9 +58,9 @@ public final class BeanNamePointcutMatchingTests {
|
||||
// Or, and, not expressions
|
||||
assertMatch("someName", "bean(someName) || bean(someOtherName)");
|
||||
assertMatch("someOtherName", "bean(someName) || bean(someOtherName)");
|
||||
|
||||
|
||||
assertMatch("someName", "!bean(someOtherName)");
|
||||
|
||||
|
||||
assertMatch("someName", "bean(someName) || !bean(someOtherName)");
|
||||
assertMatch("someName", "bean(someName) && !bean(someOtherName)");
|
||||
}
|
||||
|
||||
@@ -72,31 +72,31 @@ public final class MethodInvocationProceedingJoinPointTests {
|
||||
final Object raw = new TestBean();
|
||||
// Will be set by advice during a method call
|
||||
final int newAge = 23;
|
||||
|
||||
|
||||
ProxyFactory pf = new ProxyFactory(raw);
|
||||
pf.setExposeProxy(true);
|
||||
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
|
||||
pf.addAdvice(new MethodBeforeAdvice() {
|
||||
private int depth;
|
||||
|
||||
|
||||
public void before(Method method, Object[] args, Object target) throws Throwable {
|
||||
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
|
||||
assertTrue("Method named in toString", jp.toString().contains(method.getName()));
|
||||
// Ensure that these don't cause problems
|
||||
jp.toShortString();
|
||||
jp.toLongString();
|
||||
|
||||
|
||||
assertSame(target, AbstractAspectJAdvice.currentJoinPoint().getTarget());
|
||||
assertFalse(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget()));
|
||||
|
||||
|
||||
ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis();
|
||||
assertTrue(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis()));
|
||||
|
||||
|
||||
assertNotSame(target, thisProxy);
|
||||
|
||||
|
||||
// Check getting again doesn't cause a problem
|
||||
assertSame(thisProxy, AbstractAspectJAdvice.currentJoinPoint().getThis());
|
||||
|
||||
|
||||
// Try reentrant call--will go through this advice.
|
||||
// Be sure to increment depth to avoid infinite recursion
|
||||
if (depth++ == 0) {
|
||||
@@ -109,10 +109,10 @@ public final class MethodInvocationProceedingJoinPointTests {
|
||||
|
||||
assertSame(AopContext.currentProxy(), thisProxy);
|
||||
assertSame(target, raw);
|
||||
|
||||
|
||||
assertSame(method.getName(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getName());
|
||||
assertEquals(method.getModifiers(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers());
|
||||
|
||||
|
||||
MethodSignature msig = (MethodSignature) AbstractAspectJAdvice.currentJoinPoint().getSignature();
|
||||
assertSame("Return same MethodSignature repeatedly", msig, AbstractAspectJAdvice.currentJoinPoint().getSignature());
|
||||
assertSame("Return same JoinPoint repeatedly", AbstractAspectJAdvice.currentJoinPoint(), AbstractAspectJAdvice.currentJoinPoint());
|
||||
@@ -146,7 +146,7 @@ public final class MethodInvocationProceedingJoinPointTests {
|
||||
catch (UnsupportedOperationException ex) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
sloc.getFileName();
|
||||
fail("Can't get file name");
|
||||
@@ -191,7 +191,7 @@ public final class MethodInvocationProceedingJoinPointTests {
|
||||
// it serves our purpose here
|
||||
JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
|
||||
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
|
||||
|
||||
|
||||
assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
|
||||
assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
|
||||
assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());
|
||||
|
||||
@@ -38,37 +38,37 @@ public final class TigerAspectJAdviceParameterNameDiscovererTests
|
||||
public void testAtTarget() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@target(a)",new String[]{"a"});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAtArgs() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@args(a)",new String[]{"a"});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAtWithin() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@within(a)",new String[]{"a"});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAtWithincode() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@withincode(a)",new String[]{"a"});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAtAnnotation() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@annotation(a)",new String[]{"a"});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAmbiguousAnnotationTwoVars() {
|
||||
assertException(getMethod("twoAnnotations"),"@annotation(a) && @this(x)",AmbiguousBindingException.class,
|
||||
"Found 2 potential annotation variable(s), and 2 potential argument slots");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAmbiguousAnnotationOneVar() {
|
||||
assertException(getMethod("oneAnnotation"),"@annotation(a) && @this(x)",IllegalArgumentException.class,
|
||||
"Found 2 candidate annotation binding variables but only one potential argument binding slot");
|
||||
"Found 2 candidate annotation binding variables but only one potential argument binding slot");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,7 +32,7 @@ import test.annotation.transaction.Tx;
|
||||
import test.beans.TestBean;
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Java5-specific {@link AspectJExpressionPointcutTests}.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
@@ -54,10 +54,10 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||
methodsOnHasGeneric.put(m.getName(), m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class HasGeneric {
|
||||
|
||||
|
||||
public void setFriends(List<TestBean> friends) {
|
||||
}
|
||||
public void setEnemies(List<TestBean> enemies) {
|
||||
@@ -73,20 +73,20 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||
String expression = "execution(* set*(java.util.List<test.beans.TestBean>) )";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
|
||||
// TODO this will currently map, would be nice for optimization
|
||||
//assertTrue(ajexp.matches(HasGeneric.class));
|
||||
//assertFalse(ajexp.matches(TestBean.class));
|
||||
|
||||
|
||||
Method takesGenericList = methodsOnHasGeneric.get("setFriends");
|
||||
assertTrue(ajexp.matches(takesGenericList, HasGeneric.class));
|
||||
assertTrue(ajexp.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class));
|
||||
assertFalse(ajexp.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class));
|
||||
assertFalse(ajexp.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class));
|
||||
|
||||
|
||||
assertFalse(ajexp.matches(getAge, TestBean.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchVarargs() throws SecurityException, NoSuchMethodException {
|
||||
class MyTemplate {
|
||||
@@ -94,20 +94,20 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String expression = "execution(int *.*(String, Object...))";
|
||||
AspectJExpressionPointcut jdbcVarArgs = new AspectJExpressionPointcut();
|
||||
jdbcVarArgs.setExpression(expression);
|
||||
|
||||
|
||||
// TODO: the expression above no longer matches Object[]
|
||||
// assertFalse(jdbcVarArgs.matches(
|
||||
// JdbcTemplate.class.getMethod("queryForInt", String.class, Object[].class),
|
||||
// JdbcTemplate.class));
|
||||
|
||||
|
||||
assertTrue(jdbcVarArgs.matches(
|
||||
MyTemplate.class.getMethod("queryForInt", String.class, Object[].class),
|
||||
MyTemplate.class));
|
||||
|
||||
|
||||
Method takesGenericList = methodsOnHasGeneric.get("setFriends");
|
||||
assertFalse(jdbcVarArgs.matches(takesGenericList, HasGeneric.class));
|
||||
assertFalse(jdbcVarArgs.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class));
|
||||
@@ -115,44 +115,44 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||
assertFalse(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class));
|
||||
assertFalse(jdbcVarArgs.matches(getAge, TestBean.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithAtWithin() throws SecurityException, NoSuchMethodException {
|
||||
String expression = "@within(test.annotation.transaction.Tx)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithoutBinding() throws SecurityException, NoSuchMethodException {
|
||||
String expression = "within(@test.annotation.transaction.Tx *)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws SecurityException, NoSuchMethodException {
|
||||
String expression = "within(@(test.annotation..*) *)";
|
||||
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||
assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class),
|
||||
assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class),
|
||||
TestBean.class));
|
||||
assertTrue(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo", (Class[]) null),
|
||||
assertTrue(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo", (Class[]) null),
|
||||
SpringAnnotated.class));
|
||||
|
||||
|
||||
expression = "within(@(test.annotation.transaction..*) *)";
|
||||
AspectJExpressionPointcut springTxAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||
assertFalse(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo", (Class[]) null),
|
||||
assertFalse(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo", (Class[]) null),
|
||||
SpringAnnotated.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithExactPackageWildcard() throws SecurityException, NoSuchMethodException {
|
||||
String expression = "within(@(test.annotation.transaction.*) *)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
|
||||
private AspectJExpressionPointcut testMatchAnnotationOnClass(String expression) throws SecurityException, NoSuchMethodException {
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
|
||||
assertFalse(ajexp.matches(getAge, TestBean.class));
|
||||
assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class));
|
||||
assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
@@ -160,13 +160,13 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
return ajexp;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodWithFQN() throws SecurityException, NoSuchMethodException {
|
||||
String expression = "@annotation(test.annotation.transaction.Tx)";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
|
||||
assertFalse(ajexp.matches(getAge, TestBean.class));
|
||||
assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class));
|
||||
assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
@@ -174,13 +174,13 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||
assertTrue(ajexp.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class));
|
||||
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodWithWildcard() throws SecurityException, NoSuchMethodException {
|
||||
String expression = "execution(@(test.annotation..*) * *(..))";
|
||||
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut();
|
||||
anySpringMethodAnnotation.setExpression(expression);
|
||||
|
||||
|
||||
assertFalse(anySpringMethodAnnotation.matches(getAge, TestBean.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
@@ -194,43 +194,43 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||
String expression = "@args(*, test.annotation.EmptySpringAnnotation))";
|
||||
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
|
||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||
|
||||
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
|
||||
|
||||
assertTrue(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class),
|
||||
ProcessesSpringAnnotatedParameters.class));
|
||||
|
||||
|
||||
// True because it maybeMatches with potential argument subtypes
|
||||
assertTrue(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class));
|
||||
|
||||
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class,
|
||||
new Object[] { new TestBean(), new BeanA()})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodArgumentsWithWildcards() throws SecurityException, NoSuchMethodException {
|
||||
String expression = "execution(* *(*, @(test..*) *))";
|
||||
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
|
||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||
|
||||
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
|
||||
|
||||
assertTrue(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class),
|
||||
ProcessesSpringAnnotatedParameters.class));
|
||||
@@ -267,7 +267,7 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static class BeanA {
|
||||
private String name;
|
||||
|
||||
@@ -283,7 +283,7 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Tx
|
||||
static class BeanB {
|
||||
private String name;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class TrickyAspectJPointcutExpressionTests {
|
||||
|
||||
// Test with default class loader first...
|
||||
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, new TestServiceImpl(), "TestServiceImpl");
|
||||
|
||||
|
||||
// Then try again with a different class loader on the target...
|
||||
SimpleThrowawayClassLoader loader = new SimpleThrowawayClassLoader(new TestServiceImpl().getClass().getClassLoader());
|
||||
// Make sure the interface is loaded from the parent class loader
|
||||
@@ -102,7 +102,7 @@ public class TrickyAspectJPointcutExpressionTests {
|
||||
}
|
||||
assertEquals(1, logAdvice.getCountThrows());
|
||||
}
|
||||
|
||||
|
||||
public static class SimpleThrowawayClassLoader extends OverridingClassLoader {
|
||||
|
||||
/**
|
||||
@@ -114,7 +114,7 @@ public class TrickyAspectJPointcutExpressionTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class TestException extends RuntimeException {
|
||||
|
||||
public TestException(String string) {
|
||||
@@ -129,11 +129,11 @@ public class TrickyAspectJPointcutExpressionTests {
|
||||
@Inherited
|
||||
public static @interface Log {
|
||||
}
|
||||
|
||||
|
||||
public static interface TestService {
|
||||
public String sayHello();
|
||||
}
|
||||
|
||||
|
||||
@Log
|
||||
public static class TestServiceImpl implements TestService{
|
||||
public String sayHello() {
|
||||
@@ -142,11 +142,11 @@ public class TrickyAspectJPointcutExpressionTests {
|
||||
}
|
||||
|
||||
public class LogUserAdvice implements MethodBeforeAdvice, ThrowsAdvice {
|
||||
|
||||
|
||||
private int countBefore = 0;
|
||||
|
||||
|
||||
private int countThrows = 0;
|
||||
|
||||
|
||||
public void before(Method method, Object[] objects, Object o) throws Throwable {
|
||||
countBefore++;
|
||||
}
|
||||
@@ -163,12 +163,12 @@ public class TrickyAspectJPointcutExpressionTests {
|
||||
public int getCountThrows() {
|
||||
return countThrows;
|
||||
}
|
||||
|
||||
|
||||
public void reset() {
|
||||
countThrows = 0;
|
||||
countBefore = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class TypePatternClassFilterTests {
|
||||
assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class));
|
||||
assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAndOrNotReplacement() {
|
||||
TypePatternClassFilter tpcf = new TypePatternClassFilter("java.lang.Object or java.lang.String");
|
||||
@@ -75,7 +75,7 @@ public final class TypePatternClassFilterTests {
|
||||
assertFalse("matches Double",tpcf.matches(Double.class));
|
||||
tpcf = new TypePatternClassFilter("java.lang.Number+ and not java.lang.Float");
|
||||
assertFalse("matches Float",tpcf.matches(Float.class));
|
||||
assertTrue("matches Double",tpcf.matches(Double.class));
|
||||
assertTrue("matches Double",tpcf.matches(Double.class));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
|
||||
@@ -76,7 +76,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
* @return the fixture
|
||||
*/
|
||||
protected abstract AspectJAdvisorFactory getFixture();
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testRejectsPerCflowAspect() {
|
||||
@@ -88,7 +88,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
assertTrue(ex.getMessage().indexOf("PERCFLOW") != -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRejectsPerCflowBelowAspect() {
|
||||
try {
|
||||
@@ -105,11 +105,11 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
TestBean target = new TestBean();
|
||||
int realAge = 65;
|
||||
target.setAge(realAge);
|
||||
TestBean itb = (TestBean) createProxy(target,
|
||||
TestBean itb = (TestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean")),
|
||||
TestBean.class);
|
||||
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
|
||||
|
||||
|
||||
Advised advised = (Advised) itb;
|
||||
SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
@@ -121,10 +121,10 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
// Check that the perclause pointcut is valid
|
||||
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
|
||||
|
||||
|
||||
// Hit the method in the per clause to instantiate the aspect
|
||||
itb.getSpouse();
|
||||
|
||||
|
||||
assertTrue(maaif.isMaterialized());
|
||||
|
||||
assertEquals("Around advice must apply", 0, itb.getAge());
|
||||
@@ -190,11 +190,11 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
TestBean target = new TestBean();
|
||||
int realAge = 65;
|
||||
target.setAge(realAge);
|
||||
TestBean itb = (TestBean) createProxy(target,
|
||||
TestBean itb = (TestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerThisAspect(), "someBean")),
|
||||
TestBean.class);
|
||||
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
|
||||
|
||||
|
||||
Advised advised = (Advised) itb;
|
||||
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
|
||||
assertEquals(4, advised.getAdvisors().length);
|
||||
@@ -208,30 +208,30 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
// Check that the perclause pointcut is valid
|
||||
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
|
||||
|
||||
|
||||
// Hit the method in the per clause to instantiate the aspect
|
||||
itb.getSpouse();
|
||||
|
||||
|
||||
assertTrue(maaif.isMaterialized());
|
||||
|
||||
assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null));
|
||||
|
||||
|
||||
assertEquals("Around advice must apply", 0, itb.getAge());
|
||||
assertEquals("Around advice must apply", 1, itb.getAge());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPerTypeWithinAspect() throws SecurityException, NoSuchMethodException {
|
||||
TestBean target = new TestBean();
|
||||
int realAge = 65;
|
||||
target.setAge(realAge);
|
||||
PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory();
|
||||
TestBean itb = (TestBean) createProxy(target,
|
||||
getFixture().getAdvisors(aif),
|
||||
TestBean itb = (TestBean) createProxy(target,
|
||||
getFixture().getAdvisors(aif),
|
||||
TestBean.class);
|
||||
assertEquals("No method calls", 0, aif.getInstantiationCount());
|
||||
assertEquals("Around advice must now apply", 0, itb.getAge());
|
||||
|
||||
|
||||
Advised advised = (Advised) itb;
|
||||
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
|
||||
assertEquals(4, advised.getAdvisors().length);
|
||||
@@ -245,19 +245,19 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
// Check that the perclause pointcut is valid
|
||||
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
|
||||
|
||||
|
||||
// Hit the method in the per clause to instantiate the aspect
|
||||
itb.getSpouse();
|
||||
|
||||
|
||||
assertTrue(maaif.isMaterialized());
|
||||
|
||||
assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null));
|
||||
|
||||
|
||||
assertEquals("Around advice must still apply", 1, itb.getAge());
|
||||
assertEquals("Around advice must still apply", 2, itb.getAge());
|
||||
|
||||
TestBean itb2 = (TestBean) createProxy(target,
|
||||
getFixture().getAdvisors(aif),
|
||||
|
||||
TestBean itb2 = (TestBean) createProxy(target,
|
||||
getFixture().getAdvisors(aif),
|
||||
TestBean.class);
|
||||
assertEquals(1, aif.getInstantiationCount());
|
||||
assertEquals("Around advice be independent for second instance", 0, itb2.getAge());
|
||||
@@ -282,20 +282,20 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Test
|
||||
public void testNamedPointcutFromAspectLibraryWithBinding() {
|
||||
TestBean target = new TestBean();
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new NamedPointcutAspectFromLibraryWithBinding(),"someBean")),
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new NamedPointcutAspectFromLibraryWithBinding(),"someBean")),
|
||||
ITestBean.class);
|
||||
itb.setAge(10);
|
||||
assertEquals("Around advice must apply", 20, itb.getAge());
|
||||
assertEquals(20,target.getAge());
|
||||
}
|
||||
|
||||
|
||||
private void testNamedPointcuts(Object aspectInstance) {
|
||||
TestBean target = new TestBean();
|
||||
int realAge = 65;
|
||||
target.setAge(realAge);
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspectInstance,"someBean")),
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspectInstance,"someBean")),
|
||||
ITestBean.class);
|
||||
assertEquals("Around advice must apply", -1, itb.getAge());
|
||||
assertEquals(realAge, target.getAge());
|
||||
@@ -304,8 +304,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Test
|
||||
public void testBindingWithSingleArg() {
|
||||
TestBean target = new TestBean();
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new BindingAspectWithSingleArg(),"someBean")),
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new BindingAspectWithSingleArg(),"someBean")),
|
||||
ITestBean.class);
|
||||
itb.setAge(10);
|
||||
assertEquals("Around advice must apply", 20, itb.getAge());
|
||||
@@ -315,10 +315,10 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Test
|
||||
public void testBindingWithMultipleArgsDifferentlyOrdered() {
|
||||
ManyValuedArgs target = new ManyValuedArgs();
|
||||
ManyValuedArgs mva = (ManyValuedArgs) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ManyValuedArgs(),"someBean")),
|
||||
ManyValuedArgs mva = (ManyValuedArgs) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ManyValuedArgs(),"someBean")),
|
||||
ManyValuedArgs.class);
|
||||
|
||||
|
||||
String a = "a";
|
||||
int b = 12;
|
||||
int c = 25;
|
||||
@@ -327,7 +327,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
String expectedResult = a + b+ c + d + e;
|
||||
assertEquals(expectedResult, mva.mungeArgs(a, b, c, d, e));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In this case the introduction will be made.
|
||||
*/
|
||||
@@ -344,7 +344,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
assertFalse(lockable.locked());
|
||||
lockable.lock();
|
||||
assertTrue(lockable.locked());
|
||||
|
||||
|
||||
NotLockable notLockable2Target = new NotLockable();
|
||||
NotLockable notLockable2 = (NotLockable) createProxy(notLockable2Target,
|
||||
getFixture().getAdvisors(
|
||||
@@ -363,17 +363,17 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
}
|
||||
assertTrue(lockable2.locked());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIntroductionAdvisorExcludedFromTargetImplementingInterface() {
|
||||
assertTrue(AopUtils.findAdvisorsThatCanApply(
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(
|
||||
new MakeLockable(),"someBean")),
|
||||
new MakeLockable(),"someBean")),
|
||||
CannotBeUnlocked.class).isEmpty());
|
||||
assertEquals(2, AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIntroductionOnTargetImplementingInterface() {
|
||||
CannotBeUnlocked target = new CannotBeUnlocked();
|
||||
@@ -398,7 +398,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
// Ok
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testIntroductionOnTargetExcludedByTypePattern() {
|
||||
@@ -415,7 +415,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Test
|
||||
public void testIntroductionBasedOnAnnotationMatch_Spr5307() {
|
||||
AnnotatedTarget target = new AnnotatedTargetImpl();
|
||||
|
||||
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeAnnotatedTypeModifiable(),"someBean"));
|
||||
Object proxy = createProxy(target,
|
||||
@@ -430,19 +430,19 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
// TODO: Why does this test fail? It hasn't been run before, so it maybe never actually passed...
|
||||
public void XtestIntroductionWithArgumentBinding() {
|
||||
TestBean target = new TestBean();
|
||||
|
||||
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeITestBeanModifiable(),"someBean"));
|
||||
advisors.addAll(getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")));
|
||||
|
||||
|
||||
Modifiable modifiable = (Modifiable) createProxy(target,
|
||||
advisors,
|
||||
ITestBean.class);
|
||||
assertTrue(modifiable instanceof Modifiable);
|
||||
Lockable lockable = (Lockable) modifiable;
|
||||
assertFalse(lockable.locked());
|
||||
|
||||
|
||||
ITestBean itb = (ITestBean) modifiable;
|
||||
assertFalse(modifiable.isModified());
|
||||
int oldAge = itb.getAge();
|
||||
@@ -454,7 +454,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
assertFalse("Setting same value does not modify", modifiable.isModified());
|
||||
itb.setName("And now for something completely different");
|
||||
assertTrue(modifiable.isModified());
|
||||
|
||||
|
||||
lockable.lock();
|
||||
assertTrue(lockable.locked());
|
||||
try {
|
||||
@@ -474,8 +474,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
UnsupportedOperationException expectedException = new UnsupportedOperationException();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException),"someBean"));
|
||||
assertEquals("One advice method was found", 1, advisors.size());
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
advisors,
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
advisors,
|
||||
ITestBean.class);
|
||||
try {
|
||||
itb.getAge();
|
||||
@@ -485,7 +485,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
assertSame(expectedException, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO document this behaviour.
|
||||
// Is it different AspectJ behaviour, at least for checked exceptions?
|
||||
@Test
|
||||
@@ -494,8 +494,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
RemoteException expectedException = new RemoteException();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException),"someBean"));
|
||||
assertEquals("One advice method was found", 1, advisors.size());
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
advisors,
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
advisors,
|
||||
ITestBean.class);
|
||||
try {
|
||||
itb.getAge();
|
||||
@@ -505,7 +505,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
assertSame(expectedException, ex.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Object createProxy(Object target, List<Advisor> advisors, Class<?>... interfaces) {
|
||||
ProxyFactory pf = new ProxyFactory(target);
|
||||
if (interfaces.length > 1 || interfaces[0].isInterface()) {
|
||||
@@ -533,8 +533,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect,"someBean"));
|
||||
assertEquals("Two advice methods found", 2, advisors.size());
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
advisors,
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
advisors,
|
||||
ITestBean.class);
|
||||
itb.setName("");
|
||||
assertEquals(0, itb.getAge());
|
||||
@@ -549,8 +549,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
|
||||
ExceptionHandling afterReturningAspect = new ExceptionHandling();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(afterReturningAspect,"someBean"));
|
||||
Echo echo = (Echo) createProxy(target,
|
||||
advisors,
|
||||
Echo echo = (Echo) createProxy(target,
|
||||
advisors,
|
||||
Echo.class);
|
||||
assertEquals(0, afterReturningAspect.successCount);
|
||||
assertEquals("", echo.echo(""));
|
||||
@@ -886,45 +886,45 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
*/
|
||||
@Aspect
|
||||
abstract class AbstractMakeModifiable {
|
||||
|
||||
|
||||
public interface MutableModifable extends Modifiable {
|
||||
void markDirty();
|
||||
}
|
||||
|
||||
|
||||
public static class ModifiableImpl implements MutableModifable {
|
||||
private boolean modified;
|
||||
|
||||
|
||||
public void acceptChanges() {
|
||||
modified = false;
|
||||
}
|
||||
|
||||
|
||||
public boolean isModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
public void markDirty() {
|
||||
this.modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Before(value="execution(void set*(*)) && this(modifiable) && args(newValue)",
|
||||
|
||||
@Before(value="execution(void set*(*)) && this(modifiable) && args(newValue)",
|
||||
argNames="modifiable,newValue")
|
||||
public void recordModificationIfSetterArgumentDiffersFromOldValue(JoinPoint jp,
|
||||
public void recordModificationIfSetterArgumentDiffersFromOldValue(JoinPoint jp,
|
||||
MutableModifable mixin, Object newValue) {
|
||||
|
||||
|
||||
/*
|
||||
* We use the mixin to check and, if necessary, change,
|
||||
* modification status. We need the JoinPoint to get the
|
||||
* setter method. We use newValue for comparison.
|
||||
* modification status. We need the JoinPoint to get the
|
||||
* setter method. We use newValue for comparison.
|
||||
* We try to invoke the getter if possible.
|
||||
*/
|
||||
|
||||
|
||||
if (mixin.isModified()) {
|
||||
// Already changed, don't need to change again
|
||||
//System.out.println("changed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Find the current raw value, by invoking the corresponding setter
|
||||
Method correspondingGetter = getGetterFromSetter(((MethodSignature) jp.getSignature()).getMethod());
|
||||
boolean modified = true;
|
||||
@@ -946,12 +946,12 @@ abstract class AbstractMakeModifiable {
|
||||
mixin.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Method getGetterFromSetter(Method setter) {
|
||||
String getterName = setter.getName().replaceFirst("set", "get");
|
||||
try {
|
||||
return setter.getDeclaringClass().getMethod(getterName, (Class[]) null);
|
||||
}
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
// must be write only
|
||||
return null;
|
||||
@@ -968,7 +968,7 @@ abstract class AbstractMakeModifiable {
|
||||
*/
|
||||
@Aspect
|
||||
class MakeITestBeanModifiable extends AbstractMakeModifiable {
|
||||
|
||||
|
||||
@DeclareParents(value = "test.beans.ITestBean+",
|
||||
defaultImpl=ModifiableImpl.class)
|
||||
public static MutableModifable mixin;
|
||||
@@ -982,7 +982,7 @@ class MakeITestBeanModifiable extends AbstractMakeModifiable {
|
||||
*/
|
||||
@Aspect
|
||||
class MakeAnnotatedTypeModifiable extends AbstractMakeModifiable {
|
||||
|
||||
|
||||
@DeclareParents(value = "(@org.springframework.aop.aspectj.annotation.Measured *)",
|
||||
// @DeclareParents(value = "(@Measured *)", // this would be a nice alternative...
|
||||
defaultImpl=DefaultLockable.class)
|
||||
@@ -996,11 +996,11 @@ class MakeAnnotatedTypeModifiable extends AbstractMakeModifiable {
|
||||
*/
|
||||
@Aspect
|
||||
class MakeLockable {
|
||||
|
||||
|
||||
@DeclareParents(value = "org.springframework..*",
|
||||
defaultImpl=DefaultLockable.class)
|
||||
public static Lockable mixin;
|
||||
|
||||
|
||||
@Before(value="execution(void set*(*)) && this(mixin)", argNames="mixin")
|
||||
public void checkNotLocked(
|
||||
Lockable mixin) // Bind to arg
|
||||
@@ -1043,9 +1043,9 @@ class CannotBeUnlocked implements Lockable, Comparable<Object> {
|
||||
interface Modifiable {
|
||||
|
||||
boolean isModified();
|
||||
|
||||
|
||||
void acceptChanges();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1057,14 +1057,14 @@ interface AnnotatedTarget {
|
||||
|
||||
@Measured
|
||||
class AnnotatedTargetImpl implements AnnotatedTarget {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Measured {}
|
||||
|
||||
class NotLockable {
|
||||
|
||||
|
||||
private int intValue;
|
||||
|
||||
public int getIntValue() {
|
||||
@@ -1097,5 +1097,5 @@ class PerThisAspect {
|
||||
public void countSetter() {
|
||||
++count;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public final class ArgumentBindingTests {
|
||||
TestBean tb = new TestBean();
|
||||
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb);
|
||||
proxyFactory.addAspect(NamedPointcutWithArgs.class);
|
||||
|
||||
|
||||
ITestBean proxiedTestBean = (ITestBean) proxyFactory.getProxy();
|
||||
proxiedTestBean.setName("Supercalifragalisticexpialidocious"); // should throw
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public final class ArgumentBindingTests {
|
||||
TransactionalBean tb = new TransactionalBean();
|
||||
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb);
|
||||
proxyFactory.addAspect(PointcutWithAnnotationArgument.class);
|
||||
|
||||
|
||||
ITransactionalBean proxiedTestBean = (ITransactionalBean) proxyFactory.getProxy();
|
||||
proxiedTestBean.doInTransaction(); // should throw
|
||||
}
|
||||
|
||||
@@ -29,56 +29,56 @@ import test.beans.TestBean;
|
||||
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class AspectJPointcutAdvisorTests {
|
||||
|
||||
|
||||
private AspectJAdvisorFactory af = new ReflectiveAspectJAdvisorFactory();
|
||||
|
||||
@Test
|
||||
public void testSingleton() throws SecurityException, NoSuchMethodException {
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
|
||||
|
||||
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.ExceptionAspect(null),"someBean"),
|
||||
|
||||
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.ExceptionAspect(null),"someBean"),
|
||||
TestBean.class.getMethod("getAge", (Class[]) null),1,"someBean");
|
||||
assertSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
|
||||
assertFalse(ajpa.isPerInstance());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPerTarget() throws SecurityException, NoSuchMethodException {
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
|
||||
|
||||
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
|
||||
|
||||
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(),"someBean"), null, 1, "someBean");
|
||||
assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
|
||||
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
|
||||
assertTrue(ajpa.isPerInstance());
|
||||
|
||||
|
||||
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class));
|
||||
assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
|
||||
TestBean.class.getMethod("getAge", (Class[]) null),
|
||||
TestBean.class));
|
||||
|
||||
|
||||
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
|
||||
TestBean.class.getMethod("getSpouse", (Class[]) null),
|
||||
TestBean.class));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=AopConfigException.class)
|
||||
public void testPerCflowTarget() {
|
||||
testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowAspect.class);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=AopConfigException.class)
|
||||
public void testPerCflowBelowTarget() {
|
||||
testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowBelowAspect.class);
|
||||
}
|
||||
|
||||
|
||||
private void testIllegalInstantiationModel(Class<?> c) throws AopConfigException {
|
||||
new AspectMetadata(c,"someBean");
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -37,7 +37,7 @@ public final class AspectMetadataTests {
|
||||
public void testNotAnAspect() {
|
||||
new AspectMetadata(String.class,"someBean");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSingletonAspect() {
|
||||
AspectMetadata am = new AspectMetadata(ExceptionAspect.class,"someBean");
|
||||
@@ -45,7 +45,7 @@ public final class AspectMetadataTests {
|
||||
assertSame(Pointcut.TRUE, am.getPerClausePointcut());
|
||||
assertEquals(PerClauseKind.SINGLETON, am.getAjType().getPerClause().getKind());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPerTargetAspect() {
|
||||
AspectMetadata am = new AspectMetadata(PerTargetAspect.class,"someBean");
|
||||
@@ -53,7 +53,7 @@ public final class AspectMetadataTests {
|
||||
assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
|
||||
assertEquals(PerClauseKind.PERTARGET, am.getAjType().getPerClause().getKind());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPerThisAspect() {
|
||||
AspectMetadata am = new AspectMetadata(PerThisAspect.class,"someBean");
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.aop.aspectj.annotation;
|
||||
|
||||
/**
|
||||
* Tests for ReflectiveAtAspectJAdvisorFactory.
|
||||
* Tests for ReflectiveAtAspectJAdvisorFactory.
|
||||
* Tests are inherited: we only set the test fixture here.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
|
||||
@@ -42,9 +42,9 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
public final class AspectJPrecedenceComparatorTests {
|
||||
|
||||
/*
|
||||
* Specification for the comparator (as defined in the
|
||||
* Specification for the comparator (as defined in the
|
||||
* AspectJPrecedenceComparator class)
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Orders AspectJ advice/advisors by invocation order.
|
||||
* </p>
|
||||
|
||||
@@ -43,18 +43,18 @@ import test.parsing.CollectingReaderEventListener;
|
||||
public final class AopNamespaceHandlerEventTests {
|
||||
|
||||
private static final Class<?> CLASS = AopNamespaceHandlerEventTests.class;
|
||||
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(CLASS, "context.xml");
|
||||
private static final Resource POINTCUT_EVENTS_CONTEXT = qualifiedResource(CLASS, "pointcutEvents.xml");
|
||||
private static final Resource POINTCUT_REF_CONTEXT = qualifiedResource(CLASS, "pointcutRefEvents.xml");
|
||||
private static final Resource DIRECT_POINTCUT_EVENTS_CONTEXT = qualifiedResource(CLASS, "directPointcutEvents.xml");
|
||||
|
||||
|
||||
private CollectingReaderEventListener eventListener = new CollectingReaderEventListener();
|
||||
|
||||
private XmlBeanDefinitionReader reader;
|
||||
|
||||
private DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
|
||||
|
||||
|
||||
|
||||
@Before
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class AopNamespaceHandlerPointcutErrorTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testDuplicatePointcutConfig() {
|
||||
try {
|
||||
|
||||
@@ -26,12 +26,12 @@ import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Tests that the <aop:config/> element can be used as a top level element.
|
||||
*
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class TopLevelAopTagTests {
|
||||
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(TopLevelAopTagTests.class, "context.xml");
|
||||
|
||||
@Test
|
||||
|
||||
@@ -35,7 +35,7 @@ import test.beans.TestBean;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class AopProxyUtilsTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testCompleteProxiedInterfacesWorksWithNull() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
@@ -45,7 +45,7 @@ public final class AopProxyUtilsTests {
|
||||
assertTrue(ifaces.contains(Advised.class));
|
||||
assertTrue(ifaces.contains(SpringProxy.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCompleteProxiedInterfacesWorksWithNullOpaque() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
@@ -53,7 +53,7 @@ public final class AopProxyUtilsTests {
|
||||
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertEquals(1, completedInterfaces.length);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCompleteProxiedInterfacesAdvisedNotIncluded() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
@@ -61,14 +61,14 @@ public final class AopProxyUtilsTests {
|
||||
as.addInterface(Comparable.class);
|
||||
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertEquals(4, completedInterfaces.length);
|
||||
|
||||
|
||||
// Can't assume ordering for others, so use a list
|
||||
List<?> l = Arrays.asList(completedInterfaces);
|
||||
assertTrue(l.contains(Advised.class));
|
||||
assertTrue(l.contains(ITestBean.class));
|
||||
assertTrue(l.contains(Comparable.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCompleteProxiedInterfacesAdvisedIncluded() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
@@ -77,14 +77,14 @@ public final class AopProxyUtilsTests {
|
||||
as.addInterface(Advised.class);
|
||||
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertEquals(4, completedInterfaces.length);
|
||||
|
||||
|
||||
// Can't assume ordering for others, so use a list
|
||||
List<?> l = Arrays.asList(completedInterfaces);
|
||||
assertTrue(l.contains(Advised.class));
|
||||
assertTrue(l.contains(ITestBean.class));
|
||||
assertTrue(l.contains(Comparable.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCompleteProxiedInterfacesAdvisedNotIncludedOpaque() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
@@ -93,7 +93,7 @@ public final class AopProxyUtilsTests {
|
||||
as.addInterface(Comparable.class);
|
||||
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertEquals(3, completedInterfaces.length);
|
||||
|
||||
|
||||
// Can't assume ordering for others, so use a list
|
||||
List<?> l = Arrays.asList(completedInterfaces);
|
||||
assertFalse(l.contains(Advised.class));
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -25,9 +25,9 @@ import test.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Benchmarks for introductions.
|
||||
*
|
||||
*
|
||||
* NOTE: No assertions!
|
||||
*
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
* @since 2.0
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -34,7 +34,7 @@ import test.beans.TestBean;
|
||||
* @since 14.03.2003
|
||||
*/
|
||||
public final class MethodInvocationTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testValidInvocation() throws Throwable {
|
||||
Method m = Object.class.getMethod("hashCode", (Class[]) null);
|
||||
@@ -52,7 +52,7 @@ public final class MethodInvocationTests {
|
||||
Object rv = invocation.proceed();
|
||||
assertTrue("correct response", rv == returnValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* toString on target can cause failure.
|
||||
*/
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.core.io.Resource;
|
||||
* @since 03.09.2004
|
||||
*/
|
||||
public final class PrototypeTargetTests {
|
||||
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(PrototypeTargetTests.class, "context.xml");
|
||||
|
||||
@Test
|
||||
|
||||
@@ -64,7 +64,7 @@ public final class ProxyFactoryTests {
|
||||
assertEquals(1, pf.indexOf(advisor));
|
||||
assertEquals(-1, advised.indexOf(new DefaultPointcutAdvisor(null)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRemoveAdvisorByReference() {
|
||||
TestBean target = new TestBean();
|
||||
@@ -84,7 +84,7 @@ public final class ProxyFactoryTests {
|
||||
assertEquals(2, nop.getCount());
|
||||
assertFalse(pf.removeAdvisor(new DefaultPointcutAdvisor(null)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRemoveAdvisorByIndex() {
|
||||
TestBean target = new TestBean();
|
||||
@@ -113,7 +113,7 @@ public final class ProxyFactoryTests {
|
||||
assertEquals(1, cba.getCalls());
|
||||
assertEquals(2, nop.getCount());
|
||||
assertEquals(3, nop2.getCount());
|
||||
|
||||
|
||||
// Check out of bounds
|
||||
try {
|
||||
pf.removeAdvisor(-1);
|
||||
@@ -121,14 +121,14 @@ public final class ProxyFactoryTests {
|
||||
catch (AopConfigException ex) {
|
||||
// Ok
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
pf.removeAdvisor(2);
|
||||
}
|
||||
catch (AopConfigException ex) {
|
||||
// Ok
|
||||
}
|
||||
|
||||
|
||||
assertEquals(5, proxied.getAge());
|
||||
assertEquals(4, nop2.getCount());
|
||||
}
|
||||
@@ -191,17 +191,17 @@ public final class ProxyFactoryTests {
|
||||
assertEquals("Found correct number of interfaces", 3, factory.getProxiedInterfaces().length);
|
||||
ITestBean tb = (ITestBean) factory.getProxy();
|
||||
assertThat("Picked up secondary interface", tb, instanceOf(IOther.class));
|
||||
|
||||
|
||||
raw.setAge(25);
|
||||
assertTrue(tb.getAge() == raw.getAge());
|
||||
|
||||
long t = 555555L;
|
||||
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
|
||||
|
||||
|
||||
Class<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();
|
||||
|
||||
|
||||
factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
|
||||
|
||||
|
||||
Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
|
||||
assertEquals("Advisor proxies one more interface after introduction", oldProxiedInterfaces.length + 1, newProxiedInterfaces.length);
|
||||
|
||||
@@ -210,7 +210,7 @@ public final class ProxyFactoryTests {
|
||||
// Shouldn't fail;
|
||||
((IOther) ts).absquatulate();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInterceptorInclusionMethods() {
|
||||
class MyInterceptor implements MethodInterceptor {
|
||||
@@ -218,7 +218,7 @@ public final class ProxyFactoryTests {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NopInterceptor di = new NopInterceptor();
|
||||
NopInterceptor diUnused = new NopInterceptor();
|
||||
ProxyFactory factory = new ProxyFactory(new TestBean());
|
||||
@@ -228,7 +228,7 @@ public final class ProxyFactoryTests {
|
||||
assertTrue(!factory.adviceIncluded(diUnused));
|
||||
assertTrue(factory.countAdvicesOfType(NopInterceptor.class) == 1);
|
||||
assertTrue(factory.countAdvicesOfType(MyInterceptor.class) == 0);
|
||||
|
||||
|
||||
factory.addAdvice(0, diUnused);
|
||||
assertTrue(factory.adviceIncluded(diUnused));
|
||||
assertTrue(factory.countAdvicesOfType(NopInterceptor.class) == 2);
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class DebugInterceptorTests {
|
||||
@Test
|
||||
public void testSunnyDayPathLogsCorrectly() throws Throwable {
|
||||
Log log = createMock(Log.class);
|
||||
|
||||
|
||||
MethodInvocation methodInvocation = createMock(MethodInvocation.class);
|
||||
|
||||
expect(log.isTraceEnabled()).andReturn(true);
|
||||
@@ -56,7 +56,7 @@ public final class DebugInterceptorTests {
|
||||
@Test
|
||||
public void testExceptionPathStillLogsCorrectly() throws Throwable {
|
||||
Log log = createMock(Log.class);
|
||||
|
||||
|
||||
MethodInvocation methodInvocation = createMock(MethodInvocation.class);
|
||||
|
||||
expect(log.isTraceEnabled()).andReturn(true);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -30,20 +30,20 @@ import test.beans.TestBean;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class ExposeBeanNameAdvisorsTests {
|
||||
|
||||
|
||||
private class RequiresBeanNameBoundTestBean extends TestBean {
|
||||
private final String beanName;
|
||||
|
||||
|
||||
public RequiresBeanNameBoundTestBean(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
|
||||
public int getAge() {
|
||||
assertEquals(beanName, ExposeBeanNameAdvisors.getBeanName());
|
||||
return super.getAge();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNoIntroduction() {
|
||||
String beanName = "foo";
|
||||
@@ -52,12 +52,12 @@ public final class ExposeBeanNameAdvisorsTests {
|
||||
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
|
||||
pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorWithoutIntroduction(beanName));
|
||||
ITestBean proxy = (ITestBean) pf.getProxy();
|
||||
|
||||
|
||||
assertFalse("No introduction", proxy instanceof NamedBean);
|
||||
// Requires binding
|
||||
proxy.getAge();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithIntroduction() {
|
||||
String beanName = "foo";
|
||||
@@ -66,11 +66,11 @@ public final class ExposeBeanNameAdvisorsTests {
|
||||
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
|
||||
pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorIntroducingNamedBean(beanName));
|
||||
ITestBean proxy = (ITestBean) pf.getProxy();
|
||||
|
||||
|
||||
assertTrue("Introduction was made", proxy instanceof NamedBean);
|
||||
// Requires binding
|
||||
proxy.getAge();
|
||||
|
||||
|
||||
NamedBean nb = (NamedBean) proxy;
|
||||
assertEquals("Name returned correctly", beanName, nb.getBeanName());
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -29,12 +29,12 @@ import test.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Non-XML tests are in AbstractAopProxyTests
|
||||
*
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class ExposeInvocationInterceptorTests {
|
||||
|
||||
|
||||
private static final Resource CONTEXT =
|
||||
qualifiedResource(ExposeInvocationInterceptorTests.class, "context.xml");
|
||||
|
||||
@@ -64,7 +64,7 @@ abstract class ExposedInvocationTestBean extends TestBean {
|
||||
assertions(invocation);
|
||||
super.absquatulate();
|
||||
}
|
||||
|
||||
|
||||
protected abstract void assertions(MethodInvocation invocation);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ abstract class ExposedInvocationTestBean extends TestBean {
|
||||
class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean {
|
||||
protected void assertions(MethodInvocation invocation) {
|
||||
assertTrue(invocation.getThis() == this);
|
||||
assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
|
||||
assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
|
||||
ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.springframework.core.io.Resource;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class ScopedProxyAutowireTests {
|
||||
|
||||
|
||||
private static final Class<?> CLASS = ScopedProxyAutowireTests.class;
|
||||
|
||||
|
||||
private static final Resource SCOPED_AUTOWIRE_TRUE_CONTEXT = qualifiedResource(CLASS, "scopedAutowireTrue.xml");
|
||||
private static final Resource SCOPED_AUTOWIRE_FALSE_CONTEXT = qualifiedResource(CLASS, "scopedAutowireFalse.xml");
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public final class AopUtilsTests {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Pointcut no = new TestPointcut();
|
||||
assertFalse(AopUtils.canApply(no, Object.class));
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public final class AopUtilsTests {
|
||||
}
|
||||
|
||||
Pointcut pc = new TestPointcut();
|
||||
|
||||
|
||||
// will return true if we're not proxying interfaces
|
||||
assertTrue(AopUtils.canApply(pc, Object.class));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -30,11 +30,11 @@ import test.beans.TestBean;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class ClassFiltersTests {
|
||||
|
||||
|
||||
private ClassFilter exceptionFilter = new RootClassFilter(Exception.class);
|
||||
|
||||
|
||||
private ClassFilter itbFilter = new RootClassFilter(ITestBean.class);
|
||||
|
||||
|
||||
private ClassFilter hasRootCauseFilter = new RootClassFilter(NestedRuntimeException.class);
|
||||
|
||||
@Test
|
||||
@@ -47,7 +47,7 @@ public final class ClassFiltersTests {
|
||||
assertTrue(union.matches(RuntimeException.class));
|
||||
assertTrue(union.matches(TestBean.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIntersection() {
|
||||
assertTrue(exceptionFilter.matches(RuntimeException.class));
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -33,31 +33,31 @@ import test.beans.TestBean;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class ComposablePointcutTests {
|
||||
|
||||
|
||||
public static MethodMatcher GETTER_METHOD_MATCHER = new StaticMethodMatcher() {
|
||||
public boolean matches(Method m, Class<?> targetClass) {
|
||||
return m.getName().startsWith("get");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static MethodMatcher GET_AGE_METHOD_MATCHER = new StaticMethodMatcher() {
|
||||
public boolean matches(Method m, Class<?> targetClass) {
|
||||
return m.getName().equals("getAge");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static MethodMatcher ABSQUATULATE_METHOD_MATCHER = new StaticMethodMatcher() {
|
||||
public boolean matches(Method m, Class<?> targetClass) {
|
||||
return m.getName().equals("absquatulate");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static MethodMatcher SETTER_METHOD_MATCHER = new StaticMethodMatcher() {
|
||||
public boolean matches(Method m, Class<?> targetClass) {
|
||||
return m.getName().startsWith("set");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchAll() throws NoSuchMethodException {
|
||||
Pointcut pc = new ComposablePointcut();
|
||||
@@ -68,9 +68,9 @@ public final class ComposablePointcutTests {
|
||||
@Test
|
||||
public void testFilterByClass() throws NoSuchMethodException {
|
||||
ComposablePointcut pc = new ComposablePointcut();
|
||||
|
||||
|
||||
assertTrue(pc.getClassFilter().matches(Object.class));
|
||||
|
||||
|
||||
ClassFilter cf = new RootClassFilter(Exception.class);
|
||||
pc.intersection(cf);
|
||||
assertFalse(pc.getClassFilter().matches(Object.class));
|
||||
@@ -92,15 +92,15 @@ public final class ComposablePointcutTests {
|
||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null));
|
||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null));
|
||||
|
||||
|
||||
pc.union(GETTER_METHOD_MATCHER);
|
||||
// Should now match all getter methods
|
||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null));
|
||||
|
||||
|
||||
pc.union(ABSQUATULATE_METHOD_MATCHER);
|
||||
// Should now match absquatulate() as well
|
||||
// Should now match absquatulate() as well
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null));
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -31,7 +31,7 @@ import test.beans.TestBean;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class ControlFlowPointcutTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatches() {
|
||||
TestBean target = new TestBean();
|
||||
@@ -41,21 +41,21 @@ public final class ControlFlowPointcutTests {
|
||||
ProxyFactory pf = new ProxyFactory(target);
|
||||
ITestBean proxied = (ITestBean) pf.getProxy();
|
||||
pf.addAdvisor(new DefaultPointcutAdvisor(cflow, nop));
|
||||
|
||||
|
||||
// Not advised, not under One
|
||||
assertEquals(target.getAge(), proxied.getAge());
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
|
||||
// Will be advised
|
||||
assertEquals(target.getAge(), new One().getAge(proxied));
|
||||
assertEquals(1, nop.getCount());
|
||||
|
||||
|
||||
// Won't be advised
|
||||
assertEquals(target.getAge(), new One().nomatch(proxied));
|
||||
assertEquals(1, nop.getCount());
|
||||
assertEquals(3, cflow.getEvaluations());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check that we can use a cflow pointcut only in conjunction with
|
||||
* a static pointcut: e.g. all setter methods that are invoked under
|
||||
@@ -73,19 +73,19 @@ public final class ControlFlowPointcutTests {
|
||||
ProxyFactory pf = new ProxyFactory(target);
|
||||
ITestBean proxied = (ITestBean) pf.getProxy();
|
||||
pf.addAdvisor(new DefaultPointcutAdvisor(settersUnderOne, nop));
|
||||
|
||||
|
||||
// Not advised, not under One
|
||||
target.setAge(16);
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
|
||||
// Not advised; under One but not a setter
|
||||
assertEquals(16, new One().getAge(proxied));
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
|
||||
// Won't be advised
|
||||
new One().set(proxied);
|
||||
assertEquals(1, nop.getCount());
|
||||
|
||||
|
||||
// We saved most evaluations
|
||||
assertEquals(1, cflow.getEvaluations());
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public final class ControlFlowPointcutTests {
|
||||
assertEquals(new ControlFlowPointcut(One.class, "getAge").hashCode(), new ControlFlowPointcut(One.class, "getAge").hashCode());
|
||||
assertFalse(new ControlFlowPointcut(One.class, "getAge").hashCode() == new ControlFlowPointcut(One.class).hashCode());
|
||||
}
|
||||
|
||||
|
||||
public class One {
|
||||
int getAge(ITestBean proxied) {
|
||||
return proxied.getAge();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -79,7 +79,7 @@ public final class DelegatingIntroductionInterceptorTests {
|
||||
long timestamp = 111L;
|
||||
expect(ts.getTimeStamp()).andReturn(timestamp);
|
||||
replay(ts);
|
||||
|
||||
|
||||
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), SubTimeStamped.class));
|
||||
|
||||
SubTimeStamped tsp = (SubTimeStamped) factory.getProxy();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -37,9 +37,9 @@ public final class MethodMatchersTests {
|
||||
private final Method EXCEPTION_GETMESSAGE;
|
||||
|
||||
private final Method ITESTBEAN_SETAGE;
|
||||
|
||||
|
||||
private final Method ITESTBEAN_GETAGE;
|
||||
|
||||
|
||||
private final Method IOTHER_ABSQUATULATE;
|
||||
|
||||
public MethodMatchersTests() throws Exception {
|
||||
@@ -55,7 +55,7 @@ public final class MethodMatchersTests {
|
||||
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
|
||||
assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMethodMatcherTrueSerializable() throws Exception {
|
||||
assertSame(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE), MethodMatcher.TRUE);
|
||||
@@ -72,7 +72,7 @@ public final class MethodMatchersTests {
|
||||
assertFalse(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testDynamicAndStaticMethodMatcherIntersection() throws Exception {
|
||||
MethodMatcher mm1 = MethodMatcher.TRUE;
|
||||
@@ -87,13 +87,13 @@ public final class MethodMatchersTests {
|
||||
assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) }));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStaticMethodMatcherUnion() throws Exception {
|
||||
MethodMatcher getterMatcher = new StartsWithMatcher("get");
|
||||
MethodMatcher setterMatcher = new StartsWithMatcher("set");
|
||||
MethodMatcher union = MethodMatchers.union(getterMatcher, setterMatcher);
|
||||
|
||||
|
||||
assertFalse("Union is a static matcher", union.isRuntime());
|
||||
assertTrue("Matched setAge method", union.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
assertTrue("Matched getAge method", union.matches(ITESTBEAN_GETAGE, TestBean.class));
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -34,11 +34,11 @@ import test.util.SerializationTestUtils;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class NameMatchMethodPointcutTests {
|
||||
|
||||
|
||||
protected NameMatchMethodPointcut pc;
|
||||
|
||||
|
||||
protected Person proxied;
|
||||
|
||||
|
||||
protected SerializableNopInterceptor nop;
|
||||
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ public final class NameMatchMethodPointcutTests {
|
||||
pf.addAdvisor(new DefaultPointcutAdvisor(pc, nop));
|
||||
proxied = (Person) pf.getProxy();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchingOnly() {
|
||||
// Can't do exact matching through isMatch
|
||||
@@ -63,7 +63,7 @@ public final class NameMatchMethodPointcutTests {
|
||||
assertFalse(pc.isMatch("setName", "set"));
|
||||
assertTrue(pc.isMatch("testing", "*ing"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEmpty() throws Throwable {
|
||||
assertEquals(0, nop.getCount());
|
||||
@@ -72,8 +72,8 @@ public final class NameMatchMethodPointcutTests {
|
||||
proxied.echo(null);
|
||||
assertEquals(0, nop.getCount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchOneMethod() throws Throwable {
|
||||
pc.addMethodName("echo");
|
||||
@@ -84,7 +84,7 @@ public final class NameMatchMethodPointcutTests {
|
||||
assertEquals(0, nop.getCount());
|
||||
proxied.echo(null);
|
||||
assertEquals(1, nop.getCount());
|
||||
|
||||
|
||||
proxied.setName("");
|
||||
assertEquals(2, nop.getCount());
|
||||
proxied.setAge(25);
|
||||
@@ -102,7 +102,7 @@ public final class NameMatchMethodPointcutTests {
|
||||
proxied.echo(null);
|
||||
assertEquals(2, nop.getCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerializable() throws Throwable {
|
||||
testSets();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -31,12 +31,12 @@ import test.beans.TestBean;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class PointcutsTests {
|
||||
|
||||
|
||||
public static Method TEST_BEAN_SET_AGE;
|
||||
public static Method TEST_BEAN_GET_AGE;
|
||||
public static Method TEST_BEAN_GET_NAME;
|
||||
public static Method TEST_BEAN_ABSQUATULATE;
|
||||
|
||||
|
||||
static {
|
||||
try {
|
||||
TEST_BEAN_SET_AGE = TestBean.class.getMethod("setAge", new Class[] { int.class });
|
||||
@@ -48,7 +48,7 @@ public final class PointcutsTests {
|
||||
throw new RuntimeException("Shouldn't happen: error in test suite");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Matches only TestBean class, not subclasses
|
||||
*/
|
||||
@@ -65,13 +65,13 @@ public final class PointcutsTests {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static Pointcut allClassSetterPointcut = Pointcuts.SETTERS;
|
||||
|
||||
|
||||
// Subclass used for matching
|
||||
public static class MyTestBean extends TestBean {
|
||||
}
|
||||
|
||||
|
||||
public static Pointcut myTestBeanSetterPointcut = new StaticMethodMatcherPointcut() {
|
||||
public ClassFilter getClassFilter() {
|
||||
return new RootClassFilter(MyTestBean.class);
|
||||
@@ -81,7 +81,7 @@ public final class PointcutsTests {
|
||||
return m.getName().startsWith("set");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Will match MyTestBeanSubclass
|
||||
public static Pointcut myTestBeanGetterPointcut = new StaticMethodMatcherPointcut() {
|
||||
public ClassFilter getClassFilter() {
|
||||
@@ -92,11 +92,11 @@ public final class PointcutsTests {
|
||||
return m.getName().startsWith("get");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Still more specific class
|
||||
public static class MyTestBeanSubclass extends MyTestBean {
|
||||
}
|
||||
|
||||
|
||||
public static Pointcut myTestBeanSubclassGetterPointcut = new StaticMethodMatcherPointcut() {
|
||||
public ClassFilter getClassFilter() {
|
||||
return new RootClassFilter(MyTestBeanSubclass.class);
|
||||
@@ -106,14 +106,14 @@ public final class PointcutsTests {
|
||||
return m.getName().startsWith("get");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static Pointcut allClassGetterPointcut = Pointcuts.GETTERS;
|
||||
|
||||
|
||||
public static Pointcut allClassGetAgePointcut = new NameMatchMethodPointcut().addMethodName("getAge");
|
||||
|
||||
|
||||
public static Pointcut allClassGetNamePointcut = new NameMatchMethodPointcut().addMethodName("getName");
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testTrue() {
|
||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
||||
@@ -133,7 +133,7 @@ public final class PointcutsTests {
|
||||
assertTrue(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null));
|
||||
assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should match all setters and getters on any class
|
||||
*/
|
||||
@@ -144,7 +144,7 @@ public final class PointcutsTests {
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUnionOfSpecificGetters() {
|
||||
Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut);
|
||||
@@ -153,7 +153,7 @@ public final class PointcutsTests {
|
||||
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class, null));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
||||
|
||||
|
||||
// Union with all setters
|
||||
union = Pointcuts.union(union, allClassSetterPointcut);
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
||||
@@ -161,10 +161,10 @@ public final class PointcutsTests {
|
||||
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class, null));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
||||
|
||||
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests vertical composition. First pointcut matches all setters.
|
||||
* Second one matches all getters in the MyTestBean class. TestBean getters shouldn't pass.
|
||||
@@ -174,7 +174,7 @@ public final class PointcutsTests {
|
||||
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
||||
assertTrue(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Object[] { new Integer(6)}));
|
||||
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null));
|
||||
|
||||
|
||||
Pointcut union = Pointcuts.union(myTestBeanSetterPointcut, allClassGetterPointcut);
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class, null));
|
||||
@@ -182,7 +182,7 @@ public final class PointcutsTests {
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Object[] { new Integer(6)}));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Intersection should be MyTestBean getAge() only:
|
||||
* it's the union of allClassGetAge and subclass getters
|
||||
@@ -195,7 +195,7 @@ public final class PointcutsTests {
|
||||
assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null));
|
||||
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, MyTestBean.class, null));
|
||||
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class, null));
|
||||
|
||||
|
||||
Pointcut intersection = Pointcuts.intersection(allClassGetAgePointcut, myTestBeanGetterPointcut);
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class, null));
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class, null));
|
||||
@@ -204,7 +204,7 @@ public final class PointcutsTests {
|
||||
// Matches subclass of MyTestBean
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null));
|
||||
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null));
|
||||
|
||||
|
||||
// Now intersection with MyTestBeanSubclass getters should eliminate MyTestBean target
|
||||
intersection = Pointcuts.intersection(intersection, myTestBeanSubclassGetterPointcut);
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class, null));
|
||||
@@ -214,7 +214,7 @@ public final class PointcutsTests {
|
||||
// Still matches subclass of MyTestBean
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null));
|
||||
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null));
|
||||
|
||||
|
||||
// Now union with all TestBean methods
|
||||
Pointcut union = Pointcuts.union(intersection, allTestBeanMethodsPointcut);
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null));
|
||||
@@ -224,12 +224,12 @@ public final class PointcutsTests {
|
||||
// Still matches subclass of MyTestBean
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null));
|
||||
|
||||
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, MyTestBean.class, null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The intersection of these two pointcuts leaves nothing.
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -37,18 +37,18 @@ import test.util.SerializationTestUtils;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class RegexpMethodPointcutAdvisorIntegrationTests {
|
||||
|
||||
|
||||
private static final Resource CONTEXT =
|
||||
qualifiedResource(RegexpMethodPointcutAdvisorIntegrationTests.class, "context.xml");
|
||||
|
||||
@Test
|
||||
public void testSinglePattern() throws Throwable {
|
||||
BeanFactory bf = new XmlBeanFactory(CONTEXT);
|
||||
BeanFactory bf = new XmlBeanFactory(CONTEXT);
|
||||
ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
|
||||
// Interceptor behind regexp advisor
|
||||
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
|
||||
int newAge = 12;
|
||||
// Not advised
|
||||
advised.exceptional(null);
|
||||
@@ -58,21 +58,21 @@ public final class RegexpMethodPointcutAdvisorIntegrationTests {
|
||||
// Only setter fired
|
||||
assertEquals(1, nop.getCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMultiplePatterns() throws Throwable {
|
||||
BeanFactory bf = new XmlBeanFactory(CONTEXT);
|
||||
BeanFactory bf = new XmlBeanFactory(CONTEXT);
|
||||
// This is a CGLIB proxy, so we can proxy it to the target class
|
||||
TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised");
|
||||
// Interceptor behind regexp advisor
|
||||
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
|
||||
int newAge = 12;
|
||||
// Not advised
|
||||
advised.exceptional(null);
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
|
||||
// This is proxied
|
||||
advised.absquatulate();
|
||||
assertEquals(1, nop.getCount());
|
||||
@@ -81,21 +81,21 @@ public final class RegexpMethodPointcutAdvisorIntegrationTests {
|
||||
// Only setter fired
|
||||
assertEquals(2, nop.getCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws Throwable {
|
||||
BeanFactory bf = new XmlBeanFactory(CONTEXT);
|
||||
BeanFactory bf = new XmlBeanFactory(CONTEXT);
|
||||
// This is a CGLIB proxy, so we can proxy it to the target class
|
||||
Person p = (Person) bf.getBean("serializableSettersAdvised");
|
||||
// Interceptor behind regexp advisor
|
||||
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
|
||||
int newAge = 12;
|
||||
// Not advised
|
||||
assertEquals(0, p.getAge());
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
|
||||
// This is proxied
|
||||
p.setAge(newAge);
|
||||
assertEquals(1, nop.getCount());
|
||||
@@ -103,7 +103,7 @@ public final class RegexpMethodPointcutAdvisorIntegrationTests {
|
||||
assertEquals(newAge, p.getAge());
|
||||
// Only setter fired
|
||||
assertEquals(2, nop.getCount());
|
||||
|
||||
|
||||
// Serialize and continue...
|
||||
p = (Person) SerializationTestUtils.serializeAndDeserialize(p);
|
||||
assertEquals(newAge, p.getAge());
|
||||
|
||||
@@ -33,7 +33,7 @@ import test.beans.ITestBean;
|
||||
* @since 2.0
|
||||
*/
|
||||
public final class CommonsPoolTargetSourceProxyTests {
|
||||
|
||||
|
||||
private static final Resource CONTEXT =
|
||||
qualifiedResource(CommonsPoolTargetSourceProxyTests.class, "context.xml");
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -40,19 +40,19 @@ import test.util.SerializationTestUtils;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class HotSwappableTargetSourceTests {
|
||||
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(HotSwappableTargetSourceTests.class, "context.xml");
|
||||
|
||||
/** Initial count value set in bean factory XML */
|
||||
private static final int INITIAL_COUNT = 10;
|
||||
|
||||
private XmlBeanFactory beanFactory;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.beanFactory = new XmlBeanFactory(CONTEXT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* We must simulate container shutdown, which should clear threads.
|
||||
*/
|
||||
@@ -72,42 +72,42 @@ public final class HotSwappableTargetSourceTests {
|
||||
assertEquals(INITIAL_COUNT, proxied.getCount() );
|
||||
proxied.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, proxied.getCount() );
|
||||
|
||||
|
||||
proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
||||
proxied.doWork();
|
||||
assertEquals(INITIAL_COUNT + 2, proxied.getCount() );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testValidSwaps() {
|
||||
SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1");
|
||||
SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2");
|
||||
|
||||
|
||||
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
||||
assertEquals(target1.getCount(), proxied.getCount() );
|
||||
proxied.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, proxied.getCount() );
|
||||
|
||||
|
||||
HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
|
||||
Object old = swapper.swap(target2);
|
||||
assertEquals("Correct old target was returned", target1, old);
|
||||
|
||||
|
||||
// TODO should be able to make this assertion: need to fix target handling
|
||||
// in AdvisedSupport
|
||||
//assertEquals(target2, ((Advised) proxied).getTarget());
|
||||
|
||||
|
||||
assertEquals(20, proxied.getCount());
|
||||
proxied.doWork();
|
||||
assertEquals(21, target2.getCount());
|
||||
|
||||
|
||||
// Swap it back
|
||||
swapper.swap(target1);
|
||||
assertEquals(target1.getCount(), proxied.getCount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param invalid
|
||||
* @return the message
|
||||
*/
|
||||
@@ -122,46 +122,46 @@ public final class HotSwappableTargetSourceTests {
|
||||
// Ok
|
||||
aopex = ex;
|
||||
}
|
||||
|
||||
|
||||
// It shouldn't be corrupted, it should still work
|
||||
testBasicFunctionality();
|
||||
return aopex;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRejectsSwapToNull() {
|
||||
IllegalArgumentException ex = testRejectsSwapToInvalidValue(null);
|
||||
assertTrue(ex.getMessage().indexOf("null") != -1);
|
||||
}
|
||||
|
||||
|
||||
// TODO test reject swap to wrong interface or class?
|
||||
// how to decide what's valid?
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws Exception {
|
||||
SerializablePerson sp1 = new SerializablePerson();
|
||||
sp1.setName("Tony");
|
||||
SerializablePerson sp2 = new SerializablePerson();
|
||||
sp1.setName("Gordon");
|
||||
|
||||
|
||||
HotSwappableTargetSource hts = new HotSwappableTargetSource(sp1);
|
||||
ProxyFactory pf = new ProxyFactory();
|
||||
pf.addInterface(Person.class);
|
||||
pf.setTargetSource(hts);
|
||||
pf.addAdvisor(new DefaultPointcutAdvisor(new SerializableNopInterceptor()));
|
||||
Person p = (Person) pf.getProxy();
|
||||
|
||||
|
||||
assertEquals(sp1.getName(), p.getName());
|
||||
hts.swap(sp2);
|
||||
assertEquals(sp2.getName(), p.getName());
|
||||
|
||||
|
||||
p = (Person) SerializationTestUtils.serializeAndDeserialize(p);
|
||||
// We need to get a reference to the client-side targetsource
|
||||
hts = (HotSwappableTargetSource) ((Advised) p).getTargetSource();
|
||||
assertEquals(sp2.getName(), p.getName());
|
||||
hts.swap(sp1);
|
||||
assertEquals(sp1.getName(), p.getName());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ import test.beans.ITestBean;
|
||||
* @since 07.01.2005
|
||||
*/
|
||||
public final class LazyInitTargetSourceTests {
|
||||
|
||||
|
||||
private static final Class<?> CLASS = LazyInitTargetSourceTests.class;
|
||||
|
||||
|
||||
private static final Resource SINGLETON_CONTEXT = qualifiedResource(CLASS, "singleton.xml");
|
||||
private static final Resource CUSTOM_TARGET_CONTEXT = qualifiedResource(CLASS, "customTarget.xml");
|
||||
private static final Resource FACTORY_BEAN_CONTEXT = qualifiedResource(CLASS, "factoryBean.xml");
|
||||
|
||||
@@ -59,9 +59,9 @@ public final class PrototypeBasedTargetSourceTests {
|
||||
assertNotNull(sts.getTarget());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class TestTargetSource extends AbstractPrototypeBasedTargetSource {
|
||||
|
||||
|
||||
/**
|
||||
* Nonserializable test field to check that subclass
|
||||
* state can't prevent serialization from working
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
@@ -33,14 +33,14 @@ import test.beans.SideEffectBean;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class PrototypeTargetSourceTests {
|
||||
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(PrototypeTargetSourceTests.class, "context.xml");
|
||||
|
||||
|
||||
/** Initial count value set in bean factory XML */
|
||||
private static final int INITIAL_COUNT = 10;
|
||||
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.beanFactory = new XmlBeanFactory(CONTEXT);
|
||||
@@ -57,7 +57,7 @@ public final class PrototypeTargetSourceTests {
|
||||
assertEquals(INITIAL_COUNT, singleton.getCount() );
|
||||
singleton.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, singleton.getCount() );
|
||||
|
||||
|
||||
SideEffectBean prototype = (SideEffectBean) beanFactory.getBean("prototype");
|
||||
assertEquals(INITIAL_COUNT, prototype.getCount() );
|
||||
prototype.doWork();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
@@ -33,26 +33,26 @@ import test.beans.SideEffectBean;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class ThreadLocalTargetSourceTests {
|
||||
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(ThreadLocalTargetSourceTests.class, "context.xml");
|
||||
|
||||
/** Initial count value set in bean factory XML */
|
||||
private static final int INITIAL_COUNT = 10;
|
||||
|
||||
private XmlBeanFactory beanFactory;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.beanFactory = new XmlBeanFactory(CONTEXT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* We must simulate container shutdown, which should clear threads.
|
||||
*/
|
||||
protected void tearDown() {
|
||||
this.beanFactory.destroySingletons();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check we can use two different ThreadLocalTargetSources
|
||||
* managing objects of different types without them interfering
|
||||
@@ -64,7 +64,7 @@ public class ThreadLocalTargetSourceTests {
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
||||
apartment.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
|
||||
|
||||
|
||||
ITestBean test = (ITestBean) beanFactory.getBean("threadLocal2");
|
||||
assertEquals("Rod", test.getName());
|
||||
assertEquals("Kerry", test.getSpouse().getName());
|
||||
@@ -76,11 +76,11 @@ public class ThreadLocalTargetSourceTests {
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
||||
apartment.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
|
||||
|
||||
|
||||
apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Relies on introduction.
|
||||
*/
|
||||
@@ -101,7 +101,7 @@ public class ThreadLocalTargetSourceTests {
|
||||
// Only one thread so only one object can have been bound
|
||||
assertEquals(1, stats.getObjectCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNewThreadHasOwnInstance() throws InterruptedException {
|
||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
@@ -110,7 +110,7 @@ public class ThreadLocalTargetSourceTests {
|
||||
apartment.doWork();
|
||||
apartment.doWork();
|
||||
assertEquals(INITIAL_COUNT + 3, apartment.getCount() );
|
||||
|
||||
|
||||
class Runner implements Runnable {
|
||||
public SideEffectBean mine;
|
||||
public void run() {
|
||||
@@ -124,16 +124,16 @@ public class ThreadLocalTargetSourceTests {
|
||||
Thread t = new Thread(r);
|
||||
t.start();
|
||||
t.join();
|
||||
|
||||
|
||||
assertNotNull(r);
|
||||
|
||||
|
||||
// Check it didn't affect the other thread's copy
|
||||
assertEquals(INITIAL_COUNT + 3, apartment.getCount() );
|
||||
|
||||
// When we use other thread's copy in this thread
|
||||
|
||||
// When we use other thread's copy in this thread
|
||||
// it should behave like ours
|
||||
assertEquals(INITIAL_COUNT + 3, r.mine.getCount() );
|
||||
|
||||
|
||||
// Bound to two threads
|
||||
assertEquals(2, ((ThreadLocalTargetSourceStats) apartment).getObjectCount());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user