[jboss-cvs] JBossAS SVN: r73237 - in projects/aop/trunk/aop/src: test/org/jboss/test/aop/beforeafterthrowingscoped and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 9 16:39:55 EDT 2008


Author: flavia.rainone at jboss.com
Date: 2008-05-09 16:39:55 -0400 (Fri, 09 May 2008)
New Revision: 73237

Added:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/NullAspectFactory.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJOWithNullAspect.java
Modified:
   projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/BeforeAfterThrowingScopedTestCase.java
Log:
[JBAOP-560] Tests for this feature have been added to beforeafterthrowingscoped test suite.

Modified: projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml	2008-05-09 20:38:12 UTC (rev 73236)
+++ projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml	2008-05-09 20:39:55 UTC (rev 73237)
@@ -57,7 +57,74 @@
 		<stack-ref name="PER_CLASS"/>
 		<stack-ref name="PER_VM"/>
 	</bind>
+   
+   <!-- NULL ASPECT/INTERCEPTOR FACTORY -->
 
+   <interceptor name="vmNullIFactory" factory="org.jboss.test.aop.beforeafterthrowingscoped.NullAspectFactory"/>
+   <aspect name="vmNullFactory" factory="org.jboss.test.aop.beforeafterthrowingscoped.NullAspectFactory"/>
+   <interceptor name="classNullIFactory" factory="org.jboss.test.aop.beforeafterthrowingscoped.NullAspectFactory" scope="PER_CLASS"/>
+   <aspect name="classNullFactory" factory="org.jboss.test.aop.beforeafterthrowingscoped.NullAspectFactory" scope="PER_CLASS"/>
+   <interceptor name="classJoinpointNullIFactory" factory="org.jboss.test.aop.beforeafterthrowingscoped.NullAspectFactory" scope="PER_CLASS_JOINPOINT"/>
+   <aspect name="classJoinpointNullFactory" factory="org.jboss.test.aop.beforeafterthrowingscoped.NullAspectFactory" scope="PER_CLASS_JOINPOINT"/>
+   <interceptor name="instanceNullIFactory" factory="org.jboss.test.aop.beforeafterthrowingscoped.NullAspectFactory" scope="PER_INSTANCE"/>
+   <aspect name="instanceNullFactory" factory="org.jboss.test.aop.beforeafterthrowingscoped.NullAspectFactory" scope="PER_INSTANCE"/>
+   <interceptor name="joinpointNullIFactory" factory="org.jboss.test.aop.beforeafterthrowingscoped.NullAspectFactory" scope="PER_JOINPOINT"/>
+   <aspect name="joinpointNullFactory" factory="org.jboss.test.aop.beforeafterthrowingscoped.NullAspectFactory" scope="PER_JOINPOINT"/>
+   
+   <stack name="nullFactoryStack">
+      <interceptor-ref name="vmNullIFactory"/>
+      <before aspect="vmNullFactory" name="anyAdvice"/>
+      <around aspect="vmNullFactory" name="anyAdvice"/>
+      <after aspect="vmNullFactory" name="anyAdvice"/>
+      <throwing aspect="vmNullFactory" name="anyAdvice"/>
+      <finally aspect="vmNullFactory" name="anyAdvice"/>
+      <interceptor-ref name="classNullIFactory"/>
+      <before aspect="classNullFactory" name="anyAdvice"/>
+      <around aspect="classNullFactory" name="anyAdvice"/>
+      <after aspect="classNullFactory" name="anyAdvice"/>
+      <throwing aspect="classNullFactory" name="anyAdvice"/>
+      <finally aspect="classNullFactory" name="anyAdvice"/>
+      <interceptor-ref name="classJoinpointNullIFactory"/>
+      <before aspect="classJoinpointNullFactory" name="anyAdvice"/>
+      <around aspect="classJoinpointNullFactory" name="anyAdvice"/>
+      <after aspect="classJoinpointNullFactory" name="anyAdvice"/>
+      <throwing aspect="classJoinpointNullFactory" name="anyAdvice"/>
+      <finally aspect="classJoinpointNullFactory" name="anyAdvice"/>
+      <interceptor-ref name="instanceNullIFactory"/>
+      <before aspect="instanceNullFactory" name="anyAdvice"/>
+      <around aspect="instanceNullFactory" name="anyAdvice"/>
+      <after aspect="instanceNullFactory" name="anyAdvice"/>
+      <throwing aspect="instanceNullFactory" name="anyAdvice"/>
+      <finally aspect="instanceNullFactory" name="anyAdvice"/>
+      <interceptor-ref name="joinpointNullIFactory"/>
+      <before aspect="joinpointNullFactory" name="anyAdvice"/>
+      <around aspect="joinpointNullFactory" name="anyAdvice"/>
+      <after aspect="joinpointNullFactory" name="anyAdvice"/>
+      <throwing aspect="joinpointNullFactory" name="anyAdvice"/>
+      <finally aspect="joinpointNullFactory" name="anyAdvice"/>
+   </stack>
+   
+   <bind pointcut="field(int org.jboss.test.aop.beforeafterthrowingscoped.POJOWithNullAspect->*)">
+      <stack-ref name="nullFactoryStack"/>
+   </bind>
+   
+   <bind pointcut="construction(org.jboss.test.aop.beforeafterthrowingscoped.POJOWithNullAspect->new(..))">
+      <stack-ref name="nullFactoryStack"/>
+   </bind>
+   
+   <bind pointcut="execution(org.jboss.test.aop.beforeafterthrowingscoped.POJOWithNullAspect->new(..))">
+      <stack-ref name="nullFactoryStack"/>
+   </bind>
+   
+   <bind pointcut="execution(* org.jboss.test.aop.beforeafterthrowingscoped.POJOWithNullAspect->*(..))">
+      <stack-ref name="nullFactoryStack"/>
+   </bind>
+   
+   <bind pointcut="execution(* org.jboss.test.aop.beforeafterthrowingscoped.POJOWithNullAspect->mixedMethod(..))">
+      <stack-ref name="nullFactoryStack"/>
+      <stack-ref name="PER_INSTANCE"/>
+   </bind>
+
    <!-- Aspect used to record the caller instance
       (useful when the caller is a constructor that throws an exception) -->
    <aspect class="org.jboss.test.aop.beforeafterthrowingscoped.CallerAspect" scope="PER_VM"/>

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/BeforeAfterThrowingScopedTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/BeforeAfterThrowingScopedTestCase.java	2008-05-09 20:38:12 UTC (rev 73236)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/BeforeAfterThrowingScopedTestCase.java	2008-05-09 20:39:55 UTC (rev 73237)
@@ -949,6 +949,41 @@
       assertEquals(pv1, PerVmAspect.before);
    }
    
+   public void testNullAspectFactory() throws Exception
+   {
+      // check that all joinpoints execute without exceptions
+      int value = POJOWithNullAspect.staticField;
+      POJOWithNullAspect.staticField = value + 1;
+      POJOWithNullAspect.staticMethod();
+      POJOWithNullAspect pojo = new POJOWithNullAspect();
+      value += pojo.field;
+      pojo.field = value - 10;
+      pojo.method();
+      
+      // check that mixed method does get correctly intercepted without errors
+      PerInstanceAspect.reset();
+      pojo.mixedMethod(false);
+      assertNotNull(PerInstanceAspect.before);
+      assertNotNull(PerInstanceAspect.after);
+      assertNull(PerInstanceAspect.throwing);
+      assertNotNull(PerInstanceAspect.finaly);
+      PerInstanceAspect.reset();
+      boolean thrown = false;
+      try
+      {
+         pojo.mixedMethod(true);
+      }
+      catch(Exception e)
+      {
+         thrown = true;
+      }
+      assertTrue(thrown);
+      assertNotNull(PerInstanceAspect.before);
+      assertNull(PerInstanceAspect.after);
+      assertNotNull(PerInstanceAspect.throwing);
+      assertNotNull(PerInstanceAspect.finaly);
+   }
    
+   
    //PER_JOINPOINT should act like PER_CLASS_JOINPOINT for static fields and methods  
 }

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/NullAspectFactory.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/NullAspectFactory.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/NullAspectFactory.java	2008-05-09 20:39:55 UTC (rev 73237)
@@ -0,0 +1,68 @@
+/*
+ * 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.beforeafterthrowingscoped;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.InstanceAdvisor;
+import org.jboss.aop.advice.AspectFactory;
+import org.jboss.aop.joinpoint.Joinpoint;
+
+/**
+ * AspectFactory that returns {@code null} instances for all scopes.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ */
+public class NullAspectFactory implements AspectFactory
+{
+
+   public Object createPerClass(Advisor advisor)
+   {
+      return null;
+   }
+
+   public Object createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor)
+   {
+      return null;
+   }
+
+   public Object createPerJoinpoint(Advisor advisor, Joinpoint jp)
+   {
+      return null;
+   }
+
+   public Object createPerJoinpoint(Advisor advisor,
+         InstanceAdvisor instanceAdvisor, Joinpoint jp)
+   {
+      return null;
+   }
+
+   public Object createPerVM()
+   {
+      return null;
+   }
+
+   public String getName()
+   {
+      return null;
+   }
+}
\ No newline at end of file

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJOWithNullAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJOWithNullAspect.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJOWithNullAspect.java	2008-05-09 20:39:55 UTC (rev 73237)
@@ -0,0 +1,45 @@
+/*
+ * 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.beforeafterthrowingscoped;
+
+/**
+ * Plain old java object for testing of {@code NullAspectFactory}.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class POJOWithNullAspect
+{
+   public int field;
+   public static int staticField;
+   public POJOWithNullAspect() {}
+   public void method() {}
+   public static void staticMethod() {}
+   // method that will be intercepted by both normal aspects and
+   // NullAspectFactories
+   public void mixedMethod(boolean throwException) throws Exception
+   {
+      if (throwException)
+      {
+         throw new Exception();
+      }
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list