[jboss-cvs] JBossAS SVN: r59999 - in projects/aop/trunk/aop/src: resources/test/beforeafterArgs and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 25 09:09:21 EST 2007


Author: flavia.rainone at jboss.com
Date: 2007-01-25 09:09:21 -0500 (Thu, 25 Jan 2007)
New Revision: 59999

Added:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgAspect.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgTestCase.java
Modified:
   projects/aop/trunk/aop/src/resources/test/args/jboss-aop.xml
   projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgAspect.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgsPOJO.java
Log:
[JBAOP-320] Tests for the task.

Modified: projects/aop/trunk/aop/src/resources/test/args/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/args/jboss-aop.xml	2007-01-25 14:06:44 UTC (rev 59998)
+++ projects/aop/trunk/aop/src/resources/test/args/jboss-aop.xml	2007-01-25 14:09:21 UTC (rev 59999)
@@ -19,10 +19,7 @@
 
    <bind pointcut="execution(* org.jboss.test.aop.args.POJO->bunch(..))">
       <advice name="bunch" aspect="org.jboss.test.aop.args.ArgAspect"/>
-<!--		<advice name="bunch1" aspect="org.jboss.test.aop.args.ArgAspect"/> -->
-      <advice name="bunch2" aspect="org.jboss.test.aop.args.ArgAspect"/>
-<!--      <advice name="bunch3" aspect="org.jboss.test.aop.args.ArgAspect"/>
-      <advice name="bunch4" aspect="org.jboss.test.aop.args.ArgAspect"/> -->
+      <advice name="bunch1" aspect="org.jboss.test.aop.args.ArgAspect"/>
       <advice name="arg1" aspect="org.jboss.test.aop.args.ArgAspect"/>
       <advice name="arg2" aspect="org.jboss.test.aop.args.ArgAspect"/>
       <advice name="arg3" aspect="org.jboss.test.aop.args.ArgAspect"/>

Modified: projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml	2007-01-25 14:06:44 UTC (rev 59998)
+++ projects/aop/trunk/aop/src/resources/test/beforeafterArgs/jboss-aop.xml	2007-01-25 14:09:21 UTC (rev 59999)
@@ -2,12 +2,34 @@
 <!DOCTYPE aop SYSTEM "jboss-aop_1_0.dtd">
 
 <aop>
+
+   <!-- @Arg test -->
+	<aspect class="org.jboss.test.aop.beforeafterArgs.ArgAspect" scope="PER_VM"/>
+   
+   <bind pointcut="execution(* org.jboss.test.aop.beforeafterArgs.ArgsPOJO->bunch(..))">
+      <before name="before1" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+      <before name="before2" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+		<before name="before3" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+		<before name="before4" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+		<before name="before5" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+      <advice name="around1" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+      <advice name="around2" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+      <advice name="around3" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+      <advice name="around4" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+      <advice name="around5" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+      <after name="after1" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+      <after name="after2" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+      <after name="after3" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+      <after name="after4" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/>
+<!--      <after name="after5" aspect="org.jboss.test.aop.beforeafterArgs.ArgAspect"/> -->
+   </bind>
+
    <!-- @Args test -->
 	<aspect class="org.jboss.test.aop.beforeafterArgs.ArgsAspect" scope="PER_VM"/>
 
 	<bind pointcut="field(* org.jboss.test.aop.beforeafterArgs.ArgsPOJO->field1)">
 		<before name="before1" aspect="org.jboss.test.aop.beforeafterArgs.ArgsAspect"/>
-        <before name="before2" aspect="org.jboss.test.aop.beforeafterArgs.ArgsAspect"/>
+      <before name="before2" aspect="org.jboss.test.aop.beforeafterArgs.ArgsAspect"/>
 		<before name="before3" aspect="org.jboss.test.aop.beforeafterArgs.ArgsAspect"/>
 		<before name="before4" aspect="org.jboss.test.aop.beforeafterArgs.ArgsAspect"/>
 		<before name="before5" aspect="org.jboss.test.aop.beforeafterArgs.ArgsAspect"/>

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgAspect.java	2007-01-25 14:06:44 UTC (rev 59998)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgAspect.java	2007-01-25 14:09:21 UTC (rev 59999)
@@ -125,14 +125,8 @@
       }
    }
 
-   public int bunch1(@Arg int x, @Arg double y, @Arg float z, @Arg String str, @Arg long q)
+   public int bunch1(@Arg int x, @Arg int q, @Arg String str, @Arg double y, @Arg float z)
    {
-      Assert.fail("This advice should never be executed");
-      return 0;
-   }
-
-   public int bunch2(@Arg int x, @Arg int q, @Arg String str, @Arg double y, @Arg float z)
-   {
       bunch2Called = true;
 
       Assert.assertEquals("Arguments don't match", 1, x);
@@ -148,18 +142,6 @@
          throw new RuntimeException(throwable);
       }
    }
-
-   public int bunch3(@Arg int x, @Arg int q, @Arg int w, @Arg String str, @Arg double y, @Arg float z)
-   {
-      Assert.fail("This advice should never be executed");
-      return 0;
-   }
-
-   public int bunch4(@Arg int x, @Arg int q, @Arg float z, @Arg Collection str, @Arg double y)
-   {
-      Assert.fail("This advice should never be executed");
-      return 0;
-   }
    
    public Object arg1(@Arg int x) throws Throwable
    {

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgAspect.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgAspect.java	2007-01-25 14:09:21 UTC (rev 59999)
@@ -0,0 +1,187 @@
+/*
+ * 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 java.util.Collection;
+
+import junit.framework.Assert;
+
+import org.jboss.aop.advice.annotation.Arg;
+import org.jboss.aop.advice.annotation.Args;
+import org.jboss.aop.joinpoint.CurrentInvocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+
+/**
+ * Aspect used on @Arg parameter tests (this class complements <code>
+ * org.jboss.test.aop.args.ArgAspect</code>, by containing advices that are allowed
+ * only with generated advisors).
+ * 
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @see org.jboss.test.aop.args.ArgAspect
+ */
+public class ArgAspect
+{
+   static boolean before1 = false;
+   static boolean before2 = false;
+   static boolean before3 = false;
+   static boolean before4 = false;
+   static boolean before5 = false;
+   
+   static boolean around4 = false;
+   static boolean around5 = false;
+   
+   static boolean after1 = false;
+   static boolean after4 = false;
+   
+   static int before1X = 0;
+   static int before2X = 0;
+   static int before3Y = 0;
+   static int before5X = 0;
+   static int before5Y = 0;
+   
+   static int around5X = 0;
+   static int around5Y = 0;
+   
+   static int after1X = 0;
+   static int after4X = 0;
+   static int after4Y = 0;
+   
+   public static void clear()
+   {
+      before1 = false;
+      before2 = false;
+      before3 = false;
+      before4 = false;
+      before5 = false;
+      around4 = false;
+      around5 = false;
+      after4 = false;
+      
+      before1X = 0;
+      before2X = 0;
+      before3Y = 0;
+      before5X = 0;
+      before5Y = 0;
+      around5X = 0;
+      around5Y = 0;
+      after1X = 0;
+      after4X = 0;
+      after4Y = 0;
+   }
+   
+   public void before1(@Arg(index=0) int x)
+   {
+      before1 = true;
+      before1X = x;
+   }
+   
+   public void before2(@Arg int x)
+   {
+      before2 = true;
+      before2X = x;
+   }
+   
+   public void before3(@Arg(index=4) int y)
+   {
+      before3 = true;
+      before3Y = y;
+   }
+   
+   public void before4(@Args Object[] arguments)
+   {
+      before4 = true;
+      arguments[0] = Integer.valueOf(((Integer) arguments[0]).intValue() * 5);
+      arguments[4] = Integer.valueOf(((Integer) arguments[4]).intValue() * -17);
+   }
+   
+   public void before5(@Arg int x, @Arg int y)
+   {
+      before5 = true;
+      before5X = x;
+      before5Y = y;
+   }
+   
+   public int around1(@Arg int x, @Arg double y, @Arg float z, @Arg String str, @Arg long q)
+   {
+      Assert.fail("This advice should never be executed");
+      return 0;
+   }
+
+   public int around2(@Arg int x, @Arg int q, @Arg float z, @Arg Collection str, @Arg double y)
+   {
+      Assert.fail("This advice should never be executed");
+      return 0;
+   }
+   
+   public int around3(@Arg int x, @Arg int q, @Arg int w, @Arg String str, @Arg double y, @Arg float z)
+   {
+      Assert.fail("This advice should never be executed");
+      return 0;
+   }
+   
+   public Object around4(MethodInvocation invocation) throws Throwable
+   {
+      around4 = true;
+      Object[] arguments = invocation.getArguments();
+      arguments[0] = Integer.valueOf(((Integer) arguments[0]).intValue() - 8);
+      arguments[4] = Integer.valueOf(((Integer) arguments[4]).intValue() + 51);
+      invocation.setArguments(arguments);
+      return invocation.invokeNext();
+   }
+   
+   public int around5(@Arg(index = 4) int y, @Arg int x) throws Throwable
+   {
+      around5 = true;
+      around5X = x;
+      around5Y = y;
+      return ((Integer) CurrentInvocation.proceed()).intValue();
+   }
+   
+   public void after1(@Arg String str, @Arg(index = 0) int x)
+   {
+      after1 = true;
+      after1X = x;
+   }
+   
+   public void after2(@Arg float z, @Arg(index = 2) String str)
+   {
+      Assert.fail("This advice should never be executed");
+   }
+   
+   public void after3(@Arg(index = 5) double z)
+   {
+      Assert.fail("This advice should never be executed");
+   }
+   
+   public void after4(@Arg int x, @Arg int y)
+   {
+      after4 = true;
+      after4X = x;
+      after4Y = y;
+   }
+   
+   // TODO
+   /*public void after5(@Arg(index = 4) int x, @Arg(index = -3) int y)
+   {
+      Assert.fail("This advice should never be executed");
+   }*/
+}
\ No newline at end of file

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgTestCase.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgTestCase.java	2007-01-25 14:09:21 UTC (rev 59999)
@@ -0,0 +1,94 @@
+/*
+ * 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.test.aop.AOPTestWithSetup;
+
+/**
+ * Tests the use of @Arg parameters (this class complements <code>
+ * org.jboss.test.aop.args.ArgTestCAse</code>, by testing advices that are allowed
+ * only with generated advisors).
+ * 
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class ArgTestCase extends AOPTestWithSetup
+{
+   private ArgsPOJO pojo;
+
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("ArgTestCase");
+      suite.addTestSuite(ArgTestCase.class);
+      return suite;
+   }
+
+   public ArgTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void setUp() throws Exception
+   {
+      super.setUp();
+      this.pojo = new ArgsPOJO();
+      ArgAspect.clear();
+   }
+
+   public void test1()
+   {
+      int result = this.pojo.bunch(5, (double) 1.3, (float) 0, "test1", 1);
+      
+      
+      // TODO solve [JBAOP-35] and uncomment these lines
+      // assertEquals(value, result);
+      
+      assertTrue(ArgAspect.before1);
+      assertTrue(ArgAspect.before2);
+      assertTrue(ArgAspect.before3);
+      assertTrue(ArgAspect.before4);
+      assertTrue(ArgAspect.before5);
+      assertTrue(ArgAspect.around4);
+      assertTrue(ArgAspect.around5);
+      assertTrue(ArgAspect.after1);
+      assertTrue(ArgAspect.after4);
+      
+      assertEquals(5, ArgAspect.before1X);
+      assertEquals(5, ArgAspect.before2X);
+      assertEquals(1, ArgAspect.before3Y);
+      //assertEquals(25, ArgAspect.before5X);
+      //assertEquals(-17, ArgAspect.before5Y);
+      assertEquals(17, ArgAspect.around5X);
+      assertEquals(34, ArgAspect.around5Y);
+      //assertEquals(17, ArgAspect.after1X);
+      //assertEquals(17, ArgAspect.after4X);
+      //assertEquals(34, ArgAspect.after4Y);  
+   }
+}
\ No newline at end of file

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgsPOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgsPOJO.java	2007-01-25 14:06:44 UTC (rev 59998)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterArgs/ArgsPOJO.java	2007-01-25 14:09:21 UTC (rev 59999)
@@ -36,6 +36,11 @@
    
    public static boolean field4;
    
+   public int bunch(int x, double y, float z, String str, int q)
+   {
+      return x + (int) y + (int) z + q;
+   }
+   
    public void method1(String param1, int param2, boolean param3, ArgsPOJO[] param4)
    {}
    




More information about the jboss-cvs-commits mailing list