You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by km...@apache.org on 2010/07/17 06:23:06 UTC

svn commit: r965008 - in /openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/config/AutoConfig.java test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java

Author: kmalhi
Date: Sat Jul 17 04:23:04 2010
New Revision: 965008

URL: http://svn.apache.org/viewvc?rev=965008&view=rev
Log:
Fixed AutoConfig to also check for an empty PersistenceUnit. Added tests for @PersistenceContext usage

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java?rev=965008&r1=965007&r2=965008&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java Sat Jul 17 04:23:04 2010
@@ -266,7 +266,7 @@ public class AutoConfig implements Dynam
                     unitName = refShortName;
                 }
                 validation.fail(componentName, refType + ".noPersistenceUnits", refShortName, unitName);
-            } else if (ref.getPersistenceUnitName() == null && availableUnits.size() > 1) {
+            } else if ((ref.getPersistenceUnitName() == null || ref.getPersistenceUnitName().length()==0) && availableUnits.size() > 1) {
                 // Print a correct example of unitName in a ref
                 // DMB: Idea, the ability to set a default unit-name in openejb-jar.xml via a property
                 String sampleUnitName = availableUnits.get(0);

Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java?rev=965008&r1=965007&r2=965008&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java Sat Jul 17 04:23:04 2010
@@ -17,25 +17,81 @@
 package org.apache.openejb.config.rules;
 
 import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
 import javax.persistence.PersistenceContext;
 import javax.persistence.PersistenceContextType;
 
 import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.config.AppModule;
+import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.config.PersistenceModule;
 import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
 import org.junit.runner.RunWith;
 
 @RunWith(ValidationRunner.class)
 public class CheckPersistenceContextUsageTest {
-    @Keys( { @Key(value = "persistenceContextExtented.nonStateful"), @Key(value = "persistenceContextRef.noPersistenceUnits") })
+    @Keys( { @Key(value = "persistenceContextExtented.nonStateful"), @Key(value = "persistenceContextRef.noPersistenceUnits", count = 3),
+            @Key(value = "presistenceContextAnnotation.onClassWithNoName"), @Key(value = "presistenceContextAnnotation.onEntityManagerFactory"),
+            @Key(value = "presistenceContextAnnotation.onNonEntityManager") })
     public EjbJar wrongUsage() throws OpenEJBException {
         EjbJar ejbJar = new EjbJar();
         ejbJar.addEnterpriseBean(new StatelessBean(FooStateless.class));
         return ejbJar;
     }
 
+    @Keys( { @Key(value = "persistenceContextRef.noUnitName") })
+    public AppModule noUnitName() {
+        EjbJar ejbJar = new EjbJar();
+        ejbJar.addEnterpriseBean(new StatelessBean(FooStatelessOne.class));
+        EjbModule ejbModule = new EjbModule(ejbJar);
+        AppModule appModule = new AppModule(ejbModule.getClassLoader(), ejbModule.getJarLocation());
+        appModule.getEjbModules().add(ejbModule);
+        PersistenceUnit pu = new PersistenceUnit("fooUnit");
+        PersistenceUnit pu1 = new PersistenceUnit("fooUnit1");
+        PersistenceUnit pu2 = new PersistenceUnit("fooUnit");
+        org.apache.openejb.jee.jpa.unit.Persistence p = new org.apache.openejb.jee.jpa.unit.Persistence(pu, pu1, pu2);
+        PersistenceModule pm = new PersistenceModule("foo", p);
+        appModule.getPersistenceModules().add(pm);
+        return appModule;
+    }
+
+    @Keys( { @Key(value = "persistenceContextRef.vagueMatches") })
+    public AppModule vagueMatches() {
+        EjbJar ejbJar = new EjbJar();
+        ejbJar.addEnterpriseBean(new StatelessBean(FooStatelessTwo.class));
+        EjbModule ejbModule = new EjbModule(ejbJar);
+        AppModule appModule = new AppModule(ejbModule.getClassLoader(), ejbModule.getJarLocation());
+        appModule.getEjbModules().add(ejbModule);
+        PersistenceUnit pu = new PersistenceUnit("fooUnit");
+        org.apache.openejb.jee.jpa.unit.Persistence p = new org.apache.openejb.jee.jpa.unit.Persistence(pu);
+        PersistenceModule pm = new PersistenceModule("foo", p);
+        appModule.getPersistenceModules().add(pm);
+        PersistenceUnit pu1 = new PersistenceUnit("fooUnit");
+        org.apache.openejb.jee.jpa.unit.Persistence p1 = new org.apache.openejb.jee.jpa.unit.Persistence(pu1);
+        PersistenceModule pm1 = new PersistenceModule("foo1", p1);
+        appModule.getPersistenceModules().add(pm1);
+        return appModule;
+    }
+
+    @PersistenceContext
     private static class FooStateless {
         @PersistenceContext(type = PersistenceContextType.EXTENDED)
         EntityManager em;
+        @PersistenceContext
+        EntityManagerFactory emf;
+        @PersistenceContext
+        String nonEntityManager;
+    }
+
+    private static class FooStatelessOne {
+        @PersistenceContext
+        EntityManager em;
+    }
+
+    private static class FooStatelessTwo {
+        @PersistenceContext(unitName = "fooUnit")
+        EntityManager em1;
     }
 }