Consistent use of varargs plus related polishing
(cherry picked from commit deae872
)
This commit is contained in:
parent
bc671f05d6
commit
1cfeb07fa5
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -86,7 +86,7 @@ public interface MethodMatcher {
|
||||||
* @return whether there's a runtime match
|
* @return whether there's a runtime match
|
||||||
* @see MethodMatcher#matches(Method, Class)
|
* @see MethodMatcher#matches(Method, Class)
|
||||||
*/
|
*/
|
||||||
boolean matches(Method method, Class<?> targetClass, Object[] args);
|
boolean matches(Method method, Class<?> targetClass, Object... args);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -29,12 +29,14 @@ class TrueMethodMatcher implements MethodMatcher, Serializable {
|
||||||
|
|
||||||
public static final TrueMethodMatcher INSTANCE = new TrueMethodMatcher();
|
public static final TrueMethodMatcher INSTANCE = new TrueMethodMatcher();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enforce Singleton pattern.
|
* Enforce Singleton pattern.
|
||||||
*/
|
*/
|
||||||
private TrueMethodMatcher() {
|
private TrueMethodMatcher() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRuntime() {
|
public boolean isRuntime() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -46,11 +48,17 @@ class TrueMethodMatcher implements MethodMatcher, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method method, Class<?> targetClass, Object... args) {
|
||||||
// Should never be invoked as isRuntime returns false.
|
// Should never be invoked as isRuntime returns false.
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "MethodMatcher.TRUE";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required to support serialization. Replaces with canonical
|
* Required to support serialization. Replaces with canonical
|
||||||
* instance on deserialization, protecting Singleton pattern.
|
* instance on deserialization, protecting Singleton pattern.
|
||||||
|
@ -60,9 +68,4 @@ class TrueMethodMatcher implements MethodMatcher, Serializable {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "MethodMatcher.TRUE";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,7 +305,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method method, Class<?> targetClass, Object... args) {
|
||||||
checkReadyToMatch();
|
checkReadyToMatch();
|
||||||
ShadowMatch shadowMatch = getShadowMatch(AopUtils.getMostSpecificMethod(method, targetClass), method);
|
ShadowMatch shadowMatch = getShadowMatch(AopUtils.getMostSpecificMethod(method, targetClass), method);
|
||||||
ShadowMatch originalShadowMatch = getShadowMatch(method, method);
|
ShadowMatch originalShadowMatch = getShadowMatch(method, method);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -61,34 +61,6 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||||
private static final String AJC_MAGIC = "ajc$";
|
private static final String AJC_MAGIC = "ajc$";
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find and return the first AspectJ annotation on the given method
|
|
||||||
* (there <i>should</i> only be one anyway...)
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected static AspectJAnnotation<?> findAspectJAnnotationOnMethod(Method method) {
|
|
||||||
Class<?>[] classesToLookFor = new Class<?>[] {
|
|
||||||
Before.class, Around.class, After.class, AfterReturning.class, AfterThrowing.class, Pointcut.class};
|
|
||||||
for (Class<?> c : classesToLookFor) {
|
|
||||||
AspectJAnnotation<?> foundAnnotation = findAnnotation(method, (Class<Annotation>) c);
|
|
||||||
if (foundAnnotation != null) {
|
|
||||||
return foundAnnotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <A extends Annotation> AspectJAnnotation<A> findAnnotation(Method method, Class<A> toLookFor) {
|
|
||||||
A result = AnnotationUtils.findAnnotation(method, toLookFor);
|
|
||||||
if (result != null) {
|
|
||||||
return new AspectJAnnotation<A>(result);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Logger available to subclasses */
|
/** Logger available to subclasses */
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
|
@ -181,6 +153,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||||
throw new IllegalStateException("Expecting at least " + argNames.length +
|
throw new IllegalStateException("Expecting at least " + argNames.length +
|
||||||
" arguments in the advice declaration, but only found " + paramTypes.length);
|
" arguments in the advice declaration, but only found " + paramTypes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the simplifying assumption for now that all of the JoinPoint based arguments
|
// Make the simplifying assumption for now that all of the JoinPoint based arguments
|
||||||
// come first in the advice declaration.
|
// come first in the advice declaration.
|
||||||
int typeOffset = paramTypes.length - argNames.length;
|
int typeOffset = paramTypes.length - argNames.length;
|
||||||
|
@ -191,7 +164,36 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find and return the first AspectJ annotation on the given method
|
||||||
|
* (there <i>should</i> only be one anyway...)
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected static AspectJAnnotation<?> findAspectJAnnotationOnMethod(Method method) {
|
||||||
|
Class<?>[] classesToLookFor = new Class<?>[] {
|
||||||
|
Before.class, Around.class, After.class, AfterReturning.class, AfterThrowing.class, Pointcut.class};
|
||||||
|
for (Class<?> c : classesToLookFor) {
|
||||||
|
AspectJAnnotation<?> foundAnnotation = findAnnotation(method, (Class<Annotation>) c);
|
||||||
|
if (foundAnnotation != null) {
|
||||||
|
return foundAnnotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <A extends Annotation> AspectJAnnotation<A> findAnnotation(Method method, Class<A> toLookFor) {
|
||||||
|
A result = AnnotationUtils.findAnnotation(method, toLookFor);
|
||||||
|
if (result != null) {
|
||||||
|
return new AspectJAnnotation<A>(result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected enum AspectJAnnotationType {
|
protected enum AspectJAnnotationType {
|
||||||
|
|
||||||
AtPointcut,
|
AtPointcut,
|
||||||
AtBefore,
|
AtBefore,
|
||||||
AtAfter,
|
AtAfter,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -63,31 +63,31 @@ public interface AspectJAdvisorFactory {
|
||||||
/**
|
/**
|
||||||
* Build Spring AOP Advisors for all annotated At-AspectJ methods
|
* Build Spring AOP Advisors for all annotated At-AspectJ methods
|
||||||
* on the specified aspect instance.
|
* on the specified aspect instance.
|
||||||
* @param aif the aspect instance factory (not the aspect instance itself
|
* @param aspectInstanceFactory the aspect instance factory
|
||||||
* in order to avoid eager instantiation)
|
* (not the aspect instance itself in order to avoid eager instantiation)
|
||||||
* @return a list of advisors for this class
|
* @return a list of advisors for this class
|
||||||
*/
|
*/
|
||||||
List<Advisor> getAdvisors(MetadataAwareAspectInstanceFactory aif);
|
List<Advisor> getAdvisors(MetadataAwareAspectInstanceFactory aspectInstanceFactory);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a Spring AOP Advisor for the given AspectJ advice method.
|
* Build a Spring AOP Advisor for the given AspectJ advice method.
|
||||||
* @param candidateAdviceMethod the candidate advice method
|
* @param candidateAdviceMethod the candidate advice method
|
||||||
* @param aif the aspect instance factory
|
* @param aspectInstanceFactory the aspect instance factory
|
||||||
* @param declarationOrderInAspect the declaration order within the aspect
|
* @param declarationOrder the declaration order within the aspect
|
||||||
* @param aspectName the name of the aspect
|
* @param aspectName the name of the aspect
|
||||||
* @return {@code null} if the method is not an AspectJ advice method
|
* @return {@code null} if the method is not an AspectJ advice method
|
||||||
* or if it is a pointcut that will be used by other advice but will not
|
* or if it is a pointcut that will be used by other advice but will not
|
||||||
* create a Spring advice in its own right
|
* create a Spring advice in its own right
|
||||||
*/
|
*/
|
||||||
Advisor getAdvisor(Method candidateAdviceMethod,
|
Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory,
|
||||||
MetadataAwareAspectInstanceFactory aif, int declarationOrderInAspect, String aspectName);
|
int declarationOrder, String aspectName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a Spring AOP Advice for the given AspectJ advice method.
|
* Build a Spring AOP Advice for the given AspectJ advice method.
|
||||||
* @param candidateAdviceMethod the candidate advice method
|
* @param candidateAdviceMethod the candidate advice method
|
||||||
* @param pointcut the corresponding AspectJ expression pointcut
|
* @param expressionPointcut the AspectJ expression pointcut
|
||||||
* @param aif the aspect instance factory
|
* @param aspectInstanceFactory the aspect instance factory
|
||||||
* @param declarationOrderInAspect the declaration order within the aspect
|
* @param declarationOrder the declaration order within the aspect
|
||||||
* @param aspectName the name of the aspect
|
* @param aspectName the name of the aspect
|
||||||
* @return {@code null} if the method is not an AspectJ advice method
|
* @return {@code null} if the method is not an AspectJ advice method
|
||||||
* or if it is a pointcut that will be used by other advice but will not
|
* or if it is a pointcut that will be used by other advice but will not
|
||||||
|
@ -98,7 +98,7 @@ public interface AspectJAdvisorFactory {
|
||||||
* @see org.springframework.aop.aspectj.AspectJAfterReturningAdvice
|
* @see org.springframework.aop.aspectj.AspectJAfterReturningAdvice
|
||||||
* @see org.springframework.aop.aspectj.AspectJAfterThrowingAdvice
|
* @see org.springframework.aop.aspectj.AspectJAfterThrowingAdvice
|
||||||
*/
|
*/
|
||||||
Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut pointcut,
|
Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut,
|
||||||
MetadataAwareAspectInstanceFactory aif, int declarationOrderInAspect, String aspectName);
|
MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||||
|
|
||||||
private transient Method aspectJAdviceMethod;
|
private transient Method aspectJAdviceMethod;
|
||||||
|
|
||||||
private final AspectJAdvisorFactory atAspectJAdvisorFactory;
|
private final AspectJAdvisorFactory aspectJAdvisorFactory;
|
||||||
|
|
||||||
private final MetadataAwareAspectInstanceFactory aspectInstanceFactory;
|
private final MetadataAwareAspectInstanceFactory aspectInstanceFactory;
|
||||||
|
|
||||||
|
@ -73,28 +73,30 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||||
private Boolean isAfterAdvice;
|
private Boolean isAfterAdvice;
|
||||||
|
|
||||||
|
|
||||||
public InstantiationModelAwarePointcutAdvisorImpl(AspectJAdvisorFactory af, AspectJExpressionPointcut ajexp,
|
public InstantiationModelAwarePointcutAdvisorImpl(AspectJExpressionPointcut declaredPointcut,
|
||||||
MetadataAwareAspectInstanceFactory aif, Method method, int declarationOrderInAspect, String aspectName) {
|
Method aspectJAdviceMethod, AspectJAdvisorFactory aspectJAdvisorFactory,
|
||||||
|
MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName) {
|
||||||
|
|
||||||
this.declaredPointcut = ajexp;
|
this.declaredPointcut = declaredPointcut;
|
||||||
this.declaringClass = method.getDeclaringClass();
|
this.declaringClass = aspectJAdviceMethod.getDeclaringClass();
|
||||||
this.methodName = method.getName();
|
this.methodName = aspectJAdviceMethod.getName();
|
||||||
this.parameterTypes = method.getParameterTypes();
|
this.parameterTypes = aspectJAdviceMethod.getParameterTypes();
|
||||||
this.aspectJAdviceMethod = method;
|
this.aspectJAdviceMethod = aspectJAdviceMethod;
|
||||||
this.atAspectJAdvisorFactory = af;
|
this.aspectJAdvisorFactory = aspectJAdvisorFactory;
|
||||||
this.aspectInstanceFactory = aif;
|
this.aspectInstanceFactory = aspectInstanceFactory;
|
||||||
this.declarationOrder = declarationOrderInAspect;
|
this.declarationOrder = declarationOrder;
|
||||||
this.aspectName = aspectName;
|
this.aspectName = aspectName;
|
||||||
|
|
||||||
if (aif.getAspectMetadata().isLazilyInstantiated()) {
|
if (aspectInstanceFactory.getAspectMetadata().isLazilyInstantiated()) {
|
||||||
// Static part of the pointcut is a lazy type.
|
// Static part of the pointcut is a lazy type.
|
||||||
Pointcut preInstantiationPointcut =
|
Pointcut preInstantiationPointcut = Pointcuts.union(
|
||||||
Pointcuts.union(aif.getAspectMetadata().getPerClausePointcut(), this.declaredPointcut);
|
aspectInstanceFactory.getAspectMetadata().getPerClausePointcut(), this.declaredPointcut);
|
||||||
|
|
||||||
// Make it dynamic: must mutate from pre-instantiation to post-instantiation state.
|
// Make it dynamic: must mutate from pre-instantiation to post-instantiation state.
|
||||||
// If it's not a dynamic pointcut, it may be optimized out
|
// If it's not a dynamic pointcut, it may be optimized out
|
||||||
// by the Spring AOP infrastructure after the first evaluation.
|
// by the Spring AOP infrastructure after the first evaluation.
|
||||||
this.pointcut = new PerTargetInstantiationModelPointcut(this.declaredPointcut, preInstantiationPointcut, aif);
|
this.pointcut = new PerTargetInstantiationModelPointcut(
|
||||||
|
this.declaredPointcut, preInstantiationPointcut, aspectInstanceFactory);
|
||||||
this.lazy = true;
|
this.lazy = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -155,7 +157,7 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||||
|
|
||||||
|
|
||||||
private Advice instantiateAdvice(AspectJExpressionPointcut pcut) {
|
private Advice instantiateAdvice(AspectJExpressionPointcut pcut) {
|
||||||
return this.atAspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pcut,
|
return this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pcut,
|
||||||
this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
|
this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +281,7 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method method, Class<?> targetClass, Object... args) {
|
||||||
// This can match only on declared pointcut.
|
// This can match only on declared pointcut.
|
||||||
return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass));
|
return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass));
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,9 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||||
new Converter<Method, Annotation>() {
|
new Converter<Method, Annotation>() {
|
||||||
@Override
|
@Override
|
||||||
public Annotation convert(Method method) {
|
public Annotation convert(Method method) {
|
||||||
AspectJAnnotation<?> annotation = AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method);
|
AspectJAnnotation<?> annotation =
|
||||||
return annotation == null ? null : annotation.getAnnotation();
|
AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method);
|
||||||
|
return (annotation != null ? annotation.getAnnotation() : null);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
comparator.addComparator(new ConvertingComparator<Method, String>(
|
comparator.addComparator(new ConvertingComparator<Method, String>(
|
||||||
|
@ -95,17 +96,17 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Advisor> getAdvisors(MetadataAwareAspectInstanceFactory maaif) {
|
public List<Advisor> getAdvisors(MetadataAwareAspectInstanceFactory aspectInstanceFactory) {
|
||||||
final Class<?> aspectClass = maaif.getAspectMetadata().getAspectClass();
|
Class<?> aspectClass = aspectInstanceFactory.getAspectMetadata().getAspectClass();
|
||||||
final String aspectName = maaif.getAspectMetadata().getAspectName();
|
String aspectName = aspectInstanceFactory.getAspectMetadata().getAspectName();
|
||||||
validate(aspectClass);
|
validate(aspectClass);
|
||||||
|
|
||||||
// We need to wrap the MetadataAwareAspectInstanceFactory with a decorator
|
// We need to wrap the MetadataAwareAspectInstanceFactory with a decorator
|
||||||
// so that it will only instantiate once.
|
// so that it will only instantiate once.
|
||||||
final MetadataAwareAspectInstanceFactory lazySingletonAspectInstanceFactory =
|
MetadataAwareAspectInstanceFactory lazySingletonAspectInstanceFactory =
|
||||||
new LazySingletonAspectInstanceFactoryDecorator(maaif);
|
new LazySingletonAspectInstanceFactoryDecorator(aspectInstanceFactory);
|
||||||
|
|
||||||
final List<Advisor> advisors = new LinkedList<Advisor>();
|
List<Advisor> advisors = new LinkedList<Advisor>();
|
||||||
for (Method method : getAdvisorMethods(aspectClass)) {
|
for (Method method : getAdvisorMethods(aspectClass)) {
|
||||||
Advisor advisor = getAdvisor(method, lazySingletonAspectInstanceFactory, advisors.size(), aspectName);
|
Advisor advisor = getAdvisor(method, lazySingletonAspectInstanceFactory, advisors.size(), aspectName);
|
||||||
if (advisor != null) {
|
if (advisor != null) {
|
||||||
|
@ -171,18 +172,19 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aif,
|
public Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory,
|
||||||
int declarationOrderInAspect, String aspectName) {
|
int declarationOrderInAspect, String aspectName) {
|
||||||
|
|
||||||
validate(aif.getAspectMetadata().getAspectClass());
|
validate(aspectInstanceFactory.getAspectMetadata().getAspectClass());
|
||||||
|
|
||||||
AspectJExpressionPointcut ajexp =
|
AspectJExpressionPointcut expressionPointcut = getPointcut(
|
||||||
getPointcut(candidateAdviceMethod, aif.getAspectMetadata().getAspectClass());
|
candidateAdviceMethod, aspectInstanceFactory.getAspectMetadata().getAspectClass());
|
||||||
if (ajexp == null) {
|
if (expressionPointcut == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new InstantiationModelAwarePointcutAdvisorImpl(
|
|
||||||
this, ajexp, aif, candidateAdviceMethod, declarationOrderInAspect, aspectName);
|
return new InstantiationModelAwarePointcutAdvisorImpl(expressionPointcut, candidateAdviceMethod,
|
||||||
|
this, aspectInstanceFactory, declarationOrderInAspect, aspectName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AspectJExpressionPointcut getPointcut(Method candidateAdviceMethod, Class<?> candidateAspectClass) {
|
private AspectJExpressionPointcut getPointcut(Method candidateAdviceMethod, Class<?> candidateAspectClass) {
|
||||||
|
@ -191,6 +193,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||||
if (aspectJAnnotation == null) {
|
if (aspectJAnnotation == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
AspectJExpressionPointcut ajexp =
|
AspectJExpressionPointcut ajexp =
|
||||||
new AspectJExpressionPointcut(candidateAspectClass, new String[0], new Class<?>[0]);
|
new AspectJExpressionPointcut(candidateAspectClass, new String[0], new Class<?>[0]);
|
||||||
ajexp.setExpression(aspectJAnnotation.getPointcutExpression());
|
ajexp.setExpression(aspectJAnnotation.getPointcutExpression());
|
||||||
|
@ -199,10 +202,10 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut ajexp,
|
public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut,
|
||||||
MetadataAwareAspectInstanceFactory aif, int declarationOrderInAspect, String aspectName) {
|
MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName) {
|
||||||
|
|
||||||
Class<?> candidateAspectClass = aif.getAspectMetadata().getAspectClass();
|
Class<?> candidateAspectClass = aspectInstanceFactory.getAspectMetadata().getAspectClass();
|
||||||
validate(candidateAspectClass);
|
validate(candidateAspectClass);
|
||||||
|
|
||||||
AspectJAnnotation<?> aspectJAnnotation =
|
AspectJAnnotation<?> aspectJAnnotation =
|
||||||
|
@ -227,27 +230,32 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||||
|
|
||||||
switch (aspectJAnnotation.getAnnotationType()) {
|
switch (aspectJAnnotation.getAnnotationType()) {
|
||||||
case AtBefore:
|
case AtBefore:
|
||||||
springAdvice = new AspectJMethodBeforeAdvice(candidateAdviceMethod, ajexp, aif);
|
springAdvice = new AspectJMethodBeforeAdvice(
|
||||||
|
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||||
break;
|
break;
|
||||||
case AtAfter:
|
case AtAfter:
|
||||||
springAdvice = new AspectJAfterAdvice(candidateAdviceMethod, ajexp, aif);
|
springAdvice = new AspectJAfterAdvice(
|
||||||
|
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||||
break;
|
break;
|
||||||
case AtAfterReturning:
|
case AtAfterReturning:
|
||||||
springAdvice = new AspectJAfterReturningAdvice(candidateAdviceMethod, ajexp, aif);
|
springAdvice = new AspectJAfterReturningAdvice(
|
||||||
|
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||||
AfterReturning afterReturningAnnotation = (AfterReturning) aspectJAnnotation.getAnnotation();
|
AfterReturning afterReturningAnnotation = (AfterReturning) aspectJAnnotation.getAnnotation();
|
||||||
if (StringUtils.hasText(afterReturningAnnotation.returning())) {
|
if (StringUtils.hasText(afterReturningAnnotation.returning())) {
|
||||||
springAdvice.setReturningName(afterReturningAnnotation.returning());
|
springAdvice.setReturningName(afterReturningAnnotation.returning());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AtAfterThrowing:
|
case AtAfterThrowing:
|
||||||
springAdvice = new AspectJAfterThrowingAdvice(candidateAdviceMethod, ajexp, aif);
|
springAdvice = new AspectJAfterThrowingAdvice(
|
||||||
|
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||||
AfterThrowing afterThrowingAnnotation = (AfterThrowing) aspectJAnnotation.getAnnotation();
|
AfterThrowing afterThrowingAnnotation = (AfterThrowing) aspectJAnnotation.getAnnotation();
|
||||||
if (StringUtils.hasText(afterThrowingAnnotation.throwing())) {
|
if (StringUtils.hasText(afterThrowingAnnotation.throwing())) {
|
||||||
springAdvice.setThrowingName(afterThrowingAnnotation.throwing());
|
springAdvice.setThrowingName(afterThrowingAnnotation.throwing());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AtAround:
|
case AtAround:
|
||||||
springAdvice = new AspectJAroundAdvice(candidateAdviceMethod, ajexp, aif);
|
springAdvice = new AspectJAroundAdvice(
|
||||||
|
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||||
break;
|
break;
|
||||||
case AtPointcut:
|
case AtPointcut:
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
|
@ -256,12 +264,12 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||||
return null;
|
return null;
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException(
|
throw new UnsupportedOperationException(
|
||||||
"Unsupported advice type on method " + candidateAdviceMethod);
|
"Unsupported advice type on method: " + candidateAdviceMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now to configure the advice...
|
// Now to configure the advice...
|
||||||
springAdvice.setAspectName(aspectName);
|
springAdvice.setAspectName(aspectName);
|
||||||
springAdvice.setDeclarationOrder(declarationOrderInAspect);
|
springAdvice.setDeclarationOrder(declarationOrder);
|
||||||
String[] argNames = this.parameterNameDiscoverer.getParameterNames(candidateAdviceMethod);
|
String[] argNames = this.parameterNameDiscoverer.getParameterNames(candidateAdviceMethod);
|
||||||
if (argNames != null) {
|
if (argNames != null) {
|
||||||
springAdvice.setArgumentNamesFromStringArray(argNames);
|
springAdvice.setArgumentNamesFromStringArray(argNames);
|
||||||
|
@ -270,6 +278,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||||
return springAdvice;
|
return springAdvice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synthetic advisor that instantiates the aspect.
|
* Synthetic advisor that instantiates the aspect.
|
||||||
* Triggered by per-clause pointcut on non-singleton aspect.
|
* Triggered by per-clause pointcut on non-singleton aspect.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -113,7 +113,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||||
* Create a AdvisedSupport instance with the given parameters.
|
* Create a AdvisedSupport instance with the given parameters.
|
||||||
* @param interfaces the proxied interfaces
|
* @param interfaces the proxied interfaces
|
||||||
*/
|
*/
|
||||||
public AdvisedSupport(Class<?>[] interfaces) {
|
public AdvisedSupport(Class<?>... interfaces) {
|
||||||
this();
|
this();
|
||||||
setInterfaces(interfaces);
|
setInterfaces(interfaces);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -91,17 +91,17 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method method, Class<?> targetClass, Object... args) {
|
||||||
++this.evaluations;
|
this.evaluations++;
|
||||||
ControlFlow cflow = ControlFlowFactory.createControlFlow();
|
ControlFlow cflow = ControlFlowFactory.createControlFlow();
|
||||||
return (this.methodName != null) ? cflow.under(this.clazz, this.methodName) : cflow.under(this.clazz);
|
return (this.methodName != null ? cflow.under(this.clazz, this.methodName) : cflow.under(this.clazz));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It's useful to know how many times we've fired, for optimization.
|
* It's useful to know how many times we've fired, for optimization.
|
||||||
*/
|
*/
|
||||||
public int getEvaluations() {
|
public int getEvaluations() {
|
||||||
return evaluations;
|
return this.evaluations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,6 +115,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (this == other) {
|
if (this == other) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -138,7 +138,7 @@ public abstract class MethodMatchers {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method method, Class<?> targetClass, Object... args) {
|
||||||
return this.mm1.matches(method, targetClass, args) || this.mm2.matches(method, targetClass, args);
|
return this.mm1.matches(method, targetClass, args) || this.mm2.matches(method, targetClass, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ public abstract class MethodMatchers {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method method, Class<?> targetClass, Object... args) {
|
||||||
// Because a dynamic intersection may be composed of a static and dynamic part,
|
// Because a dynamic intersection may be composed of a static and dynamic part,
|
||||||
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
|
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
|
||||||
// it will probably be an unsupported operation.
|
// it will probably be an unsupported operation.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -71,7 +71,7 @@ public abstract class Pointcuts {
|
||||||
* @param args arguments to the method
|
* @param args arguments to the method
|
||||||
* @return whether there's a runtime match
|
* @return whether there's a runtime match
|
||||||
*/
|
*/
|
||||||
public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object[] args) {
|
public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object... args) {
|
||||||
Assert.notNull(pointcut, "Pointcut must not be null");
|
Assert.notNull(pointcut, "Pointcut must not be null");
|
||||||
if (pointcut == Pointcut.TRUE) {
|
if (pointcut == Pointcut.TRUE) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -98,9 +98,9 @@ public abstract class Pointcuts {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method, Class<?> targetClass) {
|
public boolean matches(Method method, Class<?> targetClass) {
|
||||||
return method.getName().startsWith("set") &&
|
return (method.getName().startsWith("set") &&
|
||||||
method.getParameterTypes().length == 1 &&
|
method.getParameterTypes().length == 1 &&
|
||||||
method.getReturnType() == Void.TYPE;
|
method.getReturnType() == Void.TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object readResolve() {
|
private Object readResolve() {
|
||||||
|
@ -119,8 +119,8 @@ public abstract class Pointcuts {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method, Class<?> targetClass) {
|
public boolean matches(Method method, Class<?> targetClass) {
|
||||||
return method.getName().startsWith("get") &&
|
return (method.getName().startsWith("get") &&
|
||||||
method.getParameterTypes().length == 0;
|
method.getParameterTypes().length == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object readResolve() {
|
private Object readResolve() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -32,7 +32,7 @@ public abstract class StaticMethodMatcher implements MethodMatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean matches(Method method, Class<?> targetClass, Object[] args) {
|
public final boolean matches(Method method, Class<?> targetClass, Object... args) {
|
||||||
// should never be invoked because isRuntime() returns false
|
// should never be invoked because isRuntime() returns false
|
||||||
throw new UnsupportedOperationException("Illegal MethodMatcher usage");
|
throw new UnsupportedOperationException("Illegal MethodMatcher usage");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -53,17 +53,15 @@ public final class AspectJExpressionPointcutTests {
|
||||||
|
|
||||||
private Method setSomeNumber;
|
private Method setSomeNumber;
|
||||||
|
|
||||||
private Method isPostProcessed;
|
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws NoSuchMethodException {
|
public void setUp() throws NoSuchMethodException {
|
||||||
getAge = TestBean.class.getMethod("getAge", (Class<?>[])null);
|
getAge = TestBean.class.getMethod("getAge");
|
||||||
setAge = TestBean.class.getMethod("setAge", new Class[]{int.class});
|
setAge = TestBean.class.getMethod("setAge", int.class);
|
||||||
setSomeNumber = TestBean.class.getMethod("setSomeNumber", new Class[]{Number.class});
|
setSomeNumber = TestBean.class.getMethod("setSomeNumber", Number.class);
|
||||||
isPostProcessed = TestBean.class.getMethod("isPostProcessed", (Class[]) null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatchExplicit() {
|
public void testMatchExplicit() {
|
||||||
String expression = "execution(int org.springframework.tests.sample.beans.TestBean.getAge())";
|
String expression = "execution(int org.springframework.tests.sample.beans.TestBean.getAge())";
|
||||||
|
@ -111,21 +109,9 @@ public final class AspectJExpressionPointcutTests {
|
||||||
testThisOrTarget("target");
|
testThisOrTarget("target");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class OtherIOther implements IOther {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void absquatulate() {
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This and target are equivalent. Really instanceof pointcuts.
|
* This and target are equivalent. Really instanceof pointcuts.
|
||||||
* @param which this or target
|
* @param which this or target
|
||||||
* @throws Exception
|
|
||||||
* @throws NoSuchMethodException
|
|
||||||
* @throws SecurityException
|
|
||||||
*/
|
*/
|
||||||
private void testThisOrTarget(String which) throws SecurityException, NoSuchMethodException {
|
private void testThisOrTarget(String which) throws SecurityException, NoSuchMethodException {
|
||||||
String matchesTestBean = which + "(org.springframework.tests.sample.beans.TestBean)";
|
String matchesTestBean = which + "(org.springframework.tests.sample.beans.TestBean)";
|
||||||
|
@ -138,11 +124,8 @@ public final class AspectJExpressionPointcutTests {
|
||||||
|
|
||||||
assertTrue(testBeanPc.matches(TestBean.class));
|
assertTrue(testBeanPc.matches(TestBean.class));
|
||||||
assertTrue(testBeanPc.matches(getAge, TestBean.class));
|
assertTrue(testBeanPc.matches(getAge, TestBean.class));
|
||||||
assertTrue(iOtherPc.matches(OtherIOther.class.getMethod("absquatulate", (Class<?>[])null),
|
assertTrue(iOtherPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class));
|
||||||
OtherIOther.class));
|
assertFalse(testBeanPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class));
|
||||||
|
|
||||||
assertFalse(testBeanPc.matches(OtherIOther.class.getMethod("absquatulate", (Class<?>[])null),
|
|
||||||
OtherIOther.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -171,8 +154,7 @@ public final class AspectJExpressionPointcutTests {
|
||||||
assertEquals(matchSubpackages, withinBeansPc.matches(
|
assertEquals(matchSubpackages, withinBeansPc.matches(
|
||||||
DeepBean.class.getMethod("aMethod", String.class), DeepBean.class));
|
DeepBean.class.getMethod("aMethod", String.class), DeepBean.class));
|
||||||
assertFalse(withinBeansPc.matches(String.class));
|
assertFalse(withinBeansPc.matches(String.class));
|
||||||
assertFalse(withinBeansPc.matches(OtherIOther.class.getMethod("absquatulate", (Class<?>[])null),
|
assertFalse(withinBeansPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class));
|
||||||
OtherIOther.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -183,7 +165,7 @@ public final class AspectJExpressionPointcutTests {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
catch (IllegalStateException ex) {
|
catch (IllegalStateException ex) {
|
||||||
assertTrue(ex.getMessage().indexOf("expression") != -1);
|
assertTrue(ex.getMessage().contains("expression"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +177,7 @@ public final class AspectJExpressionPointcutTests {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
catch (IllegalStateException ex) {
|
catch (IllegalStateException ex) {
|
||||||
assertTrue(ex.getMessage().indexOf("expression") != -1);
|
assertTrue(ex.getMessage().contains("expression"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +189,7 @@ public final class AspectJExpressionPointcutTests {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
catch (IllegalStateException ex) {
|
catch (IllegalStateException ex) {
|
||||||
assertTrue(ex.getMessage().indexOf("expression") != -1);
|
assertTrue(ex.getMessage().contains("expression"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,10 +208,10 @@ public final class AspectJExpressionPointcutTests {
|
||||||
//assertDoesNotMatchStringClass(classFilter);
|
//assertDoesNotMatchStringClass(classFilter);
|
||||||
|
|
||||||
assertTrue("Should match with setSomeNumber with Double input",
|
assertTrue("Should match with setSomeNumber with Double input",
|
||||||
methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Double(12)}));
|
methodMatcher.matches(setSomeNumber, TestBean.class, new Double(12)));
|
||||||
assertFalse("Should not match setSomeNumber with Integer input",
|
assertFalse("Should not match setSomeNumber with Integer input",
|
||||||
methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Integer(11)}));
|
methodMatcher.matches(setSomeNumber, TestBean.class, new Integer(11)));
|
||||||
assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class, null));
|
assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class));
|
||||||
assertTrue("Should be a runtime match", methodMatcher.isRuntime());
|
assertTrue("Should be a runtime match", methodMatcher.isRuntime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +263,6 @@ public final class AspectJExpressionPointcutTests {
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ex) {
|
catch (IllegalArgumentException ex) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
System.out.println(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,16 +307,14 @@ public final class AspectJExpressionPointcutTests {
|
||||||
@Test
|
@Test
|
||||||
public void testAndSubstitution() {
|
public void testAndSubstitution() {
|
||||||
Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
|
Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
|
||||||
PointcutExpression expr =
|
PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
|
||||||
((AspectJExpressionPointcut) pc).getPointcutExpression();
|
|
||||||
assertEquals("execution(* *(..)) && args(String)",expr.getPointcutExpression());
|
assertEquals("execution(* *(..)) && args(String)",expr.getPointcutExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleAndSubstitutions() {
|
public void testMultipleAndSubstitutions() {
|
||||||
Pointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)");
|
Pointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)");
|
||||||
PointcutExpression expr =
|
PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
|
||||||
((AspectJExpressionPointcut) pc).getPointcutExpression();
|
|
||||||
assertEquals("execution(* *(..)) && args(String) && this(Object)",expr.getPointcutExpression());
|
assertEquals("execution(* *(..)) && args(String) && this(Object)",expr.getPointcutExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,6 +323,15 @@ public final class AspectJExpressionPointcutTests {
|
||||||
pointcut.setExpression(expression);
|
pointcut.setExpression(expression);
|
||||||
return pointcut;
|
return pointcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class OtherIOther implements IOther {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void absquatulate() {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -36,7 +36,7 @@ import static org.junit.Assert.*;
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public final class TigerAspectJExpressionPointcutTests {
|
public class TigerAspectJExpressionPointcutTests {
|
||||||
|
|
||||||
// TODO factor into static in AspectJExpressionPointcut
|
// TODO factor into static in AspectJExpressionPointcut
|
||||||
private Method getAge;
|
private Method getAge;
|
||||||
|
@ -46,7 +46,7 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws NoSuchMethodException {
|
public void setUp() throws NoSuchMethodException {
|
||||||
getAge = TestBean.class.getMethod("getAge", (Class[]) null);
|
getAge = TestBean.class.getMethod("getAge");
|
||||||
// Assumes no overloading
|
// Assumes no overloading
|
||||||
for (Method m : HasGeneric.class.getMethods()) {
|
for (Method m : HasGeneric.class.getMethods()) {
|
||||||
methodsOnHasGeneric.put(m.getName(), m);
|
methodsOnHasGeneric.put(m.getName(), m);
|
||||||
|
@ -54,18 +54,6 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class HasGeneric {
|
|
||||||
|
|
||||||
public void setFriends(List<TestBean> friends) {
|
|
||||||
}
|
|
||||||
public void setEnemies(List<TestBean> enemies) {
|
|
||||||
}
|
|
||||||
public void setPartners(List<?> partners) {
|
|
||||||
}
|
|
||||||
public void setPhoneNumbers(List<String> numbers) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatchGenericArgument() {
|
public void testMatchGenericArgument() {
|
||||||
String expression = "execution(* set*(java.util.List<org.springframework.tests.sample.beans.TestBean>) )";
|
String expression = "execution(* set*(java.util.List<org.springframework.tests.sample.beans.TestBean>) )";
|
||||||
|
@ -132,15 +120,12 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||||
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws SecurityException, NoSuchMethodException {
|
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws SecurityException, NoSuchMethodException {
|
||||||
String expression = "within(@(test.annotation..*) *)";
|
String expression = "within(@(test.annotation..*) *)";
|
||||||
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression);
|
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||||
assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class),
|
assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class));
|
||||||
TestBean.class));
|
assertTrue(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class));
|
||||||
assertTrue(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo", (Class[]) null),
|
|
||||||
SpringAnnotated.class));
|
|
||||||
|
|
||||||
expression = "within(@(test.annotation.transaction..*) *)";
|
expression = "within(@(test.annotation.transaction..*) *)";
|
||||||
AspectJExpressionPointcut springTxAnnotatedPc = testMatchAnnotationOnClass(expression);
|
AspectJExpressionPointcut springTxAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||||
assertFalse(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo", (Class[]) null),
|
assertFalse(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class));
|
||||||
SpringAnnotated.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -154,7 +139,7 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||||
ajexp.setExpression(expression);
|
ajexp.setExpression(expression);
|
||||||
|
|
||||||
assertFalse(ajexp.matches(getAge, TestBean.class));
|
assertFalse(ajexp.matches(getAge, TestBean.class));
|
||||||
assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class));
|
assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||||
assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||||
assertTrue(ajexp.matches(BeanB.class.getMethod("setName", String.class), BeanB.class));
|
assertTrue(ajexp.matches(BeanB.class.getMethod("setName", String.class), BeanB.class));
|
||||||
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||||
|
@ -168,10 +153,10 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||||
ajexp.setExpression(expression);
|
ajexp.setExpression(expression);
|
||||||
|
|
||||||
assertFalse(ajexp.matches(getAge, TestBean.class));
|
assertFalse(ajexp.matches(getAge, TestBean.class));
|
||||||
assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class));
|
assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||||
assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||||
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||||
assertTrue(ajexp.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class));
|
assertTrue(ajexp.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||||
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,10 +167,10 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||||
anySpringMethodAnnotation.setExpression(expression);
|
anySpringMethodAnnotation.setExpression(expression);
|
||||||
|
|
||||||
assertFalse(anySpringMethodAnnotation.matches(getAge, TestBean.class));
|
assertFalse(anySpringMethodAnnotation.matches(getAge, TestBean.class));
|
||||||
assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class));
|
assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||||
assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||||
assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||||
assertTrue(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class));
|
assertTrue(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||||
assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,10 +181,10 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||||
|
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
|
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class));
|
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), 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("setName", String.class), BeanA.class));
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class));
|
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||||
|
|
||||||
assertTrue(takesSpringAnnotatedArgument2.matches(
|
assertTrue(takesSpringAnnotatedArgument2.matches(
|
||||||
|
@ -213,8 +198,7 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||||
|
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||||
ProcessesSpringAnnotatedParameters.class,
|
ProcessesSpringAnnotatedParameters.class, new TestBean(), new BeanA())
|
||||||
new Object[] { new TestBean(), new BeanA()})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,10 +209,10 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||||
|
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
|
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class));
|
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), 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("setName", String.class), BeanA.class));
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class));
|
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||||
|
|
||||||
assertTrue(takesSpringAnnotatedArgument2.matches(
|
assertTrue(takesSpringAnnotatedArgument2.matches(
|
||||||
|
@ -240,6 +224,19 @@ public final class TigerAspectJExpressionPointcutTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class HasGeneric {
|
||||||
|
|
||||||
|
public void setFriends(List<TestBean> friends) {
|
||||||
|
}
|
||||||
|
public void setEnemies(List<TestBean> enemies) {
|
||||||
|
}
|
||||||
|
public void setPartners(List<?> partners) {
|
||||||
|
}
|
||||||
|
public void setPhoneNumbers(List<String> numbers) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class ProcessesSpringAnnotatedParameters {
|
public static class ProcessesSpringAnnotatedParameters {
|
||||||
|
|
||||||
public void takesAnnotatedParameters(TestBean tb, SpringAnnotated sa) {
|
public void takesAnnotatedParameters(TestBean tb, SpringAnnotated sa) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,6 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.aop.aspectj.annotation;
|
package org.springframework.aop.aspectj.annotation;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -961,7 +962,7 @@ abstract class AbstractMakeModifiable {
|
||||||
private Method getGetterFromSetter(Method setter) {
|
private Method getGetterFromSetter(Method setter) {
|
||||||
String getterName = setter.getName().replaceFirst("set", "get");
|
String getterName = setter.getName().replaceFirst("set", "get");
|
||||||
try {
|
try {
|
||||||
return setter.getDeclaringClass().getMethod(getterName, (Class[]) null);
|
return setter.getDeclaringClass().getMethod(getterName);
|
||||||
}
|
}
|
||||||
catch (NoSuchMethodException ex) {
|
catch (NoSuchMethodException ex) {
|
||||||
// must be write only
|
// must be write only
|
||||||
|
|
|
@ -41,9 +41,11 @@ public class AspectJPointcutAdvisorTests {
|
||||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||||
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
|
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
|
||||||
|
|
||||||
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
|
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(
|
||||||
|
ajexp, TestBean.class.getMethod("getAge"), af,
|
||||||
new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.ExceptionAspect(null), "someBean"),
|
new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.ExceptionAspect(null), "someBean"),
|
||||||
TestBean.class.getMethod("getAge", (Class[]) null), 1, "someBean");
|
1, "someBean");
|
||||||
|
|
||||||
assertSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
|
assertSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
|
||||||
assertFalse(ajpa.isPerInstance());
|
assertFalse(ajpa.isPerInstance());
|
||||||
}
|
}
|
||||||
|
@ -53,19 +55,21 @@ public class AspectJPointcutAdvisorTests {
|
||||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||||
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
|
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
|
||||||
|
|
||||||
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
|
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(
|
||||||
new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(),"someBean"),
|
ajexp, TestBean.class.getMethod("getAge"), af,
|
||||||
TestBean.class.getMethod("getAge", (Class[]) null), 1, "someBean");
|
new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean"),
|
||||||
|
1, "someBean");
|
||||||
|
|
||||||
assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
|
assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
|
||||||
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
|
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
|
||||||
assertTrue(ajpa.isPerInstance());
|
assertTrue(ajpa.isPerInstance());
|
||||||
|
|
||||||
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class));
|
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class));
|
||||||
assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
|
assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
|
||||||
TestBean.class.getMethod("getAge", (Class[]) null), TestBean.class));
|
TestBean.class.getMethod("getAge"), TestBean.class));
|
||||||
|
|
||||||
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
|
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
|
||||||
TestBean.class.getMethod("getSpouse", (Class[]) null), TestBean.class));
|
TestBean.class.getMethod("getSpouse"), TestBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = AopConfigException.class)
|
@Test(expected = AopConfigException.class)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -37,7 +37,7 @@ public final class MethodInvocationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidInvocation() throws Throwable {
|
public void testValidInvocation() throws Throwable {
|
||||||
Method m = Object.class.getMethod("hashCode", (Class[]) null);
|
Method m = Object.class.getMethod("hashCode");
|
||||||
Object proxy = new Object();
|
Object proxy = new Object();
|
||||||
final Object returnValue = new Object();
|
final Object returnValue = new Object();
|
||||||
List<Object> is = new LinkedList<Object>();
|
List<Object> is = new LinkedList<Object>();
|
||||||
|
@ -67,7 +67,7 @@ public final class MethodInvocationTests {
|
||||||
};
|
};
|
||||||
List<Object> is = new LinkedList<Object>();
|
List<Object> is = new LinkedList<Object>();
|
||||||
|
|
||||||
Method m = Object.class.getMethod("hashCode", (Class[]) null);
|
Method m = Object.class.getMethod("hashCode");
|
||||||
Object proxy = new Object();
|
Object proxy = new Object();
|
||||||
ReflectiveMethodInvocation invocation =
|
ReflectiveMethodInvocation invocation =
|
||||||
new ReflectiveMethodInvocation(proxy, target, m, null, null, is);
|
new ReflectiveMethodInvocation(proxy, target, m, null, null, is);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -78,7 +78,7 @@ public final class ThrowsAdviceInterceptorTests {
|
||||||
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
||||||
FileNotFoundException ex = new FileNotFoundException();
|
FileNotFoundException ex = new FileNotFoundException();
|
||||||
MethodInvocation mi = mock(MethodInvocation.class);
|
MethodInvocation mi = mock(MethodInvocation.class);
|
||||||
given(mi.getMethod()).willReturn(Object.class.getMethod("hashCode", (Class[]) null));
|
given(mi.getMethod()).willReturn(Object.class.getMethod("hashCode"));
|
||||||
given(mi.getThis()).willReturn(new Object());
|
given(mi.getThis()).willReturn(new Object());
|
||||||
given(mi.proceed()).willThrow(ex);
|
given(mi.proceed()).willThrow(ex);
|
||||||
try {
|
try {
|
||||||
|
@ -140,12 +140,15 @@ public final class ThrowsAdviceInterceptorTests {
|
||||||
assertEquals(1, th.getCalls("remoteException"));
|
assertEquals(1, th.getCalls("remoteException"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
static class MyThrowsHandler extends MethodCounter implements ThrowsAdvice {
|
static class MyThrowsHandler extends MethodCounter implements ThrowsAdvice {
|
||||||
|
|
||||||
// Full method signature
|
// Full method signature
|
||||||
public void afterThrowing(Method m, Object[] args, Object target, IOException ex) {
|
public void afterThrowing(Method m, Object[] args, Object target, IOException ex) {
|
||||||
count("ioException");
|
count("ioException");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterThrowing(RemoteException ex) throws Throwable {
|
public void afterThrowing(RemoteException ex) throws Throwable {
|
||||||
count("remoteException");
|
count("remoteException");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -54,8 +54,8 @@ public abstract class AbstractRegexpMethodPointcutTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void noPatternSuppliedTests(AbstractRegexpMethodPointcut rpc) throws Exception {
|
protected void noPatternSuppliedTests(AbstractRegexpMethodPointcut rpc) throws Exception {
|
||||||
assertFalse(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), String.class));
|
assertFalse(rpc.matches(Object.class.getMethod("hashCode"), String.class));
|
||||||
assertFalse(rpc.matches(Object.class.getMethod("wait", (Class[]) null), Object.class));
|
assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class));
|
||||||
assertEquals(0, rpc.getPatterns().length);
|
assertEquals(0, rpc.getPatterns().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,38 +69,38 @@ public abstract class AbstractRegexpMethodPointcutTests {
|
||||||
|
|
||||||
protected void exactMatchTests(AbstractRegexpMethodPointcut rpc) throws Exception {
|
protected void exactMatchTests(AbstractRegexpMethodPointcut rpc) throws Exception {
|
||||||
// assumes rpc.setPattern("java.lang.Object.hashCode");
|
// assumes rpc.setPattern("java.lang.Object.hashCode");
|
||||||
assertTrue(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), String.class));
|
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class));
|
||||||
assertTrue(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), Object.class));
|
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), Object.class));
|
||||||
assertFalse(rpc.matches(Object.class.getMethod("wait", (Class[]) null), Object.class));
|
assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSpecificMatch() throws Exception {
|
public void testSpecificMatch() throws Exception {
|
||||||
rpc.setPattern("java.lang.String.hashCode");
|
rpc.setPattern("java.lang.String.hashCode");
|
||||||
assertTrue(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), String.class));
|
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class));
|
||||||
assertFalse(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), Object.class));
|
assertFalse(rpc.matches(Object.class.getMethod("hashCode"), Object.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWildcard() throws Exception {
|
public void testWildcard() throws Exception {
|
||||||
rpc.setPattern(".*Object.hashCode");
|
rpc.setPattern(".*Object.hashCode");
|
||||||
assertTrue(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), Object.class));
|
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), Object.class));
|
||||||
assertFalse(rpc.matches(Object.class.getMethod("wait", (Class[]) null), Object.class));
|
assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWildcardForOneClass() throws Exception {
|
public void testWildcardForOneClass() throws Exception {
|
||||||
rpc.setPattern("java.lang.Object.*");
|
rpc.setPattern("java.lang.Object.*");
|
||||||
assertTrue(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), String.class));
|
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class));
|
||||||
assertTrue(rpc.matches(Object.class.getMethod("wait", (Class[]) null), String.class));
|
assertTrue(rpc.matches(Object.class.getMethod("wait"), String.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatchesObjectClass() throws Exception {
|
public void testMatchesObjectClass() throws Exception {
|
||||||
rpc.setPattern("java.lang.Object.*");
|
rpc.setPattern("java.lang.Object.*");
|
||||||
assertTrue(rpc.matches(Exception.class.getMethod("hashCode", (Class[]) null), IOException.class));
|
assertTrue(rpc.matches(Exception.class.getMethod("hashCode"), IOException.class));
|
||||||
// Doesn't match a method from Throwable
|
// Doesn't match a method from Throwable
|
||||||
assertFalse(rpc.matches(Exception.class.getMethod("getMessage", (Class[]) null), Exception.class));
|
assertFalse(rpc.matches(Exception.class.getMethod("getMessage"), Exception.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -32,7 +32,7 @@ import static org.junit.Assert.*;
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public final class ComposablePointcutTests {
|
public class ComposablePointcutTests {
|
||||||
|
|
||||||
public static MethodMatcher GETTER_METHOD_MATCHER = new StaticMethodMatcher() {
|
public static MethodMatcher GETTER_METHOD_MATCHER = new StaticMethodMatcher() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,11 +62,12 @@ public final class ComposablePointcutTests {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatchAll() throws NoSuchMethodException {
|
public void testMatchAll() throws NoSuchMethodException {
|
||||||
Pointcut pc = new ComposablePointcut();
|
Pointcut pc = new ComposablePointcut();
|
||||||
assertTrue(pc.getClassFilter().matches(Object.class));
|
assertTrue(pc.getClassFilter().matches(Object.class));
|
||||||
assertTrue(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode", (Class[]) null), Exception.class));
|
assertTrue(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode"), Exception.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -93,23 +94,23 @@ public final class ComposablePointcutTests {
|
||||||
public void testUnionMethodMatcher() {
|
public void testUnionMethodMatcher() {
|
||||||
// Matches the getAge() method in any class
|
// Matches the getAge() method in any class
|
||||||
ComposablePointcut pc = new ComposablePointcut(ClassFilter.TRUE, GET_AGE_METHOD_MATCHER);
|
ComposablePointcut pc = new ComposablePointcut(ClassFilter.TRUE, GET_AGE_METHOD_MATCHER);
|
||||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
|
|
||||||
pc.union(GETTER_METHOD_MATCHER);
|
pc.union(GETTER_METHOD_MATCHER);
|
||||||
// Should now match all getter methods
|
// Should now match all getter methods
|
||||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
|
|
||||||
pc.union(ABSQUATULATE_METHOD_MATCHER);
|
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_ABSQUATULATE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
// But it doesn't match everything
|
// But it doesn't match everything
|
||||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_SET_AGE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_SET_AGE, TestBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -124,9 +125,9 @@ public final class ComposablePointcutTests {
|
||||||
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
pc.intersection(GET_AGE_METHOD_MATCHER);
|
pc.intersection(GET_AGE_METHOD_MATCHER);
|
||||||
// Use the Pointcuts matches method
|
// Use the Pointcuts matches method
|
||||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -153,4 +154,5 @@ public final class ComposablePointcutTests {
|
||||||
assertEquals(pc1, pc2);
|
assertEquals(pc1, pc2);
|
||||||
assertEquals(pc1.hashCode(), pc2.hashCode());
|
assertEquals(pc1.hashCode(), pc2.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -32,7 +32,7 @@ import static org.junit.Assert.*;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public final class MethodMatchersTests {
|
public class MethodMatchersTests {
|
||||||
|
|
||||||
private final Method EXCEPTION_GETMESSAGE;
|
private final Method EXCEPTION_GETMESSAGE;
|
||||||
|
|
||||||
|
@ -44,10 +44,10 @@ public final class MethodMatchersTests {
|
||||||
|
|
||||||
|
|
||||||
public MethodMatchersTests() throws Exception {
|
public MethodMatchersTests() throws Exception {
|
||||||
EXCEPTION_GETMESSAGE = Exception.class.getMethod("getMessage", (Class[]) null);
|
EXCEPTION_GETMESSAGE = Exception.class.getMethod("getMessage");
|
||||||
ITESTBEAN_GETAGE = ITestBean.class.getMethod("getAge", (Class[]) null);
|
ITESTBEAN_GETAGE = ITestBean.class.getMethod("getAge");
|
||||||
ITESTBEAN_SETAGE = ITestBean.class.getMethod("setAge", new Class[] { int.class });
|
ITESTBEAN_SETAGE = ITestBean.class.getMethod("setAge", int.class);
|
||||||
IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate", (Class[]) null);
|
IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,12 +82,12 @@ public final class MethodMatchersTests {
|
||||||
MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2);
|
MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2);
|
||||||
assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
|
assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
|
||||||
assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
|
assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||||
assertTrue("3Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) }));
|
assertTrue("3Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5)));
|
||||||
// Knock out dynamic part
|
// Knock out dynamic part
|
||||||
intersection = MethodMatchers.intersection(intersection, new TestDynamicMethodMatcherWhichDoesNotMatch());
|
intersection = MethodMatchers.intersection(intersection, new TestDynamicMethodMatcherWhichDoesNotMatch());
|
||||||
assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
|
assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
|
||||||
assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
|
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) }));
|
assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -125,18 +125,20 @@ public final class MethodMatchersTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TestDynamicMethodMatcherWhichMatches extends DynamicMethodMatcher {
|
private static class TestDynamicMethodMatcherWhichMatches extends DynamicMethodMatcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method m, Class<?> targetClass, Object... args) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TestDynamicMethodMatcherWhichDoesNotMatch extends DynamicMethodMatcher {
|
private static class TestDynamicMethodMatcherWhichDoesNotMatch extends DynamicMethodMatcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method m, Class<?> targetClass, Object... args) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -30,7 +30,7 @@ import static org.junit.Assert.*;
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public final class PointcutsTests {
|
public class PointcutsTests {
|
||||||
|
|
||||||
public static Method TEST_BEAN_SET_AGE;
|
public static Method TEST_BEAN_SET_AGE;
|
||||||
public static Method TEST_BEAN_GET_AGE;
|
public static Method TEST_BEAN_GET_AGE;
|
||||||
|
@ -39,10 +39,10 @@ public final class PointcutsTests {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
TEST_BEAN_SET_AGE = TestBean.class.getMethod("setAge", new Class[] { int.class });
|
TEST_BEAN_SET_AGE = TestBean.class.getMethod("setAge", int.class);
|
||||||
TEST_BEAN_GET_AGE = TestBean.class.getMethod("getAge", (Class[]) null);
|
TEST_BEAN_GET_AGE = TestBean.class.getMethod("getAge");
|
||||||
TEST_BEAN_GET_NAME = TestBean.class.getMethod("getName", (Class[]) null);
|
TEST_BEAN_GET_NAME = TestBean.class.getMethod("getName");
|
||||||
TEST_BEAN_ABSQUATULATE = TestBean.class.getMethod("absquatulate", (Class[]) null);
|
TEST_BEAN_ABSQUATULATE = TestBean.class.getMethod("absquatulate");
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new RuntimeException("Shouldn't happen: error in test suite");
|
throw new RuntimeException("Shouldn't happen: error in test suite");
|
||||||
|
@ -125,22 +125,22 @@ public final class PointcutsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrue() {
|
public void testTrue() {
|
||||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatches() {
|
public void testMatches() {
|
||||||
assertTrue(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertTrue(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
assertTrue(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,29 +149,29 @@ public final class PointcutsTests {
|
||||||
@Test
|
@Test
|
||||||
public void testUnionOfSettersAndGetters() {
|
public void testUnionOfSettersAndGetters() {
|
||||||
Pointcut union = Pointcuts.union(allClassGetterPointcut, allClassSetterPointcut);
|
Pointcut union = Pointcuts.union(allClassGetterPointcut, allClassSetterPointcut);
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnionOfSpecificGetters() {
|
public void testUnionOfSpecificGetters() {
|
||||||
Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut);
|
Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut);
|
||||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
|
|
||||||
// Union with all setters
|
// Union with all setters
|
||||||
union = Pointcuts.union(union, allClassSetterPointcut);
|
union = Pointcuts.union(union, allClassSetterPointcut);
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
|
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,16 +180,16 @@ public final class PointcutsTests {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUnionOfAllSettersAndSubclassSetters() {
|
public void testUnionOfAllSettersAndSubclassSetters() {
|
||||||
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
assertTrue(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Object[] { new Integer(6)}));
|
assertTrue(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6)));
|
||||||
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
|
|
||||||
Pointcut union = Pointcuts.union(myTestBeanSetterPointcut, allClassGetterPointcut);
|
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, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class, null));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||||
// Still doesn't match superclass setter
|
// Still doesn't match superclass setter
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Object[] { new Integer(6)}));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6)));
|
||||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -198,44 +198,44 @@ public final class PointcutsTests {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testIntersectionOfSpecificGettersAndSubclassGetters() {
|
public void testIntersectionOfSpecificGettersAndSubclassGetters() {
|
||||||
assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, MyTestBean.class, null));
|
assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||||
assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, MyTestBean.class, null));
|
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, MyTestBean.class));
|
||||||
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class, null));
|
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||||
|
|
||||||
Pointcut intersection = Pointcuts.intersection(allClassGetAgePointcut, myTestBeanGetterPointcut);
|
Pointcut intersection = Pointcuts.intersection(allClassGetAgePointcut, myTestBeanGetterPointcut);
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class));
|
||||||
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class, null));
|
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||||
// Matches subclass of MyTestBean
|
// Matches subclass of MyTestBean
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class));
|
||||||
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null));
|
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class));
|
||||||
|
|
||||||
// Now intersection with MyTestBeanSubclass getters should eliminate MyTestBean target
|
// Now intersection with MyTestBeanSubclass getters should eliminate MyTestBean target
|
||||||
intersection = Pointcuts.intersection(intersection, myTestBeanSubclassGetterPointcut);
|
intersection = Pointcuts.intersection(intersection, myTestBeanSubclassGetterPointcut);
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class));
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||||
// Still matches subclass of MyTestBean
|
// Still matches subclass of MyTestBean
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class));
|
||||||
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null));
|
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class));
|
||||||
|
|
||||||
// Now union with all TestBean methods
|
// Now union with all TestBean methods
|
||||||
Pointcut union = Pointcuts.union(intersection, allTestBeanMethodsPointcut);
|
Pointcut union = Pointcuts.union(intersection, allTestBeanMethodsPointcut);
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBean.class, null));
|
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBean.class));
|
||||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class, null));
|
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||||
// Still matches subclass of MyTestBean
|
// Still matches subclass of MyTestBean
|
||||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null));
|
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class));
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class));
|
||||||
|
|
||||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertTrue(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, MyTestBean.class, null));
|
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, MyTestBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -245,9 +245,9 @@ public final class PointcutsTests {
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleIntersection() {
|
public void testSimpleIntersection() {
|
||||||
Pointcut intersection = Pointcuts.intersection(allClassGetterPointcut, allClassSetterPointcut);
|
Pointcut intersection = Pointcuts.intersection(allClassGetterPointcut, allClassSetterPointcut);
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class));
|
||||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
|
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,13 @@ import java.util.Map;
|
||||||
import org.aopalliance.aop.Advice;
|
import org.aopalliance.aop.Advice;
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import test.mixin.LockMixin;
|
||||||
|
import test.mixin.LockMixinAdvisor;
|
||||||
|
import test.mixin.Lockable;
|
||||||
|
import test.mixin.LockedException;
|
||||||
|
|
||||||
import org.springframework.aop.Advisor;
|
import org.springframework.aop.Advisor;
|
||||||
import org.springframework.aop.AfterReturningAdvice;
|
import org.springframework.aop.AfterReturningAdvice;
|
||||||
|
@ -72,11 +75,6 @@ import org.springframework.tests.sample.beans.TestBean;
|
||||||
import org.springframework.util.SerializationTestUtils;
|
import org.springframework.util.SerializationTestUtils;
|
||||||
import org.springframework.util.StopWatch;
|
import org.springframework.util.StopWatch;
|
||||||
|
|
||||||
import test.mixin.LockMixin;
|
|
||||||
import test.mixin.LockMixinAdvisor;
|
|
||||||
import test.mixin.Lockable;
|
|
||||||
import test.mixin.LockedException;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,7 +121,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
|
|
||||||
@Test(expected = AopConfigException.class)
|
@Test(expected = AopConfigException.class)
|
||||||
public void testNoInterceptorsAndNoTarget() {
|
public void testNoInterceptorsAndNoTarget() {
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] { ITestBean.class });
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
// Add no interceptors
|
// Add no interceptors
|
||||||
AopProxy aop = createAopProxy(pc);
|
AopProxy aop = createAopProxy(pc);
|
||||||
aop.getProxy();
|
aop.getProxy();
|
||||||
|
@ -408,7 +406,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class});
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
if (context) {
|
if (context) {
|
||||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||||
}
|
}
|
||||||
|
@ -452,7 +450,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
throw expectedException;
|
throw expectedException;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class});
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||||
pc.addAdvice(mi);
|
pc.addAdvice(mi);
|
||||||
|
|
||||||
|
@ -487,7 +485,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
throw unexpectedException;
|
throw unexpectedException;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class});
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||||
pc.addAdvice(mi);
|
pc.addAdvice(mi);
|
||||||
|
|
||||||
|
@ -520,7 +518,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
throw unexpectedException;
|
throw unexpectedException;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class});
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||||
pc.addAdvice(mi);
|
pc.addAdvice(mi);
|
||||||
|
|
||||||
|
@ -548,7 +546,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
@Test
|
@Test
|
||||||
public void testTargetCanGetInvocationEvenIfNoAdviceChain() throws Throwable {
|
public void testTargetCanGetInvocationEvenIfNoAdviceChain() throws Throwable {
|
||||||
NeedsToSeeProxy target = new NeedsToSeeProxy();
|
NeedsToSeeProxy target = new NeedsToSeeProxy();
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {INeedsToSeeProxy.class});
|
AdvisedSupport pc = new AdvisedSupport(INeedsToSeeProxy.class);
|
||||||
pc.setTarget(target);
|
pc.setTarget(target);
|
||||||
pc.setExposeProxy(true);
|
pc.setExposeProxy(true);
|
||||||
|
|
||||||
|
@ -563,7 +561,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
public void testTargetCanGetInvocation() throws Throwable {
|
public void testTargetCanGetInvocation() throws Throwable {
|
||||||
final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean();
|
final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean();
|
||||||
|
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class, IOther.class});
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class);
|
||||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||||
TrapTargetInterceptor tii = new TrapTargetInterceptor() {
|
TrapTargetInterceptor tii = new TrapTargetInterceptor() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -600,7 +598,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
@Test
|
@Test
|
||||||
public void testMixinWithIntroductionAdvisor() throws Throwable {
|
public void testMixinWithIntroductionAdvisor() throws Throwable {
|
||||||
TestBean tb = new TestBean();
|
TestBean tb = new TestBean();
|
||||||
ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class});
|
ProxyFactory pc = new ProxyFactory();
|
||||||
|
pc.addInterface(ITestBean.class);
|
||||||
pc.addAdvisor(new LockMixinAdvisor());
|
pc.addAdvisor(new LockMixinAdvisor());
|
||||||
pc.setTarget(tb);
|
pc.setTarget(tb);
|
||||||
|
|
||||||
|
@ -610,7 +609,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
@Test
|
@Test
|
||||||
public void testMixinWithIntroductionInfo() throws Throwable {
|
public void testMixinWithIntroductionInfo() throws Throwable {
|
||||||
TestBean tb = new TestBean();
|
TestBean tb = new TestBean();
|
||||||
ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class});
|
ProxyFactory pc = new ProxyFactory();
|
||||||
|
pc.addInterface(ITestBean.class);
|
||||||
// We don't use an IntroductionAdvisor, we can just add an advice that implements IntroductionInfo
|
// We don't use an IntroductionAdvisor, we can just add an advice that implements IntroductionInfo
|
||||||
pc.addAdvice(new LockMixin());
|
pc.addAdvice(new LockMixin());
|
||||||
pc.setTarget(tb);
|
pc.setTarget(tb);
|
||||||
|
@ -648,7 +648,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
@Test
|
@Test
|
||||||
public void testReplaceArgument() throws Throwable {
|
public void testReplaceArgument() throws Throwable {
|
||||||
TestBean tb = new TestBean();
|
TestBean tb = new TestBean();
|
||||||
ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class});
|
ProxyFactory pc = new ProxyFactory();
|
||||||
|
pc.addInterface(ITestBean.class);
|
||||||
pc.setTarget(tb);
|
pc.setTarget(tb);
|
||||||
pc.addAdvisor(new StringSetterNullReplacementAdvice());
|
pc.addAdvisor(new StringSetterNullReplacementAdvice());
|
||||||
|
|
||||||
|
@ -825,7 +826,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
fail("Shouldn't be able to add introduction advice that introduces a class, rather than an interface");
|
fail("Shouldn't be able to add introduction advice that introduces a class, rather than an interface");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ex) {
|
catch (IllegalArgumentException ex) {
|
||||||
assertTrue(ex.getMessage().indexOf("interface") > -1);
|
assertTrue(ex.getMessage().contains("interface"));
|
||||||
}
|
}
|
||||||
// Check it still works: proxy factory state shouldn't have been corrupted
|
// Check it still works: proxy factory state shouldn't have been corrupted
|
||||||
ITestBean proxied = (ITestBean) createProxy(pc);
|
ITestBean proxied = (ITestBean) createProxy(pc);
|
||||||
|
@ -873,7 +874,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
fail("Shouldn't be able to add Advisor when frozen");
|
fail("Shouldn't be able to add Advisor when frozen");
|
||||||
}
|
}
|
||||||
catch (AopConfigException ex) {
|
catch (AopConfigException ex) {
|
||||||
assertTrue(ex.getMessage().indexOf("frozen") > -1);
|
assertTrue(ex.getMessage().contains("frozen"));
|
||||||
}
|
}
|
||||||
// Check it still works: proxy factory state shouldn't have been corrupted
|
// Check it still works: proxy factory state shouldn't have been corrupted
|
||||||
assertEquals(target.getAge(), proxied.getAge());
|
assertEquals(target.getAge(), proxied.getAge());
|
||||||
|
@ -897,7 +898,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
fail("Shouldn't be able to remove Advisor when frozen");
|
fail("Shouldn't be able to remove Advisor when frozen");
|
||||||
}
|
}
|
||||||
catch (AopConfigException ex) {
|
catch (AopConfigException ex) {
|
||||||
assertTrue(ex.getMessage().indexOf("frozen") > -1);
|
assertTrue(ex.getMessage().contains("frozen"));
|
||||||
}
|
}
|
||||||
// Didn't get removed
|
// Didn't get removed
|
||||||
assertEquals(1, advised.getAdvisors().length);
|
assertEquals(1, advised.getAdvisors().length);
|
||||||
|
@ -938,7 +939,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
public void testProxyConfigString() {
|
public void testProxyConfigString() {
|
||||||
TestBean target = new TestBean();
|
TestBean target = new TestBean();
|
||||||
ProxyFactory pc = new ProxyFactory(target);
|
ProxyFactory pc = new ProxyFactory(target);
|
||||||
pc.setInterfaces(new Class<?>[] {ITestBean.class});
|
pc.setInterfaces(ITestBean.class);
|
||||||
pc.addAdvice(new NopInterceptor());
|
pc.addAdvice(new NopInterceptor());
|
||||||
MethodBeforeAdvice mba = new CountingBeforeAdvice();
|
MethodBeforeAdvice mba = new CountingBeforeAdvice();
|
||||||
Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
|
Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
|
||||||
|
@ -946,15 +947,15 @@ public abstract class AbstractAopProxyTests {
|
||||||
ITestBean proxied = (ITestBean) createProxy(pc);
|
ITestBean proxied = (ITestBean) createProxy(pc);
|
||||||
|
|
||||||
String proxyConfigString = ((Advised) proxied).toProxyConfigString();
|
String proxyConfigString = ((Advised) proxied).toProxyConfigString();
|
||||||
assertTrue(proxyConfigString.indexOf(advisor.toString()) != -1);
|
assertTrue(proxyConfigString.contains(advisor.toString()));
|
||||||
assertTrue(proxyConfigString.indexOf("1 interface") != -1);
|
assertTrue(proxyConfigString.contains("1 interface"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCanPreventCastToAdvisedUsingOpaque() {
|
public void testCanPreventCastToAdvisedUsingOpaque() {
|
||||||
TestBean target = new TestBean();
|
TestBean target = new TestBean();
|
||||||
ProxyFactory pc = new ProxyFactory(target);
|
ProxyFactory pc = new ProxyFactory(target);
|
||||||
pc.setInterfaces(new Class<?>[] {ITestBean.class});
|
pc.setInterfaces(ITestBean.class);
|
||||||
pc.addAdvice(new NopInterceptor());
|
pc.addAdvice(new NopInterceptor());
|
||||||
CountingBeforeAdvice mba = new CountingBeforeAdvice();
|
CountingBeforeAdvice mba = new CountingBeforeAdvice();
|
||||||
Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
|
Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
|
||||||
|
@ -1055,7 +1056,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
@Test
|
@Test
|
||||||
public void testDynamicMethodPointcutThatAlwaysAppliesStatically() throws Throwable {
|
public void testDynamicMethodPointcutThatAlwaysAppliesStatically() throws Throwable {
|
||||||
TestBean tb = new TestBean();
|
TestBean tb = new TestBean();
|
||||||
ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class});
|
ProxyFactory pc = new ProxyFactory();
|
||||||
|
pc.addInterface(ITestBean.class);
|
||||||
TestDynamicPointcutAdvice dp = new TestDynamicPointcutAdvice(new NopInterceptor(), "getAge");
|
TestDynamicPointcutAdvice dp = new TestDynamicPointcutAdvice(new NopInterceptor(), "getAge");
|
||||||
pc.addAdvisor(dp);
|
pc.addAdvisor(dp);
|
||||||
pc.setTarget(tb);
|
pc.setTarget(tb);
|
||||||
|
@ -1071,7 +1073,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
@Test
|
@Test
|
||||||
public void testDynamicMethodPointcutThatAppliesStaticallyOnlyToSetters() throws Throwable {
|
public void testDynamicMethodPointcutThatAppliesStaticallyOnlyToSetters() throws Throwable {
|
||||||
TestBean tb = new TestBean();
|
TestBean tb = new TestBean();
|
||||||
ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class});
|
ProxyFactory pc = new ProxyFactory();
|
||||||
|
pc.addInterface(ITestBean.class);
|
||||||
// Could apply dynamically to getAge/setAge but not to getName
|
// Could apply dynamically to getAge/setAge but not to getName
|
||||||
TestDynamicPointcutForSettersOnly dp = new TestDynamicPointcutForSettersOnly(new NopInterceptor(), "Age");
|
TestDynamicPointcutForSettersOnly dp = new TestDynamicPointcutForSettersOnly(new NopInterceptor(), "Age");
|
||||||
pc.addAdvisor(dp);
|
pc.addAdvisor(dp);
|
||||||
|
@ -1093,7 +1096,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
@Test
|
@Test
|
||||||
public void testStaticMethodPointcut() throws Throwable {
|
public void testStaticMethodPointcut() throws Throwable {
|
||||||
TestBean tb = new TestBean();
|
TestBean tb = new TestBean();
|
||||||
ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class});
|
ProxyFactory pc = new ProxyFactory();
|
||||||
|
pc.addInterface(ITestBean.class);
|
||||||
NopInterceptor di = new NopInterceptor();
|
NopInterceptor di = new NopInterceptor();
|
||||||
TestStaticPointcutAdvice sp = new TestStaticPointcutAdvice(di, "getAge");
|
TestStaticPointcutAdvice sp = new TestStaticPointcutAdvice(di, "getAge");
|
||||||
pc.addAdvisor(sp);
|
pc.addAdvisor(sp);
|
||||||
|
@ -1207,6 +1211,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
public void testOverloadedMethodsWithDifferentAdvice() throws Throwable {
|
public void testOverloadedMethodsWithDifferentAdvice() throws Throwable {
|
||||||
Overloads target = new Overloads();
|
Overloads target = new Overloads();
|
||||||
ProxyFactory pc = new ProxyFactory(target);
|
ProxyFactory pc = new ProxyFactory(target);
|
||||||
|
|
||||||
NopInterceptor overLoadVoids = new NopInterceptor();
|
NopInterceptor overLoadVoids = new NopInterceptor();
|
||||||
pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadVoids) {
|
pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadVoids) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1214,6 +1219,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
return m.getName().equals("overload") && m.getParameterTypes().length == 0;
|
return m.getName().equals("overload") && m.getParameterTypes().length == 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
NopInterceptor overLoadInts = new NopInterceptor();
|
NopInterceptor overLoadInts = new NopInterceptor();
|
||||||
pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadInts) {
|
pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadInts) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1245,24 +1251,22 @@ public abstract class AbstractAopProxyTests {
|
||||||
pf.setExposeProxy(true);
|
pf.setExposeProxy(true);
|
||||||
final ITestBean proxy = (ITestBean) createProxy(pf);
|
final ITestBean proxy = (ITestBean) createProxy(pf);
|
||||||
Advised config = (Advised) proxy;
|
Advised config = (Advised) proxy;
|
||||||
|
|
||||||
// This class just checks proxy is bound before getTarget() call
|
// This class just checks proxy is bound before getTarget() call
|
||||||
config.setTargetSource(new TargetSource() {
|
config.setTargetSource(new TargetSource() {
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getTargetClass() {
|
public Class<?> getTargetClass() {
|
||||||
return TestBean.class;
|
return TestBean.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isStatic() {
|
public boolean isStatic() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTarget() throws Exception {
|
public Object getTarget() throws Exception {
|
||||||
assertEquals(proxy, AopContext.currentProxy());
|
assertEquals(proxy, AopContext.currentProxy());
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseTarget(Object target) throws Exception {
|
public void releaseTarget(Object target) throws Exception {
|
||||||
}
|
}
|
||||||
|
@ -1351,7 +1355,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
return invocation.proceed();
|
return invocation.proceed();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class});
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
MapAwareMethodInterceptor mami1 = new MapAwareMethodInterceptor(new HashMap<String, String>(), new HashMap<String, String>());
|
MapAwareMethodInterceptor mami1 = new MapAwareMethodInterceptor(new HashMap<String, String>(), new HashMap<String, String>());
|
||||||
Map<String, String> firstValuesToAdd = new HashMap<String, String>();
|
Map<String, String> firstValuesToAdd = new HashMap<String, String>();
|
||||||
firstValuesToAdd.put("test", "");
|
firstValuesToAdd.put("test", "");
|
||||||
|
@ -1683,7 +1687,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
super(cleaner);
|
super(cleaner);
|
||||||
setPointcut(new DynamicMethodMatcherPointcut() {
|
setPointcut(new DynamicMethodMatcherPointcut() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method m, Class<?> targetClass, Object... args) {
|
||||||
return args[0] == null;
|
return args[0] == null;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -1706,8 +1710,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
super(mi);
|
super(mi);
|
||||||
setPointcut(new DynamicMethodMatcherPointcut() {
|
setPointcut(new DynamicMethodMatcherPointcut() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method m, Class<?> targetClass, Object... args) {
|
||||||
boolean run = m.getName().indexOf(pattern) != -1;
|
boolean run = m.getName().contains(pattern);
|
||||||
if (run) ++count;
|
if (run) ++count;
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
|
@ -1725,8 +1729,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
super(mi);
|
super(mi);
|
||||||
setPointcut(new DynamicMethodMatcherPointcut() {
|
setPointcut(new DynamicMethodMatcherPointcut() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method m, Class<?> targetClass, Object... args) {
|
||||||
boolean run = m.getName().indexOf(pattern) != -1;
|
boolean run = m.getName().contains(pattern);
|
||||||
if (run) ++count;
|
if (run) ++count;
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
|
@ -1750,7 +1754,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, Class<?> targetClass) {
|
public boolean matches(Method m, Class<?> targetClass) {
|
||||||
return m.getName().indexOf(pattern) != -1;
|
return m.getName().contains(pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||||
|
|
||||||
@Test(expected = AopConfigException.class)
|
@Test(expected = AopConfigException.class)
|
||||||
public void testNoTarget() {
|
public void testNoTarget() {
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] { ITestBean.class });
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
pc.addAdvice(new NopInterceptor());
|
pc.addAdvice(new NopInterceptor());
|
||||||
AopProxy aop = createAopProxy(pc);
|
AopProxy aop = createAopProxy(pc);
|
||||||
aop.getProxy();
|
aop.getProxy();
|
||||||
|
@ -93,7 +93,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||||
bean.value = "foo";
|
bean.value = "foo";
|
||||||
mockTargetSource.setTarget(bean);
|
mockTargetSource.setTarget(bean);
|
||||||
|
|
||||||
AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
|
AdvisedSupport as = new AdvisedSupport();
|
||||||
as.setTargetSource(mockTargetSource);
|
as.setTargetSource(mockTargetSource);
|
||||||
as.addAdvice(new NopInterceptor());
|
as.addAdvice(new NopInterceptor());
|
||||||
AopProxy aop = new CglibAopProxy(as);
|
AopProxy aop = new CglibAopProxy(as);
|
||||||
|
@ -110,7 +110,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||||
bean.value = "foo";
|
bean.value = "foo";
|
||||||
mockTargetSource.setTarget(bean);
|
mockTargetSource.setTarget(bean);
|
||||||
|
|
||||||
AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
|
AdvisedSupport as = new AdvisedSupport();
|
||||||
as.setTargetSource(mockTargetSource);
|
as.setTargetSource(mockTargetSource);
|
||||||
as.addAdvice(new NopInterceptor());
|
as.addAdvice(new NopInterceptor());
|
||||||
AopProxy aop = new CglibAopProxy(as);
|
AopProxy aop = new CglibAopProxy(as);
|
||||||
|
@ -130,7 +130,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||||
bean.value = "foo";
|
bean.value = "foo";
|
||||||
mockTargetSource.setTarget(bean);
|
mockTargetSource.setTarget(bean);
|
||||||
|
|
||||||
AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
|
AdvisedSupport as = new AdvisedSupport();
|
||||||
as.setTargetSource(mockTargetSource);
|
as.setTargetSource(mockTargetSource);
|
||||||
as.addAdvice(new NopInterceptor());
|
as.addAdvice(new NopInterceptor());
|
||||||
AopProxy aop = new CglibAopProxy(as);
|
AopProxy aop = new CglibAopProxy(as);
|
||||||
|
@ -164,7 +164,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||||
CglibTestBean bean = new CglibTestBean();
|
CglibTestBean bean = new CglibTestBean();
|
||||||
bean.setName("Rob Harrop");
|
bean.setName("Rob Harrop");
|
||||||
|
|
||||||
AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
|
AdvisedSupport as = new AdvisedSupport();
|
||||||
as.setTarget(bean);
|
as.setTarget(bean);
|
||||||
as.addAdvice(new NopInterceptor());
|
as.addAdvice(new NopInterceptor());
|
||||||
AopProxy aop = new CglibAopProxy(as);
|
AopProxy aop = new CglibAopProxy(as);
|
||||||
|
@ -178,7 +178,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||||
CglibTestBean target = new CglibTestBean();
|
CglibTestBean target = new CglibTestBean();
|
||||||
target.setName("Rob Harrop");
|
target.setName("Rob Harrop");
|
||||||
|
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[]{});
|
AdvisedSupport pc = new AdvisedSupport();
|
||||||
pc.setFrozen(true);
|
pc.setFrozen(true);
|
||||||
pc.setTarget(target);
|
pc.setTarget(target);
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||||
target.reset();
|
target.reset();
|
||||||
|
|
||||||
mockTargetSource.setTarget(target);
|
mockTargetSource.setTarget(target);
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[]{});
|
AdvisedSupport pc = new AdvisedSupport();
|
||||||
pc.setTargetSource(mockTargetSource);
|
pc.setTargetSource(mockTargetSource);
|
||||||
CglibAopProxy aop = new CglibAopProxy(pc);
|
CglibAopProxy aop = new CglibAopProxy(pc);
|
||||||
aop.setConstructorArguments(new Object[] {"Rob Harrop", 22}, new Class<?>[] {String.class, int.class});
|
aop.setConstructorArguments(new Object[] {"Rob Harrop", 22}, new Class<?>[] {String.class, int.class});
|
||||||
|
@ -280,7 +280,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||||
ITestBean target = new TestBean();
|
ITestBean target = new TestBean();
|
||||||
|
|
||||||
mockTargetSource.setTarget(target);
|
mockTargetSource.setTarget(target);
|
||||||
AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
|
AdvisedSupport as = new AdvisedSupport();
|
||||||
as.setTargetSource(mockTargetSource);
|
as.setTargetSource(mockTargetSource);
|
||||||
as.addAdvice(new NopInterceptor());
|
as.addAdvice(new NopInterceptor());
|
||||||
CglibAopProxy cglib = new CglibAopProxy(as);
|
CglibAopProxy cglib = new CglibAopProxy(as);
|
||||||
|
@ -301,7 +301,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||||
ITestBean target = new TestBean();
|
ITestBean target = new TestBean();
|
||||||
mockTargetSource.setTarget(target);
|
mockTargetSource.setTarget(target);
|
||||||
|
|
||||||
AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
|
AdvisedSupport as = new AdvisedSupport();
|
||||||
as.setTargetSource(mockTargetSource);
|
as.setTargetSource(mockTargetSource);
|
||||||
as.addAdvice(new NopInterceptor());
|
as.addAdvice(new NopInterceptor());
|
||||||
as.addInterface(Serializable.class);
|
as.addInterface(Serializable.class);
|
||||||
|
@ -324,7 +324,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||||
ExceptionThrower bean = new ExceptionThrower();
|
ExceptionThrower bean = new ExceptionThrower();
|
||||||
mockTargetSource.setTarget(bean);
|
mockTargetSource.setTarget(bean);
|
||||||
|
|
||||||
AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
|
AdvisedSupport as = new AdvisedSupport();
|
||||||
as.setTargetSource(mockTargetSource);
|
as.setTargetSource(mockTargetSource);
|
||||||
as.addAdvice(new NopInterceptor());
|
as.addAdvice(new NopInterceptor());
|
||||||
AopProxy aop = new CglibAopProxy(as);
|
AopProxy aop = new CglibAopProxy(as);
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
|
||||||
public void testProxyIsJustInterface() throws Throwable {
|
public void testProxyIsJustInterface() throws Throwable {
|
||||||
TestBean raw = new TestBean();
|
TestBean raw = new TestBean();
|
||||||
raw.setAge(32);
|
raw.setAge(32);
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class});
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
pc.setTarget(raw);
|
pc.setTarget(raw);
|
||||||
JdkDynamicAopProxy aop = new JdkDynamicAopProxy(pc);
|
JdkDynamicAopProxy aop = new JdkDynamicAopProxy(pc);
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
|
||||||
final int age = 25;
|
final int age = 25;
|
||||||
MethodInterceptor mi = (invocation -> age);
|
MethodInterceptor mi = (invocation -> age);
|
||||||
|
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class});
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
pc.addAdvice(mi);
|
pc.addAdvice(mi);
|
||||||
AopProxy aop = createAopProxy(pc);
|
AopProxy aop = createAopProxy(pc);
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class, IOther.class});
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class);
|
||||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||||
TrapTargetInterceptor tii = new TrapTargetInterceptor() {
|
TrapTargetInterceptor tii = new TrapTargetInterceptor() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -129,7 +129,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsAndHashCodeDefined() throws Exception {
|
public void testEqualsAndHashCodeDefined() throws Exception {
|
||||||
AdvisedSupport as = new AdvisedSupport(new Class<?>[]{Named.class});
|
AdvisedSupport as = new AdvisedSupport(Named.class);
|
||||||
as.setTarget(new Person());
|
as.setTarget(new Person());
|
||||||
JdkDynamicAopProxy aopProxy = new JdkDynamicAopProxy(as);
|
JdkDynamicAopProxy aopProxy = new JdkDynamicAopProxy(as);
|
||||||
Named proxy = (Named) aopProxy.getProxy();
|
Named proxy = (Named) aopProxy.getProxy();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -88,6 +88,7 @@ public final class ProxyFactoryBeanTests {
|
||||||
|
|
||||||
private BeanFactory factory;
|
private BeanFactory factory;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
|
||||||
|
@ -97,6 +98,7 @@ public final class ProxyFactoryBeanTests {
|
||||||
new ClassPathResource(CONTEXT, getClass()));
|
new ClassPathResource(CONTEXT, getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsDynamicProxyWhenInterfaceSpecified() {
|
public void testIsDynamicProxyWhenInterfaceSpecified() {
|
||||||
ITestBean test1 = (ITestBean) factory.getBean("test1");
|
ITestBean test1 = (ITestBean) factory.getBean("test1");
|
||||||
|
@ -157,7 +159,7 @@ public final class ProxyFactoryBeanTests {
|
||||||
catch (BeanCreationException ex) {
|
catch (BeanCreationException ex) {
|
||||||
// Root cause of the problem must be an AOP exception
|
// Root cause of the problem must be an AOP exception
|
||||||
AopConfigException aex = (AopConfigException) ex.getCause();
|
AopConfigException aex = (AopConfigException) ex.getCause();
|
||||||
assertTrue(aex.getMessage().indexOf("interceptorNames") != -1);
|
assertTrue(aex.getMessage().contains("interceptorNames"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,13 +334,6 @@ public final class ProxyFactoryBeanTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DependsOnITestBean {
|
|
||||||
public final ITestBean tb;
|
|
||||||
public DependsOnITestBean(ITestBean tb) {
|
|
||||||
this.tb = tb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that inner bean for target means that we can use
|
* Test that inner bean for target means that we can use
|
||||||
* autowire without ambiguity from target and proxy
|
* autowire without ambiguity from target and proxy
|
||||||
|
@ -711,6 +706,8 @@ public final class ProxyFactoryBeanTests {
|
||||||
ITestBean proxy = (ITestBean) fb.getObject();
|
ITestBean proxy = (ITestBean) fb.getObject();
|
||||||
assertTrue(AopUtils.isJdkDynamicProxy(proxy));
|
assertTrue(AopUtils.isJdkDynamicProxy(proxy));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires only on void methods. Saves list of methods intercepted.
|
* Fires only on void methods. Saves list of methods intercepted.
|
||||||
*/
|
*/
|
||||||
|
@ -733,7 +730,7 @@ public final class ProxyFactoryBeanTests {
|
||||||
});
|
});
|
||||||
setPointcut(new DynamicMethodMatcherPointcut() {
|
setPointcut(new DynamicMethodMatcherPointcut() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method m, Class<?> targetClass, Object... args) {
|
||||||
return m.getReturnType() == Void.TYPE;
|
return m.getReturnType() == Void.TYPE;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -741,10 +738,20 @@ public final class ProxyFactoryBeanTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class DependsOnITestBean {
|
||||||
|
|
||||||
|
public final ITestBean tb;
|
||||||
|
|
||||||
|
public DependsOnITestBean(ITestBean tb) {
|
||||||
|
this.tb = tb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aspect interface
|
* Aspect interface
|
||||||
*/
|
*/
|
||||||
public interface AddedGlobalInterface {
|
public interface AddedGlobalInterface {
|
||||||
|
|
||||||
int globalsAdded();
|
int globalsAdded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue