[jboss-cvs] JBossAS SVN: r63441 - in projects/aop/trunk/aop/src: test/org/jboss/test/aop/beforeafterArgs and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Jun 9 23:53:18 EDT 2007
Author: flavia.rainone at jboss.com
Date: 2007-06-09 23:53:18 -0400 (Sat, 09 Jun 2007)
New Revision: 63441
Modified:
projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointAspect.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointPOJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointTestCase.java
Log:
Complete test.
Modified: projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml 2007-06-09 20:31:33 UTC (rev 63440)
+++ projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml 2007-06-10 03:53:18 UTC (rev 63441)
@@ -391,7 +391,49 @@
<bind pointcut="execution(* org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->method6(..))">
<throwing name="throwing5" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
+
+ <bind pointcut="call(org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->new(boolean)) AND withincode(org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->new(..))">
+ <before name="before6" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <after name="after4" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <throwing name="throwing6" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <finally name="finally5" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="call(org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->new(boolean)) AND withincode(public void org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->*(..))">
+ <before name="before3" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <after name="after5" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <throwing name="throwing7" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <finally name="finally6" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ </bind>
+ <bind pointcut="call(* org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->*Method(boolean)) AND withincode(org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->new(..))">
+ <before name="before7" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <after name="after6" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <throwing name="throwing8" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <finally name="finally3" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="call(* org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->*Method(boolean)) AND withincode(public void org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->*(..))">
+ <before name="before8" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <after name="after6" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <throwing name="throwing8" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <finally name="finally7" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="execution(org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->new(short,boolean))">
+ <before name="before2" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <after name="after7" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <throwing name="throwing2" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <finally name="finally7" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="construction(org.jboss.test.aop.beforeafterArgs.JoinPointPOJO->new(float,boolean))">
+ <before name="before3" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <after name="after5" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <throwing name="throwing1" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ <finally name="finally8" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ </bind>
+
<!-- Return type and @Return test -->
<aspect class="org.jboss.test.aop.beforeafterArgs.ReturnAspect" scope="PER_VM"/>
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointAspect.java 2007-06-09 20:31:33 UTC (rev 63440)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointAspect.java 2007-06-10 03:53:18 UTC (rev 63441)
@@ -25,9 +25,16 @@
import org.jboss.aop.advice.annotation.JoinPoint;
import org.jboss.aop.advice.annotation.Thrown;
+import org.jboss.aop.joinpoint.Construction;
+import org.jboss.aop.joinpoint.ConstructorCall;
+import org.jboss.aop.joinpoint.ConstructorCallByConstructor;
+import org.jboss.aop.joinpoint.ConstructorCallByMethod;
import org.jboss.aop.joinpoint.ConstructorExecution;
import org.jboss.aop.joinpoint.FieldAccess;
import org.jboss.aop.joinpoint.JoinPointBean;
+import org.jboss.aop.joinpoint.MethodCall;
+import org.jboss.aop.joinpoint.MethodCallByConstructor;
+import org.jboss.aop.joinpoint.MethodCallByMethod;
import org.jboss.aop.joinpoint.MethodExecution;
/**
@@ -63,33 +70,51 @@
beforeAdvice = "before1";
}
- public void before2(@JoinPoint Object joinPointInfo)
+ public void before2(@JoinPoint Object joinPoint)
{
beforeAdvice = "before2";
- beforeJoinPoint = (JoinPointBean) joinPointInfo;
+ beforeJoinPoint = (JoinPointBean) joinPoint;
}
- public void before3(@JoinPoint JoinPointBean joinPointInfo)
+ public void before3(@JoinPoint JoinPointBean joinPoint)
{
beforeAdvice = "before3";
- beforeJoinPoint = joinPointInfo;
+ beforeJoinPoint = joinPoint;
}
- public void before4(@JoinPoint MethodExecution joinPointInfo)
+ public void before4(@JoinPoint MethodExecution joinPoint)
{
beforeAdvice = "before4";
- beforeJoinPoint = (JoinPointBean) joinPointInfo;
+ beforeJoinPoint = (JoinPointBean) joinPoint;
}
- public void before5(@JoinPoint MethodExecution joinPointInfo)
+ public void before5(@JoinPoint MethodExecution joinPoint)
{
Assert.fail("This advice should never be executed");
}
- public void after1(@JoinPoint FieldAccess joinPointInfo)
+ public void before6(@JoinPoint ConstructorCallByConstructor joinPoint)
{
+ beforeAdvice = "before6";
+ beforeJoinPoint = joinPoint;
+ }
+
+ public void before7(@JoinPoint MethodCallByConstructor joinPoint)
+ {
+ beforeAdvice="before7";
+ beforeJoinPoint = joinPoint;
+ }
+
+ public void before8(@JoinPoint MethodCallByMethod joinPoint)
+ {
+ beforeAdvice="before8";
+ beforeJoinPoint = joinPoint;
+ }
+
+ public void after1(@JoinPoint FieldAccess joinPoint)
+ {
afterAdvice = "after1";
- afterJoinPoint = joinPointInfo;
+ afterJoinPoint = joinPoint;
}
public void after2(@JoinPoint ConstructorExecution constructorInfo)
@@ -102,35 +127,48 @@
afterAdvice = "after3";
}
- public void after4(@JoinPoint Object joinPointInfo)
+ public void after4(@JoinPoint Object joinPoint)
{
afterAdvice = "after4";
- afterJoinPoint = (JoinPointBean) joinPointInfo;
+ afterJoinPoint = (JoinPointBean) joinPoint;
}
- public void after5(@JoinPoint JoinPointBean joinPointInfo)
+ public void after5(@JoinPoint JoinPointBean joinPoint)
{
afterAdvice = "after5";
- afterJoinPoint = joinPointInfo;
+ afterJoinPoint = joinPoint;
}
- public void throwing1(@Thrown Throwable throwable, @JoinPoint Object joinPointInfo)
+ public void after6(@JoinPoint MethodCall joinPoint)
{
+ afterAdvice = "after6";
+ afterJoinPoint = joinPoint;
+ }
+
+ public void after7(@JoinPoint ConstructorExecution joinPoint)
+ {
+ afterAdvice = "after7";
+ afterJoinPoint = joinPoint;
+ }
+
+ public void throwing1(@Thrown Throwable throwable, @JoinPoint Object joinPoint)
+ {
throwingAdvice = "throwing1";
- throwingJoinPoint = (JoinPointBean) joinPointInfo;
+ throwingJoinPoint = (JoinPointBean) joinPoint;
}
- public void throwing2(@JoinPoint ConstructorExecution joinPointInfo,
+ public void throwing2(@JoinPoint ConstructorExecution joinPoint,
@Thrown Throwable throwable)
{
- Assert.fail("This advice should never be executed");
+ throwingAdvice = "throwing2";
+ throwingJoinPoint = joinPoint;
}
public void throwing3(@Thrown Throwable throwable,
- @JoinPoint JoinPointBean joinPointInfo)
+ @JoinPoint JoinPointBean joinPoint)
{
throwingAdvice = "throwing3";
- throwingJoinPoint = joinPointInfo;
+ throwingJoinPoint = joinPoint;
}
public void throwing4(@Thrown Throwable throwable)
@@ -138,17 +176,34 @@
throwingAdvice = "throwing4";
}
- public void throwing5(@JoinPoint MethodExecution joinPointInfo, @Thrown Throwable throwable)
+ public void throwing5(@JoinPoint MethodExecution joinPoint, @Thrown Throwable throwable)
{
throwingAdvice = "throwing5";
- throwingJoinPoint = joinPointInfo;
+ throwingJoinPoint = joinPoint;
}
+ public void throwing6(@JoinPoint ConstructorCallByConstructor joinPoint, @Thrown Throwable throwable)
+ {
+ throwingAdvice = "throwing6";
+ throwingJoinPoint = joinPoint;
+ }
+
+ public void throwing7(@JoinPoint ConstructorCallByMethod joinPoint, @Thrown Throwable throwable)
+ {
+ throwingAdvice = "throwing7";
+ throwingJoinPoint = joinPoint;
+ }
+
+ public void throwing8(@JoinPoint MethodCall joinPoint, @Thrown Throwable throwable)
+ {
+ throwingAdvice = "throwing8";
+ throwingJoinPoint = joinPoint;
+ }
- public void finally1(@JoinPoint FieldAccess joinPointInfo)
+ public void finally1(@JoinPoint FieldAccess joinPoint)
{
finallyAdvice = "finally1";
- finallyJoinPoint = joinPointInfo;
+ finallyJoinPoint = joinPoint;
}
public void finally2()
@@ -156,14 +211,38 @@
finallyAdvice = "finally2";
}
- public void finally3(@JoinPoint Object joinPointInfo)
+ public void finally3(@JoinPoint Object joinPoint)
{
finallyAdvice = "finally3";
- finallyJoinPoint = (JoinPointBean) joinPointInfo;
+ finallyJoinPoint = (JoinPointBean) joinPoint;
}
- public void finally4(@JoinPoint ConstructorExecution joinPointInfo)
+ public void finally4(@JoinPoint ConstructorExecution joinPoint)
{
Assert.fail("This advice should never be executed");
}
+
+ public void finally5(@JoinPoint ConstructorCall joinPoint)
+ {
+ finallyAdvice = "finally5";
+ finallyJoinPoint = joinPoint;
+ }
+
+ public void finally6(@JoinPoint ConstructorCallByMethod joinPoint)
+ {
+ finallyAdvice = "finally6";
+ finallyJoinPoint = joinPoint;
+ }
+
+ public void finally7(@JoinPoint JoinPointBean joinPoint)
+ {
+ finallyAdvice = "finally7";
+ finallyJoinPoint = joinPoint;
+ }
+
+ public void finally8(@JoinPoint Construction joinPoint)
+ {
+ finallyAdvice = "finally8";
+ finallyJoinPoint = joinPoint;
+ }
}
\ No newline at end of file
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointPOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointPOJO.java 2007-06-09 20:31:33 UTC (rev 63440)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointPOJO.java 2007-06-10 03:53:18 UTC (rev 63441)
@@ -31,6 +31,54 @@
public int number;
public String text;
+ // constructor without advices
+ public JoinPointPOJO() {}
+
+ // constructor execution
+ public JoinPointPOJO(short arg0, boolean shouldThrow) throws POJOException
+ {
+ if (shouldThrow)
+ {
+ throw new POJOException();
+ }
+ }
+
+ // construction
+ public JoinPointPOJO(float arg0, boolean shouldThrow) throws POJOException
+ {
+ if (shouldThrow)
+ {
+ throw new POJOException();
+ }
+ }
+
+ // called constructor
+ public JoinPointPOJO(boolean shouldThrow) throws POJOException
+ {
+ if (shouldThrow)
+ {
+ throw new POJOException();
+ }
+ }
+
+ // constructor call constructor
+ public JoinPointPOJO(int arg0, boolean shouldThrow) throws POJOException
+ {
+ new JoinPointPOJO(shouldThrow);
+ }
+
+ // constructor call method
+ public JoinPointPOJO(boolean arg0, boolean shouldThrow) throws POJOException
+ {
+ this.calledMethod(shouldThrow);
+ }
+
+ // constructor call static method
+ public JoinPointPOJO(char arg0, boolean shouldThrow) throws POJOException
+ {
+ calledStaticMethod(shouldThrow);
+ }
+
public void method1()
{
@@ -64,4 +112,56 @@
{
throw new POJOException();
}
+
+ // method call constructor
+ public void callConstructor(boolean shouldThrow) throws POJOException
+ {
+ new JoinPointPOJO(shouldThrow);
+ }
+
+ // static method call constructor
+ public static void staticCallConstructor(boolean shouldThrow) throws POJOException
+ {
+ new JoinPointPOJO(shouldThrow);
+ }
+
+ // method call method
+ public void callMethod(boolean shouldThrow) throws POJOException
+ {
+ calledMethod(shouldThrow);
+ }
+
+ // static method call method
+ public static void staticCallMethod(JoinPointPOJO pojo, boolean shouldThrow) throws POJOException
+ {
+ pojo.calledMethod(shouldThrow);
+ }
+
+ public void calledMethod(boolean shouldThrow) throws POJOException
+ {
+ if (shouldThrow)
+ {
+ throw new POJOException();
+ }
+ }
+
+ // method call static method
+ public void callStaticMethod(boolean shouldThrow) throws POJOException
+ {
+ calledStaticMethod(shouldThrow);
+ }
+
+ // static method call static method
+ public static void staticCallStaticMethod(boolean shouldThrow) throws POJOException
+ {
+ calledStaticMethod(shouldThrow);
+ }
+
+ public static void calledStaticMethod(boolean shouldThrow) throws POJOException
+ {
+ if (shouldThrow)
+ {
+ throw new POJOException();
+ }
+ }
}
\ No newline at end of file
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointTestCase.java 2007-06-09 20:31:33 UTC (rev 63440)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointTestCase.java 2007-06-10 03:53:18 UTC (rev 63441)
@@ -25,7 +25,15 @@
import junit.framework.TestSuite;
import junit.textui.TestRunner;
+import org.jboss.aop.Advised;
+import org.jboss.aop.joinpoint.Construction;
+import org.jboss.aop.joinpoint.ConstructorCallByConstructor;
+import org.jboss.aop.joinpoint.ConstructorCallByMethod;
+import org.jboss.aop.joinpoint.ConstructorExecution;
import org.jboss.aop.joinpoint.FieldAccess;
+import org.jboss.aop.joinpoint.JoinPointBean;
+import org.jboss.aop.joinpoint.MethodCallByConstructor;
+import org.jboss.aop.joinpoint.MethodCallByMethod;
import org.jboss.aop.joinpoint.MethodExecution;
import org.jboss.test.aop.AOPTestWithSetup;
@@ -62,8 +70,31 @@
this.pojo = new JoinPointPOJO();
}
- public void test1()
+ public void tearDown() throws Exception
{
+ JoinPointBean joinPoint = JoinPointAspect.beforeJoinPoint;
+ if (joinPoint == null)
+ {
+ joinPoint = JoinPointAspect.afterJoinPoint;
+ if (joinPoint == null)
+ {
+ joinPoint = JoinPointAspect.throwingJoinPoint;
+ if (joinPoint == null)
+ {
+ joinPoint = JoinPointAspect.finallyJoinPoint;
+ }
+ }
+ }
+ if (joinPoint != null)
+ {
+ assertSame(((Advised) pojo)._getAdvisor(), joinPoint.getAdvisor());
+ assertSame(JoinPointPOJO.class, joinPoint.getClazz());
+ }
+ super.tearDown();
+ }
+
+ public void testFieldWrite1()
+ {
pojo.number = 0;
assertEquals("before1", JoinPointAspect.beforeAdvice);
assertNull(JoinPointAspect.beforeJoinPoint);
@@ -80,7 +111,7 @@
assertFalse(fieldInfo.isRead());
}
- public void test2()
+ public void testFieldWrite2()
{
pojo.text = "test2";
assertEquals("before2", JoinPointAspect.beforeAdvice);
@@ -100,7 +131,7 @@
assertFalse(fieldInfo.isRead());
}
- public void test3()
+ public void testFieldWrite3()
{
String text = pojo.text;
assertNull(JoinPointAspect.beforeAdvice);
@@ -118,7 +149,7 @@
assertTrue(fieldInfo.isRead());
}
- public void test4()
+ public void testMethodExecution1()
{
pojo.method1();
assertEquals("before3", JoinPointAspect.beforeAdvice);
@@ -135,7 +166,7 @@
getAdvisedMethod().getName());
}
- public void test5() throws POJOException
+ public void testMethodExecution2() throws POJOException
{
pojo.method2(false);
assertEquals("before4", JoinPointAspect.beforeAdvice);
@@ -153,7 +184,7 @@
getAdvisedMethod().getName());
}
- public void test6() throws POJOException
+ public void testMethodExecutionException1()
{
boolean exceptionThrown = false;
try
@@ -182,7 +213,7 @@
getAdvisedMethod().getName());
}
- public void test7() throws POJOException
+ public void testMethodExecutionException2()
{
boolean exceptionThrown = false;
try
@@ -209,7 +240,7 @@
getAdvisedMethod().getName());
}
- public void test8() throws POJOException
+ public void testMethodExecutionException3()
{
boolean exceptionThrown = false;
try
@@ -238,7 +269,7 @@
getAdvisedMethod().getName());
}
- public void test9() throws POJOException
+ public void testMethodExecutionException4()
{
boolean exceptionThrown = false;
try
@@ -261,7 +292,7 @@
assertNull(JoinPointAspect.finallyJoinPoint);
}
- public void test10() throws POJOException
+ public void testMethodExecutionException5()
{
boolean exceptionThrown = false;
try
@@ -288,4 +319,599 @@
getAdvisedMethod().getName());
}
+
+ public void testConstructorCallByConstructor() throws POJOException
+ {
+ new JoinPointPOJO(11, false);
+
+ assertFullInterception(ConstructorCallByConstructor.class, "before6", "after4",
+ "finally5", false);
+
+ ConstructorCallByConstructor joinPoint = (ConstructorCallByConstructor)
+ JoinPointAspect.beforeJoinPoint;
+ Class[] parameters = joinPoint.getConstructor().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getConstructor().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalling().getDeclaringClass());
+ Class[] callerParameters = joinPoint.getCalling().getParameterTypes();
+ assertEquals(2, callerParameters.length);
+ assertSame(int.class, callerParameters[0]);
+ assertSame(boolean.class, callerParameters[1]);
+ }
+
+ public void testConstructorCallByConstructorException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ new JoinPointPOJO(12, true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertFullInterception(ConstructorCallByConstructor.class, "before6",
+ "throwing6", "finally5", exceptionThrown);
+
+ ConstructorCallByConstructor joinPoint = (ConstructorCallByConstructor)
+ JoinPointAspect.beforeJoinPoint;
+ Class[] parameters = joinPoint.getConstructor().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getConstructor().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalling().getDeclaringClass());
+ Class[] callerParameters = joinPoint.getCalling().getParameterTypes();
+ assertEquals(2, callerParameters.length);
+ assertSame(int.class, callerParameters[0]);
+ assertSame(boolean.class, callerParameters[1]);
+ }
+
+ public void testConstructorCallByMethod() throws POJOException
+ {
+ pojo.callConstructor(false);
+ assertFullInterception(ConstructorCallByMethod.class, "before3", "after5",
+ "finally6", false);
+
+ ConstructorCallByMethod joinPoint = (ConstructorCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ Class[] parameters = joinPoint.getConstructor().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getConstructor().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("callConstructor", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(1, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ }
+
+ public void testConstructorCallByMethodException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ pojo.callConstructor(true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertFullInterception(ConstructorCallByMethod.class, "before3", "throwing7",
+ "finally6", true);
+
+ ConstructorCallByMethod joinPoint = (ConstructorCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ Class[] parameters = joinPoint.getConstructor().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getConstructor().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("callConstructor", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(1, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ }
+
+ public void testConstructorCallByStaticMethod() throws POJOException
+ {
+ JoinPointPOJO.staticCallConstructor(false);
+
+ assertFullInterception(ConstructorCallByMethod.class, "before3", "after5",
+ "finally6", false);
+
+ ConstructorCallByMethod joinPoint = (ConstructorCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ Class[] parameters = joinPoint.getConstructor().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getConstructor().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("staticCallConstructor", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(1, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ }
+
+ public void testConstructorCallByStaticMethodException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ JoinPointPOJO.staticCallConstructor(true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertFullInterception(ConstructorCallByMethod.class, "before3", "throwing7",
+ "finally6", exceptionThrown);
+
+ ConstructorCallByMethod joinPoint = (ConstructorCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ Class[] parameters = joinPoint.getConstructor().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getConstructor().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("staticCallConstructor", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(1, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ }
+
+ public void testMethodCallByConstructor() throws POJOException
+ {
+ new JoinPointPOJO(false, false);
+ assertFullInterception(MethodCallByConstructor.class, "before7", "after6",
+ "finally3", false);
+
+ MethodCallByConstructor joinPoint = (MethodCallByConstructor)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalling().getDeclaringClass());
+ Class[] callerParameters = joinPoint.getCalling().getParameterTypes();
+ assertEquals(2, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ assertSame(boolean.class, callerParameters[1]);
+ }
+
+ public void testMethodCallByConstructorException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ new JoinPointPOJO(true, true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertFullInterception(MethodCallByConstructor.class, "before7", "throwing8",
+ "finally3", exceptionThrown);
+
+ MethodCallByConstructor joinPoint = (MethodCallByConstructor)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalling().getDeclaringClass());
+ Class[] callerParameters = joinPoint.getCalling().getParameterTypes();
+ assertEquals(2, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ assertSame(boolean.class, callerParameters[1]);
+ }
+
+ public void testMethodCallByMethod() throws POJOException
+ {
+ pojo.callMethod(false);
+ assertFullInterception(MethodCallByMethod.class, "before8", "after6",
+ "finally7", false);
+
+ MethodCallByMethod joinPoint = (MethodCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("callMethod", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(1, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ }
+
+ public void testMethodCallByMethodException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ pojo.callMethod(true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertFullInterception(MethodCallByMethod.class, "before8", "throwing8",
+ "finally7", exceptionThrown);
+
+ MethodCallByMethod joinPoint = (MethodCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("callMethod", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(1, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ }
+
+ public void testMethodCallByStaticMethod() throws POJOException
+ {
+ JoinPointPOJO.staticCallMethod(pojo, false);
+ assertFullInterception(MethodCallByMethod.class, "before8", "after6",
+ "finally7", false);
+
+ MethodCallByMethod joinPoint = (MethodCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("staticCallMethod", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(2, callerParameters.length);
+ assertSame(JoinPointPOJO.class, callerParameters[0]);
+ assertSame(boolean.class, callerParameters[1]);
+ }
+
+ public void testMethodCallByStaticMethodException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ JoinPointPOJO.staticCallMethod(pojo, true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertFullInterception(MethodCallByMethod.class, "before8", "throwing8",
+ "finally7", exceptionThrown);
+
+ MethodCallByMethod joinPoint = (MethodCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("staticCallMethod", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(2, callerParameters.length);
+ assertSame(JoinPointPOJO.class, callerParameters[0]);
+ assertSame(boolean.class, callerParameters[1]);
+ }
+
+ public void testStaticMethodCallByConstructor() throws POJOException
+ {
+ new JoinPointPOJO('a', false);
+
+ assertFullInterception(MethodCallByConstructor.class, "before7", "after6",
+ "finally3", false);
+
+ MethodCallByConstructor joinPoint = (MethodCallByConstructor)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledStaticMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalling().getDeclaringClass());
+ Class[] callerParameters = joinPoint.getCalling().getParameterTypes();
+ assertEquals(2, callerParameters.length);
+ assertSame(char.class, callerParameters[0]);
+ assertSame(boolean.class, callerParameters[1]);
+ }
+
+ public void testStaticMethodCallByConstructorException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ new JoinPointPOJO('b', true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertFullInterception(MethodCallByConstructor.class, "before7", "throwing8",
+ "finally3", exceptionThrown);
+
+ MethodCallByConstructor joinPoint = (MethodCallByConstructor)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledStaticMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalling().getDeclaringClass());
+ Class[] callerParameters = joinPoint.getCalling().getParameterTypes();
+ assertEquals(2, callerParameters.length);
+ assertSame(char.class, callerParameters[0]);
+ assertSame(boolean.class, callerParameters[1]);
+ }
+
+ public void testStaticMethodCallByMethod() throws POJOException
+ {
+ pojo.callStaticMethod(false);
+
+ assertFullInterception(MethodCallByMethod.class, "before8", "after6",
+ "finally7", false);
+
+ MethodCallByMethod joinPoint = (MethodCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledStaticMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("callStaticMethod", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(1, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ }
+
+ public void testStaticMethodCallByMethodException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ pojo.callStaticMethod(true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertFullInterception(MethodCallByMethod.class, "before8", "throwing8",
+ "finally7", exceptionThrown);
+
+ MethodCallByMethod joinPoint = (MethodCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledStaticMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("callStaticMethod", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(1, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ }
+
+ public void testStaticMethodCallByStaticMethod() throws POJOException
+ {
+ JoinPointPOJO.staticCallStaticMethod(false);
+
+ assertFullInterception(MethodCallByMethod.class, "before8", "after6",
+ "finally7", false);
+
+ MethodCallByMethod joinPoint = (MethodCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledStaticMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("staticCallStaticMethod", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(1, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ }
+
+ public void testStaticMethodCallByStaticMethodException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ JoinPointPOJO.staticCallStaticMethod(true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertFullInterception(MethodCallByMethod.class, "before8", "throwing8",
+ "finally7", exceptionThrown);
+
+ MethodCallByMethod joinPoint = (MethodCallByMethod)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame("calledStaticMethod", joinPoint.getMethod().getName());
+ Class[] parameters = joinPoint.getMethod().getParameterTypes();
+ assertEquals(1, parameters.length);
+ assertSame(boolean.class, parameters[0]);
+ assertSame(JoinPointPOJO.class, joinPoint.getMethod().getDeclaringClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCalledClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingClass());
+ assertSame(JoinPointPOJO.class, joinPoint.getCallingMethod().getDeclaringClass());
+ assertSame("staticCallStaticMethod", joinPoint.getCallingMethod().getName());
+ Class[] callerParameters = joinPoint.getCallingMethod().getParameterTypes();
+ assertEquals(1, callerParameters.length);
+ assertSame(boolean.class, callerParameters[0]);
+ }
+
+ public void testConstructorExecution() throws POJOException
+ {
+ new JoinPointPOJO((short) 5, false);
+
+ assertFullInterception(ConstructorExecution.class, "before2", "after7",
+ "finally7", false);
+
+ ConstructorExecution joinPoint = (ConstructorExecution)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame(JoinPointPOJO.class, joinPoint.getConstructor().getDeclaringClass());
+ Class[] parameters = joinPoint.getConstructor().getParameterTypes();
+ assertEquals(2, parameters.length);
+ assertSame(short.class, parameters[0]);
+ assertSame(boolean.class, parameters[1]);
+ }
+
+ public void testConstructorExecutionException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ new JoinPointPOJO((short) 15, true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertFullInterception(ConstructorExecution.class, "before2", "throwing2",
+ "finally7", exceptionThrown);
+
+ ConstructorExecution joinPoint = (ConstructorExecution)
+ JoinPointAspect.beforeJoinPoint;
+ assertSame(JoinPointPOJO.class, joinPoint.getConstructor().getDeclaringClass());
+ Class[] parameters = joinPoint.getConstructor().getParameterTypes();
+ assertEquals(2, parameters.length);
+ assertSame(short.class, parameters[0]);
+ assertSame(boolean.class, parameters[1]);
+ }
+
+ public void testConstruction() throws POJOException
+ {
+ new JoinPointPOJO((float) 5.0, false);
+
+ assertFullInterception(Construction.class, "before3", "after5", "finally8",
+ false);
+
+ Construction joinPoint = (Construction) JoinPointAspect.beforeJoinPoint;
+ assertSame(JoinPointPOJO.class, joinPoint.getConstructor().getDeclaringClass());
+ Class[] parameters = joinPoint.getConstructor().getParameterTypes();
+ assertEquals(2, parameters.length);
+ assertSame(float.class, parameters[0]);
+ assertSame(boolean.class, parameters[1]);
+ }
+
+ public void testConstructionException()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ new JoinPointPOJO((float) 51.0, true);
+ }
+ catch (POJOException e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
+ assertNull(JoinPointAspect.beforeAdvice);
+ assertNull(JoinPointAspect.beforeJoinPoint);
+ assertNull(JoinPointAspect.afterAdvice);
+ assertNull(JoinPointAspect.afterJoinPoint);
+ assertNull(JoinPointAspect.throwingAdvice);
+ assertNull(JoinPointAspect.throwingJoinPoint);
+ assertNull(JoinPointAspect.finallyAdvice);
+ assertNull(JoinPointAspect.finallyJoinPoint);
+ }
+
+ private void assertFullInterception(Class<? extends JoinPointBean> expectedType,
+ String beforeAdvice, String afterAdvice, String finallyAdvice,
+ boolean exceptionThrown)
+ {
+ JoinPointBean afterJoinPoint = null;
+
+ assertEquals(beforeAdvice, JoinPointAspect.beforeAdvice);
+ if (exceptionThrown)
+ {
+ assertNull(JoinPointAspect.afterAdvice);
+ assertNull(JoinPointAspect.afterJoinPoint);
+ assertEquals(afterAdvice, JoinPointAspect.throwingAdvice);
+ afterJoinPoint = JoinPointAspect.throwingJoinPoint;
+ }
+ else
+ {
+ assertEquals(afterAdvice, JoinPointAspect.afterAdvice);
+ afterJoinPoint = JoinPointAspect.afterJoinPoint;
+ assertNull(afterAdvice, JoinPointAspect.throwingAdvice);
+ assertNull(JoinPointAspect.throwingJoinPoint);
+ }
+ assertEquals(finallyAdvice, JoinPointAspect.finallyAdvice);
+
+ assertNotNull(JoinPointAspect.beforeJoinPoint);
+ assertTrue(expectedType.isAssignableFrom(JoinPointAspect.beforeJoinPoint.getClass()));
+ assertSame(JoinPointAspect.beforeJoinPoint, afterJoinPoint);
+ assertSame(afterJoinPoint, JoinPointAspect.finallyJoinPoint);
+ }
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list