[jboss-cvs] JBossAS SVN: r102730 - in projects/metadata/common/trunk/src: test/java/org/jboss/test/metadata and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 22 14:56:59 EDT 2010


Author: jaikiran
Date: 2010-03-22 14:56:58 -0400 (Mon, 22 Mar 2010)
New Revision: 102730

Added:
   projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/jbmeta271/
   projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/jbmeta271/SimpleClassWithPersistenceContextInjection.java
   projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/jbmeta271/unit/
   projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/jbmeta271/unit/PersistenceContextProcessorTestCase.java
Modified:
   projects/metadata/common/trunk/src/main/java/org/jboss/metadata/annotation/creator/AbstractPersistenceContextProcessor.java
Log:
JBMETA-271 Fixed the injection target name generation for @PersistenceContext annotation processing

Modified: projects/metadata/common/trunk/src/main/java/org/jboss/metadata/annotation/creator/AbstractPersistenceContextProcessor.java
===================================================================
--- projects/metadata/common/trunk/src/main/java/org/jboss/metadata/annotation/creator/AbstractPersistenceContextProcessor.java	2010-03-22 18:12:49 UTC (rev 102729)
+++ projects/metadata/common/trunk/src/main/java/org/jboss/metadata/annotation/creator/AbstractPersistenceContextProcessor.java	2010-03-22 18:56:58 UTC (rev 102730)
@@ -95,7 +95,8 @@
          ref.setProperties(refProperties);
       }
 
-      Set<ResourceInjectionTargetMetaData> injectionTargets = ProcessorUtils.getInjectionTargets(name, element);
+      String injectionName = ProcessorUtils.getName(element);
+      Set<ResourceInjectionTargetMetaData> injectionTargets = ProcessorUtils.getInjectionTargets(injectionName, element);
       if(injectionTargets != null)
          ref.setInjectionTargets(injectionTargets);
 

Added: projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/jbmeta271/SimpleClassWithPersistenceContextInjection.java
===================================================================
--- projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/jbmeta271/SimpleClassWithPersistenceContextInjection.java	                        (rev 0)
+++ projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/jbmeta271/SimpleClassWithPersistenceContextInjection.java	2010-03-22 18:56:58 UTC (rev 102730)
@@ -0,0 +1,39 @@
+/*
+* 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.metadata.jbmeta271;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+/**
+ * BeanWithPersistenceContextInjection
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class SimpleClassWithPersistenceContextInjection
+{
+
+   @PersistenceContext (name = "emENCName")
+   private EntityManager emFieldName;
+   
+}

Added: projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/jbmeta271/unit/PersistenceContextProcessorTestCase.java
===================================================================
--- projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/jbmeta271/unit/PersistenceContextProcessorTestCase.java	                        (rev 0)
+++ projects/metadata/common/trunk/src/test/java/org/jboss/test/metadata/jbmeta271/unit/PersistenceContextProcessorTestCase.java	2010-03-22 18:56:58 UTC (rev 102730)
@@ -0,0 +1,76 @@
+/*
+* 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.metadata.jbmeta271.unit;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.jboss.metadata.annotation.creator.PersistenceContextFieldProcessor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.javaee.spec.PersistenceContextReferenceMetaData;
+import org.jboss.metadata.javaee.spec.PersistenceContextReferencesMetaData;
+import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
+import org.jboss.test.metadata.common.PackageScanner;
+import org.jboss.test.metadata.common.ScanPackage;
+import org.jboss.test.metadata.jbmeta271.SimpleClassWithPersistenceContextInjection;
+import org.junit.Test;
+
+/**
+ * PersistenceContextProcessorTestCase
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class PersistenceContextProcessorTestCase
+{
+
+   @Test
+   public void testPersistenceContextAnnotationProcessing() throws Exception
+   {
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      PersistenceContextFieldProcessor pcFieldProcessor = new PersistenceContextFieldProcessor(finder);
+      Field field = SimpleClassWithPersistenceContextInjection.class.getDeclaredField("emFieldName");
+      
+      PersistenceContextReferencesMetaData pcRefs = new PersistenceContextReferencesMetaData();
+      pcFieldProcessor.process(pcRefs, field);
+      
+      Assert.assertEquals("Unexpected number of persistence context references",1, pcRefs.size());
+      
+      PersistenceContextReferenceMetaData pcRef = PersistenceContextReferencesMetaData.getByName("emENCName", pcRefs);
+      
+      Assert.assertNotNull("PersistenceContext reference not found", pcRef);
+      Set<ResourceInjectionTargetMetaData> injectionTargets = pcRef.getInjectionTargets();
+      Assert.assertNotNull("Injection targets for persistence context reference not found", injectionTargets);
+      
+      Assert.assertEquals("Unexpected number of injection targets found",1, injectionTargets.size());
+      for (ResourceInjectionTargetMetaData injectionTarget : injectionTargets)
+      {
+         Assert.assertEquals("Unexpected injection target class name", SimpleClassWithPersistenceContextInjection.class.getName(), injectionTarget.getInjectionTargetClass());
+         Assert.assertEquals("Unexpected injection target targetName", field.getName(), injectionTarget.getInjectionTargetName());
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list