[jboss-cvs] JBossAS SVN: r64206 - in projects/aop/trunk/aop/src: test/org/jboss/test/aop/beforeafterthrowingscoped and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 23 16:28:07 EDT 2007
Author: flavia.rainone at jboss.com
Date: 2007-07-23 16:28:07 -0400 (Mon, 23 Jul 2007)
New Revision: 64206
Modified:
projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/CallerAspect.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/CallerJoinpointScopedTestCase.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJOCaller.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/TargetPOJO.java
Log:
[JBAOP-427] Tests documented
Modified: projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml 2007-07-23 19:39:26 UTC (rev 64205)
+++ projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml 2007-07-23 20:28:07 UTC (rev 64206)
@@ -1,5 +1,6 @@
<aop>
- <aspect class="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" scope="PER_INSTANCE"/>
+
+ <aspect class="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" scope="PER_INSTANCE"/>
<aspect class="org.jboss.test.aop.beforeafterthrowingscoped.PerJoinpointAspect" scope="PER_JOINPOINT"/>
<aspect class="org.jboss.test.aop.beforeafterthrowingscoped.PerClassJoinpointAspect" scope="PER_CLASS_JOINPOINT"/>
<aspect class="org.jboss.test.aop.beforeafterthrowingscoped.PerClassAspect" scope="PER_CLASS"/>
@@ -57,6 +58,8 @@
<stack-ref name="PER_VM"/>
</bind>
+ <!-- Aspect used to record the caller instance
+ (useful when the caller is a constructor that throws an exception) -->
<aspect class="org.jboss.test.aop.beforeafterthrowingscoped.CallerAspect" scope="PER_VM"/>
<bind pointcut="call(* org.jboss.test.aop.beforeafterthrowingscoped.*TargetPOJO*->*(boolean)) OR call(org.jboss.test.aop.beforeafterthrowingscoped.*TargetPOJO*->new(boolean))"> -->
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/CallerAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/CallerAspect.java 2007-07-23 19:39:26 UTC (rev 64205)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/CallerAspect.java 2007-07-23 20:28:07 UTC (rev 64206)
@@ -24,6 +24,11 @@
import org.jboss.aop.advice.annotation.Caller;
/**
+ * Aspect that records the caller instance.
+ *
+ * Useful when the caller is a constructor that throws an exception. In this type of
+ * scenario, the test method cannot access the instance caller.
+ *
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
*
*/
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/CallerJoinpointScopedTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/CallerJoinpointScopedTestCase.java 2007-07-23 19:39:26 UTC (rev 64205)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/CallerJoinpointScopedTestCase.java 2007-07-23 20:28:07 UTC (rev 64206)
@@ -31,6 +31,7 @@
import org.jboss.test.aop.AOPTestWithSetup;
/**
+ * Scoped aspect tests on call joinpoints scenarios.
*
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
*/
@@ -77,6 +78,14 @@
}
}
+ /**
+ * Performs the specified call from inside all caller contexts (constructor,
+ * method and static method)
+ *
+ * @param callAction the call action to be performed.
+ *
+ * @throws ThrownByTestException if an unexpected exception is thrown by the call
+ */
public void performCall(CallAction callAction) throws ThrownByTestException
{
// reset aspects
@@ -85,18 +94,25 @@
SuperTargetPOJO[] targets = new SuperTargetPOJO[]
{new SuperTargetPOJO(), new TargetPOJO1(), new TargetPOJO2()};
-
+ // for each possible target
for (SuperTargetPOJO target: targets)
{
+ // call from constructor and from method
createAndExecuteMethod(callAction, target);
+ // call from static method
executeStaticMethod(callAction, target);
}
}
/**
- * @param callAction
- * @param target
- * @throws ThrownByTestException
+ * Performs <code>callAction</code> on <code>target</code> from inside
+ * constructors and methods.
+ *
+ * @param callAction the call action to be performed
+ * @param target the target of the call
+ *
+ * @throws ThrownByTestException if an unexpected exception is thrown from the
+ * call
*/
private void createAndExecuteMethod(CallAction callAction, SuperTargetPOJO target) throws ThrownByTestException
{
@@ -156,7 +172,8 @@
String superJoinPointByMethod = "super" + callAction + "bymethod";
String joinPointByMethod1 = callAction + "bymethod1";
String joinPointByMethod2 = callAction + "bymethod2";
-
+ // IMPORTANT: call some times using the same caller, to test PER_INSTANCE and
+ // PER_JOINPOINT correctly
for (int i = 0; i < 3; i++)
{
// super by method
@@ -246,6 +263,14 @@
}
}
+ /**
+ * Performs <code>callAction</code> from inside static methods.
+ *
+ * @param callAction the call action to be performed
+ * @param target target of the action
+ *
+ * @throws ThrownByTestException if an unexpected exception is thrown by the call
+ */
public void executeStaticMethod(CallAction callAction, SuperTargetPOJO target) throws ThrownByTestException
{
String superJoinPoint = "super" + callAction;
@@ -339,6 +364,7 @@
}
/**
+ *
* @param caller1
*/
private void checkAspects(SuperPOJOCaller context, Class<?> contextClass,
@@ -349,7 +375,15 @@
}
/**
- * @param target
+ * Records the scoped aspect instances and performs assertion by comparing
+ * with aspect instances previously recorded.
+ *
+ * @param context the context from where the intercepted call was performed.
+ * Can be <code>null</code> if the call context is static
+ * @param contextClass the class of context (useful with context is a static
+ * method)
+ * @param joinPoint a description that identifies uniquely the intercepted call
+ * joinpoint
*/
private void recordAspects(SuperPOJOCaller context, Class<?> contextClass, String joinPoint)
{
@@ -363,6 +397,12 @@
AspectRegister.addPerVmAspect();
}
+ /**
+ * Checks null and non-null aspect instances.
+ *
+ * @param exceptionThrown indicates whether the joinpoint threw an exception
+ * @param staticContext indicates whether the call context (caller) was static
+ */
private void assertAspects(boolean exceptionThrown, boolean staticContext)
{
Object afterAspect = null;
@@ -469,6 +509,9 @@
assertSame(afterAspect, PerVmAspect.finaly);
}
+ /**
+ * Resets all aspect information regarding a previous joinpoint interception.
+ */
private void resetAll()
{
PerInstanceAspect.reset();
@@ -479,39 +522,68 @@
CallerAspect.reset();
}
+ /**
+ * Records scoped aspect instances for equality assertion.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
static class AspectRegister
{
+ // map of per class aspect instances
private static Map<Class, PerClassAspect> PER_CLASS =
new HashMap<Class, PerClassAspect>();
+ // map of per joinpoitn aspect instances
private static Map<String, PerJoinpointAspect> PER_JOINPOINT =
new HashMap<String, PerJoinpointAspect>();
+ // map of per instance aspect instances
private static Map<SuperPOJOCaller, PerInstanceAspect> PER_INSTANCE =
new HashMap<SuperPOJOCaller, PerInstanceAspect>();
+ // map of per class joinpoint aspect instances
private static Map<String, PerClassJoinpointAspect> PER_CLASS_JOINPOINT =
new HashMap<String, PerClassJoinpointAspect>();
-
+ // the single instance of per vm aspect
private static PerVmAspect PER_VM = null;
+ /*
+ * Adds the PerJoinpointAspect instance used during the last joinpoint
+ * execution.
+ */
public static void addPerJoinpointAspect(String joinpoint, SuperPOJOCaller instance)
{
addAspect(joinpoint + instance, PerJoinpointAspect.before, PER_JOINPOINT);
}
+ /*
+ * Adds the PerInstanceAspect instance used during the last joinpoint
+ * execution.
+ */
public static void addPerInstanceAspect(SuperPOJOCaller instance)
{
addAspect(instance, PerInstanceAspect.before, PER_INSTANCE);
}
+ /*
+ * Adds the PerClassJoinpointAspect instance used during the last joinpoint
+ * execution.
+ */
public static void addPerClassJoinpointAspect(Class clazz, String joinpoint)
{
addAspect(clazz + joinpoint, PerClassJoinpointAspect.before , PER_CLASS_JOINPOINT);
}
+ /*
+ * Adds the PerClassAspect instance used during the last joinpoint
+ * execution.
+ */
public static void addPerClassAspect(Class clazz)
{
addAspect(clazz, PerClassAspect.before, PER_CLASS);
}
+ /*
+ * Adds the PerVMAspect instance used during the last joinpoint
+ * execution.
+ */
public static void addPerVmAspect()
{
if (PER_VM != null)
@@ -521,16 +593,22 @@
PER_VM = PerVmAspect.before;
}
+ /*
+ * Adds <code>aspect</code> to <code>map</code>.
+ */
private static <K, V>void addAspect(K key, V aspect, Map<K, V> map)
{
+ // if this instance is already registered, assert it is the same instance
if (map.containsKey(key))
{
assertSame(map.get(key), aspect);
}
+ // otherwise, add this instance to the map
else
{
map.put(key, aspect);
}
+ // check that this instance is different from all other instances in map
for (Map.Entry<K, V> e: map.entrySet())
{
if (e.getKey() != key && !e.getKey().equals(key))
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJOCaller.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJOCaller.java 2007-07-23 19:39:26 UTC (rev 64205)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJOCaller.java 2007-07-23 20:28:07 UTC (rev 64206)
@@ -21,6 +21,11 @@
*/
package org.jboss.test.aop.beforeafterthrowingscoped;
+/**
+ * Represents a call to be performed by the caller.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
enum CallAction
{
CALL_CONSTRUCTOR("constructor"),
@@ -99,6 +104,11 @@
}
}
+/**
+ * Caller1 (for call joinpoints)
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
class POJOCaller1 extends SuperPOJOCaller
{
// constructor that is not intercepted
@@ -108,6 +118,7 @@
public POJOCaller1(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
{
+ // perform caller1 own calls (ignore super constructor calls)
switch(callAction)
{
case CALL_CONSTRUCTOR:
@@ -155,6 +166,11 @@
}
}
+/**
+ * Caller2 (for call joinpoints)
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
class POJOCaller2 extends SuperPOJOCaller
{
// constructor that is not intercepted
@@ -165,19 +181,8 @@
public POJOCaller2(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
{
+ // call super target constructor this time
super(target, callAction, throwException);
- /*switch(callAction)
- {
- case CALL_CONSTRUCTOR:
- new TargetPOJO2(throwException);
- break;
- case CALL_METHOD:
- target.method(throwException);
- break;
- case CALL_STATIC_METHOD:
- TargetPOJO2.staticMethod(throwException);
- break;
- }*/
}
public void method2(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/TargetPOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/TargetPOJO.java 2007-07-23 19:39:26 UTC (rev 64205)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/TargetPOJO.java 2007-07-23 20:28:07 UTC (rev 64206)
@@ -30,7 +30,7 @@
{
// constructor whose call is not intercepted
public SuperTargetPOJO() {}
-
+
public SuperTargetPOJO(boolean throwException) throws ThrownByTestException
{
if (throwException)
More information about the jboss-cvs-commits
mailing list