From a8fc8dfa769b21bbe4534b4a4e62746f7d1f9ba1 Mon Sep 17 00:00:00 2001 From: Michael Dick Date: Thu, 2 Aug 2007 20:33:18 +0000 Subject: [PATCH] OPENJPA-295 improved testcase git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@562244 13f79535-47bb-0310-9956-ffa450edef68 --- .../jdbc/meta/TestMappingToolTemporal.java | 68 +++++++++---------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/TestMappingToolTemporal.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/TestMappingToolTemporal.java index 500935eb6..1720b84ae 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/TestMappingToolTemporal.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/TestMappingToolTemporal.java @@ -21,51 +21,49 @@ package org.apache.openjpa.jdbc.meta; import java.io.IOException; import java.sql.SQLException; -import javax.persistence.EntityManager; - +import org.apache.openjpa.persistence.OpenJPAPersistence; import org.apache.openjpa.persistence.simple.TemporalFieldTypes; -import org.apache.openjpa.persistence.test.SQLListenerTestCase; +import org.apache.openjpa.persistence.test.SingleEMTestCase; -public class TestMappingToolTemporal extends SQLListenerTestCase { +public class TestMappingToolTemporal extends SingleEMTestCase { public void setUp() { - setUp(CLEAR_TABLES, TemporalFieldTypes.class); + setUp(TemporalFieldTypes.class); } public void testMappingToolTemporal() throws IOException, SQLException { + ClassMapping mapping = (ClassMapping) OpenJPAPersistence.cast(emf) + .getConfiguration().getMetaDataRepositoryInstance() + .getMetaData("TemporalFieldTypes", getClass().getClassLoader(), + true); - EntityManager em = emf.createEntityManager(); - em.getTransaction().begin(); - em.persist(new TemporalFieldTypes()); - em.getTransaction().commit(); - em.close(); + assertEquals(java.sql.Types.TIMESTAMP, mapping.getFieldMapping( + "dateDefaultField").getValueMapping().getColumns()[0].getType()); - // first check to see if we issued any create table statements at - // all; if not, then the table has already been created in the - // database, so the subsequent validation of the column types - // will fail simply because the table creation isn't happening - try { - assertSQL("CREATE TABLE TemporalFieldTypes .*"); - } catch (Throwable t) { - return; - } + assertEquals(java.sql.Types.DATE, mapping.getFieldMapping( + "dateDateField").getValueMapping().getColumns()[0].getType()); - assertSQL("CREATE TABLE TemporalFieldTypes " - + "(.*dateDefaultField TIMESTAMP.*)"); - assertSQL("CREATE TABLE TemporalFieldTypes " - + "(.*dateDateField DATE.*)"); - assertSQL("CREATE TABLE TemporalFieldTypes " - + "(.*dateTimeField TIME.*)"); - assertSQL("CREATE TABLE TemporalFieldTypes " - + "(.*dateTimestampField TIMESTAMP.*)"); + assertEquals(java.sql.Types.TIME, mapping.getFieldMapping( + "dateTimeField").getValueMapping().getColumns()[0].getType()); - assertSQL("CREATE TABLE TemporalFieldTypes " - + "(.*calendarDefaultField TIMESTAMP.*)"); - assertSQL("CREATE TABLE TemporalFieldTypes " - + "(.*calendarDateField DATE.*)"); - assertSQL("CREATE TABLE TemporalFieldTypes " - + "(.*calendarTimeField TIME.*)"); - assertSQL("CREATE TABLE TemporalFieldTypes " - + "(.*calendarTimestampField TIMESTAMP.*)"); + assertEquals(java.sql.Types.TIMESTAMP, mapping.getFieldMapping( + "dateTimestampField").getValueMapping().getColumns()[0] + .getType()); + + assertEquals(java.sql.Types.TIMESTAMP, mapping.getFieldMapping( + "calendarDefaultField").getValueMapping().getColumns()[0] + .getType()); + + assertEquals(java.sql.Types.DATE, mapping.getFieldMapping( + "calendarDateField").getValueMapping().getColumns()[0] + .getType()); + + assertEquals(java.sql.Types.TIME, mapping.getFieldMapping( + "calendarTimeField").getValueMapping().getColumns()[0] + .getType()); + + assertEquals(java.sql.Types.TIMESTAMP, mapping.getFieldMapping( + "calendarTimestampField").getValueMapping().getColumns()[0] + .getType()); } }