HHH-7187 - Fix tests against MySQL
This commit is contained in:
parent
5a2b019e66
commit
6aed8651a6
|
@ -27,6 +27,7 @@ import java.io.IOException;
|
|||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Before;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
@ -45,6 +46,8 @@ import org.hibernate.testing.BeforeClassOnce;
|
|||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public abstract class AbstractEntityTest extends AbstractEnversTest {
|
||||
public static final Dialect DIALECT = Dialect.getDialect();
|
||||
|
||||
private EntityManagerFactoryImpl emf;
|
||||
private EntityManager entityManager;
|
||||
private AuditReader auditReader;
|
||||
|
@ -56,6 +59,10 @@ public abstract class AbstractEntityTest extends AbstractEnversTest {
|
|||
|
||||
public void addConfigurationProperties(Properties configuration) { }
|
||||
|
||||
protected static Dialect getDialect() {
|
||||
return DIALECT;
|
||||
}
|
||||
|
||||
private void closeEntityManager() {
|
||||
if (entityManager != null) {
|
||||
entityManager.close();
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.hibernate.envers.test.integration.readwriteexpression;
|
|||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -11,8 +12,8 @@ import org.hibernate.envers.test.Priority;
|
|||
|
||||
public class ReadWriteExpressionChange extends AbstractEntityTest {
|
||||
|
||||
private static final double HEIGHT_INCHES = 73;
|
||||
private static final double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d;
|
||||
private static final Double HEIGHT_INCHES = 73.0d;
|
||||
private static final Double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d;
|
||||
|
||||
private Integer id;
|
||||
|
||||
|
@ -36,18 +37,18 @@ public class ReadWriteExpressionChange extends AbstractEntityTest {
|
|||
public void shouldRespectWriteExpression() {
|
||||
EntityManager em = getEntityManager();
|
||||
List resultList = em.createNativeQuery("select size_in_cm from t_staff_AUD where id ="+id).getResultList();
|
||||
assert 1 == resultList.size();
|
||||
Assert.assertEquals(1, resultList.size());
|
||||
Double sizeInCm = (Double) resultList.get(0);
|
||||
assert sizeInCm.equals(HEIGHT_CENTIMETERS);
|
||||
Assert.assertEquals(HEIGHT_CENTIMETERS, sizeInCm.doubleValue(), 0.00000001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRespectReadExpression() {
|
||||
List<Number> revisions = getAuditReader().getRevisions(Staff.class, id);
|
||||
assert 1 == revisions.size();
|
||||
Assert.assertEquals(1, revisions.size());
|
||||
Number number = revisions.get(0);
|
||||
Staff staffRev = getAuditReader().find(Staff.class, id, number);
|
||||
assert HEIGHT_INCHES == staffRev.getSizeInInches();
|
||||
Assert.assertEquals(HEIGHT_INCHES, staffRev.getSizeInInches(), 0.00000001);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,7 +56,8 @@ public class CustomDate extends AbstractEntityTest {
|
|||
public void initData() throws InterruptedException {
|
||||
timestamp1 = System.currentTimeMillis();
|
||||
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(1100); // CustomDateRevEntity.dateTimestamp field maps to date type which on some RDBMSs gets
|
||||
// truncated to seconds (for example MySQL 5.1).
|
||||
|
||||
// Revision 1
|
||||
EntityManager em = getEntityManager();
|
||||
|
@ -68,7 +69,8 @@ public class CustomDate extends AbstractEntityTest {
|
|||
|
||||
timestamp2 = System.currentTimeMillis();
|
||||
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(1100); // CustomDateRevEntity.dateTimestamp field maps to date type which on some RDBMSs gets
|
||||
// truncated to seconds (for example MySQL 5.1).
|
||||
|
||||
// Revision 2
|
||||
em.getTransaction().begin();
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.util.Arrays;
|
|||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
@ -18,6 +20,7 @@ import org.hibernate.mapping.Table;
|
|||
* exist in a different database schema.
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@RequiresDialect({H2Dialect.class})
|
||||
public class DifferentDBSchemaTest extends AbstractEntityTest {
|
||||
private static final String SCHEMA_NAME = "ENVERS_AUDIT";
|
||||
private Integer steId = null;
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.util.Set;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.hibernate.dialect.MySQL5Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
@ -426,7 +427,12 @@ public class ValidityAuditStrategyRevEndTsTest extends AbstractEntityTest {
|
|||
if (revendTimestamp == null) {
|
||||
assert revEnd == null;
|
||||
} else {
|
||||
assert revendTimestamp.getTime() == revEnd.getTimestamp();
|
||||
if (getDialect() instanceof MySQL5Dialect) {
|
||||
// MySQL5 DATETIME column type does not contain milliseconds.
|
||||
assert revendTimestamp.getTime() == (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000));
|
||||
} else {
|
||||
assert revendTimestamp.getTime() == revEnd.getTimestamp();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue