Return-Path: Delivered-To: apmail-openjpa-commits-archive@www.apache.org Received: (qmail 20170 invoked from network); 15 Oct 2010 02:37:54 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Oct 2010 02:37:54 -0000 Received: (qmail 87966 invoked by uid 500); 15 Oct 2010 02:37:54 -0000 Delivered-To: apmail-openjpa-commits-archive@openjpa.apache.org Received: (qmail 87908 invoked by uid 500); 15 Oct 2010 02:37:54 -0000 Mailing-List: contact commits-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list commits@openjpa.apache.org Received: (qmail 87900 invoked by uid 99); 15 Oct 2010 02:37:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Oct 2010 02:37:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Oct 2010 02:37:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 23A7F23889BF; Fri, 15 Oct 2010 02:36:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1022812 - /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conf/TestSwitchConnection.java Date: Fri, 15 Oct 2010 02:36:57 -0000 To: commits@openjpa.apache.org From: allee8285@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101015023657.23A7F23889BF@eris.apache.org> Author: allee8285 Date: Fri Oct 15 02:36:56 2010 New Revision: 1022812 URL: http://svn.apache.org/viewvc?rev=1022812&view=rev Log: OPENJPA-1764 Fix test cases where finally { closeEMF(emf1) } still required ConnectionDriverName be specified. Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conf/TestSwitchConnection.java Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conf/TestSwitchConnection.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conf/TestSwitchConnection.java?rev=1022812&r1=1022811&r2=1022812&view=diff ============================================================================== --- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conf/TestSwitchConnection.java (original) +++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/conf/TestSwitchConnection.java Fri Oct 15 02:36:56 2010 @@ -38,7 +38,7 @@ public class TestSwitchConnection extend private String[] jndiNames = { "jdbc/mocked1" }; protected void init(String cfName) { - EntityManagerFactory emf1 = getEmf("openjpa.ConnectionFactoryName", cfName, true); + EntityManagerFactory emf1 = getEmf(true, "openjpa.ConnectionFactoryName", cfName); EntityManager em = emf1.createEntityManager(); em.getTransaction().begin(); em.createQuery("Delete from confPerson").executeUpdate(); @@ -64,22 +64,23 @@ public class TestSwitchConnection extend } } - protected EntityManagerFactory getEmf(String cfPropertyName, String cfPropertyValue) { - return getEmf(cfPropertyName, cfPropertyValue, false); + protected EntityManagerFactory getEmf(String ...props) { + return getEmf(false, props); } - protected EntityManagerFactory getEmf(String cfPropertyName, String cfPropertyValue, boolean syncMappings) { + protected EntityManagerFactory getEmf(boolean syncMappings, String ...props) { // null out the driver to prevent system properties from taking effect. // do not set connectionFactoryModeManaged - or connectionFactory2 will be used. - if(syncMappings) { - return createEMF( - "openjpa.jdbc.SynchronizeMappings", "buildSchema", - "openjpa.ConnectionDriverName", "", - cfPropertyName,cfPropertyValue); - } - return createEMF( - "openjpa.ConnectionDriverName", "", - cfPropertyName,cfPropertyValue); + int additionalProp = syncMappings ? 4 : 2; + Object[] modProps = new Object[props.length + additionalProp]; + modProps[0] = "openjpa.ConnectionDriverName"; + modProps[1] = ""; + if (syncMappings) { + modProps[2] = "openjpa.jdbc.SynchronizeMappings"; + modProps[3] = "buildSchema"; + } + System.arraycopy(props, 0, modProps, additionalProp, props.length); + return createEMF(modProps); } protected EntityManager getEm(EntityManagerFactory emf1, String name, String value) { @@ -184,7 +185,8 @@ public class TestSwitchConnection extend EntityManagerFactory emf1 = null; try { - emf1 = getEmf("openjpa.DataCache", "true"); + emf1 = getEmf("openjpa.DataCache", "true", + "openjpa.ConnectionFactoryName", defaultJndiName); getEm(emf1, "openjpa.ConnectionFactoryName", "jdbc/NotReal"); fail("Expected an excepton when creating an EM with a bogus JNDI name"); } catch (ArgumentException e) { @@ -200,7 +202,8 @@ public class TestSwitchConnection extend EntityManagerFactory emf1 = null; try { - emf1 = getEmf("openjpa.QueryCache", "true"); + emf1 = getEmf("openjpa.QueryCache", "true", + "openjpa.ConnectionFactoryName", defaultJndiName); getEm(emf1, "openjpa.ConnectionFactoryName", "jdbc/NotReal"); fail("Expected an excepton when creating an EM with a bogus JNDI name"); } catch (ArgumentException e) { @@ -216,7 +219,8 @@ public class TestSwitchConnection extend EntityManagerFactory emf1 = null; try { - emf1 = getEmf("openjpa.jdbc.SynchronizeMappings", "buildSchema"); + emf1 = getEmf("openjpa.jdbc.SynchronizeMappings", "buildSchema", + "openjpa.ConnectionFactoryName", defaultJndiName); getEm(emf1, "openjpa.ConnectionFactoryName", "jdbc/NotReal"); fail("Expected an excepton when creating an EM with a bogus JNDI name"); } catch (ArgumentException e) {