[jboss-cvs] JBossAS SVN: r107990 - in projects/interceptors/trunk: jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Sep 5 03:56:26 EDT 2010


Author: jaikiran
Date: 2010-09-05 03:56:26 -0400 (Sun, 05 Sep 2010)
New Revision: 107990

Added:
   projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/InterceptorWithPostConstructAndAroundInvoke.java
   projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/NotAnInterceptor.java
Modified:
   projects/interceptors/trunk/jboss-interceptor-core/src/main/java/org/jboss/interceptor/reader/SimpleInterceptorMetadata.java
   projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/InterceptorClassMetadataTestCase.java
   projects/interceptors/trunk/jboss-interceptor-spi/src/main/java/org/jboss/interceptor/spi/metadata/InterceptorMetadata.java
Log:
JBINTER-15 and JBINTER-16 : Added getInterceptorClass() and isEligible() methods on InterceptorMetadata along with the relevant testcases

Modified: projects/interceptors/trunk/jboss-interceptor-core/src/main/java/org/jboss/interceptor/reader/SimpleInterceptorMetadata.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor-core/src/main/java/org/jboss/interceptor/reader/SimpleInterceptorMetadata.java	2010-09-04 15:38:13 UTC (rev 107989)
+++ projects/interceptors/trunk/jboss-interceptor-core/src/main/java/org/jboss/interceptor/reader/SimpleInterceptorMetadata.java	2010-09-05 07:56:26 UTC (rev 107990)
@@ -49,6 +49,14 @@
       this.interceptorMethodMap = interceptorMethodMap;
    }
 
+   /**
+    * {@inheritDoc}
+    */
+   public ClassMetadata<?> getInterceptorClass()
+   {
+      return this.interceptorClass;
+   }
+   
    public List<MethodMetadata> getInterceptorMethods(InterceptionType interceptionType)
    {
       if (interceptorMethodMap != null)
@@ -66,6 +74,20 @@
    {
       return targetClass;
    }
+   
+   /**
+    * {@inheritDoc}
+    */
+   public boolean isEligible(InterceptionType interceptionType)
+   {
+      if (this.interceptorMethodMap == null)
+      {
+         return false;
+      }
+      List<MethodMetadata> interceptorMethods = this.interceptorMethodMap.get(interceptionType);
+      // return true if there are any interceptor methods for this interception type
+      return interceptorMethods != null && interceptorMethods.isEmpty() == false;
+   }
 
    private Object writeReplace()
    {

Modified: projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/InterceptorClassMetadataTestCase.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/InterceptorClassMetadataTestCase.java	2010-09-04 15:38:13 UTC (rev 107989)
+++ projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/InterceptorClassMetadataTestCase.java	2010-09-05 07:56:26 UTC (rev 107990)
@@ -20,8 +20,11 @@
 
 import java.util.List;
 
+import junit.framework.Assert;
+
 import org.jboss.interceptor.reader.InterceptorMetadataUtils;
 import org.jboss.interceptor.reader.ReflectiveClassMetadata;
+import org.jboss.interceptor.spi.metadata.ClassMetadata;
 import org.jboss.interceptor.spi.metadata.InterceptorMetadata;
 import org.jboss.interceptor.spi.metadata.MethodMetadata;
 import org.jboss.interceptor.spi.model.InterceptionType;
@@ -143,6 +146,54 @@
 
    }
 
+   /**
+    * Tests that the {@link InterceptorMetadata#isEligible(InterceptionType)} method works 
+    * as expected against interceptors with different {@link InterceptionType}s
+    */
+   @Test
+   public void testEligibilityForInterceptionType()
+   {
+      // test an interceptor which has interceptor methods for all InterceptionTypes
+      InterceptorMetadata interceptorWithAllInterceptionTypes = InterceptorMetadataUtils.readMetadataForInterceptorClass(ReflectiveClassMetadata.of(InterceptorWithAllMethods.class));
+      
+      Assert.assertTrue("Interceptor was expected to be eligible for: " + InterceptionType.POST_CONSTRUCT, interceptorWithAllInterceptionTypes.isEligible(InterceptionType.POST_CONSTRUCT));
+      Assert.assertTrue("Interceptor was expected to be eligible for: " + InterceptionType.PRE_DESTROY, interceptorWithAllInterceptionTypes.isEligible(InterceptionType.PRE_DESTROY));
+      Assert.assertTrue("Interceptor was expected to be eligible for: " + InterceptionType.PRE_PASSIVATE, interceptorWithAllInterceptionTypes.isEligible(InterceptionType.PRE_PASSIVATE));
+      Assert.assertTrue("Interceptor was expected to be eligible for: " + InterceptionType.POST_ACTIVATE, interceptorWithAllInterceptionTypes.isEligible(InterceptionType.POST_ACTIVATE));
+      Assert.assertTrue("Interceptor was expected to be eligible for: " + InterceptionType.AROUND_INVOKE, interceptorWithAllInterceptionTypes.isEligible(InterceptionType.AROUND_INVOKE));
+   
+      // now test an interceptor which has interceptor methods for only a few InterceptionTypes
+      InterceptorMetadata interceptorWithAroundInvokeAndPostConstruct = InterceptorMetadataUtils.readMetadataForInterceptorClass(ReflectiveClassMetadata.of(InterceptorWithPostConstructAndAroundInvoke.class));
+      Assert.assertTrue("Interceptor was expected to be eligible for: " + InterceptionType.POST_CONSTRUCT, interceptorWithAroundInvokeAndPostConstruct.isEligible(InterceptionType.POST_CONSTRUCT));
+      Assert.assertTrue("Interceptor was expected to be eligible for: " + InterceptionType.AROUND_INVOKE, interceptorWithAroundInvokeAndPostConstruct.isEligible(InterceptionType.AROUND_INVOKE));
+      Assert.assertFalse("Interceptor was expected to be ineligible for: " + InterceptionType.PRE_DESTROY, interceptorWithAroundInvokeAndPostConstruct.isEligible(InterceptionType.PRE_DESTROY));
+      Assert.assertFalse("Interceptor was expected to be ineligible for: " + InterceptionType.PRE_PASSIVATE, interceptorWithAroundInvokeAndPostConstruct.isEligible(InterceptionType.PRE_PASSIVATE));
+      Assert.assertFalse("Interceptor was expected to be ineligible for: " + InterceptionType.POST_ACTIVATE, interceptorWithAroundInvokeAndPostConstruct.isEligible(InterceptionType.POST_ACTIVATE));
+      
+      
+      // test with a simple class which isn't eligible for any of the interception types
+      InterceptorMetadata notAnInterceptor = InterceptorMetadataUtils.readMetadataForInterceptorClass(ReflectiveClassMetadata.of(NotAnInterceptor.class));
+      Assert.assertFalse("Interceptor was expected to be ineligible for: " + InterceptionType.POST_CONSTRUCT, notAnInterceptor.isEligible(InterceptionType.POST_CONSTRUCT));
+      Assert.assertFalse("Interceptor was expected to be ineligible for: " + InterceptionType.AROUND_INVOKE, notAnInterceptor.isEligible(InterceptionType.AROUND_INVOKE));
+      Assert.assertFalse("Interceptor was expected to be ineligible for: " + InterceptionType.PRE_DESTROY, notAnInterceptor.isEligible(InterceptionType.PRE_DESTROY));
+      Assert.assertFalse("Interceptor was expected to be ineligible for: " + InterceptionType.PRE_PASSIVATE, notAnInterceptor.isEligible(InterceptionType.PRE_PASSIVATE));
+      Assert.assertFalse("Interceptor was expected to be ineligible for: " + InterceptionType.POST_ACTIVATE, notAnInterceptor.isEligible(InterceptionType.POST_ACTIVATE));
 
+      
+   }
 
+   /**
+    * Tests that the {@link InterceptorMetadata#getInterceptorClass()} returns the correct
+    * {@link ClassMetadata}
+    */
+   @Test
+   public void testInterceptorClassMetaData()
+   {
+      InterceptorMetadata interceptorWithAllInterceptionTypes = InterceptorMetadataUtils.readMetadataForInterceptorClass(ReflectiveClassMetadata.of(InterceptorWithAllMethods.class));
+      
+      ClassMetadata<?> interceptorClass = interceptorWithAllInterceptionTypes.getInterceptorClass();
+      Assert.assertNotNull("ClassMetadata not found on interceptor metadata created out of class: " + InterceptorWithAllMethods.class, interceptorClass);
+      Assert.assertEquals("Unexpected ClassMetadata found on interceptor metadata created out of class: " + InterceptorWithAllMethods.class, InterceptorWithAllMethods.class.getName(), interceptorClass.getClassName());
+   }
+
 }

Added: projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/InterceptorWithPostConstructAndAroundInvoke.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/InterceptorWithPostConstructAndAroundInvoke.java	                        (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/InterceptorWithPostConstructAndAroundInvoke.java	2010-09-05 07:56:26 UTC (rev 107990)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.interceptors.metadata;
+
+import javax.annotation.PostConstruct;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * InterceptorWithPostConstructAndAroundInvoke
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class InterceptorWithPostConstructAndAroundInvoke
+{
+
+   @PostConstruct
+   public void postConstruct(InvocationContext ctx)
+   {
+
+   }
+
+   @AroundInvoke
+   public Object around(InvocationContext ctx) throws Exception
+   {
+      return ctx.proceed();
+   }
+}

Added: projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/NotAnInterceptor.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/NotAnInterceptor.java	                        (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor-core/src/test/java/org/jboss/interceptors/metadata/NotAnInterceptor.java	2010-09-05 07:56:26 UTC (rev 107990)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.interceptors.metadata;
+
+/**
+ * NotAnInterceptor
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class NotAnInterceptor
+{
+
+}

Modified: projects/interceptors/trunk/jboss-interceptor-spi/src/main/java/org/jboss/interceptor/spi/metadata/InterceptorMetadata.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor-spi/src/main/java/org/jboss/interceptor/spi/metadata/InterceptorMetadata.java	2010-09-04 15:38:13 UTC (rev 107989)
+++ projects/interceptors/trunk/jboss-interceptor-spi/src/main/java/org/jboss/interceptor/spi/metadata/InterceptorMetadata.java	2010-09-05 07:56:26 UTC (rev 107990)
@@ -27,6 +27,13 @@
 public interface InterceptorMetadata
 {
    /**
+    * Returns the class for which this interceptor metadata was created 
+    * 
+    * @return
+    */
+   ClassMetadata<?> getInterceptorClass();
+   
+   /**
     * Returns the list of interceptor methods of this class for a given 
     * interception type.
     *
@@ -34,6 +41,15 @@
     * @return a list of methods
     */
    List<MethodMetadata> getInterceptorMethods(InterceptionType interceptionType);
+   
+   /**
+    * Returns true if the interceptor corresponding to this {@link InterceptorMetadata}
+    * has interceptor methods for the given <code>interceptionType</code>. Else returns false.
+    *   
+    * @param interceptionType The {@link InterceptionType}
+    * @return
+    */
+   boolean isEligible(InterceptionType interceptionType);
 
    boolean isTargetClass();
 }



More information about the jboss-cvs-commits mailing list