[jboss-cvs] JBossAS SVN: r72273 - in projects/ejb3/trunk/interceptors/src/test: java/org/jboss/ejb3/test/interceptors/defaultinterceptors and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 16 08:20:29 EDT 2008


Author: kabir.khan at jboss.com
Date: 2008-04-16 08:20:29 -0400 (Wed, 16 Apr 2008)
New Revision: 72273

Added:
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/AnnotatedBean.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/ClassInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/DefaultInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/Interceptions.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/MethodInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/unit/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/unit/DefaultInterceptorsTestCase.java
   projects/ejb3/trunk/interceptors/src/test/resources/defaultinterceptors/
   projects/ejb3/trunk/interceptors/src/test/resources/defaultinterceptors/META-INF/
   projects/ejb3/trunk/interceptors/src/test/resources/defaultinterceptors/META-INF/ejb-jar.xml
Log:
Add test for default interceptors 

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/AnnotatedBean.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/AnnotatedBean.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/AnnotatedBean.java	2008-04-16 12:20:29 UTC (rev 72273)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.ejb3.test.interceptors.defaultinterceptors;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Interceptors(ClassInterceptor.class)
+public class AnnotatedBean
+{
+   @Interceptors(MethodInterceptor.class)
+   public int defaultOrderMethod()
+   {
+      return 100;
+   }
+   
+   @Interceptors(MethodInterceptor.class)
+   public int xmlOrderedMethod()
+   {
+      return 200;
+   }
+   
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext ctx) throws Exception
+   {
+      Interceptions.add(this);
+      return ctx.proceed();
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/ClassInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/ClassInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/ClassInterceptor.java	2008-04-16 12:20:29 UTC (rev 72273)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.ejb3.test.interceptors.defaultinterceptors;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassInterceptor
+{
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext ctx) throws Exception
+   {
+      Interceptions.add(this);
+      return ctx.proceed();
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/DefaultInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/DefaultInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/DefaultInterceptor.java	2008-04-16 12:20:29 UTC (rev 72273)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.ejb3.test.interceptors.defaultinterceptors;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultInterceptor
+{
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext ctx) throws Exception
+   {
+      Interceptions.add(this);
+      return ctx.proceed();
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/Interceptions.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/Interceptions.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/Interceptions.java	2008-04-16 12:20:29 UTC (rev 72273)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.ejb3.test.interceptors.defaultinterceptors;
+
+import java.util.ArrayList;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Interceptions
+{
+   private static ArrayList<Class<?>> interceptions = new ArrayList<Class<?>>();
+   
+   public static void add(Object icptr)
+   {
+      interceptions.add(icptr.getClass());
+   }
+   
+   public static void clear()
+   {
+      interceptions.clear();
+   }
+   
+   public static ArrayList<Class<?>> getInterceptions()
+   {
+      return interceptions;
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/MethodInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/MethodInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/MethodInterceptor.java	2008-04-16 12:20:29 UTC (rev 72273)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.ejb3.test.interceptors.defaultinterceptors;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class MethodInterceptor
+{
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext ctx) throws Exception
+   {
+      Interceptions.add(this);
+      return ctx.proceed();
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/unit/DefaultInterceptorsTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/unit/DefaultInterceptorsTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/defaultinterceptors/unit/DefaultInterceptorsTestCase.java	2008-04-16 12:20:29 UTC (rev 72273)
@@ -0,0 +1,175 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.ejb3.test.interceptors.defaultinterceptors.unit;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.ejb3.interceptors.container.BeanContext;
+import org.jboss.ejb3.interceptors.direct.AbstractDirectContainer;
+import org.jboss.ejb3.interceptors.metadata.BeanInterceptorMetaDataBridge;
+import org.jboss.ejb3.interceptors.metadata.InterceptorComponentMetaDataLoaderFactory;
+import org.jboss.ejb3.interceptors.metadata.InterceptorMetaDataBridge;
+import org.jboss.ejb3.metadata.MetaDataBridge;
+import org.jboss.ejb3.metadata.annotation.AnnotationRepositoryToMetaData;
+import org.jboss.ejb3.test.interceptors.common.AOPDeployer;
+import org.jboss.ejb3.test.interceptors.defaultinterceptors.AnnotatedBean;
+import org.jboss.ejb3.test.interceptors.defaultinterceptors.ClassInterceptor;
+import org.jboss.ejb3.test.interceptors.defaultinterceptors.DefaultInterceptor;
+import org.jboss.ejb3.test.interceptors.defaultinterceptors.Interceptions;
+import org.jboss.ejb3.test.interceptors.defaultinterceptors.MethodInterceptor;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.spec.EjbJar30MetaData;
+import org.jboss.metadata.ejb.spec.InterceptorMetaData;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.jboss.xb.builder.JBossXBBuilder;
+import org.w3c.dom.ls.LSInput;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultInterceptorsTestCase extends TestCase
+{
+   private static final Logger log = Logger.getLogger(DefaultInterceptorsTestCase.class);
+   
+   private class MyContainer<T> extends AbstractDirectContainer<T, MyContainer<T>>
+   {
+      public MyContainer(String name, String domainName, Class<? extends T> beanClass, JBossEnterpriseBeanMetaData beanMetaData)
+      {
+         super();
+         
+         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+         AnnotationRepositoryToMetaData annotations = new AnnotationRepositoryToMetaData(beanClass, beanMetaData, name, classLoader);
+         List<MetaDataBridge<InterceptorMetaData>> interceptorBridges = new ArrayList<MetaDataBridge<InterceptorMetaData>>();
+         interceptorBridges.add(new InterceptorMetaDataBridge());
+         annotations.addComponentMetaDataLoaderFactory(new InterceptorComponentMetaDataLoaderFactory(interceptorBridges));
+         annotations.addMetaDataBridge(new BeanInterceptorMetaDataBridge());
+         
+         initializeAdvisor(name, getDomain(domainName), beanClass, annotations);
+      }
+
+      public void testAdvisor()
+      {
+         MyContainer<?> container = getAdvisor().getContainer();
+         assertNotNull("container not set in managed object advisor", container);
+         assertTrue(container == this);
+      }
+   }
+   
+   protected static SchemaBindingResolver schemaResolverForClass(final Class<?> root)
+   {
+      return new SchemaBindingResolver()
+      {
+         public String getBaseURI()
+         {
+            return null;
+         }
+
+         public SchemaBinding resolve(String nsUri, String baseURI, String schemaLocation)
+         {
+            return JBossXBBuilder.build(root);
+         }
+
+         public LSInput resolveAsLSInput(String nsUri, String baseUri, String schemaLocation)
+         {
+            return null;
+         }
+
+         public void setBaseURI(String baseURI)
+         {
+         }
+      };
+   }
+
+   // FIXME: use the right jboss-aop.xml
+   AOPDeployer deployer = new AOPDeployer("proxy/jboss-aop.xml");
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      log.info(deployer.deploy());
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      log.info(deployer.undeploy());
+   }
+   
+   public void test() throws Throwable
+   {
+      AspectManager.verbose = true;
+      
+      // To make surefire happy
+      Thread.currentThread().setContextClassLoader(AnnotatedBean.class.getClassLoader());
+      
+      // Bootstrap metadata
+      UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+      Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+      URL url = Thread.currentThread().getContextClassLoader().getResource("defaultinterceptors/META-INF/ejb-jar.xml");
+      EjbJar30MetaData metaData = (EjbJar30MetaData) unmarshaller.unmarshal(url.toString(), schemaResolverForClass(EjbJar30MetaData.class));
+      JBoss50MetaData jbossMetaData = new JBoss50MetaData();
+      jbossMetaData.merge(null, metaData);
+      
+      JBossEnterpriseBeanMetaData beanMetaData = jbossMetaData.getEnterpriseBean("AnnotatedBean");
+      assertNotNull(beanMetaData);
+      
+      MyContainer<AnnotatedBean> container = new MyContainer<AnnotatedBean>("AnnotatedBean", "Test", AnnotatedBean.class, beanMetaData);
+      container.testAdvisor();
+      
+      BeanContext<AnnotatedBean> bean = container.construct();
+
+      Interceptions.clear();
+      container.invoke(bean, "defaultOrderMethod", new Object[0]);
+      ArrayList<Class<?>> interceptions = Interceptions.getInterceptions();
+      assertEquals(4, interceptions.size());
+      assertEquals(DefaultInterceptor.class, interceptions.get(0));
+      assertEquals(ClassInterceptor.class, interceptions.get(1));
+      assertEquals(MethodInterceptor.class, interceptions.get(2));
+      assertEquals(AnnotatedBean.class, interceptions.get(3));
+      
+
+      Interceptions.clear();
+      container.invoke(bean, "xmlOrderedMethod", new Object[0]);
+      interceptions = Interceptions.getInterceptions();
+      assertEquals(4, interceptions.size());      
+      assertEquals(MethodInterceptor.class, interceptions.get(0));
+      assertEquals(ClassInterceptor.class, interceptions.get(1));
+      assertEquals(DefaultInterceptor.class, interceptions.get(2));
+      assertEquals(AnnotatedBean.class, interceptions.get(3));
+      
+      log.info("======= Done");
+   }
+   
+}

Added: projects/ejb3/trunk/interceptors/src/test/resources/defaultinterceptors/META-INF/ejb-jar.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/defaultinterceptors/META-INF/ejb-jar.xml	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/resources/defaultinterceptors/META-INF/ejb-jar.xml	2008-04-16 12:20:29 UTC (rev 72273)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ejb-jar
+        xmlns="http://java.sun.com/xml/ns/javaee"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+                            http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
+        version="3.0">
+    <display-name>InterceptorsTest</display-name>
+    <!-- Must define a bean here, because we have no annotation on it -->
+    <!-- (Can't use @Stateless within ejb3-interceptors) -->
+    <enterprise-beans>
+    	<session>
+    		<ejb-name>AnnotatedBean</ejb-name>
+    	</session>
+    </enterprise-beans>
+    <assembly-descriptor>
+      <interceptor-binding>
+         <ejb-name>*</ejb-name>
+         <interceptor-class>org.jboss.ejb3.test.interceptors.defaultinterceptors.DefaultInterceptor</interceptor-class>
+      </interceptor-binding>
+      <interceptor-binding>
+         <ejb-name>AnnotatedBean</ejb-name>
+         <interceptor-order>
+            <interceptor-class>org.jboss.ejb3.test.interceptors.defaultinterceptors.MethodInterceptor</interceptor-class>
+            <interceptor-class>org.jboss.ejb3.test.interceptors.defaultinterceptors.ClassInterceptor</interceptor-class>
+            <interceptor-class>org.jboss.ejb3.test.interceptors.defaultinterceptors.DefaultInterceptor</interceptor-class>
+         </interceptor-order>
+         <method>
+            <method-name>xmlOrderedMethod</method-name>
+         </method>
+      </interceptor-binding>
+    </assembly-descriptor>
+</ejb-jar>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list