[jboss-cvs] JBossAS SVN: r109815 - in projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/javaee: jbmeta323 and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 10 03:32:32 EST 2010


Author: jaikiran
Date: 2010-12-10 03:32:31 -0500 (Fri, 10 Dec 2010)
New Revision: 109815

Added:
   projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/javaee/jbmeta323/
   projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/javaee/jbmeta323/EJBAnnotationProcessorUnitTestCase.java
   projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/javaee/jbmeta323/SimpleBean.java
Log:
JBMETA-323 Added a testcase for processing @EJB with a lookup attribute

Added: projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/javaee/jbmeta323/EJBAnnotationProcessorUnitTestCase.java
===================================================================
--- projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/javaee/jbmeta323/EJBAnnotationProcessorUnitTestCase.java	                        (rev 0)
+++ projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/javaee/jbmeta323/EJBAnnotationProcessorUnitTestCase.java	2010-12-10 08:32:31 UTC (rev 109815)
@@ -0,0 +1,95 @@
+/*
+ * 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.test.metadata.javaee.jbmeta323;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.ejb.EJB;
+
+import junit.framework.Assert;
+
+import org.jboss.metadata.annotation.creator.EJBFieldProcessor;
+import org.jboss.metadata.annotation.creator.EJBMethodProcessor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.javaee.spec.AnnotatedEJBReferenceMetaData;
+import org.jboss.metadata.javaee.spec.AnnotatedEJBReferencesMetaData;
+import org.junit.Test;
+
+/**
+ * Tests that the {@link EJB @EJB} annotation is processed correctly for the 
+ * "lookup" attribute 
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class EJBAnnotationProcessorUnitTestCase
+{
+   /**
+    * Tests that a method annotated with {@link EJB @EJB}, with a "lookup" attribute
+    * on the annotation, is processed correctly
+    *  
+    */
+   @Test
+   public void testLookupAttributeProcessingOnMethod() throws Exception
+   {
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      EJBMethodProcessor ejbMethodProcessor = new EJBMethodProcessor(finder);
+      Method method = SimpleBean.class.getDeclaredMethod("setEjb", new Class<?>[] {SimpleBean.class});
+
+      AnnotatedEJBReferencesMetaData annotatedEjbRefs = new AnnotatedEJBReferencesMetaData();
+      ejbMethodProcessor.process(annotatedEjbRefs, method);
+
+      Assert.assertEquals("Unexpected number of annotated @EJB context references", 1, annotatedEjbRefs.size());
+
+      AnnotatedEJBReferenceMetaData annotatedEjbRef = AnnotatedEJBReferencesMetaData.getByName(SimpleBean.class.getName() + "/ejb", annotatedEjbRefs);
+
+      Assert.assertNotNull("@EJB reference not found", annotatedEjbRef);
+      Assert.assertEquals("Unexpected value for lookup attribute of @EJB", "dummy", annotatedEjbRef.getLookupName());
+   }
+   
+   
+   /**
+    * Tests that a field annotated with {@link EJB @EJB}, with a "lookup" attribute
+    * on the annotation, is processed correctly
+    *  
+    */
+   @Test
+   public void testLookupAttributeProcessingOnField() throws Exception
+   {
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      EJBFieldProcessor ejbFieldProcessor = new EJBFieldProcessor(finder);
+      Field field = SimpleBean.class.getDeclaredField("otherBean");
+
+      AnnotatedEJBReferencesMetaData annotatedEjbRefs = new AnnotatedEJBReferencesMetaData();
+      ejbFieldProcessor.process(annotatedEjbRefs, field);
+
+      Assert.assertEquals("Unexpected number of annotated @EJB context references", 1, annotatedEjbRefs.size());
+
+      AnnotatedEJBReferenceMetaData annotatedEjbRef = AnnotatedEJBReferencesMetaData.getByName(SimpleBean.class.getName() + "/otherBean", annotatedEjbRefs);
+
+      Assert.assertNotNull("@EJB reference not found", annotatedEjbRef);
+      Assert.assertEquals("Unexpected value for lookup attribute of @EJB", "dummy2", annotatedEjbRef.getLookupName());
+   }
+}

Added: projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/javaee/jbmeta323/SimpleBean.java
===================================================================
--- projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/javaee/jbmeta323/SimpleBean.java	                        (rev 0)
+++ projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/javaee/jbmeta323/SimpleBean.java	2010-12-10 08:32:31 UTC (rev 109815)
@@ -0,0 +1,45 @@
+/*
+ * 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.test.metadata.javaee.jbmeta323;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+
+/**
+ * SimpleBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+public class SimpleBean
+{
+
+   @EJB(lookup = "dummy2")
+   private SimpleBean otherBean;
+   
+   @EJB(lookup = "dummy")
+   public void setEjb(SimpleBean other)
+   {
+      // do nothing      
+   }
+}



More information about the jboss-cvs-commits mailing list