[jboss-cvs] JBossAS SVN: r94848 - in projects/jpa/trunk/spi: src/main/java/org/jboss/jpa/spi and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 14 06:26:43 EDT 2009


Author: wolfc
Date: 2009-10-14 06:26:42 -0400 (Wed, 14 Oct 2009)
New Revision: 94848

Added:
   projects/jpa/trunk/spi/src/test/java/org/
   projects/jpa/trunk/spi/src/test/java/org/jboss/
   projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/
   projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/
   projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/test/
   projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/test/registry/
   projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/test/registry/MockPersistenceUnit.java
   projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/test/registry/PersistenceUnitRegistryTestCase.java
Modified:
   projects/jpa/trunk/spi/.settings/org.eclipse.jdt.core.prefs
   projects/jpa/trunk/spi/src/main/java/org/jboss/jpa/spi/PersistenceUnitRegistry.java
Log:
JBJPA-16: proper check for existing persistence unit

Modified: projects/jpa/trunk/spi/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/jpa/trunk/spi/.settings/org.eclipse.jdt.core.prefs	2009-10-14 10:10:27 UTC (rev 94847)
+++ projects/jpa/trunk/spi/.settings/org.eclipse.jdt.core.prefs	2009-10-14 10:26:42 UTC (rev 94848)
@@ -1,5 +1,12 @@
-#Thu Oct 08 15:00:29 CEST 2009
+#Wed Oct 14 12:06:44 CEST 2009
 eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
 org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
 org.eclipse.jdt.core.compiler.source=1.5

Modified: projects/jpa/trunk/spi/src/main/java/org/jboss/jpa/spi/PersistenceUnitRegistry.java
===================================================================
--- projects/jpa/trunk/spi/src/main/java/org/jboss/jpa/spi/PersistenceUnitRegistry.java	2009-10-14 10:10:27 UTC (rev 94847)
+++ projects/jpa/trunk/spi/src/main/java/org/jboss/jpa/spi/PersistenceUnitRegistry.java	2009-10-14 10:26:42 UTC (rev 94848)
@@ -36,7 +36,7 @@
 
    public static void register(PersistenceUnit container)
    {
-      if (persistenceUnits.contains(container.getName())) throw new RuntimeException("Persistence Unit is already registered: " + container.getName());
+      if (persistenceUnits.containsKey(container.getName())) throw new RuntimeException("Persistence Unit is already registered: " + container.getName());
       persistenceUnits.put(container.getName(), container);
    }
 

Added: projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/test/registry/MockPersistenceUnit.java
===================================================================
--- projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/test/registry/MockPersistenceUnit.java	                        (rev 0)
+++ projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/test/registry/MockPersistenceUnit.java	2009-10-14 10:26:42 UTC (rev 94848)
@@ -0,0 +1,78 @@
+/*
+ * 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.jpa.spi.test.registry;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.jboss.jpa.spi.PersistenceUnit;
+import org.jboss.jpa.spi.XPCResolver;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockPersistenceUnit implements PersistenceUnit
+{
+   private String name;
+
+   public MockPersistenceUnit(String name)
+   {
+      this.name = name;
+   }
+   
+   public EntityManagerFactory getContainerEntityManagerFactory()
+   {
+      // TODO Auto-generated method stub
+      throw new RuntimeException("NYI");
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public EntityManager getTransactionScopedEntityManager()
+   {
+      // TODO Auto-generated method stub
+      throw new RuntimeException("NYI");
+   }
+
+   public XPCResolver getXPCResolver()
+   {
+      // TODO Auto-generated method stub
+      throw new RuntimeException("NYI");
+   }
+
+   public boolean isInTx()
+   {
+      // TODO Auto-generated method stub
+      throw new RuntimeException("NYI");
+   }
+
+   public void verifyInTx()
+   {
+      // TODO Auto-generated method stub
+      throw new RuntimeException("NYI");
+   }
+
+}

Added: projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/test/registry/PersistenceUnitRegistryTestCase.java
===================================================================
--- projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/test/registry/PersistenceUnitRegistryTestCase.java	                        (rev 0)
+++ projects/jpa/trunk/spi/src/test/java/org/jboss/jpa/spi/test/registry/PersistenceUnitRegistryTestCase.java	2009-10-14 10:26:42 UTC (rev 94848)
@@ -0,0 +1,72 @@
+/*
+ * 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.jpa.spi.test.registry;
+
+import static org.junit.Assert.fail;
+
+import org.jboss.jpa.spi.PersistenceUnit;
+import org.jboss.jpa.spi.PersistenceUnitRegistry;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class PersistenceUnitRegistryTestCase
+{
+   @Test
+   public void testDuplicatedName()
+   {
+      PersistenceUnit pu1 = new MockPersistenceUnit("test");
+      PersistenceUnit pu2 = new MockPersistenceUnit("test");
+      
+      PersistenceUnitRegistry.register(pu1);
+      try
+      {
+         PersistenceUnitRegistry.register(pu2);
+         fail("should throw a RuntimeException");
+      }
+      catch(RuntimeException e)
+      {
+         // good
+      }
+      PersistenceUnitRegistry.unregister(pu1);
+   }
+   
+   @Test
+   public void testDuplicateRegistration()
+   {
+      PersistenceUnit pu1 = new MockPersistenceUnit("test");
+      
+      PersistenceUnitRegistry.register(pu1);
+      try
+      {
+         PersistenceUnitRegistry.register(pu1);
+         fail("should throw a RuntimeException");
+      }
+      catch(RuntimeException e)
+      {
+         // good
+      }
+      PersistenceUnitRegistry.unregister(pu1);
+   }
+}




More information about the jboss-cvs-commits mailing list