Skip to content

Commit b211a47

Browse files
committed
overwrite the previous useless test for @source
with one that actually tests something meaningful
1 parent 04c266d commit b211a47

File tree

1 file changed

+30
-55
lines changed

1 file changed

+30
-55
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/various/TimestampTest.java

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,45 @@
44
*/
55
package org.hibernate.orm.test.annotations.various;
66

7-
import org.hibernate.boot.MetadataSources;
8-
import org.hibernate.boot.registry.StandardServiceRegistry;
9-
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
10-
import org.hibernate.boot.spi.MetadataImplementor;
11-
import org.hibernate.testing.orm.junit.BaseUnitTest;
12-
import org.hibernate.testing.util.ServiceRegistryUtil;
13-
import org.hibernate.type.BasicType;
14-
import org.hibernate.type.StandardBasicTypes;
15-
import org.junit.jupiter.api.AfterAll;
16-
import org.junit.jupiter.api.BeforeAll;
7+
import org.hibernate.testing.orm.junit.DomainModel;
8+
import org.hibernate.testing.orm.junit.SessionFactory;
9+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
1710
import org.junit.jupiter.api.Test;
1811

19-
import static org.assertj.core.api.Assertions.assertThat;
12+
import java.sql.Timestamp;
13+
import java.util.Date;
14+
15+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
16+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2017

2118
/**
2219
* Test for the @Timestamp annotation.
2320
*
2421
* @author Hardy Ferentschik
2522
*/
26-
@BaseUnitTest
23+
@SessionFactory
24+
@DomainModel(annotatedClasses = {VMTimestamped.class, DBTimestamped.class})
2725
public class TimestampTest {
28-
private StandardServiceRegistry ssr;
29-
private MetadataImplementor metadata;
30-
31-
@BeforeAll
32-
public void setUp() {
33-
ssr = ServiceRegistryUtil.serviceRegistry();
34-
metadata = (MetadataImplementor) new MetadataSources( ssr )
35-
.addAnnotatedClass( VMTimestamped.class )
36-
.addAnnotatedClass( DBTimestamped.class )
37-
.getMetadataBuilder()
38-
.build();
39-
}
40-
41-
@AfterAll
42-
public void tearDown() {
43-
if ( ssr != null ) {
44-
StandardServiceRegistryBuilder.destroy( ssr );
45-
}
46-
}
47-
48-
@Test
49-
public void testTimestampSourceIsVM() {
50-
assertTimestampSource( VMTimestamped.class );
51-
}
52-
53-
@Test
54-
public void testTimestampSourceIsDB() {
55-
assertTimestampSource( DBTimestamped.class );
56-
}
57-
58-
private void assertTimestampSource(Class<?> clazz ) {
59-
assertTimestampSource( clazz,
60-
metadata.getTypeConfiguration().getBasicTypeRegistry()
61-
.resolve( StandardBasicTypes.TIMESTAMP ) );
62-
}
26+
@Test void test(SessionFactoryScope scope) {
27+
scope.inTransaction( session -> {
28+
var vmTimestamped = new VMTimestamped();
29+
session.persist( vmTimestamped );
30+
var dbTimestamped = new DBTimestamped();
31+
session.persist( dbTimestamped );
32+
session.flush();
33+
assertNotNull( vmTimestamped.getLastUpdate() );
34+
assertNotNull( dbTimestamped.getLastUpdate() );
35+
assertInstanceOf( Date.class, vmTimestamped.getLastUpdate() );
36+
assertInstanceOf( Timestamp.class, dbTimestamped.getLastUpdate() );
37+
} );
38+
scope.inTransaction( session -> {
39+
var vmTimestamped = session.find(VMTimestamped.class, 1);
40+
var dbTimestamped = session.find(DBTimestamped.class, 1);
41+
assertNotNull( vmTimestamped.getLastUpdate() );
42+
assertNotNull( dbTimestamped.getLastUpdate() );
43+
assertInstanceOf( Timestamp.class, vmTimestamped.getLastUpdate() );
44+
assertInstanceOf( Timestamp.class, dbTimestamped.getLastUpdate() );
45+
} );
6346

64-
private void assertTimestampSource(Class<?> clazz, BasicType<?> basicType) {
65-
var persistentClass = metadata.getEntityBinding( clazz.getName() );
66-
assertThat( persistentClass ).isNotNull();
67-
var versionProperty = persistentClass.getVersion();
68-
assertThat( versionProperty ).isNotNull();
69-
assertThat( versionProperty.getType().getName() )
70-
.describedAs( "Wrong timestamp type" )
71-
.isEqualTo( basicType.getName() );
7247
}
7348
}

0 commit comments

Comments
 (0)