[jboss-cvs] JBossAS SVN: r88324 - in projects/aop/branches/Branch_2_1/aop/src: test/java/org/jboss/test/aop/arguments and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 7 01:54:36 EDT 2009
Author: flavia.rainone at jboss.com
Date: 2009-05-07 01:54:35 -0400 (Thu, 07 May 2009)
New Revision: 88324
Added:
projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/NoPrecedenceArgumentsAspect.java
Modified:
projects/aop/branches/Branch_2_1/aop/src/resources/test/arguments/jboss-aop.xml
projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsAspect.java
projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsPOJO.java
projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsTestCase.java
Log:
[JBAOP-726] Merged current version of arguments tests with the old version. Normally, the previous commit would have been rolled back, but given that the new version of those tests uncovered a new bug, I'm keeping the new version, and merging it with the old one.
Modified: projects/aop/branches/Branch_2_1/aop/src/resources/test/arguments/jboss-aop.xml
===================================================================
--- projects/aop/branches/Branch_2_1/aop/src/resources/test/arguments/jboss-aop.xml 2009-05-07 05:51:50 UTC (rev 88323)
+++ projects/aop/branches/Branch_2_1/aop/src/resources/test/arguments/jboss-aop.xml 2009-05-07 05:54:35 UTC (rev 88324)
@@ -54,7 +54,7 @@
<stack-ref name="set"/>
</bind>
- <bind pointcut="call(* org.jboss.test.aop.arguments.CalledPOJO->*(..))" cflow="(ArgumentsPOJO2_constructor OR ArgumentsPOJO2_method)">
+ <bind pointcut="call(* org.jboss.test.aop.arguments.CalledPOJO->*(int))" cflow="(ArgumentsPOJO2_constructor OR ArgumentsPOJO2_method)">
<stack-ref name="set"/>
</bind>
@@ -62,10 +62,40 @@
<advice name="getAndChangeArgumentsAdvice" aspect="org.jboss.test.aop.arguments.ArgumentsAspect"/>
</bind>
- <precedence>
+ <!-- <precedence>
<advice name="getArgumentsAdvice1" aspect="org.jboss.test.aop.arguments.ArgumentsAspect"/>
<advice name="setArgumentsAdvice" aspect="org.jboss.test.aop.arguments.ArgumentsAspect"/>
<advice name="getArgumentsAdvice2" aspect="org.jboss.test.aop.arguments.ArgumentsAspect"/>
<advice name="getAndChangeArgumentsAdvice" aspect="org.jboss.test.aop.arguments.ArgumentsAspect"/>
- </precedence>
+ </precedence> -->
+
+ <aspect class="org.jboss.test.aop.arguments.NoPrecedenceArgumentsAspect" scope="PER_VM"/>
+
+ <bind pointcut="call(* org.jboss.test.aop.arguments.CalledPOJO->*(long))" cflow="(ArgumentsPOJO2_constructor OR ArgumentsPOJO2_method)">
+ <advice name="getArgumentsAdvice1" aspect="org.jboss.test.aop.arguments.NoPrecedenceArgumentsAspect"/>
+ <advice name="setArgumentsAdvice" aspect="org.jboss.test.aop.arguments.NoPrecedenceArgumentsAspect"/>
+ <advice name="getArgumentsAdvice2" aspect="org.jboss.test.aop.arguments.NoPrecedenceArgumentsAspect"/>
+ </bind>
+
+ <bind pointcut="call(static * org.jboss.test.aop.arguments.CalledPOJO->*(long))" cflow="(ArgumentsPOJO2_constructor OR ArgumentsPOJO2_method)">
+ <advice name="getAndChangeArgumentsAdvice" aspect="org.jboss.test.aop.arguments.NoPrecedenceArgumentsAspect"/>
+ </bind>
+
+ <stack name="noPrecedenceGetAndChange">
+ <advice name="getArgumentsAdvice1" aspect="org.jboss.test.aop.arguments.NoPrecedenceArgumentsAspect"/>
+ <advice name="getAndChangeArgumentsAdvice" aspect="org.jboss.test.aop.arguments.NoPrecedenceArgumentsAspect"/>
+ <advice name="getArgumentsAdvice2" aspect="org.jboss.test.aop.arguments.NoPrecedenceArgumentsAspect"/>
+ </stack>
+
+ <bind pointcut="call(org.jboss.test.aop.arguments.CalledPOJO->new(long))" cflow="(ArgumentsPOJO1_constructor OR ArgumentsPOJO1_method)">
+ <stack-ref name="noPrecedenceGetAndChange"/>
+ </bind>
+
+ <bind pointcut="call(* org.jboss.test.aop.arguments.CalledPOJO->*(long))" cflow="(ArgumentsPOJO1_constructor OR ArgumentsPOJO1_method)">
+ <stack-ref name="noPrecedenceGetAndChange"/>
+ </bind>
+
+ <bind pointcut="call(static * org.jboss.test.aop.arguments.CalledPOJO->*(long))" cflow="(ArgumentsPOJO1_constructor OR ArgumentsPOJO1_method)">
+ <advice name="setArgumentsAdvice" aspect="org.jboss.test.aop.arguments.NoPrecedenceArgumentsAspect"/>
+ </bind>
</aop>
\ No newline at end of file
Modified: projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsAspect.java
===================================================================
--- projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsAspect.java 2009-05-07 05:51:50 UTC (rev 88323)
+++ projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsAspect.java 2009-05-07 05:54:35 UTC (rev 88324)
@@ -50,7 +50,14 @@
Object[] arguments = getArguments(invocation);
if (arguments != null && arguments.length == 1)
{
- arguments[0] = Integer.valueOf(((Integer) arguments[0]).intValue() /2);
+ if (arguments[0] instanceof Integer)
+ {
+ arguments[0] = Integer.valueOf(((Integer) arguments[0]).intValue() /2);
+ }
+ else if (arguments[0] instanceof Long)
+ {
+ arguments[0] = Long.valueOf(((Long) arguments[0]).intValue() /2);
+ }
}
return invocation.invokeNext();
}
@@ -67,7 +74,6 @@
public Object getArgumentsAdvice2(Invocation invocation) throws Throwable
{
-
Object[] arguments = getArguments(invocation);
if (arguments != null && arguments.length == 1)
{
@@ -78,7 +84,13 @@
public Object setArgumentsAdvice(Invocation invocation) throws Throwable
{
+ Object[] oldArguments = getArguments(invocation);
Object[] arguments = new Object[] {Integer.valueOf(37)};
+ if (oldArguments != null && oldArguments.length == 1 &&
+ oldArguments[0] instanceof Long)
+ {
+ arguments[0] = Long.valueOf(37);
+ }
if (invocation instanceof ConstructorInvocation &&
// avoid constructors that receive an intance of Call enum
((ConstructorInvocation) invocation).getArguments().length == 1)
Modified: projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsPOJO.java
===================================================================
--- projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsPOJO.java 2009-05-07 05:51:50 UTC (rev 88323)
+++ projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsPOJO.java 2009-05-07 05:54:35 UTC (rev 88324)
@@ -43,6 +43,11 @@
this.arg = call.perform(arg);
}
+ public ArgumentsPOJO1(Call call, long arg)
+ {
+ this.arg = call.perform((int)arg);
+ }
+
public int method(int arg)
{
return arg * 3;
@@ -69,6 +74,10 @@
return CalledPOJO.staticMethod(arg);
}
+ public int callPOJOStatic(long arg)
+ {
+ return CalledPOJO.staticMethod(arg);
+ }
}
/**
@@ -118,39 +127,49 @@
return CalledPOJO.staticMethod(arg);
}
+ public int callPOJOStatic(long arg)
+ {
+ return CalledPOJO.staticMethod(arg);
+ }
+
}
-abstract class Call
+enum Call
{
- public static final Call CONSTRUCTOR = new Call("CONSTRUCTOR")
+ CONSTRUCTOR
{
public int perform(int arg)
{
CalledPOJO pojo = new CalledPOJO(arg);
return pojo.arg;
}
- };
+ },
- public static final Call METHOD = new Call("METHOD")
+ METHOD
{
public int perform(int arg)
{
CalledPOJO pojo = new CalledPOJO();
return pojo.method(arg);
}
- };
+ },
- public static final Call STATIC_METHOD = new Call("STATIC_METHOD")
+ STATIC_METHOD
{
public int perform(int arg)
{
return CalledPOJO.staticMethod(arg);
}
+ },
+
+ STATIC_METHOD_2
+ {
+ public int perform(int arg)
+ {
+ return CalledPOJO.staticMethod((long) arg);
+ }
};
- // TODO replace by enum
- private Call(String name) {}
-
public abstract int perform(int arg);
}
@@ -179,4 +198,9 @@
{
return arg - 1;
}
+
+ public static int staticMethod(long arg)
+ {
+ return (int) arg - 1;
+ }
}
\ No newline at end of file
Modified: projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsTestCase.java
===================================================================
--- projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsTestCase.java 2009-05-07 05:51:50 UTC (rev 88323)
+++ projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/ArgumentsTestCase.java 2009-05-07 05:54:35 UTC (rev 88324)
@@ -275,4 +275,52 @@
assertEquals(1, ArgumentsAspect.arguments2.length);
assertEquals(18, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
}
+
+ public void testNoPrecedenceConCallStaticPOJO1()
+ {
+ ArgumentsPOJO1 pojo = new ArgumentsPOJO1(Call.STATIC_METHOD_2, -2041);
+ assertEquals(36, pojo.arg);
+
+ assertNotNull(ArgumentsAspect.arguments1);
+ assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+ assertEquals(1, ArgumentsAspect.arguments1.length);
+ assertEquals(-1020, ((Long) ArgumentsAspect.arguments1[0]).intValue());
+ }
+
+ public void testNoPrecedenceConCallStaticPOJO2()
+ {
+ ArgumentsPOJO2 pojo = new ArgumentsPOJO2(Call.STATIC_METHOD_2, -8);
+ assertEquals(17, pojo.arg);
+
+ assertNotNull(ArgumentsAspect.arguments1);
+ assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+ assertEquals(1, ArgumentsAspect.arguments1.length);
+ assertEquals(-8, ((Long) ArgumentsAspect.arguments1[0]).intValue());
+ assertEquals(1, ArgumentsAspect.arguments2.length);
+ assertEquals(18, ((Long) ArgumentsAspect.arguments2[0]).intValue());
+ }
+
+ public void testNoPrecedenceMethodCallStaticPOJO1()
+ {
+ // intercepted twice by each advice: once for caller, once for called
+ assertEquals(36, pojo1.callPOJOStatic((long) 123456));
+
+ assertNotNull(ArgumentsAspect.arguments1);
+ assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+ assertEquals(1, ArgumentsAspect.arguments1.length);
+ assertEquals(30864, ((Long) ArgumentsAspect.arguments1[0]).intValue());
+ }
+
+ public void testNoPrecedenceMethodCallStaticPOJO2()
+ {
+ // intercepted twice by each advice: once for caller, once for called
+ assertEquals(17, pojo2.callPOJOStatic((new Long(99999)).longValue()) );
+
+ assertNotNull(ArgumentsAspect.arguments1);
+ assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+ assertEquals(1, ArgumentsAspect.arguments1.length);
+ assertEquals(37, ((Long) ArgumentsAspect.arguments1[0]).intValue());
+ assertEquals(1, ArgumentsAspect.arguments2.length);
+ assertEquals(18, ((Long) ArgumentsAspect.arguments2[0]).intValue());
+ }
}
\ No newline at end of file
Added: projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/NoPrecedenceArgumentsAspect.java
===================================================================
--- projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/NoPrecedenceArgumentsAspect.java (rev 0)
+++ projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/arguments/NoPrecedenceArgumentsAspect.java 2009-05-07 05:54:35 UTC (rev 88324)
@@ -0,0 +1,35 @@
+/*
+ * 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.arguments;
+
+/**
+ *
+ * Aspect that contains the same advice as ArgumentsAspect, but has not precedence
+ * declarations.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class NoPrecedenceArgumentsAspect extends ArgumentsAspect
+{
+
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list