[jboss-cvs] JBossAS SVN: r58706 - in projects/aop/trunk/aop/src: main/org/jboss/aop/advice main/org/jboss/aop/advice/annotation main/org/jboss/aop/instrument resources/test/args test/org/jboss/test/aop/args test/org/jboss/test/aop/beforeafter
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 28 12:25:44 EST 2006
Author: flaviarnn
Date: 2006-11-28 12:24:44 -0500 (Tue, 28 Nov 2006)
New Revision: 58706
Added:
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgAspect.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgPOJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgPOJOInterface.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgTestCase.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationAspect.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationPOJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationTestCase.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointAspect.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointPOJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointTestCase.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/POJOException.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnAspect.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnPOJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnTestCase.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/SubValue.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/SuperValue.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownAspect.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownPOJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownTestCase.java
Removed:
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgsTestCase.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/Aspect.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/POJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/PojoInterface.java
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceMethodProperties.java
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
projects/aop/trunk/aop/src/resources/test/args/jboss-aop.xml
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/ArgsAspect.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/BeforeAfterThrowingTestCase.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/GeneralAspect.java
Log:
[JBAOP-37] Added some improvements to code and a lot of new tests.
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceMethodProperties.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceMethodProperties.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceMethodProperties.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -132,7 +132,7 @@
public boolean isAdviceVoid() throws NotFoundException
{
- return adviceMethod.getReturnType().equals(CtClass.voidType);
+ return adviceMethod.getReturnType().equals(void.class);
}
public Method getAdviceMethod()
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -3,6 +3,7 @@
import java.lang.reflect.Method;
import org.jboss.aop.advice.AdviceMethodProperties;
+import org.jboss.aop.advice.annotation.AdviceMethodFactory.ReturnType;
/**
* Contains information about an advice method and its matching process.
@@ -38,13 +39,14 @@
*
* @param clazz the type of an annotated parameter
* @param lookingFor the expected type of the parameter
- * @return -1 if a value of type <code>lookingFor</code> can't be assigned to
- * a parameter of type <code>class</code>; the distance between <code>class
- * </code> and <code>lookingFor</code> otherwise.
+ * @return {@link AdviceMethodFactory#NOT_ASSIGNABLE_DEGREE if a value of type <code>
+ * lookingFor</code> can't be assigned to a parameter of type <code>class
+ * </code>; the distance between <code>class </code> and <code>lookingFor
+ * </code> otherwise.
*/
- protected int matchClass(Class clazz, Class lookingFor)
+ protected short matchClass(Class clazz, Class lookingFor)
{
- return matchClass(clazz, lookingFor, 0);
+ return matchClass(clazz, lookingFor, (short) 0);
}
/**
@@ -58,11 +60,11 @@
* a parameter of type <code>class</code>; the distance between <code>class
* </code> and <code>lookingFor</code> otherwise.
*/
- private int matchClass(Class wanted, Class candidate, int matchDegree)
+ private short matchClass(Class wanted, Class candidate, short matchDegree)
{
if (candidate == null)
{
- return -1;
+ return AdviceMethodFactory.NOT_ASSIGNABLE_DEGREE;
}
if (candidate.equals(wanted))
{
@@ -84,10 +86,38 @@
{
return matchDegree;
}
- return -1;
+ return AdviceMethodFactory.NOT_ASSIGNABLE_DEGREE;
}
/**
+ * Returns the distance in hierarchy between the annotated parameter identified by
+ * <code>annotationIndex</code>, and the expected type of this parameter.
+ *
+ * @param annotationIndex identifies a parameter annotation rule
+ * @param properties contains information about the queried advice method
+ * @return the assignability degree if there is a parameter with the
+ * annotation identified by <code>typeIndex</code>;
+ * {@link AdviceMethodFactory#NOT_ASSIGNABLE_DEGREE} otherwise.
+ */
+ public short getReturnAssignabilityDegree(AdviceMethodProperties properties)
+ {
+ Class returnType = this.method.getReturnType();
+ if (returnType == void.class)
+ {
+ return AdviceMethodFactory.NOT_ASSIGNABLE_DEGREE;
+ }
+ short degree = this.matchClass(properties.getJoinpointReturnType(), returnType);
+ if (degree == AdviceMethodFactory.NOT_ASSIGNABLE_DEGREE)
+ {
+ // return type is Object.class and join point return type is not
+ // Object is worse than join point return type, but better than -1
+ return AdviceMethodFactory.MAX_ASSIGNABLE_DEGREE;
+ }
+ return degree;
+ }
+
+
+ /**
* Returns the rank of this advice.
* @return the rank value
*/
@@ -116,11 +146,11 @@
*
* @param properties contains information about the queried method
* @param mutuallyExclusive a list of mutually exclusive rules
- * @param canReturn indicates whether the advice method should return a value
+ * @param returnType the expected return type
* @return <code>true</code> only if this advice is valid
*/
public abstract boolean validate(AdviceMethodProperties properties,
- int[][] mutuallyExclusive, boolean canReturn);
+ int[][] mutuallyExclusive, ReturnType returnType);
/**
* Returns the distance in hierarchy between the annotated parameter identified by
@@ -129,9 +159,10 @@
* @param annotationIndex identifies a parameter annotation rule
* @param properties contains information about the queried advice method
* @return the assignability degree if there is a parameter with the
- * annotation identified by <code>typeIndex</code>; -1 otherwise.
+ * annotation identified by <code>typeIndex</code>;
+ * {@link AdviceMethodFactory#NOT_ASSIGNABLE_DEGREE} otherwise.
*/
- public abstract int getAssignabilityDegree(int annotationIndex,
+ public abstract short getAssignabilityDegree(int annotationIndex,
AdviceMethodProperties properties);
/**
@@ -140,5 +171,4 @@
* @param properties contains information about the queried advice method.
*/
public abstract void assignAdviceInfo(AdviceMethodProperties properties);
-
}
\ No newline at end of file
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -23,6 +23,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -44,26 +45,31 @@
public class AdviceMethodFactory
{
/**
+ * Rule to be applied for advice return types
+ */
+ enum ReturnType {VOID, ANY, NOT_VOID};
+
+ /**
* Factory that selects advice methods for <i>before</i> interception.
*/
public static final AdviceMethodFactory BEFORE = new AdviceMethodFactory (null,
new ParameterAnnotationRule[]{ParameterAnnotationRule.JOIN_POINT,
ParameterAnnotationRule.ARGS, ParameterAnnotationRule.ARG},
- new int[][]{{1,2}}, false);
+ new int[][]{{1,2}}, ReturnType.VOID);
/**
* Factory that selects advice methods for <i>after</i> interception.
*/
public static final AdviceMethodFactory AFTER = new AdviceMethodFactory (null,
new ParameterAnnotationRule[]{ParameterAnnotationRule.JOIN_POINT,
ParameterAnnotationRule.RETURN, ParameterAnnotationRule.ARGS,
- ParameterAnnotationRule.ARG}, new int[][]{{2, 3}}, true);
+ ParameterAnnotationRule.ARG}, new int[][]{{2, 3}}, ReturnType.ANY);
/**
* Factory that selects advice methods for <i>throwing</i> interception.
*/
public static final AdviceMethodFactory THROWING = new AdviceMethodFactory (null,
new ParameterAnnotationRule[]{ParameterAnnotationRule.JOIN_POINT,
ParameterAnnotationRule.THROWABLE, ParameterAnnotationRule.ARGS,
- ParameterAnnotationRule.ARG}, new int[][]{{2, 3}}, false);
+ ParameterAnnotationRule.ARG}, new int[][]{{2, 3}}, ReturnType.VOID);
/**
* Factory that selects advice methods for <i>aroung</i> interception.
*/
@@ -83,8 +89,8 @@
// not annotated
for (Annotation annotation: annotations[0])
{
- if (annotation.annotationType().getClass().getPackage() ==
- AdviceMethodProperties.class.getPackage())
+ if (annotation.annotationType().getPackage() ==
+ AdviceMethodFactory.class.getPackage())
{
return false;
}
@@ -96,13 +102,27 @@
{
adviceMatchingMessage.append("\n[warn] - method ");
adviceMatchingMessage.append(method);
- adviceMatchingMessage.append(" doesn't match default around signature because it returns ");
+ adviceMatchingMessage.append(" does not match default around signature because it returns ");
adviceMatchingMessage.append(method.getReturnType());
adviceMatchingMessage.append(" intead of java.lang.Object");
}
return false;
}
- return true;
+ // throws Throwable
+ for (Class exceptionType: method.getExceptionTypes())
+ {
+ if (exceptionType == Throwable.class)
+ {
+ return true;
+ }
+ }
+ if (AspectManager.verbose)
+ {
+ adviceMatchingMessage.append("\n[warn] - method ");
+ adviceMatchingMessage.append(method);
+ adviceMatchingMessage.append(" does not match default around signature because it does not throw Throwable");
+ }
+ return false;
}
public AdviceInfo getAdviceInfo(Method method)
@@ -111,7 +131,7 @@
return new AdviceInfo(method, 500)
{
public boolean validate(AdviceMethodProperties properties,
- int[][] mutuallyExclusive, boolean mustReturn)
+ int[][] mutuallyExclusive, ReturnType adviceReturn)
{
if(parameterTypes[0].isAssignableFrom(properties.getInvocationType()))
{
@@ -121,13 +141,13 @@
{
adviceMatchingMessage.append("\n[warn] - argument 0 of method ");
adviceMatchingMessage.append(method);
- adviceMatchingMessage.append(" isn't assignable from ");
+ adviceMatchingMessage.append(" is not assignable from ");
adviceMatchingMessage.append(properties.getInvocationType());
}
return false;
}
- public int getAssignabilityDegree(int typeIndex,
+ public short getAssignabilityDegree(int typeIndex,
AdviceMethodProperties properties)
{
return matchClass(parameterTypes[0], properties.getInvocationType());
@@ -143,10 +163,12 @@
},
new ParameterAnnotationRule[]{ParameterAnnotationRule.INVOCATION,
ParameterAnnotationRule.ARGS, ParameterAnnotationRule.ARG},
- new int[][]{{1, 2}}, true);
+ new int[][]{{1, 2}}, ReturnType.NOT_VOID);
- static StringBuffer adviceMatchingMessage = new StringBuffer();
+ static StringBuffer adviceMatchingMessage;
+ static final short NOT_ASSIGNABLE_DEGREE = Short.MAX_VALUE;
+ static final short MAX_ASSIGNABLE_DEGREE = NOT_ASSIGNABLE_DEGREE - 1;
/**
* Method that returns log information about the last matching process executed.
@@ -157,11 +179,10 @@
public final static String getAdviceMatchingMessage()
{
String message = adviceMatchingMessage.toString();
- adviceMatchingMessage = new StringBuffer();
return message;
}
- private boolean canReturn;
+ private ReturnType adviceReturn;
private AdviceSignatureRule adviceSignatureRule;
private ParameterAnnotationRule[] rules;
private int[][] mutuallyExclusive;
@@ -180,12 +201,12 @@
*/
private AdviceMethodFactory(AdviceSignatureRule adviceSignatureRule,
ParameterAnnotationRule[] rules, int[][] mutuallyExclusive,
- boolean canReturn)
+ ReturnType adviceReturn)
{
this.adviceSignatureRule = adviceSignatureRule;
this.rules = rules;
this.mutuallyExclusive = mutuallyExclusive;
- this.canReturn = canReturn;
+ this.adviceReturn = adviceReturn;
}
/**
@@ -197,6 +218,10 @@
*/
public final AdviceMethodProperties findAdviceMethod(AdviceMethodProperties properties)
{
+ if (AspectManager.verbose)
+ {
+ adviceMatchingMessage = new StringBuffer();
+ }
Method[] methods = ReflectUtils.getMethodsWithName(
properties.getAspectClass(), properties.getAdviceName());
@@ -208,7 +233,7 @@
adviceMatchingMessage.append(properties.getAspectClass());
adviceMatchingMessage.append(".");
adviceMatchingMessage.append(properties.getAdviceName());
- adviceMatchingMessage.append("not found");
+ adviceMatchingMessage.append(" not found");
}
return null;
}
@@ -272,7 +297,7 @@
while (iterator.hasNext())
{
AdviceInfo advice = iterator.next();
- if (advice.validate(properties, mutuallyExclusive, canReturn))
+ if (advice.validate(properties, mutuallyExclusive, adviceReturn))
{
bestAdvice = advice;
break;
@@ -298,7 +323,7 @@
AdviceInfo advice = iterator.next();
if (advice.getRank() == bestAdvice.getRank())
{
- if (!advice.validate(properties, mutuallyExclusive, canReturn))
+ if (!advice.validate(properties, mutuallyExclusive, adviceReturn))
{
iterator.remove();
}
@@ -337,8 +362,9 @@
AdviceInfo bestMatch(Collection<AdviceInfo> greatestRank,
AdviceMethodProperties properties)
{
- int bestDegree = -1;
+ short bestDegree = NOT_ASSIGNABLE_DEGREE;
AdviceInfo bestAdvice = null;
+ Collection<AdviceInfo> removeList = new ArrayList<AdviceInfo>();
// rule i is more important than rule i + 1
for (int i = 0; i < rules.length; i++)
{
@@ -346,7 +372,22 @@
iterator.hasNext();)
{
AdviceInfo currentAdvice = iterator.next();
- int currentDegree = currentAdvice.getAssignabilityDegree(i, properties);
+ short currentDegree = currentAdvice.getAssignabilityDegree(i, properties);
+ if (currentDegree < bestDegree)
+ {
+ if (bestAdvice != null)
+ {
+ removeList.add(bestAdvice);
+ }
+ bestAdvice = currentAdvice;
+ bestDegree = currentDegree;
+ }
+ else if (currentDegree > bestDegree)
+ {
+ iterator.remove();
+ }
+ }
+ /*
// advice has no annotation of type i
if (currentDegree == -1)
{
@@ -377,18 +418,28 @@
{
greatestRank.remove(currentAdvice);
}
- }
+ }*/
// found the best
- if (greatestRank.size() == 1)
+ if (greatestRank.size() - removeList.size() == 1)
{
- return greatestRank.iterator().next();
+ return bestAdvice;
}
+ greatestRank.removeAll(removeList);
// reset values
+ removeList.clear();
bestAdvice = null;
- bestDegree = -1;
+ bestDegree = NOT_ASSIGNABLE_DEGREE;
}
- // two or more advices with the same match degree, pick any one of them
- return greatestRank.iterator().next();
+ for (AdviceInfo currentAdvice: greatestRank)
+ {
+ int currentDegree = currentAdvice.getReturnAssignabilityDegree(properties);
+ if (currentDegree < bestDegree)
+ {
+ bestAdvice = currentAdvice;
+ }
+ }
+ // in case of two or more advices with the same match degree, pick any one of them
+ return bestAdvice;
}
/**
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -11,6 +11,7 @@
import org.jboss.aop.AspectManager;
import org.jboss.aop.advice.AdviceMethodProperties;
+import org.jboss.aop.advice.annotation.AdviceMethodFactory.ReturnType;
/**
* Information about an advice method whose parameters should annotated according to
@@ -123,7 +124,7 @@
}
public boolean validate(AdviceMethodProperties properties,
- int[][] mutuallyExclusive, boolean canReturn)
+ int[][] mutuallyExclusive, ReturnType returnType)
{
for (ParameterAnnotationType paramType: paramTypes)
{
@@ -132,18 +133,28 @@
return false;
}
}
- if (canReturn && properties.getJoinpointReturnType() != void.class &&
- !properties.getJoinpointReturnType().
- isAssignableFrom(method.getReturnType()))
+ switch (returnType)
{
- if (AspectManager.verbose)
- {
- AdviceMethodFactory.adviceMatchingMessage.append("\n[warn] - return value of ");
- AdviceMethodFactory.adviceMatchingMessage.append(method);
- AdviceMethodFactory.adviceMatchingMessage.append(" can not be assigned to type ");
- AdviceMethodFactory.adviceMatchingMessage.append(properties.getJoinpointReturnType());
- }
- return false;
+ case ANY:
+ if (method.getReturnType() == void.class)
+ {
+ break;
+ }
+ case NOT_VOID:
+ if (properties.getJoinpointReturnType() != void.class &&
+ method.getReturnType() != Object.class &&
+ !properties.getJoinpointReturnType().
+ isAssignableFrom(method.getReturnType()))
+ {
+ if (AspectManager.verbose)
+ {
+ AdviceMethodFactory.adviceMatchingMessage.append("\n[warn] - return value of ");
+ AdviceMethodFactory.adviceMatchingMessage.append(method);
+ AdviceMethodFactory.adviceMatchingMessage.append(" can not be assigned to type ");
+ AdviceMethodFactory.adviceMatchingMessage.append(properties.getJoinpointReturnType());
+ }
+ return false;
+ }
}
for (int i = 0; i < mutuallyExclusive.length; i++)
@@ -173,7 +184,7 @@
return true;
}
- public int getAssignabilityDegree(int annotationIndex,
+ public short getAssignabilityDegree(int annotationIndex,
AdviceMethodProperties properties)
{
return paramTypes[annotationIndex].getAssignabilityDegree(properties);
@@ -434,7 +445,7 @@
* @return the assignability degree if this parameter type on the
* advice method
*/
- public abstract int getAssignabilityDegree(AdviceMethodProperties properties);
+ public abstract short getAssignabilityDegree(AdviceMethodProperties properties);
/**
* Assigns information regarding all occurences of this parameter type on the
@@ -499,7 +510,7 @@
return true;
}
- public final int getAssignabilityDegree(AdviceMethodProperties properties)
+ public final short getAssignabilityDegree(AdviceMethodProperties properties)
{
if (this.index == -1)
{
@@ -602,7 +613,7 @@
return true;
}
- public int getAssignabilityDegree(AdviceMethodProperties properties)
+ public short getAssignabilityDegree(AdviceMethodProperties properties)
{
if (indexesLength == 0)
{
@@ -610,7 +621,7 @@
}
Class[] expectedTypes = (Class[]) rule.getAssignableFrom(properties);
Class[] paramTypes = method.getParameterTypes();
- int level = 0;
+ short level = 0;
for (int i = 0; i < indexesLength; i++)
{
level += matchClass(method.getParameterTypes()[this.indexes[i][0]],
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -1462,8 +1462,9 @@
if (AspectManager.verbose)
{
- System.out.println("[warn] No matching advice called '" + setups[i].getAdviceName() +
- "' could be found in " + setups[i].getAspectClass().getName() + " for joinpoint " + info);
+ System.out.print("[warn] No matching advice called '" + setups[i].getAdviceName() +
+ "' could be found in " + setups[i].getAspectClass().getName() +
+ " for joinpoint " + info + ":");
System.out.println(AdviceMethodFactory.getAdviceMatchingMessage());
}
}
Modified: projects/aop/trunk/aop/src/resources/test/args/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/args/jboss-aop.xml 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/resources/test/args/jboss-aop.xml 2006-11-28 17:24:44 UTC (rev 58706)
@@ -2,30 +2,198 @@
<!DOCTYPE aop SYSTEM "jboss-aop_1_0.dtd">
<aop>
- <aspect class="org.jboss.test.aop.args.Aspect" scope="PER_VM"/>
+ <!-- @Invocation test -->
+ <aspect class="org.jboss.test.aop.args.InvocationAspect" scope="PER_VM"/>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.InvocationPOJO->method1(..))">
+ <before name="before" aspect="org.jboss.test.aop.args.InvocationAspect"/>
+ <advice name="aroundMethodExecution1" aspect="org.jboss.test.aop.args.InvocationAspect"/>
+ <after name="after" aspect="org.jboss.test.aop.args.InvocationAspect"/>
+ <throwing name="throwing" aspect="org.jboss.test.aop.args.InvocationAspect"/>
+ </bind>
- <bind pointcut="execution(* org.jboss.test.aop.args.POJO->bunchArgs(..))">
- <advice name="bunchArgs" aspect="org.jboss.test.aop.args.Aspect"/>
+ <bind pointcut="execution(* org.jboss.test.aop.args.InvocationPOJO->method2(..))">
+ <advice name="aroundMethodExecution2" aspect="org.jboss.test.aop.args.InvocationAspect"/>
</bind>
+
+ <bind pointcut="get(* org.jboss.test.aop.args.InvocationPOJO->number)">
+ <advice name="aroundFieldRead" aspect="org.jboss.test.aop.args.InvocationAspect"/>
+ </bind>
- <bind pointcut="execution(* org.jboss.test.aop.args.POJO->bunchArgsWithInvocation(..))">
- <advice name="bunchArgsWithInvocation" aspect="org.jboss.test.aop.args.Aspect"/>
+ <bind pointcut="set(* org.jboss.test.aop.args.InvocationPOJO->number)">
+ <advice name="aroundFieldWrite" aspect="org.jboss.test.aop.args.InvocationAspect"/>
</bind>
+
+ <bind pointcut="call(* org.jboss.test.aop.args.InvocationPOJO->calleeMethod(..)) AND
+ withincode(* org.jboss.test.aop.args.InvocationPOJO->callerMethod(..))">
+ <advice name="aroundMethodCalledByMethod" aspect="org.jboss.test.aop.args.InvocationAspect"/>
+ </bind>
- <bind pointcut="execution(* org.jboss.test.aop.args.POJO->bunchWrapped(..))">
- <advice name="wrap" aspect="org.jboss.test.aop.args.Aspect"/>
+ <!-- @JoinPoint test -->
+ <aspect class="org.jboss.test.aop.args.JoinPointAspect" scope="PER_VM"/>
+
+ <bind pointcut="field(* org.jboss.test.aop.args.JoinPointPOJO->number)">
+ <before name="before1" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ <after name="after1" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
</bind>
- <bind pointcut="execution(* org.jboss.test.aop.args.POJO->bunch(..))">
- <advice name="bunch" aspect="org.jboss.test.aop.args.Aspect"/>
- <advice name="arg1" aspect="org.jboss.test.aop.args.Aspect"/>
- <advice name="arg2" aspect="org.jboss.test.aop.args.Aspect"/>
- <advice name="arg3" aspect="org.jboss.test.aop.args.Aspect"/>
- <advice name="arg4" aspect="org.jboss.test.aop.args.Aspect"/>
- <advice name="arg15" aspect="org.jboss.test.aop.args.Aspect"/>
- <advice name="arg24" aspect="org.jboss.test.aop.args.Aspect"/>
+ <bind pointcut="set(* org.jboss.test.aop.args.JoinPointPOJO->text)">
+ <before name="before2" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ <after name="after2" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
</bind>
- <bind pointcut="execution(java.lang.String org.jboss.test.aop.args.POJO->echo(java.lang.String))">
- <advice name="echo" aspect="org.jboss.test.aop.args.Aspect"/>
+
+ <bind pointcut="get(* org.jboss.test.aop.args.JoinPointPOJO->text)">
+ <before name="before5" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ <after name="after5" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
</bind>
-</aop>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.JoinPointPOJO->method1(..))">
+ <before name="before3" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ <after name="after3" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.JoinPointPOJO->method2(..))">
+ <before name="before4" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ <after name="after4" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ <throwing name="throwing1" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.JoinPointPOJO->method3(..))">
+ <throwing name="throwing2" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.JoinPointPOJO->method4(..))">
+ <throwing name="throwing3" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.JoinPointPOJO->method5(..))">
+ <throwing name="throwing4" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.JoinPointPOJO->method6(..))">
+ <throwing name="throwing5" aspect="org.jboss.test.aop.args.JoinPointAspect"/>
+ </bind>
+
+ <!-- Return type and @Return test -->
+ <aspect class="org.jboss.test.aop.args.ReturnAspect" scope="PER_VM"/>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method1(..))">
+ <before name="before" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <advice name="around1" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after1" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method2(..))">
+ <advice name="around2" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after2" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method3(..))">
+ <before name="before" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <advice name="around3" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after3" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method4(..))">
+ <advice name="around4" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after4" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method5(..))">
+ <advice name="around5" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after5" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method6(..))">
+ <advice name="around6" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after6" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method7(..))">
+ <advice name="around7" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after7" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method8(..))">
+ <before name="before" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <advice name="around8" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after8" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method9(..))">
+ <advice name="around9" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after9" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method10(..))">
+ <before name="before" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <advice name="around10" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after10" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ReturnPOJO->method11(..))">
+ <advice name="around11" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ <after name="after11" aspect="org.jboss.test.aop.args.ReturnAspect"/>
+ </bind>
+
+ <!-- @Thrown test -->
+ <aspect class="org.jboss.test.aop.args.ThrownAspect" scope="PER_VM"/>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ThrownPOJO->method1(..))">
+ <throwing name="throwing1" aspect="org.jboss.test.aop.args.ThrownAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ThrownPOJO->method2(..))">
+ <throwing name="throwing2" aspect="org.jboss.test.aop.args.ThrownAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ThrownPOJO->method3(..))">
+ <throwing name="throwing3" aspect="org.jboss.test.aop.args.ThrownAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ThrownPOJO->method4(..))">
+ <throwing name="throwing4" aspect="org.jboss.test.aop.args.ThrownAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ThrownPOJO->method5(..))">
+ <throwing name="throwing5" aspect="org.jboss.test.aop.args.ThrownAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ThrownPOJO->method6(..))">
+ <throwing name="throwing6" aspect="org.jboss.test.aop.args.ThrownAspect"/>
+ <throwing name="throwing7" aspect="org.jboss.test.aop.args.ThrownAspect"/>
+ </bind>
+
+ <!-- @Arg test -->
+ <aspect class="org.jboss.test.aop.args.ArgAspect" scope="PER_VM"/>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ArgPOJO->bunchArgs(..))">
+ <advice name="bunchArgs" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ArgPOJO->bunchArgsWithInvocation(..))">
+ <advice name="bunchArgsWithInvocation" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ArgPOJO->bunchWrapped(..))">
+ <advice name="wrap" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ </bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.args.ArgPOJO->bunch(..))">
+ <advice name="bunch" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="bunch1" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="bunch2" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="bunch3" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="bunch4" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="arg1" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="arg2" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="arg3" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="arg4" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="arg15" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="arg24" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ <advice name="emptyArg" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ </bind>
+ <bind pointcut="execution(java.lang.String org.jboss.test.aop.args.ArgPOJO->echo(java.lang.String))">
+ <advice name="echo" aspect="org.jboss.test.aop.args.ArgAspect"/>
+ </bind>
+</aop>
\ No newline at end of file
Copied: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgAspect.java (from rev 58671, projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/Aspect.java)
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/Aspect.java 2006-11-24 17:17:52 UTC (rev 58671)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgAspect.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,213 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.aop.args;
+
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+import org.jboss.aop.advice.annotation.Arg;
+import org.jboss.aop.advice.annotation.Invocation;
+import org.jboss.aop.joinpoint.CurrentInvocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+
+/**
+ * Aspect used on @Arg parameter tests.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class ArgAspect implements ArgPOJOInterface
+{
+ public static boolean echoCalled = false;
+ public static boolean wrapped = false;
+ public static boolean args = false;
+ public static boolean argsWithInvocation = false;
+ public static boolean bunchCalled = false;
+ public static boolean bunch2Called = false;
+ public static boolean arg1Called = false;
+ public static boolean arg2Called = false;
+ public static boolean arg3Called = false;
+ public static boolean arg4Called = false;
+ public static boolean arg15Called = false;
+ public static boolean arg24Called = false;
+ public static boolean emptyArgCalled = false;
+
+ public static void clear()
+ {
+ echoCalled = false;
+ wrapped = false;
+ args = false;
+ argsWithInvocation = false;
+ bunchCalled = false;
+ bunch2Called = false;
+ arg1Called = false;
+ arg2Called = false;
+ arg3Called = false;
+ arg4Called = false;
+ arg15Called = false;
+ arg24Called = false;
+ emptyArgCalled = false;
+ }
+
+ public String echo(@Arg String arg)
+ {
+ echoCalled = true;
+
+ Assert.assertEquals("Args don't match", "hello", arg);
+
+ try
+ {
+ return (String) CurrentInvocation.proceed();
+ }
+ catch (Throwable throwable)
+ {
+
+ throw new RuntimeException(throwable);
+ }
+ }
+
+ public Object wrap(MethodInvocation invocation) throws Throwable
+ {
+ wrapped = true;
+ return invocation.invokeNext();
+ }
+
+ public Object bunchArgs(@Arg int x, @Arg double y, @Arg float z,
+ @Arg String str, @Arg int q) throws Throwable
+ {
+ args = true;
+ return (Integer)CurrentInvocation.proceed();
+ }
+
+ public int bunchArgsWithInvocation(
+ @Invocation MethodInvocation invocation,
+ @Arg int x, @Arg double y, @Arg float z, @Arg String str, @Arg int q) throws Throwable
+ {
+ argsWithInvocation = true;
+ return (Integer) invocation.invokeNext();
+ }
+
+ public int bunch(@Arg int x, @Arg double y, @Arg float z, @Arg String str, @Arg int q)
+ {
+ bunchCalled = true;
+
+ Assert.assertEquals("Arguments don't match", 1, x);
+ Assert.assertEquals("Arguments don't match", 2.2, y);
+ Assert.assertEquals("Arguments don't match", 3.3F, z);
+ Assert.assertEquals("Arguments don't match", "four", str);
+ try
+ {
+ return ((Integer) CurrentInvocation.proceed()).intValue();
+ }
+ catch (Throwable throwable)
+ {
+ throw new RuntimeException(throwable);
+ }
+ }
+
+ public int bunch1(@Arg int x, @Arg double y, @Arg float z, @Arg String str, @Arg long q)
+ {
+ Assert.fail("This advice should never be executed");
+ return 0;
+ }
+
+ public int bunch2(@Arg int x, @Arg int q, @Arg String str, @Arg double y, @Arg float z)
+ {
+ bunch2Called = true;
+
+ Assert.assertEquals("Arguments don't match", 1, x);
+ Assert.assertEquals("Arguments don't match", 2.2, y);
+ Assert.assertEquals("Arguments don't match", 3.3F, z);
+ Assert.assertEquals("Arguments don't match", "four", str);
+ try
+ {
+ return ((Integer) CurrentInvocation.proceed()).intValue();
+ }
+ catch (Throwable throwable)
+ {
+ throw new RuntimeException(throwable);
+ }
+ }
+
+ public int bunch3(@Arg int x, @Arg int q, @Arg int w, @Arg String str, @Arg double y, @Arg float z)
+ {
+ Assert.fail("This advice should never be executed");
+ return 0;
+ }
+
+ public int bunch4(@Arg int x, @Arg int q, @Arg float z, @Arg Collection str, @Arg double y)
+ {
+ Assert.fail("This advice should never be executed");
+ return 0;
+ }
+
+ public Object arg1(@Arg int x) throws Throwable
+ {
+ arg1Called = true;
+ Assert.assertEquals("Arguments don't match", 1, x);
+ return CurrentInvocation.proceed();
+ }
+
+ public int arg2(@Arg double y) throws Throwable
+ {
+ arg2Called = true;
+ Assert.assertEquals("Arguments don't match", 2.2, y);
+ return (Integer) CurrentInvocation.proceed();
+ }
+
+ public Object arg3(@Arg float z) throws Throwable
+ {
+ arg3Called = true;
+ Assert.assertEquals("Arguments don't match", 3.3F, z);
+ return CurrentInvocation.proceed();
+ }
+
+ public Object arg4(@Arg Object str) throws Throwable
+ {
+ arg4Called = true;
+ Assert.assertEquals("Arguments don't match", "four", str);
+ return (Integer) CurrentInvocation.proceed();
+ }
+
+ public Object arg15(@Arg int x, @Arg int q) throws Throwable
+ {
+ arg15Called = true;
+ Assert.assertEquals("Arguments don't match", 1, x);
+ Assert.assertEquals("Arguments don't match", 5, q);
+ return CurrentInvocation.proceed();
+ }
+
+ public int arg24(@Arg String str, @Arg double y) throws Throwable
+ {
+ arg24Called = true;
+ Assert.assertEquals("Arguments don't match", 2.2, y);
+ Assert.assertEquals("Arguments don't match", "four", str);
+ return (Integer) CurrentInvocation.proceed();
+ }
+
+ public Object emptyArg() throws Throwable
+ {
+ emptyArgCalled = true;
+ return CurrentInvocation.proceed();
+ }
+}
\ No newline at end of file
Copied: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgPOJO.java (from rev 58452, projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/POJO.java)
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/POJO.java 2006-11-16 15:59:40 UTC (rev 58452)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgPOJO.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.aop.args;
+
+/**
+ * Plain old java object used on @Arg parameter tests.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class ArgPOJO implements ArgPOJOInterface
+{
+ public String echo(String echo)
+ {
+ return echo;
+ }
+
+ public int bunch(int x, double y, float z, String str, int q)
+ {
+ return x + (int) y + (int) z + q;
+ }
+
+ public int bunchArgs(int x, double y, float z, String str, int q)
+ {
+ return x + (int) y + (int) z + q;
+ }
+
+ public int bunchArgsWithInvocation(int x, double y, float z, String str, int q)
+ {
+ return x + (int) y + (int) z + q;
+ }
+
+ public int bunchWrapped(int x, double y, float z, String str, int q)
+ {
+ return x + (int) y + (int) z + q;
+ }
+}
\ No newline at end of file
Copied: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgPOJOInterface.java (from rev 58452, projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/PojoInterface.java)
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/PojoInterface.java 2006-11-16 15:59:40 UTC (rev 58452)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgPOJOInterface.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.aop.args;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public interface ArgPOJOInterface
+{
+ String echo(String echo);
+
+ int bunch(int x, double y, float z, String str, int q);
+
+}
Copied: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgTestCase.java (from rev 58452, projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgsTestCase.java)
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgsTestCase.java 2006-11-16 15:59:40 UTC (rev 58452)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgTestCase.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.aop.args;
+
+import org.jboss.test.aop.AOPTestWithSetup;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+
+/**
+ * Tests the use of @Arg parameters.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class ArgTestCase extends AOPTestWithSetup
+{
+ ArgPOJO pojo;
+
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("ArgTestCase");
+ suite.addTestSuite(ArgTestCase.class);
+ return suite;
+ }
+
+ public ArgTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ pojo = new ArgPOJO();
+ ArgAspect.clear();
+ }
+
+ public void testBench()
+ {
+ {
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < 1000000; i++)
+ {
+ pojo.bunchArgs(1, 2.2, 3.3F, "four", 5);
+ }
+ long end = System.currentTimeMillis() - start;
+ System.out.println("bunchArgs: " + end);
+ }
+
+ {
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < 1000000; i++)
+ {
+ pojo.bunchWrapped(1, 2.2, 3.3F, "four", 5);
+ }
+ long end = System.currentTimeMillis() - start;
+ System.out.println("bunchWrapped: " + end);
+ }
+
+ {
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < 1000000; i++)
+ {
+ pojo.bunchArgsWithInvocation(1, 2.2, 3.3F, "four", 5);
+ }
+ long end = System.currentTimeMillis() - start;
+ System.out.println("bunchArgsWithInvocation: " + end);
+ }
+ assertTrue(ArgAspect.argsWithInvocation);
+ assertTrue(ArgAspect.args);
+ assertTrue(ArgAspect.wrapped);
+ }
+
+ public void testEcho()
+ {
+ pojo.echo("hello");
+ assertTrue(ArgAspect.echoCalled);
+ }
+
+ public void testBunch()
+ {
+ pojo.bunch(1, 2.2, 3.3F, "four", 5);
+ assertTrue(ArgAspect.bunchCalled);
+ assertTrue(ArgAspect.bunch2Called);
+ assertTrue(ArgAspect.arg1Called);
+ assertTrue(ArgAspect.arg2Called);
+ assertTrue(ArgAspect.arg3Called);
+ assertTrue(ArgAspect.arg4Called);
+ assertTrue(ArgAspect.arg15Called);
+ assertTrue(ArgAspect.arg24Called);
+ assertTrue(ArgAspect.emptyArgCalled);
+ }
+}
\ No newline at end of file
Deleted: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgsTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgsTestCase.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgsTestCase.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -1,125 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.aop.args;
-
-import org.jboss.test.aop.AOPTestWithSetup;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
-
-/**
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class ArgsTestCase extends AOPTestWithSetup
-{
-
- public static void main(String[] args)
- {
- TestRunner.run(suite());
- }
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite("AnnotatedTester");
- suite.addTestSuite(ArgsTestCase.class);
- return suite;
- }
-
- public ArgsTestCase(String name)
- {
- super(name);
- }
-
- public void testBench()
- {
- POJO pojo = new POJO();
-
- {
- long start = System.currentTimeMillis();
- for (int i = 0; i < 1000000; i++)
- {
- pojo.bunchArgs(1, 2.2, 3.3F, "four", 5);
- }
- long end = System.currentTimeMillis() - start;
- System.out.println("bunchArgs: " + end);
- }
-
- {
- long start = System.currentTimeMillis();
- for (int i = 0; i < 1000000; i++)
- {
- pojo.bunchWrapped(1, 2.2, 3.3F, "four", 5);
- }
- long end = System.currentTimeMillis() - start;
- System.out.println("bunchWrapped: " + end);
- }
-
- {
- long start = System.currentTimeMillis();
- for (int i = 0; i < 1000000; i++)
- {
- pojo.bunchArgsWithInvocation(1, 2.2, 3.3F, "four", 5);
- }
- long end = System.currentTimeMillis() - start;
- System.out.println("bunchArgsWithInvocation: " + end);
- }
-
- assertTrue(Aspect.argsWithInvocation);
- assertTrue(Aspect.args);
- assertTrue(Aspect.wrapped);
-
- }
-
- public void testEcho()
- {
- POJO pojo = new POJO();
-
- Aspect.echoCalled = false;
- pojo.echo("hello");
- assertTrue(Aspect.echoCalled);
- }
-
- public void testBunch()
- {
- POJO pojo = new POJO();
-
- Aspect.bunchCalled = false;
- Aspect.arg1Called = false;
- Aspect.arg2Called = false;
- Aspect.arg3Called = false;
- Aspect.arg4Called = false;
- Aspect.arg15Called = false;
- Aspect.arg24Called = false;
- pojo.bunch(1, 2.2, 3.3F, "four", 5);
- assertTrue(Aspect.bunchCalled);
- assertTrue(Aspect.arg1Called);
- assertTrue(Aspect.arg2Called);
- assertTrue(Aspect.arg3Called);
- assertTrue(Aspect.arg4Called);
- assertTrue(Aspect.arg15Called);
- assertTrue(Aspect.arg24Called);
- }
-
-}
Deleted: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/Aspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/Aspect.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/Aspect.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -1,162 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.aop.args;
-
-import org.jboss.aop.advice.annotation.Arg;
-import org.jboss.aop.advice.annotation.Invocation;
-import org.jboss.aop.joinpoint.CurrentInvocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class Aspect implements PojoInterface
-{
- public static boolean echoCalled = false;
-
- public String echo(@Arg String arg)
- {
- echoCalled = true;
-
- if (!arg.equals("hello")) throw new RuntimeException("Args don't match");
-
- try
- {
- return (String) CurrentInvocation.proceed();
- }
- catch (Throwable throwable)
- {
- throw new RuntimeException(throwable);
- }
- }
-
- public static boolean wrapped = false;
-
- public Object wrap(MethodInvocation invocation) throws Throwable
- {
- wrapped = true;
- return invocation.invokeNext();
- }
-
- public static boolean args = false;
-// TODO talk to kabir returned Object
- public int bunchArgs(@Arg int x, @Arg double y, @Arg float z,
- @Arg String str, @Arg int q) throws Throwable
- {
- args = true;
- return (Integer)CurrentInvocation.proceed();
- }
-
- public static boolean argsWithInvocation = false;
-// TODO idem
- public int bunchArgsWithInvocation(
- @Invocation MethodInvocation invocation,
- @Arg int x, @Arg double y, @Arg float z, @Arg String str, @Arg int q) throws Throwable
- {
- argsWithInvocation = true;
- return (Integer) invocation.invokeNext();
- }
-
-
- public static boolean bunchCalled = false;
-
- public int bunch(@Arg int x, @Arg double y, @Arg float z, @Arg String str, @Arg int q)
- {
- bunchCalled = true;
-
- if (x != 1 && y != 2.2 && z != 3.3F && !str.equals("four") && q != 5)
- {
- throw new RuntimeException("Arguments don't match");
- }
- try
- {
- return ((Integer) CurrentInvocation.proceed()).intValue();
- }
- catch (Throwable throwable)
- {
- throw new RuntimeException(throwable);
- }
- }
-
- public static boolean arg1Called = false;
-// TODO Idem
- public int arg1(@Arg int x) throws Throwable
- {
- arg1Called = true;
-
- if (x != 1) throw new RuntimeException("Args don't match");
- return (Integer) CurrentInvocation.proceed();
- }
-
- public static boolean arg2Called = false;
-// TODO idem
- public int arg2(@Arg double y) throws Throwable
- {
- arg2Called = true;
-
- if (y != 2.2) throw new RuntimeException("Args don't match");
- return (Integer) CurrentInvocation.proceed();
- }
-
- public static boolean arg3Called = false;
-// TODO Idem
- public int arg3(@Arg float z) throws Throwable
- {
- arg3Called = true;
-
- if (z != 3.3F) throw new RuntimeException("Args don't match for arg3: " + z);
- return (Integer) CurrentInvocation.proceed();
- }
-
- public static boolean arg4Called = false;
-// TODO Idem
- public int arg4(@Arg String str) throws Throwable
- {
- arg4Called = true;
-
- if (!str.equals("four")) throw new RuntimeException("Args don't match");
- return (Integer) CurrentInvocation.proceed();
- }
-
- public static boolean arg15Called = false;
-// TODO Idem
- public int arg15(@Arg int x, @Arg int q) throws Throwable
- {
- arg15Called = true;
-
- if (x != 1 && q != 5) throw new RuntimeException("Args don't match");
- return (Integer) CurrentInvocation.proceed();
- }
-
- public static boolean arg24Called = false;
-// TODO Idem
- public int arg24(@Arg double y, @Arg String str) throws Throwable
- {
- arg24Called = true;
-
- if (y != 2.2 && !str.equals("four")) throw new RuntimeException("Args don't match");
- return (Integer) CurrentInvocation.proceed();
- }
-}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationAspect.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationAspect.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,77 @@
+package org.jboss.test.aop.args;
+
+import junit.framework.Assert;
+
+import org.jboss.aop.joinpoint.ConstructorInvocation;
+import org.jboss.aop.joinpoint.FieldInvocation;
+import org.jboss.aop.joinpoint.FieldReadInvocation;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * Aspect used on @org.jboss.aop.advice.annotation.Invocation parameter tests.
+ *
+ * @author Flavia Rainone
+ */
+public class InvocationAspect
+{
+ static String advice = null;
+ static Object invokeReturn = null;
+
+ public static void clear()
+ {
+ advice = null;
+ invokeReturn = null;
+ }
+
+ public void before(@org.jboss.aop.advice.annotation.Invocation Object object)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public void after(@org.jboss.aop.advice.annotation.Invocation Object object)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public void throwing(@org.jboss.aop.advice.annotation.Invocation Object object)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public Object aroundMethodExecution1()
+ {
+ advice = "aroundMethodExecution1";
+ return "aroundMethodExecution1";
+ }
+
+ public int aroundMethodExecution2(@org.jboss.aop.advice.annotation.Invocation
+ ConstructorInvocation invocation) throws Throwable
+ {
+ Assert.fail("This advice should never be executed");
+ return 0;
+ }
+
+ public Object aroundMethodCalledByMethod(@org.jboss.aop.advice.annotation.Invocation
+ Invocation invocation) throws Throwable
+ {
+ advice = "aroundMethodCalledByMethod";
+ invokeReturn = invocation.invokeNext();
+ return 15000;
+ }
+
+ public Object aroundFieldWrite(@org.jboss.aop.advice.annotation.Invocation
+ FieldInvocation invocation) throws Throwable
+ {
+ advice = "aroundFieldWrite";
+ invokeReturn = invocation.invokeNext();
+ return null;
+ }
+
+ public int aroundFieldRead(@org.jboss.aop.advice.annotation.Invocation
+ FieldReadInvocation invocation) throws Throwable
+ {
+ advice = "aroundFieldRead";
+ invokeReturn = invocation.invokeNext();
+ return 500;
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationPOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationPOJO.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationPOJO.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,32 @@
+package org.jboss.test.aop.args;
+
+/**
+ * Plain old java object used on @org.jboss.aop.advice.annotation.Invocation parameter
+ * tests.
+ *
+ * @author Flavia Rainone
+ */
+public class InvocationPOJO
+{
+ public int number;
+
+ public int callerMethod(int i)
+ {
+ return calleeMethod(i);
+ }
+
+ private int calleeMethod(int i)
+ {
+ return i*2;
+ }
+
+ public String method1()
+ {
+ return "method";
+ }
+
+ public int method2()
+ {
+ return 2;
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationTestCase.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/InvocationTestCase.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,76 @@
+package org.jboss.test.aop.args;
+
+import org.jboss.test.aop.AOPTestWithSetup;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Tests the use of @org.jboss.aop.advice.annotation.Invocation parameters.
+ *
+ * @author Flavia Rainone
+ */
+public class InvocationTestCase extends AOPTestWithSetup
+{
+ private InvocationPOJO pojo;
+
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("InvocationTestCase");
+ suite.addTestSuite(InvocationTestCase.class);
+ return suite;
+ }
+
+ public InvocationTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ InvocationAspect.clear();
+ this.pojo = new InvocationPOJO();
+ }
+
+ public void test1()
+ {
+ assertEquals("aroundMethodExecution1", pojo.method1());
+ assertEquals("aroundMethodExecution1", InvocationAspect.advice);
+ assertNull(InvocationAspect.invokeReturn);
+ }
+
+ public void test2()
+ {
+ assertEquals(2, pojo.method2());
+ assertNull(InvocationAspect.advice);
+ assertNull(InvocationAspect.invokeReturn);
+ }
+
+ public void test3()
+ {
+ assertEquals(15000, pojo.callerMethod(20));
+ assertEquals("aroundMethodCalledByMethod", InvocationAspect.advice);
+ assertNotNull(InvocationAspect.invokeReturn);
+ assertEquals(40, ((Integer) InvocationAspect.invokeReturn).intValue());
+ }
+
+ public void test4()
+ {
+ pojo.number = 35;
+ assertEquals("aroundFieldWrite", InvocationAspect.advice);
+ assertNull(InvocationAspect.invokeReturn);
+
+
+ assertEquals(500, pojo.number);
+ assertEquals("aroundFieldRead", InvocationAspect.advice);
+ assertNotNull(InvocationAspect.invokeReturn);
+ assertEquals(35, ((Integer) InvocationAspect.invokeReturn).intValue());
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointAspect.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointAspect.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,121 @@
+package org.jboss.test.aop.args;
+
+import junit.framework.Assert;
+
+import org.jboss.aop.ConstructorInfo;
+import org.jboss.aop.FieldInfo;
+import org.jboss.aop.JoinPointInfo;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.annotation.JoinPoint;
+import org.jboss.aop.advice.annotation.Thrown;
+
+/**
+ * Aspect used on @JoinPoint parameter tests.
+ *
+ * @author Flavia Rainone
+ */
+public class JoinPointAspect
+{
+ static String beforeAdvice = null;
+ static JoinPointInfo beforeJoinPointInfo = null;
+ static String afterAdvice = null;
+ static JoinPointInfo afterJoinPointInfo = null;
+ static String throwingAdvice = null;
+ static JoinPointInfo throwingJoinPointInfo = null;
+
+ public static void clear()
+ {
+ beforeAdvice = null;
+ beforeJoinPointInfo = null;
+ afterAdvice = null;
+ afterJoinPointInfo = null;
+ throwingAdvice = null;
+ throwingJoinPointInfo = null;
+ }
+
+ public void before1()
+ {
+ beforeAdvice = "before1";
+ }
+
+ public void before2(@JoinPoint Object joinPointInfo)
+ {
+ beforeAdvice = "before2";
+ beforeJoinPointInfo = (JoinPointInfo) joinPointInfo;
+ }
+
+ public void before3(@JoinPoint JoinPointInfo joinPointInfo)
+ {
+ beforeAdvice = "before3";
+ beforeJoinPointInfo = joinPointInfo;
+ }
+
+ public void before4(@JoinPoint MethodInfo joinPointInfo)
+ {
+ beforeAdvice = "before4";
+ beforeJoinPointInfo = (JoinPointInfo) joinPointInfo;
+ }
+
+ public void before5(@JoinPoint MethodInfo joinPointInfo)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public void after1(@JoinPoint FieldInfo joinPointInfo)
+ {
+ afterAdvice = "after1";
+ afterJoinPointInfo = joinPointInfo;
+ }
+
+ public void after2(@JoinPoint ConstructorInfo constructorInfo)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public void after3()
+ {
+ afterAdvice = "after3";
+ }
+
+ public void after4(@JoinPoint Object joinPointInfo)
+ {
+ afterAdvice = "after4";
+ afterJoinPointInfo = (JoinPointInfo) joinPointInfo;
+ }
+
+ public void after5(@JoinPoint JoinPointInfo joinPointInfo)
+ {
+ afterAdvice = "after5";
+ afterJoinPointInfo = joinPointInfo;
+ }
+
+ public void throwing1(@Thrown Throwable throwable, @JoinPoint Object joinPointInfo)
+ {
+ throwingAdvice = "throwing1";
+ throwingJoinPointInfo = (JoinPointInfo) joinPointInfo;
+ }
+
+ public void throwing2(@JoinPoint ConstructorInfo joinPointInfo,
+ @Thrown Throwable throwable)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public void throwing3(@Thrown Throwable throwable,
+ @JoinPoint JoinPointInfo joinPointInfo)
+ {
+ throwingAdvice = "throwing3";
+ throwingJoinPointInfo = joinPointInfo;
+ }
+
+ public void throwing4(@Thrown Throwable throwable)
+ {
+ throwingAdvice = "throwing4";
+ }
+
+ public void throwing5(@JoinPoint MethodInfo joinPointInfo, @Thrown Throwable throwable)
+ {
+ throwingAdvice = "throwing5";
+ throwingJoinPointInfo = joinPointInfo;
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointPOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointPOJO.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointPOJO.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,46 @@
+package org.jboss.test.aop.args;
+
+/**
+ * Plain old java object used on @JoinPoint parameter tests.
+ *
+ * @author Flavia Rainone
+ */
+public class JoinPointPOJO
+{
+ public int number;
+ public String text;
+
+ public void method1()
+ {
+
+ }
+
+ public String method2(boolean shouldThrow) throws POJOException
+ {
+ if (shouldThrow)
+ {
+ throw new POJOException();
+ }
+ return "method3";
+ }
+
+ public void method3() throws POJOException
+ {
+ throw new POJOException();
+ }
+
+ public void method4() throws POJOException
+ {
+ throw new POJOException();
+ }
+
+ public void method5() throws POJOException
+ {
+ throw new POJOException();
+ }
+
+ public void method6() throws POJOException
+ {
+ throw new POJOException();
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointTestCase.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/JoinPointTestCase.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,227 @@
+package org.jboss.test.aop.args;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.aop.FieldInfo;
+import org.jboss.aop.MethodInfo;
+import org.jboss.test.aop.AOPTestWithSetup;
+
+/**
+ * Tests the use of @JoinPoint parameters.
+ *
+ * @author Flavia Rainone
+ */
+public class JoinPointTestCase extends AOPTestWithSetup
+{
+ private JoinPointPOJO pojo;
+
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("JoinPointTestCase");
+ suite.addTestSuite(JoinPointTestCase.class);
+ return suite;
+ }
+
+ public JoinPointTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ JoinPointAspect.clear();
+ this.pojo = new JoinPointPOJO();
+ }
+
+ public void test1()
+ {
+ pojo.number = 0;
+ assertEquals("before1", JoinPointAspect.beforeAdvice);
+ assertNull(JoinPointAspect.beforeJoinPointInfo);
+ assertEquals("after1", JoinPointAspect.afterAdvice);
+ assertNotNull(JoinPointAspect.afterJoinPointInfo);
+ assertTrue(JoinPointAspect.afterJoinPointInfo instanceof FieldInfo);
+ FieldInfo fieldInfo = (FieldInfo) JoinPointAspect.afterJoinPointInfo;
+ assertEquals("number", fieldInfo.getAdvisedField().getName());
+ assertFalse(fieldInfo.isRead());
+ }
+
+ public void test2()
+ {
+ pojo.text = "test2";
+ assertEquals("before2", JoinPointAspect.beforeAdvice);
+ assertNotNull(JoinPointAspect.beforeJoinPointInfo);
+ assertNull(JoinPointAspect.afterAdvice);
+ assertNull(JoinPointAspect.afterJoinPointInfo);
+
+ assertTrue(JoinPointAspect.beforeJoinPointInfo instanceof FieldInfo);
+ FieldInfo fieldInfo = (FieldInfo) JoinPointAspect.beforeJoinPointInfo;
+ assertEquals("text", fieldInfo.getAdvisedField().getName());
+ assertFalse(fieldInfo.isRead());
+ }
+
+ public void test3()
+ {
+ String text = pojo.text;
+ assertNull(JoinPointAspect.beforeAdvice);
+ assertNull(JoinPointAspect.beforeJoinPointInfo);
+ assertEquals("after5", JoinPointAspect.afterAdvice);
+ assertNotNull(JoinPointAspect.afterJoinPointInfo);
+ assertTrue(JoinPointAspect.afterJoinPointInfo instanceof FieldInfo);
+ FieldInfo fieldInfo = (FieldInfo) JoinPointAspect.afterJoinPointInfo;
+ assertEquals("text", fieldInfo.getAdvisedField().getName());
+ assertTrue(fieldInfo.isRead());
+ }
+
+ public void test4()
+ {
+ pojo.method1();
+ assertEquals("before3", JoinPointAspect.beforeAdvice);
+ assertNotNull(JoinPointAspect.beforeJoinPointInfo);
+ assertEquals("after3", JoinPointAspect.afterAdvice);
+ assertNull(JoinPointAspect.afterJoinPointInfo);
+ assertTrue(JoinPointAspect.beforeJoinPointInfo instanceof MethodInfo);
+ assertEquals("method1", ((MethodInfo) JoinPointAspect.beforeJoinPointInfo).
+ getAdvisedMethod().getName());
+ }
+
+ public void test5() throws POJOException
+ {
+ pojo.method2(false);
+ assertEquals("before4", JoinPointAspect.beforeAdvice);
+ assertNotNull(JoinPointAspect.beforeJoinPointInfo);
+ assertEquals("after4", JoinPointAspect.afterAdvice);
+ assertNotNull(JoinPointAspect.afterJoinPointInfo);
+ assertNull(JoinPointAspect.throwingAdvice);
+ assertNull(JoinPointAspect.throwingJoinPointInfo);
+ assertSame(JoinPointAspect.beforeJoinPointInfo, JoinPointAspect.afterJoinPointInfo);
+ assertTrue(JoinPointAspect.beforeJoinPointInfo instanceof MethodInfo);
+ assertEquals("method2", ((MethodInfo) JoinPointAspect.beforeJoinPointInfo).
+ getAdvisedMethod().getName());
+ }
+
+ public void test6() throws POJOException
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ pojo.method2(true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertEquals("before4", JoinPointAspect.beforeAdvice);
+ assertNotNull(JoinPointAspect.beforeJoinPointInfo);
+ assertNull(JoinPointAspect.afterAdvice);
+ assertNull(JoinPointAspect.afterJoinPointInfo);
+ assertEquals("throwing1", JoinPointAspect.throwingAdvice);
+ assertNotNull(JoinPointAspect.throwingJoinPointInfo);
+ assertSame(JoinPointAspect.beforeJoinPointInfo,
+ JoinPointAspect.throwingJoinPointInfo);
+ assertTrue(JoinPointAspect.beforeJoinPointInfo instanceof MethodInfo);
+ assertEquals("method2", ((MethodInfo) JoinPointAspect.beforeJoinPointInfo).
+ getAdvisedMethod().getName());
+ }
+
+ public void test7() throws POJOException
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ pojo.method3();
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertNull(JoinPointAspect.beforeAdvice);
+ assertNull(JoinPointAspect.beforeJoinPointInfo);
+ assertNull(JoinPointAspect.afterAdvice);
+ assertNull(JoinPointAspect.afterJoinPointInfo);
+ assertNull(JoinPointAspect.throwingAdvice);
+ assertNull(JoinPointAspect.throwingJoinPointInfo);
+ }
+
+ public void test8() throws POJOException
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ pojo.method4();
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertNull(JoinPointAspect.beforeAdvice);
+ assertNull(JoinPointAspect.beforeJoinPointInfo);
+ assertNull(JoinPointAspect.afterAdvice);
+ assertNull(JoinPointAspect.afterJoinPointInfo);
+ assertEquals("throwing3", JoinPointAspect.throwingAdvice);
+ assertNotNull(JoinPointAspect.throwingJoinPointInfo);
+ assertTrue(JoinPointAspect.throwingJoinPointInfo instanceof MethodInfo);
+ assertEquals("method4", ((MethodInfo) JoinPointAspect.throwingJoinPointInfo).
+ getAdvisedMethod().getName());
+ }
+
+ public void test9() throws POJOException
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ pojo.method5();
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertNull(JoinPointAspect.beforeAdvice);
+ assertNull(JoinPointAspect.beforeJoinPointInfo);
+ assertNull(JoinPointAspect.afterAdvice);
+ assertNull(JoinPointAspect.afterJoinPointInfo);
+ assertEquals("throwing4", JoinPointAspect.throwingAdvice);
+ assertNull(JoinPointAspect.throwingJoinPointInfo);
+ }
+
+ public void test10() throws POJOException
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ pojo.method6();
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertNull(JoinPointAspect.beforeAdvice);
+ assertNull(JoinPointAspect.beforeJoinPointInfo);
+ assertNull(JoinPointAspect.afterAdvice);
+ assertNull(JoinPointAspect.afterJoinPointInfo);
+ assertEquals("throwing5", JoinPointAspect.throwingAdvice);
+ assertNotNull(JoinPointAspect.throwingJoinPointInfo);
+ assertTrue(JoinPointAspect.throwingJoinPointInfo instanceof MethodInfo);
+ assertEquals("method6", ((MethodInfo) JoinPointAspect.throwingJoinPointInfo).
+ getAdvisedMethod().getName());
+
+ }
+}
\ No newline at end of file
Deleted: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/POJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/POJO.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/POJO.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.aop.args;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class POJO implements PojoInterface
-{
- public String echo(String echo)
- {
- return echo;
- }
-
- public int bunch(int x, double y, float z, String str, int q)
- {
- return x + (int) y + (int) z + q;
- }
-
- public int bunchArgs(int x, double y, float z, String str, int q)
- {
- return x + (int) y + (int) z + q;
- }
-
- public int bunchArgsWithInvocation(int x, double y, float z, String str, int q)
- {
- return x + (int) y + (int) z + q;
- }
-
- public int bunchWrapped(int x, double y, float z, String str, int q)
- {
- return x + (int) y + (int) z + q;
- }
-
-}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/POJOException.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/POJOException.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/POJOException.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,34 @@
+package org.jboss.test.aop.args;
+
+/**
+ * Class used on annotated parameter tests.
+ *
+ * @author Flavia Rainone
+ */
+public class POJOException extends Exception
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * A number that identifies the exception thrown.
+ */
+ int number;
+
+ /**
+ * Constructor.
+ */
+ public POJOException()
+ {
+ this(0);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param number a number identifying the exception.
+ */
+ public POJOException(int number)
+ {
+ this.number = number;
+ }
+}
\ No newline at end of file
Deleted: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/PojoInterface.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/PojoInterface.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/PojoInterface.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.aop.args;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public interface PojoInterface
-{
- String echo(String echo);
-
- int bunch(int x, double y, float z, String str, int q);
-
-}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnAspect.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnAspect.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,185 @@
+package org.jboss.test.aop.args;
+
+import junit.framework.Assert;
+
+import org.jboss.aop.JoinPointInfo;
+import org.jboss.aop.advice.annotation.JoinPoint;
+import org.jboss.aop.advice.annotation.Return;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * Aspect used both on @Return parameter tests, and on advice return type tests.
+ *
+ * @author Flavia Rainone
+ */
+public class ReturnAspect
+{
+ public static String aroundAdvice = null;
+ public static Object aroundReturn = null;
+ public static String afterAdvice = null;
+ public static Object afterReturn = null;
+
+ public static void clear()
+ {
+ aroundAdvice = null;
+ aroundReturn = null;
+ afterAdvice = null;
+ afterReturn = null;
+ }
+
+ public void before(@Return Object object)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public void throwing(@Return Object object)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public void around1(Invocation invocation) throws Exception
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public void around2(@org.jboss.aop.advice.annotation.Invocation
+ Invocation invocation) throws Exception
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public Object around3(Invocation invocation) throws Throwable
+ {
+ aroundAdvice = "around3";
+ aroundReturn = invocation.invokeNext();
+ return aroundAdvice;
+ }
+
+ public Object around4(@org.jboss.aop.advice.annotation.Invocation
+ Invocation invocation) throws Throwable
+ {
+ aroundAdvice = "around4";
+ aroundReturn = invocation.invokeNext();
+ return aroundAdvice;
+ }
+
+ public Object around5()
+ {
+ aroundAdvice = "around5";
+ return aroundAdvice;
+ }
+
+ public void around6()
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public String around7(@org.jboss.aop.advice.annotation.Invocation Invocation
+ invocation) throws Throwable
+ {
+ aroundAdvice = "around7";
+ aroundReturn = invocation.invokeNext();
+ return aroundAdvice;
+ }
+
+ public SubValue around8()
+ {
+ aroundAdvice = "around8";
+ return new SubValue(80);
+ }
+
+ public SuperValue around9(@org.jboss.aop.advice.annotation.Invocation Invocation
+ invocation) throws Throwable
+ {
+ Assert.fail("This advice should never be executed");
+ return null;
+ }
+
+ public SubValue around10(@org.jboss.aop.advice.annotation.Invocation Invocation
+ invocation) throws Throwable
+ {
+ aroundAdvice = "around10";
+ aroundReturn = invocation.invokeNext();
+ return new SubValue(100);
+ }
+
+ public SuperValue around11(@org.jboss.aop.advice.annotation.Invocation Invocation
+ invocation) throws Throwable
+ {
+ aroundAdvice = "around11";
+ aroundReturn = invocation.invokeNext();
+ return new SuperValue(110);
+ }
+
+
+ public void after1(@org.jboss.aop.advice.annotation.JoinPoint JoinPointInfo info) throws Exception
+ {
+ afterAdvice = "after1";
+ }
+
+ public void after2(@Return Object returnedValue) throws Exception
+ {
+ afterAdvice = "after2";
+ afterReturn = returnedValue;
+ }
+
+ public Object after3(@JoinPoint JoinPointInfo info, @Return String returnedValue)
+ throws Throwable
+ {
+ afterAdvice = "after3";
+ afterReturn = returnedValue;
+ return afterAdvice;
+ }
+
+ public Object after4(@Return Object returnedValue) throws Throwable
+ {
+ afterAdvice = "after4";
+ afterReturn = returnedValue;
+ return afterAdvice;
+ }
+
+ public Object after5()
+ {
+ afterAdvice = "after5";
+ return afterAdvice;
+ }
+
+ public void after6()
+ {
+ afterAdvice = "after6";
+ }
+
+ public String after7(@JoinPoint JoinPointInfo joinPoint,
+ @Return String returnedValue) throws Throwable
+ {
+ afterAdvice = "after7";
+ afterReturn = returnedValue;
+ return afterAdvice;
+ }
+
+ public SubValue after8()
+ {
+ afterAdvice = "after8";
+ return new SubValue(800);
+ }
+
+ public SuperValue after9() throws Throwable
+ {
+ Assert.fail("This advice should never be executed");
+ return null;
+ }
+
+ public SubValue after10(@Return SubValue returnedValue) throws Throwable
+ {
+ afterAdvice = "after10";
+ afterReturn = returnedValue;
+ return new SubValue(1000);
+ }
+
+ public SubValue after11(@Return SuperValue returnedValue) throws Throwable
+ {
+ afterAdvice = "after11";
+ afterReturn = returnedValue;
+ return new SubValue(1100);
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnPOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnPOJO.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnPOJO.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,67 @@
+package org.jboss.test.aop.args;
+
+/**
+ * Plain old java object used both on @Return parameter tests, and on advice return type
+ * tests.
+ *
+ * @author Flavia Rainone
+ */
+public class ReturnPOJO
+{
+ public void method1() {}
+
+ public String method2()
+ {
+ return "method2";
+ }
+
+ public String method3()
+ {
+ return "method3";
+ }
+
+ public String method4()
+ {
+ return "method4";
+ }
+
+ public String method5()
+ {
+ return "method5";
+ }
+
+ public String method6()
+ {
+ return "method6";
+ }
+
+ public String method7()
+ {
+ return "method7";
+ }
+
+ public SubValue method8()
+ {
+ return new SubValue(8);
+ }
+
+ public SubValue method9()
+ {
+ return new SubValue(9);
+ }
+
+ public SuperValue method10()
+ {
+ return new SuperValue(10);
+ }
+
+ public SuperValue method11()
+ {
+ return new SuperValue(11);
+ }
+
+ public Object method12() throws POJOException
+ {
+ throw new POJOException();
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnTestCase.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ReturnTestCase.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,160 @@
+package org.jboss.test.aop.args;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.aop.AOPTestWithSetup;
+
+/**
+ * Tests both the use of @Return parameters, and the use of return values in advices.
+ *
+ * @author Flavia Rainone
+ */
+public class ReturnTestCase extends AOPTestWithSetup
+{
+ private ReturnPOJO pojo;
+
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("ReturnTestCase");
+ suite.addTestSuite(ReturnTestCase.class);
+ return suite;
+ }
+
+ public ReturnTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ ReturnAspect.clear();
+ this.pojo = new ReturnPOJO();
+ }
+
+ public void test1()
+ {
+ pojo.method1();
+ assertNull(ReturnAspect.aroundAdvice);
+ assertNull(ReturnAspect.aroundReturn);
+ assertEquals("after1", ReturnAspect.afterAdvice);
+ assertNull(ReturnAspect.afterReturn);
+ }
+
+ public void test2()
+ {
+ assertEquals("method2", pojo.method2());
+ assertNull(ReturnAspect.aroundAdvice);
+ assertNull(ReturnAspect.aroundReturn);
+ assertEquals("after2", ReturnAspect.afterAdvice);
+ assertEquals("method2", ReturnAspect.afterReturn);
+ }
+
+ public void test3()
+ {
+ assertEquals("after3", pojo.method3());
+ assertEquals("around3", ReturnAspect.aroundAdvice);
+ assertEquals("method3", ReturnAspect.aroundReturn);
+ assertEquals("after3", ReturnAspect.afterAdvice);
+ assertEquals("around3", ReturnAspect.afterReturn);
+ }
+
+ public void test4()
+ {
+ assertEquals("after4", pojo.method4());
+ assertEquals("around4", ReturnAspect.aroundAdvice);
+ assertEquals("method4", ReturnAspect.aroundReturn);
+ assertEquals("after4", ReturnAspect.afterAdvice);
+ assertEquals("around4", ReturnAspect.afterReturn);
+ }
+
+ public void test5()
+ {
+ assertEquals("after5", pojo.method5());
+ assertEquals("around5", ReturnAspect.aroundAdvice);
+ assertNull(ReturnAspect.aroundReturn);
+ assertEquals("after5", ReturnAspect.afterAdvice);
+ assertNull(ReturnAspect.afterReturn);
+ }
+
+ public void test6()
+ {
+ assertEquals("method6", pojo.method6());
+ assertNull(ReturnAspect.aroundAdvice);
+ assertNull(ReturnAspect.aroundReturn);
+ assertEquals("after6", ReturnAspect.afterAdvice);
+ assertNull(ReturnAspect.afterReturn);
+ }
+
+ public void test7()
+ {
+ assertEquals("after7", pojo.method7());
+ assertEquals("around7", ReturnAspect.aroundAdvice);
+ assertEquals("method7", ReturnAspect.aroundReturn);
+ assertEquals("after7", ReturnAspect.afterAdvice);
+ assertEquals("around7", ReturnAspect.afterReturn);
+ }
+
+ public void test8()
+ {
+ SubValue value = pojo.method8();
+ assertNotNull(value);
+ assertEquals(800, value.i);
+ assertEquals("around8", ReturnAspect.aroundAdvice);
+ assertNull(ReturnAspect.aroundReturn);
+ assertEquals("after8", ReturnAspect.afterAdvice);
+ assertNull(ReturnAspect.afterReturn);
+ }
+
+ public void test9()
+ {
+ SubValue value = pojo.method9();
+ assertNotNull(value);
+ assertEquals(9, value.i);
+ assertNull(ReturnAspect.aroundAdvice);
+ assertNull(ReturnAspect.aroundReturn);
+ assertNull(ReturnAspect.afterAdvice);
+ assertNull(ReturnAspect.afterReturn);
+ }
+
+ public void test10()
+ {
+ SuperValue value = pojo.method10();
+ assertNotNull(value);
+ assertEquals(100, value.i);
+ assertEquals("around10", ReturnAspect.aroundAdvice);
+ assertNotNull(ReturnAspect.aroundReturn);
+ assertEquals(10, ((SuperValue) ReturnAspect.aroundReturn).i);
+ assertNull(ReturnAspect.afterAdvice);
+ assertNull(ReturnAspect.afterReturn);
+ }
+
+ public void test11()
+ {
+ SuperValue value = pojo.method11();
+ assertNotNull(value);
+ assertEquals(1100, value.i);
+ assertEquals("around11", ReturnAspect.aroundAdvice);
+ assertNotNull(ReturnAspect.aroundReturn);
+ assertEquals(11, ((SuperValue) ReturnAspect.aroundReturn).i);
+ assertEquals("after11", ReturnAspect.afterAdvice);
+ assertNotNull(ReturnAspect.afterReturn);
+ assertEquals(110, ((SuperValue) ReturnAspect.afterReturn).i);
+ }
+
+ public void test12()
+ {
+ try
+ {
+ pojo.method12();
+ }
+ catch(POJOException e){}
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/SubValue.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/SubValue.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/SubValue.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.args;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 39449 $
+ */
+public class SubValue extends SuperValue
+{
+
+ public SubValue(int i)
+ {
+ // FIXME SubValue constructor
+ super(i);
+ }
+
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/SuperValue.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/SuperValue.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/SuperValue.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.args;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 39449 $
+ */
+public class SuperValue
+{
+ int i;
+ public SuperValue(int i)
+ {
+ this.i = i;
+ }
+
+ public int getValue()
+ {
+ return i;
+ }
+
+ public void doubleValue()
+ {
+ i *= 2;
+ }
+
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownAspect.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownAspect.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,67 @@
+package org.jboss.test.aop.args;
+
+import junit.framework.Assert;
+
+import org.jboss.aop.advice.annotation.Arg;
+import org.jboss.aop.advice.annotation.Thrown;
+
+/**
+ * Aspect used on @Thrown parameter tests.
+ *
+ * @author Flavia Rainone
+ */
+public class ThrownAspect
+{
+
+ public static String advice;
+ public static Throwable thrown;
+ public static int thrownNumber;
+
+ public static void clear()
+ {
+ advice = null;
+ thrown = null;
+ thrownNumber = 0;
+ }
+
+ public void throwing1()
+ {
+ advice = "throwing1";
+ }
+
+ public void throwing2(@Thrown Throwable throwable, @Arg int i)
+ {
+ advice = "throwing2";
+ thrownNumber = i;
+ thrown = throwable;
+ }
+
+ public void throwing3(@Thrown Exception exception)
+ {
+ advice = "throwing3";
+ thrownNumber = ((POJOException) exception).number;
+ thrown = exception;
+ }
+
+ public void throwing4(@Thrown POJOException pojoException, @Arg int i)
+ {
+ advice = "throwing4";
+ thrownNumber = i;
+ thrown = pojoException;
+ }
+
+ public void throwing5(@Thrown RuntimeException runtimeException)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public void throwing6(Throwable throwable)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+
+ public void throwing7(@Arg int i)
+ {
+ Assert.fail("This advice should never be executed");
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownPOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownPOJO.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownPOJO.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,39 @@
+package org.jboss.test.aop.args;
+
+/**
+ * Plain old java object used on @Thrown parameter tests.
+ *
+ * @author Flavia Rainone
+ */
+public class ThrownPOJO
+{
+ public void method1(int i) throws POJOException
+ {
+ throw new POJOException(i);
+ }
+
+ public void method2(int i) throws POJOException
+ {
+ throw new POJOException(i);
+ }
+
+ public void method3(int i) throws POJOException
+ {
+ throw new POJOException(i);
+ }
+
+ public void method4(int i) throws POJOException
+ {
+ throw new POJOException(i);
+ }
+
+ public void method5(int i) throws POJOException
+ {
+ throw new POJOException(i);
+ }
+
+ public void method6() throws POJOException
+ {
+ throw new POJOException(6);
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownTestCase.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ThrownTestCase.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -0,0 +1,156 @@
+package org.jboss.test.aop.args;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.aop.AOPTestWithSetup;
+
+/**
+ * Tests parameter annotation @Thrown.
+ *
+ * @author Flavia Rainone
+ *
+ */
+public class ThrownTestCase extends AOPTestWithSetup
+{
+ private ThrownPOJO pojo;
+
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("ThrownTestCase");
+ suite.addTestSuite(ThrownTestCase.class);
+ return suite;
+ }
+
+ public ThrownTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ ThrownAspect.clear();
+ this.pojo = new ThrownPOJO();
+ }
+
+ public void test1()
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.method1(11);
+ }
+ catch(POJOException pojoException)
+ {
+ thrown = true;
+ assertEquals(11, pojoException.number);
+ assertNull(ThrownAspect.advice);
+ assertNull(ThrownAspect.thrown);
+ assertEquals(0, ThrownAspect.thrownNumber);
+ }
+ assertTrue(thrown);
+ }
+
+ public void test2()
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.method2(23);
+ }
+ catch(POJOException pojoException)
+ {
+ thrown = true;
+ assertEquals(23, pojoException.number);
+ assertEquals("throwing2", ThrownAspect.advice);
+ assertEquals(pojoException, ThrownAspect.thrown);
+ assertEquals(23, ThrownAspect.thrownNumber);
+ }
+ assertTrue(thrown);
+ }
+
+ public void test3()
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.method3(37);
+ }
+ catch(POJOException pojoException)
+ {
+ thrown = true;
+ assertEquals(37, pojoException.number);
+ assertNull(ThrownAspect.advice);
+ assertNull(ThrownAspect.thrown);
+ assertEquals(0, ThrownAspect.thrownNumber);
+ /*assertEquals("throwing3", ThrownAspect.advice);
+ assertEquals(pojoException, ThrownAspect.thrown);
+ assertEquals(37, ThrownAspect.thrownNumber);*/
+ }
+ assertTrue(thrown);
+ }
+
+ public void test4()
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.method4(43);
+ }
+ catch(POJOException pojoException)
+ {
+ thrown = true;
+ assertEquals(43, pojoException.number);
+ assertNull(ThrownAspect.advice);
+ assertNull(ThrownAspect.thrown);
+ assertEquals(0, ThrownAspect.thrownNumber);
+ /*assertEquals("throwing4", ThrownAspect.advice);
+ assertEquals(pojoException, ThrownAspect.thrown);
+ assertEquals(43, ThrownAspect.thrownNumber);*/
+ }
+ assertTrue(thrown);
+ }
+
+ public void test5()
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.method5(59);
+ }
+ catch(POJOException pojoException)
+ {
+ thrown = true;
+ assertEquals(59, pojoException.number);
+ assertNull(ThrownAspect.advice);
+ assertNull(ThrownAspect.thrown);
+ assertEquals(0, ThrownAspect.thrownNumber);
+ }
+ assertTrue(thrown);
+ }
+
+ public void test6()
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.method6();
+ }
+ catch(POJOException pojoException)
+ {
+ thrown = true;
+ assertEquals(6, pojoException.number);
+ assertNull(ThrownAspect.advice);
+ assertNull(ThrownAspect.thrown);
+ assertEquals(0, ThrownAspect.thrownNumber);
+ }
+ assertTrue(thrown);
+ }
+}
\ No newline at end of file
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/ArgsAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/ArgsAspect.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/ArgsAspect.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -97,23 +97,23 @@
return ret;
}
- //This should be able to handle both reads and writes
- public int after(@JoinPoint FieldInfo fp, @Arg @Return int i)
+ //This should be able to handle writes
+ public int after(@JoinPoint FieldInfo fp, @Arg int i)
{
after = "after3";
return i;
}
- //This should be able to handle both reads and writes
- public SubValue after(@JoinPoint FieldInfo fp, @Return @Arg SubValue ret)
+ //This should be able to handle reads
+ public SubValue after(@JoinPoint FieldInfo fp, @Return SubValue ret)
{
after = "after4";
ret.doubleValue();
return ret;
}
- //This should be able to handle both reads and writes
- public SuperValue after(@Return @Arg SuperValue ret)
+ //This should be able to handle reads
+ public SuperValue after(@Return SuperValue ret)
{
after = "after5";
ret.doubleValue();
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/BeforeAfterThrowingTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/BeforeAfterThrowingTestCase.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/BeforeAfterThrowingTestCase.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -205,7 +205,7 @@
int i = pojo.i;
assertEquals("before4", ArgsAspect.before);
assertNull(ArgsAspect.throwing);
- assertEquals("after3", ArgsAspect.after);
+ assertEquals(null, ArgsAspect.after);
}
public void testFieldsWithInheritance() throws Exception
@@ -218,7 +218,7 @@
pojo.superValue = new SuperValue(5);
assertEquals("before4", ArgsAspect.before);
assertNull(ArgsAspect.throwing);
- assertEquals("after5", ArgsAspect.after);
+ assertEquals(null, ArgsAspect.after);
ArgsAspect.clear();
System.out.println("* Reading superValue");
@@ -226,7 +226,7 @@
assertEquals("before4", ArgsAspect.before);
assertNull(ArgsAspect.throwing);
assertEquals("after5", ArgsAspect.after);
- assertEquals(20, superVal.getValue()); //The after4 and after5 methods double the value
+ assertEquals(10, superVal.getValue()); //The after4 and after5 methods double the value
ArgsAspect.clear();
@@ -234,7 +234,7 @@
pojo.subValue = new SubValue(5);
assertEquals("before5", ArgsAspect.before);
assertNull(ArgsAspect.throwing);
- assertEquals("after4", ArgsAspect.after);
+ assertEquals(null, ArgsAspect.after);
ArgsAspect.clear();
System.out.println("* Writing subValue");
@@ -242,7 +242,7 @@
assertEquals("before4", ArgsAspect.before);
assertNull(ArgsAspect.throwing);
assertEquals("after4", ArgsAspect.after);
- assertEquals(20, subVal.getValue());//The after4 methods double the value
+ assertEquals(10, subVal.getValue());//The after4 methods double the value
}
public void testMethodsWithInheritance()
@@ -270,18 +270,14 @@
subValue = pojo.method(subValue, 5);
assertEquals("before", GeneralAspect.before);
assertNull(ArgsAspect.throwing);
- // TODO talk to Kabir about this
- assertEquals(null, GeneralAspect.after);
- //assertEquals("after", GeneralAspect.after);
+ assertEquals("after", GeneralAspect.after);
GeneralAspect.clear();
System.out.println(" * Testing method(SuperValue, int)");
superValue = pojo.method(superValue, 10);
assertEquals("before", GeneralAspect.before);
assertNull(ArgsAspect.throwing);
- // TODO idem
- assertEquals(null, GeneralAspect.after);
- //assertEquals("after", GeneralAspect.after);
+ assertEquals("after", GeneralAspect.after);
ArgsAspect.clear();
System.out.println(" * Testing method(SubValue, SubValue)");
@@ -297,4 +293,4 @@
assertNull(ArgsAspect.throwing);
assertEquals("after7", ArgsAspect.after);
}
-}
+}
\ No newline at end of file
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/GeneralAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/GeneralAspect.java 2006-11-28 16:24:22 UTC (rev 58705)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/GeneralAspect.java 2006-11-28 17:24:44 UTC (rev 58706)
@@ -48,13 +48,10 @@
before = "before";
}
- //TODO talk to Kabir about Object vs POJO
- public POJO after(@JoinPoint JoinPointInfo jp, @Return Object ret,
+ public Object after(@JoinPoint JoinPointInfo jp, @Return Object ret,
@Arg SuperValue superValue, @Arg int i)
{
after = "after";
- return (POJO) ret;
+ return ret;
}
-
-
-}
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list