openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r740986 - in /openjpa/trunk/openjpa-persistence-jdbc: ./ src/test/java/org/apache/openjpa/conf/ src/test/java/org/apache/openjpa/persistence/kernel/ src/test/java/org/apache/openjpa/persistence/simple/ src/test/resources/META-INF/
Date Thu, 05 Feb 2009 03:21:26 GMT
Author: jrbauer
Date: Thu Feb  5 03:21:25 2009
New Revision: 740986

URL: http://svn.apache.org/viewvc?rev=740986&view=rev
Log:
OPENJPA-849 Committing code and corresponding tests contributed by Dianne Richards

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPropertiesMethods.java
  (with props)
Modified:
    openjpa/trunk/openjpa-persistence-jdbc/pom.xml
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestBadJdbcUrl.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml

Modified: openjpa/trunk/openjpa-persistence-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/pom.xml?rev=740986&r1=740985&r2=740986&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/pom.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/pom.xml Thu Feb  5 03:21:25 2009
@@ -552,7 +552,7 @@
                             <value>DefaultLevel=${openjpa.loglevel}</value>
                         </property>
                         <property>
-                            <name>openjpa.ConnectionDriverName</name>
+                            <name>javax.persistence.jdbc.driver</name>
                             <value>org.apache.commons.dbcp.BasicDataSource</value>
                         </property>
                         <property>

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestBadJdbcUrl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestBadJdbcUrl.java?rev=740986&r1=740985&r2=740986&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestBadJdbcUrl.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestBadJdbcUrl.java
Thu Feb  5 03:21:25 2009
@@ -59,7 +59,7 @@
 	 */
 	public void testBadUrlProtocolValueWithValidDriverClass() {
 		Properties p = new Properties();
-		p.put("openjpa.ConnectionDriverName", GOOD_DRIVER);
+		p.put("javax.persistence.jdbc.driver", GOOD_DRIVER);
 		p.put("openjpa.ConnectionURL", BAD_URL_PROTOCOL);
 		verifyConnectException(p, PersistenceException.class,
 				UserException.class, GOOD_DRIVER, BAD_URL_PROTOCOL);
@@ -70,7 +70,7 @@
 	 */
 	public void testBadUrlProtocolValueWithValidDataSource() {
 		Properties p = new Properties();
-		p.put("openjpa.ConnectionDriverName", GOOD_DATASOURCE);
+		p.put("javax.persistence.jdbc.driver", GOOD_DATASOURCE);
 		p.put("openjpa.ConnectionURL", BAD_URL_PROTOCOL);
 		p.put("openjpa.ConnectionProperties", BAD_CONN_PROPS);
 		verifyConnectException(p, PersistenceException.class,
@@ -82,7 +82,7 @@
 	 */
 	public void testBadUrlSubprotocolValueWithValidDriverClass() {
 		Properties p = new Properties();
-		p.put("openjpa.ConnectionDriverName", GOOD_DRIVER);
+		p.put("javax.persistence.jdbc.driver", GOOD_DRIVER);
 		p.put("openjpa.ConnectionURL", BAD_URL_SUBPROTOCOL);
 		verifyConnectException(p, PersistenceException.class,
 				UserException.class, GOOD_DRIVER, BAD_URL_SUBPROTOCOL);
@@ -93,7 +93,7 @@
 	 */
 	public void testBadUrlSubprotocolValueWithValidDataSource() {
 		Properties p = new Properties();
-		p.put("openjpa.ConnectionDriverName", GOOD_DRIVER);
+		p.put("javax.persistence.jdbc.driver", GOOD_DRIVER);
 		p.put("openjpa.ConnectionURL", BAD_URL_SUBPROTOCOL);
 		verifyConnectException(p, PersistenceException.class,
 				UserException.class, GOOD_DRIVER, BAD_URL_SUBPROTOCOL);
@@ -104,7 +104,7 @@
 	 */
 	public void testValidUrlWithInvalidDriver() {
 		Properties p = new Properties();
-		p.put("openjpa.ConnectionDriverName", BAD_DRIVER);
+		p.put("javax.persistence.jdbc.driver", BAD_DRIVER);
 		p.put("openjpa.ConnectionURL", GOOD_URL);
 		verifyConnectException(p, PersistenceException.class,
 				UserException.class, GOOD_URL, BAD_DRIVER);

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java?rev=740986&r1=740985&r2=740986&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java
Thu Feb  5 03:21:25 2009
@@ -187,7 +187,7 @@
     public void testPlatform() {
         OpenJPAEntityManagerFactory pmf =
             (OpenJPAEntityManagerFactory) getEmf();
-        assertNotNull(pmf.getProperties().getProperty("Platform"));
+        assertNotNull(pmf.getProperties().get("Platform"));
     }
 
     protected OpenJPAEntityManagerFactory getEmf(Map props) {

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPropertiesMethods.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPropertiesMethods.java?rev=740986&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPropertiesMethods.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPropertiesMethods.java
Thu Feb  5 03:21:25 2009
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.simple;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.openjpa.kernel.AutoClear;
+import org.apache.openjpa.lib.conf.Value;
+import org.apache.openjpa.persistence.AutoClearType;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * This test case tests the getProperties() and getSupportedProperties() methods
+ * for the EntityManager and EntityManagerFactory.
+ * 
+ * @author Dianne Richards
+ * 
+ */
+public class TestPropertiesMethods extends SingleEMFTestCase {
+    OpenJPAEntityManager em;
+
+    public void setUp() throws Exception {
+        setUp("openjpa.DataCacheTimeout", "3",
+            "openjpa.ConnectionURL",
+            "jdbc:derby:target/database/jpa-test-database;create=true");
+        assertNotNull(emf);
+        em = emf.createEntityManager();
+        assertNotNull(em);
+    }
+    
+    /**
+     * Test the EntityManager getProperties() method.
+     */
+    public void testEMGetProperties() {
+        Map<String, Object> emProperties = em.getProperties();
+
+        // First, check a default property
+        String autoClear = (String) emProperties.get("openjpa.AutoClear");
+        assertEquals(String.valueOf(AutoClear.CLEAR_DATASTORE), autoClear);
+        
+        // Next, check that the correct property key is returned for
+        // some properties that can have 2 keys. The success of this test
+        // case is dependent on the connection system values that are set
+        // in the pom.xml file for the test harness. It assumes that the
+        // system value keys are javax.persistence.jdbc.driver and 
+        // openjpa.ConnectionProperties. If either one of these are changed,
+        // this test case may fail.
+        String javaxConnectionDriver =
+            (String) emProperties.get("javax.persistence.jdbc.driver");
+        assertNotNull(javaxConnectionDriver);
+        String openjpaConnectionURL =
+            (String) emProperties.get("openjpa.ConnectionURL");
+        assertNotNull(openjpaConnectionURL);
+        
+        // Next, check that the javax.persistent property is returned instead
+        // of the corresponding openjpa one when no value has been set.
+        boolean javaxUserNameExists =
+            emProperties.containsKey("javax.persistence.jdbc.user");
+        assertTrue(javaxUserNameExists);
+        boolean openjpaUserNameExists =
+            emProperties.containsKey("openjpaConnectionUserName");
+        assertFalse(openjpaUserNameExists);
+        
+        // Next, change a property and check for the changed value
+        em.setAutoClear(AutoClearType.ALL);
+        emProperties = em.getProperties();
+        autoClear = (String) emProperties.get("openjpa.AutoClear");
+        assertEquals(String.valueOf(AutoClear.CLEAR_ALL), autoClear);
+        
+        // Make sure the password property is not returned.
+        boolean javaxPasswordExists =
+            emProperties.containsKey("javax.persistence.jdbc.password");
+        assertFalse(javaxPasswordExists);
+        boolean openjpaPasswordExists =
+            emProperties.containsKey("openjpa.ConnectionPassword");
+        assertFalse(openjpaPasswordExists);
+        
+        // Add a dummy javax.persistence... equivalent key to one of the
+        // values that can be changed to force the code down a specific path.
+        Value autoClearValue = emf.getConfiguration().getValue("AutoClear");
+        assertNotNull(autoClearValue);
+        autoClearValue.addEquivalentKey("javax.persistence.AutoClear");
+        emProperties = em.getProperties();
+        assertFalse(emProperties.containsKey("openjpa.AutoClear"));
+        assertTrue(emProperties.containsKey("javax.persistence.AutoClear"));
+    }
+
+    /**
+     * Test the EntityManagerFactory getProperties() method.
+     */
+    public void testEMFGetProperties() {
+        Map<String, Object> emfProperties = emf.getProperties();
+
+        // First, check a default property
+        String dataCacheManager =
+            (String) emfProperties.get("openjpa.DataCacheManager");
+        assertEquals("default", dataCacheManager);
+
+        // Next, check a property that was set during emf creation
+        String dataCacheTimeout =
+            (String) emfProperties.get("openjpa.DataCacheTimeout");
+        assertEquals(3, Integer.valueOf(dataCacheTimeout).intValue());
+
+        // Next get the Platform value set by the JDBCBrokerFactory
+        // or possibly a subclass
+        String platform = (String) emfProperties.get("Platform");
+        assertNotNull(platform);
+
+        // Next get one of the values set by the AbstractBrokerFactory
+        // or possibly a subclass
+        String vendorName = (String) emfProperties.get("VendorName");
+        assertNotNull(vendorName);
+    }
+
+    /**
+     * Test the EntityManagerFactory getSupportedProperties() method.
+     */
+    public void testEMFGetSupportedProperties() {
+        Set<String> emfSupportedProperties = emf.getSupportedProperties();
+        assertNotNull(emfSupportedProperties);
+        assertTrue(emfSupportedProperties.contains("openjpa.IgnoreChanges"));
+    }
+
+    /**
+     * Test the EntityManager getSupportedProperties() method.
+     */
+    public void testEMGetSupportedProperties() {
+        Set<String> emSupportedProperties = em.getSupportedProperties();
+        assertNotNull(emSupportedProperties);
+        assertTrue(emSupportedProperties.contains("openjpa.AutoDetach"));
+        
+        // Make sure the all possible keys are returned
+        assertTrue(emSupportedProperties.contains(
+            "javax.persistence.lock.timeout"));
+        assertTrue(emSupportedProperties.contains("openjpa.LockTimeout"));
+        
+        // Make sure the spec property for query timeout, that only has one
+        // key, is returned.
+        assertTrue(emSupportedProperties.contains(
+            "javax.persistence.query.timeout"));
+    }
+
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPropertiesMethods.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=740986&r1=740985&r2=740986&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Thu
Feb  5 03:21:25 2009
@@ -71,7 +71,7 @@
 
     <persistence-unit name="invalid">
         <properties>
-            <property name="openjpa.ConnectionDriverName"
+            <property name="javax.persistence.jdbc.driver"
                 value="org.apache.commons.dbcp.BasicDataSource" />
             <property name="openjpa.ConnectionProperties"
                 value="DriverClassName=not.a.real.Driver,Url=jdbc:notreal://"/>



Mime
View raw message