HHH-8401 : Unit test fixes
(cherry picked from commit 45511f10ae
)
Conflicts:
hibernate-core/src/test/java/org/hibernate/test/temporal/TimestampPropertyTest.java
hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java
This commit is contained in:
parent
b4446f368e
commit
c29cbf1753
|
@ -37,7 +37,7 @@ public class Department implements java.io.Serializable {
|
||||||
private String deptName;
|
private String deptName;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
@GeneratedValue
|
||||||
@Column(name="id_dep")
|
@Column(name="id_dep")
|
||||||
public Integer getDeptNo() {
|
public Integer getDeptNo() {
|
||||||
return this.deptNo;
|
return this.deptNo;
|
||||||
|
|
|
@ -41,7 +41,7 @@ import javax.persistence.Table;
|
||||||
public class Employee implements Serializable {
|
public class Employee implements Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
@GeneratedValue
|
||||||
@Column(name="id_emp")
|
@Column(name="id_emp")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ import javax.persistence.Table;
|
||||||
public class Title implements Serializable {
|
public class Title implements Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
@GeneratedValue
|
||||||
@Column(name="id_title")
|
@Column(name="id_title")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,13 @@ public class TimePropertyTest extends BaseCoreFunctionalTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.getTransaction().begin();
|
||||||
|
final Query queryWithParameter = s.createQuery( "from TimePropertyTest$Entity where tAsDate=?" ).setParameter( 0, eOrig.tAsDate );
|
||||||
|
final Entity eQueriedWithParameter = (Entity) queryWithParameter.uniqueResult();
|
||||||
|
assertNotNull( eQueriedWithParameter );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTimeGeneratedByColumnDefinition() {
|
public void testTimeGeneratedByColumnDefault() {
|
||||||
final Entity eOrig = new Entity();
|
final Entity eOrig = new Entity();
|
||||||
|
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
|
@ -112,22 +112,22 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase {
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
assertNotNull( eOrig.tsColumnDefinition );
|
assertNotNull( eOrig.tsColumnDefault );
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
final Entity eGotten = (Entity) s.get( Entity.class, eOrig.id );
|
final Entity eGotten = (Entity) s.get( Entity.class, eOrig.id );
|
||||||
final String tsColumnDefinitionOrigFormatted = timestampFormat.format( eOrig.tsColumnDefinition );
|
final String tsColumnDefaultOrigFormatted = timestampFormat.format( eOrig.tsColumnDefault );
|
||||||
final String tsColumnDefinitionGottenFormatted = timestampFormat.format( eGotten.tsColumnDefinition );
|
final String tsColumnDefaultGottenFormatted = timestampFormat.format( eGotten.tsColumnDefault );
|
||||||
assertEquals( tsColumnDefinitionOrigFormatted , tsColumnDefinitionGottenFormatted );
|
assertEquals( tsColumnDefaultOrigFormatted , tsColumnDefaultGottenFormatted );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
final Query queryWithParameter =
|
final Query queryWithParameter =
|
||||||
s.createQuery( "from TimestampPropertyTest$Entity where tsColumnDefinition=?" )
|
s.createQuery( "from TimestampPropertyTest$Entity where tsColumnDefault=?" )
|
||||||
.setParameter( 0, eOrig.tsColumnDefinition );
|
.setParameter( 0, eOrig.tsColumnDefault );
|
||||||
final Entity eQueriedWithParameter = (Entity) queryWithParameter.uniqueResult();
|
final Entity eQueriedWithParameter = (Entity) queryWithParameter.uniqueResult();
|
||||||
assertNotNull( eQueriedWithParameter );
|
assertNotNull( eQueriedWithParameter );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
|
@ -136,8 +136,8 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase {
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
final Query queryWithTimestamp =
|
final Query queryWithTimestamp =
|
||||||
s.createQuery( "from TimestampPropertyTest$Entity where tsColumnDefinition=?" )
|
s.createQuery( "from TimestampPropertyTest$Entity where tsColumnDefault=?" )
|
||||||
.setTimestamp( 0, eOrig.tsColumnDefinition );
|
.setTimestamp( 0, eOrig.tsColumnDefault );
|
||||||
final Entity eQueriedWithTimestamp = (Entity) queryWithTimestamp.uniqueResult();
|
final Entity eQueriedWithTimestamp = (Entity) queryWithTimestamp.uniqueResult();
|
||||||
assertNotNull( eQueriedWithTimestamp );
|
assertNotNull( eQueriedWithTimestamp );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
|
@ -150,7 +150,6 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase {
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
return new Class[] { Entity.class };
|
return new Class[] { Entity.class };
|
||||||
|
@ -167,7 +166,7 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Temporal( value = TemporalType.TIMESTAMP )
|
@Temporal( value = TemporalType.TIMESTAMP )
|
||||||
@Generated( value = GenerationTime.INSERT )
|
@Generated( value = GenerationTime.INSERT )
|
||||||
@Column( columnDefinition = "datetime(6) default NOW(6)" )
|
@ColumnDefault( value = "CURRENT_TIMESTAMP" )
|
||||||
private Date tsColumnDefinition;
|
private Date tsColumnDefault;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.dialect.MySQL57InnoDBDialect;
|
||||||
import org.hibernate.dialect.MySQL5Dialect;
|
import org.hibernate.dialect.MySQL5Dialect;
|
||||||
import org.hibernate.dialect.SybaseASE15Dialect;
|
import org.hibernate.dialect.SybaseASE15Dialect;
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
@ -423,17 +424,24 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyRevEndTimeStamps(String debugInfo, List<Map<String, Object>> revisionEntities) {
|
private void verifyRevEndTimeStamps(String debugInfo, List<Map<String, Object>> revisionEntities) {
|
||||||
for (Map<String, Object> revisionEntity : revisionEntities) {
|
for ( Map<String, Object> revisionEntity : revisionEntities ) {
|
||||||
Date revendTimestamp = (Date) revisionEntity.get(revendTimestampColumName);
|
Date revendTimestamp = (Date) revisionEntity.get( revendTimestampColumName );
|
||||||
SequenceIdRevisionEntity revEnd = (SequenceIdRevisionEntity) revisionEntity.get("REVEND");
|
SequenceIdRevisionEntity revEnd = (SequenceIdRevisionEntity) revisionEntity.get( "REVEND" );
|
||||||
|
|
||||||
if (revendTimestamp == null) {
|
if ( revendTimestamp == null ) {
|
||||||
Assert.assertNull(revEnd);
|
Assert.assertNull( revEnd );
|
||||||
} else {
|
}
|
||||||
if (getDialect() instanceof MySQL5Dialect) {
|
else {
|
||||||
|
if ( getDialect() instanceof MySQL5Dialect && !( getDialect() instanceof MySQL57InnoDBDialect) ) {
|
||||||
// MySQL5 DATETIME column type does not contain milliseconds.
|
// MySQL5 DATETIME column type does not contain milliseconds.
|
||||||
Assert.assertEquals(revendTimestamp.getTime(), (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000)));
|
// MySQL 5.7 supports milliseconds and when MySQL57InnoDBDialect is used, it is assumed that
|
||||||
} else if (getDialect() instanceof SybaseASE15Dialect) {
|
// the column is defined as DATETIME(6).
|
||||||
|
Assert.assertEquals(
|
||||||
|
revendTimestamp.getTime(),
|
||||||
|
(revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if ( getDialect() instanceof SybaseASE15Dialect ) {
|
||||||
// Sybase "DATETIME values are accurate to 1/300 second on platforms that support this level of granularity".
|
// Sybase "DATETIME values are accurate to 1/300 second on platforms that support this level of granularity".
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
revendTimestamp.getTime() / 1000.0, revEnd.getTimestamp() / 1000.0, 1.0 / 300.0
|
revendTimestamp.getTime() / 1000.0, revEnd.getTimestamp() / 1000.0, 1.0 / 300.0
|
||||||
|
|
Loading…
Reference in New Issue