[jboss-cvs] JBossAS SVN: r74311 - in projects/metadata/trunk/src: test/java/org/jboss/test/metadata/jbmeta40/unit and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 9 11:13:24 EDT 2008


Author: emuckenhuber
Date: 2008-06-09 11:13:24 -0400 (Mon, 09 Jun 2008)
New Revision: 74311

Added:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/ImplicitLocalProcessor.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta40/unit/JBossImplicitLocalIntefaceUnitTestCase.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta41/unit/JBossProcessingUnitTestCase.java
Modified:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractSessionBeanProcessor.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta40/unit/ImplicitLocalIntefaceUnitTestCase.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta41/unit/HomeProcessingUnitTestCase.java
Log:
[JBMETA-45] missing processor for jboss50creator

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractSessionBeanProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractSessionBeanProcessor.java	2008-06-09 13:35:03 UTC (rev 74310)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractSessionBeanProcessor.java	2008-06-09 15:13:24 UTC (rev 74311)
@@ -55,6 +55,7 @@
       addTypeProcessor(new LocalHomeProcessor(finder));
       addTypeProcessor(new RemoteProcessor(finder));
       addTypeProcessor(new RemoteHomeProcessor(finder));
+      addTypeProcessor(new ImplicitLocalProcessor(finder));
 
       addMethodProcessor(new InitProcessor(finder));
       addMethodProcessor(new TimeoutProcessor(finder));

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/ImplicitLocalProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/ImplicitLocalProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/ImplicitLocalProcessor.java	2008-06-09 15:13:24 UTC (rev 74311)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.metadata.annotation.creator.ejb.jboss;
+
+import java.io.Externalizable;
+import java.io.Serializable;
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.EJBLocalObject;
+import javax.ejb.Remote;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
+
+/**
+ * Process the implicit local business interface (4.6.6)
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ImplicitLocalProcessor extends AbstractFinderUser implements Processor<JBossSessionBeanMetaData, Class<?>>
+{
+
+   public ImplicitLocalProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   public void process(JBossSessionBeanMetaData metaData, Class<?> type)
+   {
+      
+      // If there are already local business interfaces specified
+      if(metaData.getBusinessLocals() != null && metaData.getBusinessLocals().size() > 0)
+         return;
+      
+      // If there are already remote business interfaces specified
+      if(metaData.getBusinessRemotes() != null && metaData.getBusinessRemotes().size() > 0)
+         return;
+      
+      // Don't check super class
+      if(!metaData.getEjbClass().equals(type.getName()))
+         return;
+      
+      // Get the a single interface
+      Class<?> businessInterface = extractInterface(type.getInterfaces());
+      if(businessInterface == null)
+         return;
+      
+      // Check if the interface is a remote one      
+      Remote remote = finder.getAnnotation(businessInterface, Remote.class);
+      if(remote != null)
+         return;
+      
+      // A business interface must not extend EJBLocalObject
+      if(EJBLocalObject.class.isAssignableFrom(businessInterface))
+         throw new IllegalStateException("EJB 3.0 Core Specification Violation (4.6.6): The session bean’s business interface "+ businessInterface + " must not extend the javax.ejb.EJBLocalObject interface.");
+      
+      // Add this businessInterface as the local business interface
+      if(metaData.getBusinessLocals() == null)
+         metaData.setBusinessLocals(new BusinessLocalsMetaData());
+      
+      // Finally add local business interface
+      metaData.getBusinessLocals().add(businessInterface.getName());
+   }
+   
+   /**
+    * Extracts a single interface.
+    * 
+    * @param interfaces
+    * @return The extracted interface class. null if there are none or more interfaces
+    */
+   private static Class<?> extractInterface(Class<?>... interfaces)
+   {
+      Class<?> iFace = null;
+      for(Class<?> candidate : interfaces)
+      {
+         // Ignore specific interfaces
+         if(Serializable.class.equals(candidate))
+            continue;
+         else if (Externalizable.class.equals(candidate))
+            continue;
+         else if (candidate.getName().startsWith("javax.ejb"))
+            continue;
+         else if (candidate.getName().startsWith("org.jboss.aop"))
+            continue;
+         else
+         {
+            // Just allow one interface otherwise return null
+            if(iFace == null)
+               iFace = candidate;
+            else
+               return null;
+         }
+      }
+      return iFace;
+   }
+}
\ No newline at end of file

Modified: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta40/unit/ImplicitLocalIntefaceUnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta40/unit/ImplicitLocalIntefaceUnitTestCase.java	2008-06-09 13:35:03 UTC (rev 74310)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta40/unit/ImplicitLocalIntefaceUnitTestCase.java	2008-06-09 15:13:24 UTC (rev 74311)
@@ -39,6 +39,8 @@
 import org.jboss.test.metadata.jbmeta40.RemoteInterface;
 
 /**
+ * Test implicit home interfaces (Ejb30Creator)
+ * 
  * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
  * @version $Revision$
  */

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta40/unit/JBossImplicitLocalIntefaceUnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta40/unit/JBossImplicitLocalIntefaceUnitTestCase.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta40/unit/JBossImplicitLocalIntefaceUnitTestCase.java	2008-06-09 15:13:24 UTC (rev 74311)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.metadata.jbmeta40.unit;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.test.metadata.common.PackageScanner;
+import org.jboss.test.metadata.common.ScanPackage;
+import org.jboss.test.metadata.jbmeta40.ExpectedLocalInterface;
+import org.jboss.test.metadata.jbmeta40.OtherInterface;
+import org.jboss.test.metadata.jbmeta40.RemoteInterface;
+
+/**
+ * Test implicit home interfaces (JBoss50Creator)
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class JBossImplicitLocalIntefaceUnitTestCase extends TestCase
+{
+
+   private JBoss50MetaData jbossMetaData;
+   
+   @Override
+   @ScanPackage("org.jboss.test.metadata.jbmeta40")
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+
+      Collection<Class<?>> classes = PackageScanner.loadClasses();
+      
+      //enableTrace("org.jboss.metadata.annotation.creator");
+      JBoss50Creator creator = new JBoss50Creator(finder);
+
+      jbossMetaData = creator.create(classes);
+
+      assertTrue(jbossMetaData.isEJB3x());
+      assertEquals("3.0", jbossMetaData.getVersion());
+
+      assertNotNull("no beans defined", jbossMetaData.getEnterpriseBeans());
+   }
+   
+   public void testExpectedLocal()
+   {
+      JBossSessionBeanMetaData sb = (JBossSessionBeanMetaData) jbossMetaData.getEnterpriseBean("MyBean");
+      assertNotNull(sb);
+      assertEquals(1, sb.getBusinessLocals().size());
+      assertTrue( sb.getBusinessLocals().contains(ExpectedLocalInterface.class.getName()));
+      assertNull(sb.getBusinessRemotes());
+   }
+   
+   public void testRemoteInterface()
+   {
+      JBossSessionBeanMetaData sb = (JBossSessionBeanMetaData) jbossMetaData.getEnterpriseBean("RemoteBean");
+      assertNotNull(sb);
+      assertNull(sb.getBusinessLocals());
+   }
+   
+   public void testAnotherStatelessBean()
+   {
+      JBossSessionBeanMetaData sb = (JBossSessionBeanMetaData) jbossMetaData.getEnterpriseBean("AnotherStatelessBean");
+      assertNotNull(sb);
+      assertNull(sb.getBusinessLocals());
+      assertNull(sb.getBusinessRemotes());
+   }
+   
+   public void testMyOtherBean()
+   {
+      JBossSessionBeanMetaData sb = (JBossSessionBeanMetaData) jbossMetaData.getEnterpriseBean("MyOtherBean");
+      assertNotNull(sb);
+      assertNull(sb.getBusinessLocals());
+      assertNotNull(sb.getBusinessRemotes());
+   }
+   
+   public void testMyStatelessBean()
+   {
+      JBossSessionBeanMetaData sb = (JBossSessionBeanMetaData) jbossMetaData.getEnterpriseBean("MyStatelessBean");
+      assertNotNull(sb);
+      assertNotNull(sb.getBusinessLocals());
+      assertTrue(sb.getBusinessLocals().contains(ExpectedLocalInterface.class.getName()));
+      assertFalse(sb.getBusinessLocals().contains(OtherInterface.class.getName()));
+      assertNotNull(sb.getBusinessRemotes());
+      assertTrue(sb.getBusinessRemotes().contains(RemoteInterface.class.getName()));
+   }
+}
+

Modified: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta41/unit/HomeProcessingUnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta41/unit/HomeProcessingUnitTestCase.java	2008-06-09 13:35:03 UTC (rev 74310)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta41/unit/HomeProcessingUnitTestCase.java	2008-06-09 15:13:24 UTC (rev 74311)
@@ -48,6 +48,7 @@
 
 /**
  * Test processing of the local and remote business interfaces of a EJB 2.x Local/Remote Home
+ * (EJB30Creator)
  * 
  * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
  * @version $Revision$

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta41/unit/JBossProcessingUnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta41/unit/JBossProcessingUnitTestCase.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta41/unit/JBossProcessingUnitTestCase.java	2008-06-09 15:13:24 UTC (rev 74311)
@@ -0,0 +1,168 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.metadata.jbmeta41.unit;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.Collection;
+import java.util.HashSet;
+
+import junit.framework.TestCase;
+
+import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.test.metadata.common.PackageScanner;
+import org.jboss.test.metadata.jbmeta41.MultipleReturnTypeBean;
+import org.jboss.test.metadata.jbmeta41.MyFailingStatelessBean;
+import org.jboss.test.metadata.jbmeta41.MyOtherFailingStateLessBean;
+import org.jboss.test.metadata.jbmeta41.MyStateful21Local;
+import org.jboss.test.metadata.jbmeta41.MyStateful21Remote;
+import org.jboss.test.metadata.jbmeta41.MyStatefulBean;
+import org.jboss.test.metadata.jbmeta41.WrongCreateStatelessBean;
+import org.jboss.test.metadata.jbmeta42.MyStateless21Local;
+import org.jboss.test.metadata.jbmeta42.MyStateless21Remote;
+import org.jboss.test.metadata.jbmeta42.MyStatelessLocal;
+import org.jboss.test.metadata.jbmeta42.MyStatelessRemote;
+
+/**
+ * Test processing of the local and remote business interfaces of a EJB 2.x Local/Remote Home
+ * (JBoss50Creator)
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class JBossProcessingUnitTestCase extends TestCase
+{
+      
+   public void testStatelessHomeandLocalHome()
+   {
+      Collection<Class<?>> classes = PackageScanner.loadClasses("org.jboss.test.metadata.jbmeta42");
+      
+      JBossSessionBeanMetaData sessionBeanMetaData = getSessionBeanMetaData(classes, "MyStatelessBean");
+      assertNotNull(sessionBeanMetaData);
+      
+      // Check if EjbHome and EjbLocalHome are defined
+      assertEquals(MyStateless21Local.class.getName(), sessionBeanMetaData.getLocal());
+      assertEquals(MyStateless21Remote.class.getName(), sessionBeanMetaData.getRemote());
+      
+      // 
+      assertTrue(sessionBeanMetaData.getBusinessLocals().contains(MyStatelessLocal.class.getName()));
+      assertFalse(sessionBeanMetaData.getBusinessLocals().contains(MyStateless21Local.class.getName()));
+      
+      assertTrue(sessionBeanMetaData.getBusinessRemotes().contains(MyStatelessRemote.class.getName()));
+      assertFalse(sessionBeanMetaData.getBusinessRemotes().contains(MyStateless21Remote.class.getName()));
+   }
+   
+   public void testStatefulHomeandLocalHome()
+   {
+      Collection<Class<?>> classes = new HashSet<Class<?>>();
+      classes.add(MyStatefulBean.class);
+      
+      JBossSessionBeanMetaData sessionBeanMetaData = getSessionBeanMetaData(classes, "MyStatefulBean");
+      assertNotNull(sessionBeanMetaData);
+      
+      //
+      assertEquals(MyStateful21Local.class.getName(), sessionBeanMetaData.getLocal());
+      assertEquals(MyStateful21Remote.class.getName(), sessionBeanMetaData.getRemote());
+   }
+   
+   // Test multiple create methods on a stateless bean 
+   public void testMyFailingStatelessBean()
+   {
+      try
+      {
+         Collection<Class<?>> classes = new HashSet<Class<?>>();
+         classes.add(MyFailingStatelessBean.class);
+         
+         getSessionBeanMetaData(classes, "MyFailingStatelessBean");
+         fail("A stateless session bean must define exactly one create method with no arguments");
+      }
+      catch(Exception e)
+      {
+         // ok
+      }
+   }
+   
+   // Test a wrong remote interface as a return type of a localHome
+   public void testMyOhterFailingStatelessBean()
+   {
+      try
+      {
+         Collection<Class<?>> classes = new HashSet<Class<?>>();
+         classes.add(MyOtherFailingStateLessBean.class);
+         
+         getSessionBeanMetaData(classes, "MyOtherFailingStateLessBean");
+         fail("The session bean’s local interface interface org.jboss.test.metadata.jbmeta41.MyStateful21Remote must extend the javax.ejb.EJBLocalObject");
+      }
+      catch(Exception e)
+      {
+         // ok
+      }
+   }
+   
+   //
+   public void testMultipleReturnTypeBean()
+   {
+      try
+      {
+         Collection<Class<?>> classes = new HashSet<Class<?>>();
+         classes.add(MultipleReturnTypeBean.class);
+         
+         getSessionBeanMetaData(classes, "MultipleReturnTypeBean");
+         fail("An EJB 2.1 view can't have multiple remote/local interfaces");
+      }
+      catch(Exception e)
+      {
+         // ok
+      }
+   }
+   
+   public void testWrongCreateStatelessBean()
+   {
+      try
+      {
+         Collection<Class<?>> classes = new HashSet<Class<?>>();
+         classes.add(WrongCreateStatelessBean.class);
+         
+         getSessionBeanMetaData(classes, "WrongCreateStatelessBean");
+         fail("A stateless session bean must define exactly one create method with no arguments.");
+      }
+      catch(Exception e)
+      {
+         // ok
+      }
+   }
+   
+   
+   private JBossSessionBeanMetaData getSessionBeanMetaData(Collection<Class<?>> classes, String enterpriseBean)
+   {
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      JBoss50Creator creator = new JBoss50Creator(finder);
+
+      JBoss50MetaData jbossMetaData = creator.create(classes);
+      
+      assertEquals("3.0", jbossMetaData.getVersion());      
+      return (JBossSessionBeanMetaData) jbossMetaData.getEnterpriseBean(enterpriseBean);
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list