[jboss-cvs] JBossAS SVN: r64179 - 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
Sat Jul 21 21:20:58 EDT 2007
Author: flavia.rainone at jboss.com
Date: 2007-07-21 21:20:57 -0400 (Sat, 21 Jul 2007)
New Revision: 64179
Added:
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
Modified:
projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml
Log:
[JBAOP-427] First version of call tests for batf.
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-21 20:32:14 UTC (rev 64178)
+++ projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml 2007-07-22 01:20:57 UTC (rev 64179)
@@ -5,36 +5,67 @@
<aspect class="org.jboss.test.aop.beforeafterthrowingscoped.PerClassAspect" scope="PER_CLASS"/>
<aspect class="org.jboss.test.aop.beforeafterthrowingscoped.PerVmAspect" scope="PER_VM"/>
- <bind pointcut="all(org.jboss.test.aop.beforeafterthrowingscoped.POJOWithPerInstanceAspects)">
- <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" name="before"/>
+ <stack name="PER_INSTANCE">
+ <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" name="before"/>
<after aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" name="after"/>
<throwing aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" name="throwing"/>
<finally aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" name="finaly"/>
+ </stack>
+
+ <bind pointcut="all(org.jboss.test.aop.beforeafterthrowingscoped.POJOWithPerInstanceAspects)">
+ <stack-ref name="PER_INSTANCE"/>
</bind>
- <bind pointcut="all(org.jboss.test.aop.beforeafterthrowingscoped.POJOWithPerJoinpointAspects)">
- <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerJoinpointAspect" name="before"/>
+ <stack name="PER_JOINPOINT">
+ <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerJoinpointAspect" name="before"/>
<after aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerJoinpointAspect" name="after"/>
<throwing aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerJoinpointAspect" name="throwing"/>
<finally aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerJoinpointAspect" name="finaly"/>
+ </stack>
+
+ <bind pointcut="all(org.jboss.test.aop.beforeafterthrowingscoped.POJOWithPerJoinpointAspects)">
+ <stack-ref name="PER_JOINPOINT"/>
</bind>
- <bind pointcut="all(org.jboss.test.aop.beforeafterthrowingscoped.POJOWithPerClassJoinpointAspects)">
- <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassJoinpointAspect" name="before"/>
+ <stack name="PER_CLASS_JOINPOINT">
+ <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassJoinpointAspect" name="before"/>
<after aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassJoinpointAspect" name="after"/>
<throwing aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassJoinpointAspect" name="throwing"/>
<finally aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassJoinpointAspect" name="finaly"/>
+ </stack>
+
+ <bind pointcut="all(org.jboss.test.aop.beforeafterthrowingscoped.POJOWithPerClassJoinpointAspects)">
+ <stack-ref name="PER_CLASS_JOINPOINT"/>
</bind>
- <bind pointcut="all(org.jboss.test.aop.beforeafterthrowingscoped.POJOWithPerClassAndPerVmAspects)">
- <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerVmAspect" name="before"/>
+ <stack name="PER_CLASS">
+ <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassAspect" name="before"/>
+ <after aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassAspect" name="after"/>
+ <throwing aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassAspect" name="throwing"/>
+ <finally aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassAspect" name="finaly"/>
+ </stack>
+
+ <stack name="PER_VM">
+ <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerVmAspect" name="before"/>
<after aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerVmAspect" name="after"/>
<throwing aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerVmAspect" name="throwing"/>
<finally aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerVmAspect" name="finaly"/>
- <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassAspect" name="before"/>
- <after aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassAspect" name="after"/>
- <throwing aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassAspect" name="throwing"/>
- <finally aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerClassAspect" name="finaly"/>
+ </stack>
+
+ <bind pointcut="all(org.jboss.test.aop.beforeafterthrowingscoped.POJOWithPerClassAndPerVmAspects)">
+ <stack-ref name="PER_CLASS"/>
+ <stack-ref name="PER_VM"/>
</bind>
-
+
+ <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))"> -->
+ <stack-ref name="PER_INSTANCE"/>
+ <stack-ref name="PER_JOINPOINT"/>
+ <stack-ref name="PER_CLASS_JOINPOINT"/>
+ <stack-ref name="PER_CLASS"/>
+ <stack-ref name="PER_VM"/>
+ <before aspect="org.jboss.test.aop.beforeafterthrowingscoped.CallerAspect" name="advice"/>
+ </bind>
+
</aop>
\ No newline at end of file
Added: 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 (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/CallerAspect.java 2007-07-22 01:20:57 UTC (rev 64179)
@@ -0,0 +1,43 @@
+/*
+ * 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.beforeafterthrowingscoped;
+
+import org.jboss.aop.advice.annotation.Caller;
+
+/**
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ */
+public class CallerAspect
+{
+ public static SuperPOJOCaller CALLER;
+
+ public static void reset()
+ {
+ CALLER = null;
+ }
+
+ public void advice(@Caller SuperPOJOCaller caller)
+ {
+ CALLER = caller;
+ }
+}
\ No newline at end of file
Added: 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 (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/CallerJoinpointScopedTestCase.java 2007-07-22 01:20:57 UTC (rev 64179)
@@ -0,0 +1,510 @@
+/*
+ * 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.beforeafterthrowingscoped;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.aop.AOPTestWithSetup;
+
+/**
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class CallerJoinpointScopedTestCase extends AOPTestWithSetup
+{
+ public CallerJoinpointScopedTestCase(String arg)
+ {
+ super(arg);
+ }
+
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("CallerJoinpointScopedTestCase");
+ suite.addTestSuite(CallerJoinpointScopedTestCase.class);
+ return suite;
+ }
+
+ public void testConstructorCall() throws ThrownByTestException
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ performCall(CallAction.CALL_CONSTRUCTOR);
+ }
+ }
+
+ // TODO JBAOP-444
+// public void testMethodCall() throws ThrownByTestException
+// {
+// for (int i = 0; i < 10; i++)
+// {
+// performCall(CallAction.CALL_METHOD);
+// }
+// }
+
+ public void testStaticMethodCall() throws ThrownByTestException
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ performCall(CallAction.CALL_STATIC_METHOD);
+ }
+ }
+
+ public void performCall(CallAction callAction) throws ThrownByTestException
+ {
+ // reset aspects
+ resetAll();
+ // create targets
+ SuperTargetPOJO[] targets = new SuperTargetPOJO[]
+ {new SuperTargetPOJO(), new TargetPOJO1(), new TargetPOJO2()};
+
+
+ for (SuperTargetPOJO target: targets)
+ {
+ createAndExecuteMethod(callAction, target);
+ executeStaticMethod(callAction, target);
+ }
+ }
+
+ /**
+ * @param callAction
+ * @param target
+ * @throws ThrownByTestException
+ */
+ private void createAndExecuteMethod(CallAction callAction, SuperTargetPOJO target) throws ThrownByTestException
+ {
+ String superJoinPointByCon = "super" + callAction + "bycon";
+ String joinPointByCon1 = callAction + "bycon1";
+ String joinPointByCon2 = callAction + "bycon2";
+
+ // by con
+ SuperPOJOCaller superCaller = new SuperPOJOCaller(target, callAction, false);
+ checkAspects(superCaller, SuperPOJOCaller.class, superJoinPointByCon, false);
+
+ // super by con with exception
+ boolean exceptionThrown = false;
+ try
+ {
+ new SuperPOJOCaller(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(CallerAspect.CALLER, SuperPOJOCaller.class, superJoinPointByCon, exceptionThrown);
+
+ // by con 1
+ POJOCaller1 caller1 = new POJOCaller1(target, callAction, false);
+ checkAspects(caller1, POJOCaller1.class, joinPointByCon1, false);
+
+ // by con 1 with exception
+ try
+ {
+ new POJOCaller1(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(CallerAspect.CALLER, POJOCaller1.class, joinPointByCon1, exceptionThrown);
+
+ // by con2
+ POJOCaller2 caller2 = new POJOCaller2(target, callAction, false);
+ checkAspects(caller2, POJOCaller2.class, joinPointByCon2, false);
+
+ // by con 2 with exception
+ try
+ {
+ new POJOCaller2(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(CallerAspect.CALLER, POJOCaller2.class, joinPointByCon2, exceptionThrown);
+
+ String superJoinPointByMethod = "super" + callAction + "bymethod";
+ String joinPointByMethod1 = callAction + "bymethod1";
+ String joinPointByMethod2 = callAction + "bymethod2";
+
+ for (int i = 0; i < 3; i++)
+ {
+ // super by method
+ superCaller.method(target, callAction, false);
+ checkAspects(superCaller, SuperPOJOCaller.class, superJoinPointByMethod, false);
+
+ // super by method with exception
+ try
+ {
+ superCaller.method(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(superCaller, SuperPOJOCaller.class, superJoinPointByMethod, exceptionThrown);
+ exceptionThrown = false;
+
+ // super by method - 1
+ caller1.method(target, callAction, false);
+ checkAspects(caller1, POJOCaller1.class, superJoinPointByMethod, false);
+
+ // super by method - 1 - with exception
+ try
+ {
+ caller1.method(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(caller1, POJOCaller1.class, superJoinPointByMethod, exceptionThrown);
+ exceptionThrown = false;
+
+ // super by method - 2
+ caller2.method(target, callAction, false);
+ checkAspects(caller2, POJOCaller2.class, superJoinPointByMethod, false);
+
+ // super by method - 2 - with exception
+ try
+ {
+ caller2.method(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(caller2, POJOCaller2.class, superJoinPointByMethod, exceptionThrown);
+ exceptionThrown = false;
+
+ // by method1
+ caller1.method1(target, callAction, false);
+ checkAspects(caller1, POJOCaller1.class, joinPointByMethod1, false);
+
+ // by method1 with exception
+ try
+ {
+ caller1.method1(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(caller1, POJOCaller1.class, joinPointByMethod1, exceptionThrown);
+ exceptionThrown = false;
+
+ // by method2
+ caller2.method2(target, callAction, false);
+ checkAspects(caller2, POJOCaller2.class, joinPointByMethod2, false);
+
+ // by method2 with exception
+ try
+ {
+ caller2.method2(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(caller2, POJOCaller2.class, joinPointByMethod2, exceptionThrown);
+ exceptionThrown = false;
+ }
+ }
+
+ public void executeStaticMethod(CallAction callAction, SuperTargetPOJO target) throws ThrownByTestException
+ {
+ String superJoinPoint = "super" + callAction;
+ String joinPoint1 = callAction + "1";
+ String joinPoint2 = callAction + "2";
+
+ // by static method
+ SuperPOJOCaller.staticMethod(target, callAction, false);
+ checkAspects(null, SuperPOJOCaller.class, superJoinPoint, false);
+
+ // super by static method with exception
+ boolean exceptionThrown = false;
+ try
+ {
+ SuperPOJOCaller.staticMethod(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(null, SuperPOJOCaller.class, superJoinPoint, exceptionThrown);
+ exceptionThrown = false;
+
+ // by static method1
+ POJOCaller1.staticMethod1(target, callAction, false);
+ checkAspects(null, POJOCaller1.class, joinPoint1, false);
+
+ // by static method1 with exception
+ try
+ {
+ POJOCaller1.staticMethod1(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(null, POJOCaller1.class, joinPoint1, exceptionThrown);
+ exceptionThrown = false;
+
+ // by static method2
+ POJOCaller2.staticMethod2(target, callAction, false);
+ checkAspects(null, POJOCaller2.class, joinPoint2, false);
+
+ // by static method2
+ try
+ {
+ POJOCaller2.staticMethod2(target, callAction, true);
+ }
+ catch(ThrownByTestException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ checkAspects(null, POJOCaller2.class, joinPoint2, exceptionThrown);
+ }
+
+ /**
+ * @param caller1
+ */
+ private void checkAspects(SuperPOJOCaller context, Class<?> contextClass,
+ String joinPoint, boolean exceptionThrown){
+ assertAspects(exceptionThrown, context == null);
+ recordAspects(context, contextClass, joinPoint);
+ resetAll();
+ }
+
+ /**
+ * @param target
+ */
+ private void recordAspects(SuperPOJOCaller context, Class<?> contextClass, String joinPoint)
+ {
+ if (context != null)
+ {
+ AspectRegister.addPerInstanceAspect(context);
+ }
+ AspectRegister.addPerJoinpointAspect(joinPoint, context);
+ AspectRegister.addPerClassJoinpointAspect(contextClass, joinPoint);
+ AspectRegister.addPerClassAspect(contextClass);
+ AspectRegister.addPerVmAspect();
+ }
+
+ private void assertAspects(boolean exceptionThrown, boolean staticContext)
+ {
+ Object afterAspect = null;
+
+ // PER INSTANCE
+ if (staticContext)
+ {
+ assertNull(PerInstanceAspect.before);
+ assertNull(PerInstanceAspect.after);
+ assertNull(PerInstanceAspect.throwing);
+ assertNull(PerInstanceAspect.finaly);
+ }
+ else
+ {
+ assertNotNull(PerInstanceAspect.before);
+ if (exceptionThrown)
+ {
+ assertNull(PerInstanceAspect.after);
+ assertNotNull(PerInstanceAspect.throwing);
+ afterAspect = PerInstanceAspect.throwing;
+ }
+ else
+ {
+ assertNotNull(PerInstanceAspect.after);
+ assertNull(PerInstanceAspect.throwing);
+ afterAspect = PerInstanceAspect.after;
+ }
+ assertNotNull(PerInstanceAspect.finaly);
+ assertSame(PerInstanceAspect.before, afterAspect);
+ assertSame(afterAspect, PerInstanceAspect.finaly);
+ }
+
+ // PER JOINPOINT
+ assertNotNull(PerJoinpointAspect.before);
+ if (exceptionThrown)
+ {
+ assertNull(PerJoinpointAspect.after);
+ assertNotNull(PerJoinpointAspect.throwing);
+ afterAspect = PerJoinpointAspect.throwing;
+ }
+ else
+ {
+ assertNotNull(PerJoinpointAspect.after);
+ assertNull(PerJoinpointAspect.throwing);
+ afterAspect = PerJoinpointAspect.after;
+ }
+ assertNotNull(PerJoinpointAspect.finaly);
+ assertSame(PerJoinpointAspect.before, afterAspect);
+ assertSame(afterAspect, PerJoinpointAspect.finaly);
+
+ // PER CLASS JOINPOINT
+ assertNotNull(PerClassJoinpointAspect.before);
+ if (exceptionThrown)
+ {
+ assertNull(PerClassJoinpointAspect.after);
+ assertNotNull(PerClassJoinpointAspect.throwing);
+ afterAspect = PerClassJoinpointAspect.throwing;
+ }
+ else
+ {
+ assertNotNull(PerClassJoinpointAspect.after);
+ assertNull(PerClassJoinpointAspect.throwing);
+ afterAspect = PerClassJoinpointAspect.after;
+ }
+ assertNotNull(PerClassJoinpointAspect.finaly);
+ assertSame(PerClassJoinpointAspect.before, afterAspect);
+ assertSame(afterAspect, PerClassJoinpointAspect.finaly);
+
+ // PER CLASS
+ assertNotNull(PerClassAspect.before);
+ if (exceptionThrown)
+ {
+ assertNull(PerClassAspect.after);
+ assertNotNull(PerClassAspect.throwing);
+ afterAspect = PerClassAspect.throwing;
+ }
+ else
+ {
+ assertNotNull(PerClassAspect.after);
+ assertNull(PerClassAspect.throwing);
+ afterAspect = PerClassAspect.after;
+ }
+ assertNotNull(PerClassAspect.finaly);
+ assertSame(PerClassAspect.before, afterAspect);
+ assertSame(afterAspect, PerClassAspect.finaly);
+
+ // PER VM
+ assertNotNull(PerVmAspect.before);
+ if (exceptionThrown)
+ {
+ assertNull(PerVmAspect.after);
+ assertNotNull(PerVmAspect.throwing);
+ afterAspect = PerVmAspect.throwing;
+ }
+ else
+ {
+ assertNotNull(PerVmAspect.after);
+ assertNull(PerVmAspect.throwing);
+ afterAspect = PerVmAspect.after;
+
+ }
+ assertNotNull(PerVmAspect.finaly);
+ assertSame(PerVmAspect.before, afterAspect);
+ assertSame(afterAspect, PerVmAspect.finaly);
+ }
+
+ private void resetAll()
+ {
+ PerInstanceAspect.reset();
+ PerJoinpointAspect.reset();
+ PerClassJoinpointAspect.reset();
+ PerClassAspect.reset();
+ PerVmAspect.reset();
+ CallerAspect.reset();
+ }
+
+ static class AspectRegister
+ {
+ private static Map<Class, PerClassAspect> PER_CLASS =
+ new HashMap<Class, PerClassAspect>();
+ private static Map<String, PerJoinpointAspect> PER_JOINPOINT =
+ new HashMap<String, PerJoinpointAspect>();
+ private static Map<SuperPOJOCaller, PerInstanceAspect> PER_INSTANCE =
+ new HashMap<SuperPOJOCaller, PerInstanceAspect>();
+ private static Map<String, PerClassJoinpointAspect> PER_CLASS_JOINPOINT =
+ new HashMap<String, PerClassJoinpointAspect>();
+
+ private static PerVmAspect PER_VM = null;
+
+ public static void addPerJoinpointAspect(String joinpoint, SuperPOJOCaller instance)
+ {
+ addAspect(joinpoint + instance, PerJoinpointAspect.before, PER_JOINPOINT);
+ }
+
+ public static void addPerInstanceAspect(SuperPOJOCaller instance)
+ {
+ addAspect(instance, PerInstanceAspect.before, PER_INSTANCE);
+ }
+
+ public static void addPerClassJoinpointAspect(Class clazz, String joinpoint)
+ {
+ addAspect(clazz + joinpoint, PerClassJoinpointAspect.before , PER_CLASS_JOINPOINT);
+ }
+
+ public static void addPerClassAspect(Class clazz)
+ {
+ addAspect(clazz, PerClassAspect.before, PER_CLASS);
+ }
+
+ public static void addPerVmAspect()
+ {
+ if (PER_VM != null)
+ {
+ assertSame(PER_VM, PerVmAspect.before);
+ }
+ PER_VM = PerVmAspect.before;
+ }
+
+ private static <K, V>void addAspect(K key, V aspect, Map<K, V> map)
+ {
+ if (map.containsKey(key))
+ {
+ assertSame(map.get(key), aspect);
+ }
+ else
+ {
+ map.put(key, aspect);
+ }
+ for (Map.Entry<K, V> e: map.entrySet())
+ {
+ if (e.getKey() != key && !e.getKey().equals(key))
+ {
+ assertNotSame("Unexpected same value\nkey1:" + e.getKey() + " - key2:" + key, e.getValue(), aspect);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Added: 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 (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJOCaller.java 2007-07-22 01:20:57 UTC (rev 64179)
@@ -0,0 +1,214 @@
+/*
+ * 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.beforeafterthrowingscoped;
+
+enum CallAction
+{
+ CALL_CONSTRUCTOR("constructor"),
+ CALL_METHOD("method"),
+ CALL_STATIC_METHOD("staticmethod");
+
+ private String name;
+
+ CallAction(String name)
+ {
+ this.name = name;
+ }
+
+ public String toString()
+ {
+ return this.name;
+ }
+};
+
+/**
+ * Super class of caller (for call joinpoints)
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class SuperPOJOCaller
+{
+ // constructor that is not intercepted
+ public SuperPOJOCaller() {}
+
+ public SuperPOJOCaller(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
+ {
+ switch(callAction)
+ {
+ case CALL_CONSTRUCTOR:
+ new SuperTargetPOJO(throwException);
+ break;
+ case CALL_METHOD:
+ target.method(throwException);
+ break;
+ case CALL_STATIC_METHOD:
+ SuperTargetPOJO.staticMethod(throwException);
+ break;
+ }
+ }
+
+ public void method(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
+ {
+ switch(callAction)
+ {
+ case CALL_CONSTRUCTOR:
+ new SuperTargetPOJO(throwException);
+ break;
+ case CALL_METHOD:
+ target.method(throwException);
+ break;
+ case CALL_STATIC_METHOD:
+ SuperTargetPOJO.staticMethod(throwException);
+ break;
+ }
+ }
+
+ public static void staticMethod(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
+ {
+ switch(callAction)
+ {
+ case CALL_CONSTRUCTOR:
+ new SuperTargetPOJO(throwException);
+ break;
+ case CALL_METHOD:
+ target.method(throwException);
+ break;
+ case CALL_STATIC_METHOD:
+ SuperTargetPOJO.staticMethod(throwException);
+ break;
+ }
+ }
+}
+
+class POJOCaller1 extends SuperPOJOCaller
+{
+ // constructor that is not intercepted
+ public POJOCaller1() {
+ super();
+ }
+
+ public POJOCaller1(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
+ {
+ switch(callAction)
+ {
+ case CALL_CONSTRUCTOR:
+ new TargetPOJO1(throwException);
+ break;
+ case CALL_METHOD:
+ target.method(throwException);
+ break;
+ case CALL_STATIC_METHOD:
+ TargetPOJO1.staticMethod(throwException);
+ break;
+ }
+ }
+
+ public static void staticMethod1(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
+ {
+ switch(callAction)
+ {
+ case CALL_CONSTRUCTOR:
+ new TargetPOJO1(throwException);
+ break;
+ case CALL_METHOD:
+ target.method(throwException);
+ break;
+ case CALL_STATIC_METHOD:
+ TargetPOJO1.staticMethod(throwException);
+ break;
+ }
+ }
+
+ public void method1(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
+ {
+ switch(callAction)
+ {
+ case CALL_CONSTRUCTOR:
+ new TargetPOJO1(throwException);
+ break;
+ case CALL_METHOD:
+ target.method(throwException);
+ break;
+ case CALL_STATIC_METHOD:
+ TargetPOJO1.staticMethod(throwException);
+ break;
+ }
+ }
+}
+
+class POJOCaller2 extends SuperPOJOCaller
+{
+ // constructor that is not intercepted
+ public POJOCaller2()
+ {
+ super();
+ }
+
+ public POJOCaller2(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
+ {
+ 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
+ {
+ 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 static void staticMethod2(SuperTargetPOJO target, CallAction callAction, boolean throwException) throws ThrownByTestException
+ {
+ switch(callAction)
+ {
+ case CALL_CONSTRUCTOR:
+ new TargetPOJO2(throwException);
+ break;
+ case CALL_METHOD:
+ target.method(throwException);
+ break;
+ case CALL_STATIC_METHOD:
+ TargetPOJO2.staticMethod(throwException);
+ break;
+ }
+ }
+}
\ No newline at end of file
Added: 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 (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/TargetPOJO.java 2007-07-22 01:20:57 UTC (rev 64179)
@@ -0,0 +1,111 @@
+/*
+ * 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.beforeafterthrowingscoped;
+
+/**
+ * Target super class of call joinpoints.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class SuperTargetPOJO
+{
+ // constructor whose call is not intercepted
+ public SuperTargetPOJO() {}
+
+ public SuperTargetPOJO(boolean throwException) throws ThrownByTestException
+ {
+ if (throwException)
+ {
+ throw new ThrownByTestException();
+ }
+ }
+
+ public static void staticMethod(boolean throwException) throws ThrownByTestException
+ {
+ if (throwException)
+ {
+ throw new ThrownByTestException();
+ }
+ }
+
+ public void method(boolean throwException) throws ThrownByTestException
+ {
+ if (throwException)
+ {
+ throw new ThrownByTestException();
+ }
+ }
+}
+
+/**
+ * Target 1 (used on call joinpoints).
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class TargetPOJO1 extends SuperTargetPOJO
+{
+ // constructor whose call is not intercepted
+ public TargetPOJO1() {}
+
+ public TargetPOJO1(boolean throwException) throws ThrownByTestException
+ {
+ if (throwException)
+ {
+ throw new ThrownByTestException();
+ }
+ }
+
+ public static void staticMethod1(boolean throwException) throws ThrownByTestException
+ {
+ if (throwException)
+ {
+ throw new ThrownByTestException();
+ }
+ }
+}
+
+/**
+ * Target 2 (used on call joinpoints).
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class TargetPOJO2 extends SuperTargetPOJO
+{
+ // constructor whose call is not intercepted
+ public TargetPOJO2() {}
+
+ public TargetPOJO2(boolean throwException) throws ThrownByTestException
+ {
+ if (throwException)
+ {
+ throw new ThrownByTestException();
+ }
+ }
+
+ public static void staticMethod2(boolean throwException) throws ThrownByTestException
+ {
+ if (throwException)
+ {
+ throw new ThrownByTestException();
+ }
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list