From a99e618f5ae5d23ff8bf6f4f8a50a5cb357a4a85 Mon Sep 17 00:00:00 2001 From: Michael Dick Date: Mon, 11 Oct 2010 21:45:47 +0000 Subject: [PATCH] Testcase updates for Sybase git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1021522 13f79535-47bb-0310-9956-ffa450edef68 --- .../criteria/TestTypesafeCriteria.java | 8 ++--- .../persistence/event/TestBeforeCommit.java | 23 ++++++++----- .../openjpa/persistence/jdbc/TestLobs.java | 33 ++++++++++++++++--- .../spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java | 2 +- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java index b40b2ae66..dfc357d6f 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java @@ -46,8 +46,8 @@ import javax.persistence.criteria.Subquery; import javax.persistence.metamodel.EntityType; import javax.persistence.metamodel.Metamodel; +import org.apache.openjpa.jdbc.sql.AbstractSQLServerDictionary; import org.apache.openjpa.jdbc.sql.OracleDictionary; -import org.apache.openjpa.jdbc.sql.SQLServerDictionary; import org.apache.openjpa.persistence.test.AllowFailure; /** @@ -1568,12 +1568,12 @@ public class TestTypesafeCriteria extends CriteriaTest { String jpql = "select c.accountNum*10.32597 from Customer c where c.id=10"; long accountNumber = 1234516279; - if (getDictionary() instanceof SQLServerDictionary) { + if (getDictionary() instanceof AbstractSQLServerDictionary) { // @AllowFailure - // TODO - Skipping for MSSQL, as the calculation result has a precision larger than 38 + // TODO - Skipping for MSSQL & Sybase, as the calculation result has a precision larger than 38 // params=(BigDecimal) 10.3259699999999998709654391859658062458038330078125 getEntityManagerFactory().getConfiguration().getLog("test").warn( - "SKIPPING testBigDecimalConversion() for SQLServer"); + "SKIPPING testBigDecimalConversion() for SQLServer & Sybase"); return; } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/event/TestBeforeCommit.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/event/TestBeforeCommit.java index 2808f5bc0..2e30b3698 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/event/TestBeforeCommit.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/event/TestBeforeCommit.java @@ -22,6 +22,7 @@ import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; import javax.persistence.Query; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.event.TransactionEvent; import org.apache.openjpa.event.TransactionListener; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; @@ -107,12 +108,10 @@ public class TestBeforeCommit extends AbstractPersistenceTestCase implements Tra ae = doQuery(em); if (dict instanceof OracleDictionary) { assertNull(ae.getName()); - } - else if (dict instanceof SybaseDictionary) { + } else if (dict instanceof SybaseDictionary) { // Sybase converts "" to " " - assertEquals(" ", ae.getName()); - } - else { + assertEquals(" ", ae.getName()); + } else { assertEquals("", ae.getName()); } assertEquals(1, ae.getVersion()); @@ -124,15 +123,23 @@ public class TestBeforeCommit extends AbstractPersistenceTestCase implements Tra // when BeforeCommit was fired AE was not managed. As a result its state is out of sync with the database. assertEquals("Ava", ae.getName()); ae = doQuery(em); - if (dict instanceof OracleDictionary) + if (dict instanceof OracleDictionary) { assertNull(ae.getName()); - else + } else if (dict instanceof SybaseDictionary) { + assertEquals(" ", ae.getName()); + } else { assertEquals("", ae.getName()); + } assertEquals(1, ae.getVersion()); } public void beforeCommit(TransactionEvent event) { - ae.setName(ae.getName() == null ? "Ava" : ae.getName()+ "Ava"); + if(StringUtils.isBlank(ae.getName())) { + ae.setName("Ava"); + } + else { + ae.setName(ae.getName() + "Ava"); + } } private AnEntity doQuery(EntityManager em) { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestLobs.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestLobs.java index e3ada0cb5..feeeacbb7 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestLobs.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/TestLobs.java @@ -24,6 +24,7 @@ import javax.persistence.RollbackException; import junit.framework.AssertionFailedError; +import org.apache.openjpa.jdbc.sql.SybaseDictionary; import org.apache.openjpa.persistence.kernel.common.apps.Blobs; import org.apache.openjpa.persistence.kernel.common.apps.Lobs; import org.apache.openjpa.persistence.test.SingleEMFTestCase; @@ -83,7 +84,7 @@ public class TestLobs extends SingleEMFTestCase { em.close(); } - public void testBlobZeroLengthByteArray() { + public void testBlobZeroLengthByteArray() throws Exception { // test with 0 length bytes byte[] bytes = new byte[0]; EntityManager em = emf.createEntityManager(); @@ -93,7 +94,16 @@ public class TestLobs extends SingleEMFTestCase { lobs.setLobNotNullable(bytes); lobs.setLobNullable(bytes); em.persist(lobs); - em.getTransaction().commit(); + try { + em.getTransaction().commit(); + } catch (Exception e) { + if (getDBDictionary() instanceof SybaseDictionary) { + assertTrue(e instanceof RollbackException); + return; + } else { + throw e; + } + } em.close(); em = emf.createEntityManager(); @@ -192,8 +202,23 @@ public class TestLobs extends SingleEMFTestCase { em.getTransaction().begin(); Query query = em.createQuery("select e from Lobs e"); lobs = (Lobs)query.getSingleResult(); - assertTrue(lobs.getLobNullable() == null || lobs.getLobNullable().length() == 0); - assertTrue(lobs.getLobNotNullable() == null || lobs.getLobNotNullable().length() == 0); + + if (lobs.getLobNullable() != null) { + if (getDBDictionary() instanceof SybaseDictionary) { + // Sybase stores empty strings as " " + assertEquals(" ", lobs.getLobNullable()); + } else { + assertEquals(0, lobs.getLobNullable().length()); + } + } + if (lobs.getLobNotNullable() != null) { + if (getDBDictionary() instanceof SybaseDictionary) { + // Sybase stores empty strings as " " + assertEquals(" ", lobs.getLobNotNullable()); + } else { + assertEquals(0, lobs.getLobNotNullable().length()); + } + } assertEquals(lobs.getLobNullable(), lobs.getLobNotNullable()); em.remove(lobs); em.getTransaction().commit(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java index bba19ba17..d89b7fa36 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java @@ -95,7 +95,7 @@ public class TestSpec10_1_27_Ex4 extends SQLListenerTestCase { setCandidate(q, Company.class); rs = q.getResultList(); Map.Entry me = (Map.Entry) rs.get(0); - assertTrue(d.equals(me.getKey())); + assertEquals(d, me.getKey()); em.clear(); query = "select KEY(e) from Company c " +