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:
Gail Badner 2014-12-17 23:21:51 -08:00
parent b4446f368e
commit c29cbf1753
6 changed files with 38 additions and 24 deletions

View File

@ -37,7 +37,7 @@ public class Department implements java.io.Serializable {
private String deptName;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue
@Column(name="id_dep")
public Integer getDeptNo() {
return this.deptNo;

View File

@ -41,7 +41,7 @@ import javax.persistence.Table;
public class Employee implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue
@Column(name="id_emp")
private Integer id;

View File

@ -37,7 +37,7 @@ import javax.persistence.Table;
public class Title implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue
@Column(name="id_title")
private Integer id;

View File

@ -69,6 +69,13 @@ public class TimePropertyTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit();
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.getTransaction().begin();

View File

@ -103,7 +103,7 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase {
}
@Test
public void testTimeGeneratedByColumnDefinition() {
public void testTimeGeneratedByColumnDefault() {
final Entity eOrig = new Entity();
Session s = openSession();
@ -112,22 +112,22 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit();
s.close();
assertNotNull( eOrig.tsColumnDefinition );
assertNotNull( eOrig.tsColumnDefault );
s = openSession();
s.getTransaction().begin();
final Entity eGotten = (Entity) s.get( Entity.class, eOrig.id );
final String tsColumnDefinitionOrigFormatted = timestampFormat.format( eOrig.tsColumnDefinition );
final String tsColumnDefinitionGottenFormatted = timestampFormat.format( eGotten.tsColumnDefinition );
assertEquals( tsColumnDefinitionOrigFormatted , tsColumnDefinitionGottenFormatted );
final String tsColumnDefaultOrigFormatted = timestampFormat.format( eOrig.tsColumnDefault );
final String tsColumnDefaultGottenFormatted = timestampFormat.format( eGotten.tsColumnDefault );
assertEquals( tsColumnDefaultOrigFormatted , tsColumnDefaultGottenFormatted );
s.getTransaction().commit();
s.close();
s = openSession();
s.getTransaction().begin();
final Query queryWithParameter =
s.createQuery( "from TimestampPropertyTest$Entity where tsColumnDefinition=?" )
.setParameter( 0, eOrig.tsColumnDefinition );
s.createQuery( "from TimestampPropertyTest$Entity where tsColumnDefault=?" )
.setParameter( 0, eOrig.tsColumnDefault );
final Entity eQueriedWithParameter = (Entity) queryWithParameter.uniqueResult();
assertNotNull( eQueriedWithParameter );
s.getTransaction().commit();
@ -136,8 +136,8 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.getTransaction().begin();
final Query queryWithTimestamp =
s.createQuery( "from TimestampPropertyTest$Entity where tsColumnDefinition=?" )
.setTimestamp( 0, eOrig.tsColumnDefinition );
s.createQuery( "from TimestampPropertyTest$Entity where tsColumnDefault=?" )
.setTimestamp( 0, eOrig.tsColumnDefault );
final Entity eQueriedWithTimestamp = (Entity) queryWithTimestamp.uniqueResult();
assertNotNull( eQueriedWithTimestamp );
s.getTransaction().commit();
@ -150,7 +150,6 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase {
s.close();
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Entity.class };
@ -167,7 +166,7 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase {
@Temporal( value = TemporalType.TIMESTAMP )
@Generated( value = GenerationTime.INSERT )
@Column( columnDefinition = "datetime(6) default NOW(6)" )
private Date tsColumnDefinition;
@ColumnDefault( value = "CURRENT_TIMESTAMP" )
private Date tsColumnDefault;
}
}

View File

@ -37,6 +37,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.dialect.MySQL57InnoDBDialect;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.SybaseASE15Dialect;
import org.hibernate.ejb.Ejb3Configuration;
@ -423,17 +424,24 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe
}
private void verifyRevEndTimeStamps(String debugInfo, List<Map<String, Object>> revisionEntities) {
for (Map<String, Object> revisionEntity : revisionEntities) {
Date revendTimestamp = (Date) revisionEntity.get(revendTimestampColumName);
SequenceIdRevisionEntity revEnd = (SequenceIdRevisionEntity) revisionEntity.get("REVEND");
for ( Map<String, Object> revisionEntity : revisionEntities ) {
Date revendTimestamp = (Date) revisionEntity.get( revendTimestampColumName );
SequenceIdRevisionEntity revEnd = (SequenceIdRevisionEntity) revisionEntity.get( "REVEND" );
if (revendTimestamp == null) {
Assert.assertNull(revEnd);
} else {
if (getDialect() instanceof MySQL5Dialect) {
if ( revendTimestamp == null ) {
Assert.assertNull( revEnd );
}
else {
if ( getDialect() instanceof MySQL5Dialect && !( getDialect() instanceof MySQL57InnoDBDialect) ) {
// MySQL5 DATETIME column type does not contain milliseconds.
Assert.assertEquals(revendTimestamp.getTime(), (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000)));
} else if (getDialect() instanceof SybaseASE15Dialect) {
// MySQL 5.7 supports milliseconds and when MySQL57InnoDBDialect is used, it is assumed that
// 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".
Assert.assertEquals(
revendTimestamp.getTime() / 1000.0, revEnd.getTimestamp() / 1000.0, 1.0 / 300.0