HHH-7187 - Fixing tests on PostgreSQL

This commit is contained in:
Lukasz Antoniak 2012-04-14 17:25:46 +02:00 committed by Strong Liu
parent 68dda2c242
commit b8e356f966
6 changed files with 39 additions and 11 deletions

View File

@ -24,8 +24,10 @@
package org.hibernate.envers.test.integration.data;
import java.util.Arrays;
import java.util.Properties;
import javax.persistence.EntityManager;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.junit.Test;
import org.hibernate.ejb.Ejb3Configuration;
@ -44,6 +46,15 @@ public class LobSerializables extends AbstractEntityTest {
cfg.addAnnotatedClass(LobSerializableTestEntity.class);
}
@Override
public void addConfigurationProperties(Properties configuration) {
super.addConfigurationProperties(configuration);
if (getDialect() instanceof PostgreSQL82Dialect) {
// In PostgreSQL LOBs cannot be used in auto-commit mode.
configuration.setProperty("hibernate.connection.autocommit", "false");
}
}
@Test
public void initData() {
EntityManager em = getEntityManager();

View File

@ -24,8 +24,10 @@
package org.hibernate.envers.test.integration.data;
import java.util.Arrays;
import java.util.Properties;
import javax.persistence.EntityManager;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.junit.Test;
import org.hibernate.ejb.Ejb3Configuration;
@ -45,6 +47,15 @@ public class Lobs extends AbstractEntityTest {
cfg.addAnnotatedClass(LobTestEntity.class);
}
@Override
public void addConfigurationProperties(Properties configuration) {
super.addConfigurationProperties(configuration);
if (getDialect() instanceof PostgreSQL82Dialect) {
// In PostgreSQL LOBs cannot be used in auto-commit mode.
configuration.setProperty("hibernate.connection.autocommit", "false");
}
}
@Test
@Priority(10)
public void initData() {

View File

@ -31,6 +31,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.Priority;
@ -70,8 +71,8 @@ public class BasicSametable extends AbstractEntityTest {
session.createSQLQuery("CREATE TABLE children(parent_id integer, child1_id integer NULL, child2_id integer NULL)").executeUpdate();
session.createSQLQuery("DROP TABLE children_AUD").executeUpdate();
session.createSQLQuery("CREATE TABLE children_AUD(REV integer NOT NULL, REVEND integer, REVTYPE " +
(getDialect() instanceof Oracle8iDialect ? "number(3,0)" : "tinyint") + ", " +
"parent_id integer, child1_id integer NULL, child2_id integer NULL)").executeUpdate();
(getDialect() instanceof Oracle8iDialect ? "number(3,0)" : (getDialect() instanceof PostgreSQL82Dialect ? "smallint" : "tinyint")) +
", parent_id integer, child1_id integer NULL, child2_id integer NULL)").executeUpdate();
em.getTransaction().commit();
em.clear();

View File

@ -1,9 +1,10 @@
package org.hibernate.envers.test.integration.reventity.trackmodifiedentities;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;
import javax.persistence.EntityManager;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.ejb.Ejb3Configuration;
@ -11,6 +12,7 @@ import org.hibernate.envers.CrossTypeRevisionChangesReader;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.entities.StrTestEntity;
import org.hibernate.envers.test.tools.TestTools;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
@ -21,7 +23,6 @@ public class TrackingEntitiesMultipleChangesTest extends AbstractEntityTest {
@Override
public void configure(Ejb3Configuration cfg) {
cfg.setProperty("org.hibernate.envers.track_entities_changed_in_revision", "true");
cfg.addAnnotatedClass(StrTestEntity.class);
}
@ -69,7 +70,7 @@ public class TrackingEntitiesMultipleChangesTest extends AbstractEntityTest {
StrTestEntity ste1 = new StrTestEntity("x", steId1);
StrTestEntity ste2 = new StrTestEntity("y", steId2);
assert Arrays.asList(ste1, ste2).equals(getCrossTypeRevisionChangesReader().findEntities(1));
Assert.assertEquals(TestTools.makeSet(ste1, ste2), new HashSet<Object>(getCrossTypeRevisionChangesReader().findEntities(1)));
}
@Test
@ -77,14 +78,14 @@ public class TrackingEntitiesMultipleChangesTest extends AbstractEntityTest {
StrTestEntity ste1 = new StrTestEntity("z", steId1);
StrTestEntity ste2 = new StrTestEntity(null, steId2);
assert Arrays.asList(ste1, ste2).equals(getCrossTypeRevisionChangesReader().findEntities(2));
Assert.assertEquals(TestTools.makeSet(ste1, ste2), new HashSet<Object>(getCrossTypeRevisionChangesReader().findEntities(2)));
}
@Test
public void testTrackUpdateAndRemoveTheSameEntity() {
StrTestEntity ste1 = new StrTestEntity(null, steId1);
assert Arrays.asList(ste1).equals(getCrossTypeRevisionChangesReader().findEntities(3));
Assert.assertEquals(TestTools.makeSet(ste1), new HashSet<Object>(getCrossTypeRevisionChangesReader().findEntities(3)));
}
private CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() {

View File

@ -37,6 +37,7 @@ import org.hibernate.dialect.Oracle8iDialect;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.strategy.ValidityAuditStrategy;
@ -110,8 +111,9 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends AbstractEntityT
"CREATE TABLE children_AUD(REV integer NOT NULL, REVEND integer, "
+ revendTimestampColumName + " "
+ (getDialect() instanceof SQLServerDialect ? "datetime" : "timestamp")
+ ", REVTYPE " + (getDialect() instanceof Oracle8iDialect ? "number(3,0)" : "tinyint") + ", "
+ "parent_id integer, child1_id integer NULL, child2_id integer NULL)")
+ ", REVTYPE " + (getDialect() instanceof Oracle8iDialect ? "number(3,0)"
: (getDialect() instanceof PostgreSQL82Dialect ? "smallint" : "tinyint"))
+ ", parent_id integer, child1_id integer NULL, child2_id integer NULL)")
.executeUpdate();
em.getTransaction().commit();
em.clear();

View File

@ -39,6 +39,7 @@ import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.enhanced.DefaultRevisionEntity;
@ -111,8 +112,9 @@ public class ValidityAuditStrategyRevEndTsTest extends AbstractEntityTest {
"CREATE TABLE children_AUD(REV integer NOT NULL, REVEND integer, "
+ revendTimestampColumName + " "
+ (getDialect() instanceof SQLServerDialect ? "datetime" : "timestamp")
+ ", REVTYPE " + (getDialect() instanceof Oracle8iDialect ? "number(3,0)" : "tinyint") + ", "
+ "parent_id integer, child1_id integer NULL, child2_id integer NULL)")
+ ", REVTYPE " + (getDialect() instanceof Oracle8iDialect ? "number(3,0)"
: (getDialect() instanceof PostgreSQL82Dialect ? "smallint" : "tinyint"))
+ ", parent_id integer, child1_id integer NULL, child2_id integer NULL)")
.executeUpdate();
em.getTransaction().commit();
em.clear();