[jboss-cvs] JBossAS SVN: r92597 - projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/precedence.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 19 21:45:35 EDT 2009


Author: flavia.rainone at jboss.com
Date: 2009-08-19 21:45:35 -0400 (Wed, 19 Aug 2009)
New Revision: 92597

Modified:
   projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/precedence/PrecedenceTester.java
Log:
[JBAOP-748] PrecedenceTester now asserts only whether the precedence constraints are being applied.

Modified: projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/precedence/PrecedenceTester.java
===================================================================
--- projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/precedence/PrecedenceTester.java	2009-08-20 01:44:35 UTC (rev 92596)
+++ projects/aop/branches/Branch_2_1/aop/src/test/java/org/jboss/test/aop/precedence/PrecedenceTester.java	2009-08-20 01:45:35 UTC (rev 92597)
@@ -21,11 +21,12 @@
  */
 package org.jboss.test.aop.precedence;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import java.util.ArrayList;
-
 import org.jboss.test.aop.AOPTestWithSetup;
 
 /**
@@ -37,57 +38,17 @@
 @SuppressWarnings({"unchecked"})
 public class PrecedenceTester extends AOPTestWithSetup
 {
-   //Don't list per_instance aspects for constructor
-   final static String[] PRECEDENCE_ALL_CONSTRUCTOR = {
-      "FirstInterceptor",
-      "FirstInterceptor2",
-      "SimpleInterceptor2",
-      "SimpleInterceptor3",
-      "TestAspect.advice",
-      "TestAspect2.advice",
-      "LastAspect.advice",
-      "LastAspect2.advice"};
-
-   final static String[] PRECEDENCE_ALL = {
-      "FirstInterceptor",
-      "FirstInterceptor2",
-      "SimpleInterceptor",
-      "SimpleInterceptor2",
-      "SimpleInterceptor3",
-      "TestAspect.advice",
-      "TestAspect2.advice",
-      "TestAspect3.advice",
-      "LastAspect.advice",
-      "LastAspect2.advice"};
-
-   final static String[] PRECEDENCE_TWO = {
-      "FirstInterceptor",
-      "FirstInterceptor2",
-      "SimpleInterceptor",
-      "TestAspect.advice",
-      "TestAspect.advice2",
-      "TestAspect.advice3",
-      "TestAspect2.advice",
-      "LastAspect.advice",
-      "LastAspect2.advice"};
-
-   final static String[] PRECEDENCE_THREE = {
-      "FirstInterceptor",
-      "FirstInterceptor2",
-      "TestAspect.advice",
-      "TestAspect.advice2",
-      "TestAspect.advice3",
-      "LastAspect.advice",
-      "LastAspect2.advice"};
-
-   final static String[] PRECEDENCE_SEVEN = {
-      "SimpleInterceptor",
-      "SimpleInterceptor2",
-      "SimpleInterceptor3",
-      "TestAspect.advice",
-      "TestAspect.advice2",
-      "TestAspect.advice3"};
-
+  final static Precedence[] precedences = {
+      new Precedence("SimpleInterceptor2", "TestAspect.advice"),
+      new Precedence("SimpleInterceptor2", "SimpleInterceptor3"),
+      new Precedence("SimpleInterceptor3", "TestAspect.advice"),
+      new Precedence("TestAspect.advice", "TestAspect2.advice"),
+      new Precedence("TestAspect.advice2", "TestAspect.advice3"),
+      new Precedence("TestAspect.advice3", "TestAspect2.advice"),
+      new Precedence("SimpleInterceptor", "SimpleInterceptor2"),
+      new Precedence("TestAspect2.advice", "TestAspect3.advice")
+   };
+         
    private POJO pojo;
 
    public static Test suite()
@@ -114,7 +75,16 @@
       System.out.println("*** Invoke constructor");
       Interceptions.reset();
       new POJO();
-      checkInterceptions(PRECEDENCE_ALL_CONSTRUCTOR);
+      checkInterceptions(8);
+      /* expected something like 
+      "FirstInterceptor",
+      "FirstInterceptor2",
+      "SimpleInterceptor2",
+      "SimpleInterceptor3",
+      "TestAspect.advice",
+      "TestAspect2.advice",
+      "LastAspect.advice",
+      "LastAspect2.advice"*/
    }
 
    @SuppressWarnings("all")
@@ -123,7 +93,19 @@
       System.out.println("*** Invoke field read");
       Interceptions.reset();
       int i = pojo.var;
-      checkInterceptions(PRECEDENCE_ALL);
+      checkInterceptions(10);
+      /* expected something like
+      "FirstInterceptor",
+      "FirstInterceptor2",
+      "SimpleInterceptor",
+      "SimpleInterceptor2",
+      "SimpleInterceptor3",
+      "TestAspect.advice",
+      "TestAspect2.advice",
+      "TestAspect3.advice",
+      "LastAspect.advice",
+      "LastAspect2.advice"
+       */
    }
 
    public void testVarWrite()
@@ -131,7 +113,19 @@
       System.out.println("*** Invoke field write");
       Interceptions.reset();
       pojo.var = 1;
-      checkInterceptions(PRECEDENCE_ALL);
+      checkInterceptions(10);
+      /* expected something like
+      "FirstInterceptor",
+      "FirstInterceptor2",
+      "SimpleInterceptor",
+      "SimpleInterceptor2",
+      "SimpleInterceptor3",
+      "TestAspect.advice",
+      "TestAspect2.advice",
+      "TestAspect3.advice",
+      "LastAspect.advice",
+      "LastAspect2.advice"
+       */
    }
 
    public void testOneMethod()
@@ -139,60 +133,162 @@
       System.out.println("*** Invoke oneMethod");
       Interceptions.reset();
       pojo.oneMethod();
-      checkInterceptions(PRECEDENCE_ALL);
+      checkInterceptions(10);
+      /* expected something like
+      "FirstInterceptor",
+      "FirstInterceptor2",
+      "SimpleInterceptor",
+      "SimpleInterceptor2",
+      "SimpleInterceptor3",
+      "TestAspect.advice",
+      "TestAspect2.advice",
+      "TestAspect3.advice",
+      "LastAspect.advice",
+      "LastAspect2.advice"
+       */
    }
 
    public void testTwoMethod()
    {
       Interceptions.reset();
       pojo.twoMethod();
-      checkInterceptions(PRECEDENCE_TWO);
+      checkInterceptions(9);
+      /* expected something like
+      "FirstInterceptor",
+      "FirstInterceptor2",
+      "SimpleInterceptor",
+      "TestAspect.advice",
+      "TestAspect.advice2",
+      "TestAspect.advice3",
+      "TestAspect2.advice",
+      "LastAspect.advice",
+      "LastAspect2.advice"
+       */
    }
 
    public void testThreeMethod()
    {
       Interceptions.reset();
       pojo.threeMethod();
-      checkInterceptions(PRECEDENCE_THREE);
+      checkInterceptions(7);
+      /* expected something like
+      "FirstInterceptor",
+      "FirstInterceptor2",
+      "TestAspect.advice",
+      "TestAspect.advice2",
+      "TestAspect.advice3",
+      "LastAspect.advice",
+      "LastAspect2.advice" */
    }
 
    public void testFourMethod()
    {
       Interceptions.reset();
       pojo.fourMethod();
-      checkInterceptions(PRECEDENCE_TWO);
+      checkInterceptions(9);
+      /* expected something like
+      "FirstInterceptor",
+      "FirstInterceptor2",
+      "SimpleInterceptor",
+      "TestAspect.advice",
+      "TestAspect.advice2",
+      "TestAspect.advice3",
+      "TestAspect2.advice",
+      "LastAspect.advice",
+      "LastAspect2.advice"
+       */
    }
 
    public void testFiveMethod()
    {
       Interceptions.reset();
       POJO.factoryMethod();
-      checkInterceptions(PRECEDENCE_THREE);
+      checkInterceptions(7);
+      /* expected something like
+      "FirstInterceptor",
+      "FirstInterceptor2",
+      "TestAspect.advice",
+      "TestAspect.advice2",
+      "TestAspect.advice3",
+      "LastAspect.advice",
+      "LastAspect2.advice" */
    }
 
    public void testSixMethod()
    {
       Interceptions.reset();
       pojo.sixMethod();
-      checkInterceptions(PRECEDENCE_THREE);
+      checkInterceptions(7);
+      /* expected something like
+      "FirstInterceptor",
+      "FirstInterceptor2",
+      "TestAspect.advice",
+      "TestAspect.advice2",
+      "TestAspect.advice3",
+      "LastAspect.advice",
+      "LastAspect2.advice" */
    }
 
    public void testSevenMethod()
    {
       Interceptions.reset();
       pojo.sevenMethod();
-      checkInterceptions(PRECEDENCE_SEVEN);
+      checkInterceptions(6);
+      /* expected something like
+      "SimpleInterceptor",
+      "SimpleInterceptor2",
+      "SimpleInterceptor3",
+      "TestAspect.advice",
+      "TestAspect.advice2",
+      "TestAspect.advice3"*/
    }
 
-   private void checkInterceptions(String[] expected)
+   private void checkInterceptions(int expected)
    {
       ArrayList intercepted = Interceptions.intercepted;
-      assertEquals("Wrong number of interceptions", expected.length ,intercepted.size());
+      assertEquals("Wrong number of interceptions", expected,intercepted.size());
+      // for printing error messages only
+      StringBuffer interceptedAdviceString = new StringBuffer('\"');
+      if (expected > 0)
+      {
+         Iterator<String> iterator = Interceptions.intercepted.iterator();
+         interceptedAdviceString.append('\"').append(iterator.next());
+         while (iterator.hasNext())
+         {
+            interceptedAdviceString.append(", ").append(iterator.next());
+         }
+      }
+      interceptedAdviceString.append('\"');
+      
+      for (Precedence precedence: precedences)
+      {
+         boolean foundSecondAdvice = false;
+         
+         for (String advice: Interceptions.intercepted)
+         {
+            if (advice.equals(precedence.firstAdvice))
+            {
+               // can only have found first advice before second advice
+               assertFalse("Precedence rule not asserted: " + precedence.firstAdvice + 
+                     " is after " + precedence.secondAdvice + " at chain " +
+                     interceptedAdviceString, foundSecondAdvice );
+            }
+            else if (advice.equals(precedence.secondAdvice))
+            {
+               foundSecondAdvice = true;
+            }
+         }
+      }
+   }
 
-      for (int i = 0 ; i < expected.length ; i++)
+   private static class Precedence
+   {
+      public String firstAdvice;
+      public String secondAdvice;
+      public Precedence(String firstAdvice, String secondAdvice)
       {
-         assertEquals("Wrong interception at index " + i, expected[i], (String)intercepted.get(i));
+         this.firstAdvice= firstAdvice;
+         this.secondAdvice= secondAdvice;
       }
    }
-
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list