[jboss-cvs] JBossAS SVN: r64785 - 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
Wed Aug 22 14:39:53 EDT 2007
Author: flavia.rainone at jboss.com
Date: 2007-08-22 14:39:53 -0400 (Wed, 22 Aug 2007)
New Revision: 64785
Added:
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointInvalidTestCase.java
Modified:
projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointInvalidPOJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointPOJO.java
Log:
[JBAOP-387] Added tests for invalid advices with @Joinpoint-annotated parameters.
Modified: projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml 2007-08-22 17:50:49 UTC (rev 64784)
+++ projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml 2007-08-22 18:39:53 UTC (rev 64785)
@@ -747,7 +747,7 @@
<after name="after1" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
- <bind pointcut="field(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->number)">
+ <bind pointcut="field(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->numberBefore9)">
<before name="before9" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
@@ -756,8 +756,11 @@
<finally name="finally1" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
- <bind pointcut="set(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->text)">
+ <bind pointcut="set(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->textAfter2)">
<after name="after2" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="set(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->textAfter8)">
<after name="after8" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
@@ -765,7 +768,7 @@
<after name="after5" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
- <bind pointcut="get(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->text)">
+ <bind pointcut="get(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->textBefore5)">
<before name="before5" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
@@ -774,7 +777,7 @@
<after name="after3" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
- <bind pointcut="execution(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->method1(..))">
+ <bind pointcut="execution(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->method1Finally9(..))">
= <finally name="finally9" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
@@ -790,7 +793,7 @@
<finally name="finally2" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
- <bind pointcut="execution(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->method3(..))">
+ <bind pointcut="execution(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->method3Throwing2(..))">
<throwing name="throwing2" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
@@ -803,7 +806,7 @@
<throwing name="throwing4" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
- <bind pointcut="execution(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->method5(..))">
+ <bind pointcut="execution(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->method5Finally4(..))">
<finally name="finally4" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
@@ -825,8 +828,11 @@
<finally name="finally6" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
- <bind pointcut="call(org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->new(boolean)) AND withincode(public void org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->*(..))">
+ <bind pointcut="call(org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->new(boolean)) AND withincode(public void org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->*Throwing9(..))">
<throwing name="throwing9" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="call(org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->new(boolean)) AND withincode(public void org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->*Throwing10(..))">
<throwing name="throwing10" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
@@ -837,8 +843,11 @@
<finally name="finally3" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
- <bind pointcut="call(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->*Method(boolean)) AND withincode(org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->new(..))">
+ <bind pointcut="call(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->*MethodThrowing9(boolean)) AND withincode(org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->new(..))">
<throwing name="throwing9" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
+ </bind>
+
+ <bind pointcut="call(* org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->*MethodThrowing10(boolean)) AND withincode(org.jboss.test.aop.beforeafterArgs.JoinPointInvalidPOJO->new(..))">
<throwing name="throwing10" aspect="org.jboss.test.aop.beforeafterArgs.JoinPointAspect"/>
</bind>
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointInvalidPOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointInvalidPOJO.java 2007-08-22 17:50:49 UTC (rev 64784)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointInvalidPOJO.java 2007-08-22 18:39:53 UTC (rev 64785)
@@ -28,30 +28,17 @@
*/
public class JoinPointInvalidPOJO
{
- public int number;
- public String text;
+ /* int number */
+ public int numberBefore9;
+ /* String text */
+ public String textAfter2;
+ public String textAfter8;
+ public String textBefore5;
+
// constructor without advices
public JoinPointInvalidPOJO() {}
- // constructor execution
- public JoinPointInvalidPOJO(short arg0, boolean shouldThrow) throws POJOException
- {
- if (shouldThrow)
- {
- throw new POJOException();
- }
- }
-
- // construction
- public JoinPointInvalidPOJO(float arg0, boolean shouldThrow) throws POJOException
- {
- if (shouldThrow)
- {
- throw new POJOException();
- }
- }
-
// called constructor
public JoinPointInvalidPOJO(boolean shouldThrow) throws POJOException
{
@@ -61,69 +48,63 @@
}
}
- // constructor call constructor
- public JoinPointInvalidPOJO(int arg0, boolean shouldThrow) throws POJOException
- {
- new JoinPointInvalidPOJO(shouldThrow);
- }
-
// constructor call method
+
public JoinPointInvalidPOJO(boolean arg0, boolean shouldThrow) throws POJOException
{
- this.calledMethod(shouldThrow);
+ this.calledMethodThrowing9(shouldThrow);
}
- // constructor call static method
- public JoinPointInvalidPOJO(char arg0, boolean shouldThrow) throws POJOException
+ public JoinPointInvalidPOJO(long arg0, boolean shouldThrow) throws POJOException
{
- calledStaticMethod(shouldThrow);
+ this.calledMethodThrowing10(shouldThrow);
}
- public void method1()
- {
-
- }
+ /* method1() */
- public void method3() throws POJOException
+ public void method1Finally9(){}
+
+ /* method3() */
+
+ public void method3Throwing2() throws POJOException
{
throw new POJOException();
}
- public void method5() throws POJOException
+ /* method5() */
+
+ public void method5Finally4() throws POJOException
{
throw new POJOException();
}
- public void method6() throws POJOException
+ /* callConstructor(boolean) */
+
+ public void callConstructorThrowing9(boolean shouldThrow) throws POJOException
{
- throw new POJOException();
- }
-
- // method call constructor
- public void callConstructor(boolean shouldThrow) throws POJOException
- {
new JoinPointInvalidPOJO(shouldThrow);
}
- // static method call constructor
- public static void staticCallConstructor(boolean shouldThrow) throws POJOException
+ public void callConstructorThrowing10(boolean shouldThrow) throws POJOException
{
new JoinPointInvalidPOJO(shouldThrow);
}
- // method call method
- public void callMethod(boolean shouldThrow) throws POJOException
+ /* staticCallConstructor(boolean) */
+
+ public static void staticCallConstructorThrowing9(boolean shouldThrow) throws POJOException
{
- calledMethod(shouldThrow);
+ new JoinPointInvalidPOJO(shouldThrow);
}
- // static method call method
- public static void staticCallMethod(JoinPointInvalidPOJO pojo, boolean shouldThrow) throws POJOException
+ public static void staticCallConstructorThrowing10(boolean shouldThrow) throws POJOException
{
- pojo.calledMethod(shouldThrow);
+ new JoinPointInvalidPOJO(shouldThrow);
}
- public void calledMethod(boolean shouldThrow) throws POJOException
+ /* calledMethod(boolean) */
+
+ public void calledMethodThrowing9(boolean shouldThrow) throws POJOException
{
if (shouldThrow)
{
@@ -131,20 +112,8 @@
}
}
- // method call static method
- public void callStaticMethod(boolean shouldThrow) throws POJOException
+ public void calledMethodThrowing10(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();
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointInvalidTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointInvalidTestCase.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointInvalidTestCase.java 2007-08-22 18:39:53 UTC (rev 64785)
@@ -0,0 +1,306 @@
+/*
+ * 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.beforeafterArgs;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.aop.Advised;
+import org.jboss.aop.advice.NoMatchingAdviceException;
+import org.jboss.aop.joinpoint.JoinPointBean;
+import org.jboss.test.aop.AOPTestWithSetup;
+
+/**
+ * Tests the use of @JoinPoint parameters with invalid advices.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class JoinPointInvalidTestCase extends AOPTestWithSetup
+{
+ private JoinPointInvalidPOJO pojo;
+
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("JoinPointTestCase");
+ suite.addTestSuite(JoinPointInvalidTestCase.class);
+ return suite;
+ }
+
+ public JoinPointInvalidTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ JoinPointAspect.clear();
+ this.pojo = new JoinPointInvalidPOJO();
+ }
+
+ 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()
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.numberBefore9 = 0;
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ }
+
+ public void testFieldWrite2()
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.textAfter2 = "test2";
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+
+ thrown = false;
+ try
+ {
+ pojo.textAfter8 = "test2";
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ }
+
+ public void testFieldRead()
+ {
+ boolean thrown = false;
+ try
+ {
+ String text = pojo.textBefore5;
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ }
+
+ public void testMethodExecution1()
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.method1Finally9();
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ }
+
+ public void testMethodExecutionException1() throws POJOException
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.method3Throwing2();
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ }
+
+ public void testMethodExecutionException2() throws POJOException
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.method5Finally4();
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ }
+
+ public void testConstructorCallByMethod() throws POJOException
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.callConstructorThrowing9(false);
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+
+ thrown = false;
+ try
+ {
+ pojo.callConstructorThrowing10(false);
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ }
+
+ public void testConstructorCallByMethodException() throws POJOException
+ {
+ boolean thrown = false;
+ try
+ {
+ pojo.callConstructorThrowing9(true);
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+
+ thrown = false;
+ try
+ {
+ pojo.callConstructorThrowing10(true);
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ }
+
+ public void testConstructorCallByStaticMethod() throws POJOException
+ {
+ boolean thrown = false;
+ try
+ {
+ JoinPointInvalidPOJO.staticCallConstructorThrowing9(false);
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+
+ thrown = false;
+ try
+ {
+ JoinPointInvalidPOJO.staticCallConstructorThrowing10(false);
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ }
+
+ public void testConstructorCallByStaticMethodException() throws POJOException
+ {
+ boolean thrown = false;
+ try
+ {
+ JoinPointInvalidPOJO.staticCallConstructorThrowing9(true);
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+
+ thrown = false;
+ try
+ {
+ JoinPointInvalidPOJO.staticCallConstructorThrowing10(true);
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ }
+
+ public void testMethodCallByConstructor() throws Exception
+ {
+ boolean thrown = false;
+ try
+ {
+ new JoinPointInvalidPOJO(false, false);
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+
+ thrown = false;
+ try
+ {
+ new JoinPointInvalidPOJO(0l, false);
+ }
+ catch (NoMatchingAdviceException e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ }
+}
\ 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-08-22 17:50:49 UTC (rev 64784)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/JoinPointPOJO.java 2007-08-22 18:39:53 UTC (rev 64785)
@@ -79,10 +79,7 @@
calledStaticMethod(shouldThrow);
}
- public void method1()
- {
-
- }
+ public void method1() {}
public String method2(boolean shouldThrow) throws POJOException
{
More information about the jboss-cvs-commits
mailing list