HHH-15982 Refactor tests to use StatementInspector
This commit is contained in:
parent
bf60dd9d2a
commit
e26f4d25ab
|
@ -8,10 +8,8 @@ package org.hibernate.orm.test.mapping.converted.converter.onetoone;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.hibernate.engine.internal.StatisticalLoggingSessionEventListener;
|
||||
|
||||
import org.hibernate.testing.jdbc.SQLStatementInspector;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
|
@ -36,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
/**
|
||||
* @author Marco Belladelli
|
||||
*/
|
||||
@SessionFactory
|
||||
@SessionFactory(useCollectingStatementInspector = true)
|
||||
@DomainModel(annotatedClasses = {
|
||||
BidirectionalOneToOneWithConverterEagerTest.FooEntity.class,
|
||||
BidirectionalOneToOneWithConverterEagerTest.BarEntity.class,
|
||||
|
@ -72,24 +70,18 @@ public class BidirectionalOneToOneWithConverterEagerTest {
|
|||
|
||||
@Test
|
||||
public void testBidirectionalFetch(SessionFactoryScope scope) {
|
||||
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
|
||||
statementInspector.clear();
|
||||
scope.inTransaction( session -> {
|
||||
FooEntity foo = session.find( FooEntity.class, 1L );
|
||||
|
||||
final AtomicInteger queryExecutionCount = new AtomicInteger();
|
||||
session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
|
||||
@Override
|
||||
public void jdbcExecuteStatementStart() {
|
||||
super.jdbcExecuteStatementStart();
|
||||
queryExecutionCount.getAndIncrement();
|
||||
}
|
||||
} );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
|
||||
BarEntity bar = foo.getBar();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
assertEquals( 0.5, bar.getaDouble() );
|
||||
|
||||
FooEntity associatedFoo = bar.getFoo();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
assertEquals( "foo_name", associatedFoo.getName() );
|
||||
assertEquals( foo, associatedFoo );
|
||||
|
||||
|
@ -99,24 +91,18 @@ public class BidirectionalOneToOneWithConverterEagerTest {
|
|||
|
||||
@Test
|
||||
public void testBidirectionalFetchInverse(SessionFactoryScope scope) {
|
||||
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
|
||||
statementInspector.clear();
|
||||
scope.inTransaction( session -> {
|
||||
BarEntity bar = session.find( BarEntity.class, 1L );
|
||||
|
||||
final AtomicInteger queryExecutionCount = new AtomicInteger();
|
||||
session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
|
||||
@Override
|
||||
public void jdbcExecuteStatementStart() {
|
||||
super.jdbcExecuteStatementStart();
|
||||
queryExecutionCount.getAndIncrement();
|
||||
}
|
||||
} );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
|
||||
FooEntity foo = bar.getFoo();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
assertEquals( "foo_name", foo.getName() );
|
||||
|
||||
BarEntity associatedBar = foo.getBar();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
assertEquals( 0.5, associatedBar.getaDouble() );
|
||||
assertEquals( bar, associatedBar );
|
||||
|
||||
|
|
|
@ -8,10 +8,8 @@ package org.hibernate.orm.test.mapping.converted.converter.onetoone;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.hibernate.engine.internal.StatisticalLoggingSessionEventListener;
|
||||
|
||||
import org.hibernate.testing.jdbc.SQLStatementInspector;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
|
@ -36,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
/**
|
||||
* @author Marco Belladelli
|
||||
*/
|
||||
@SessionFactory
|
||||
@SessionFactory(useCollectingStatementInspector = true)
|
||||
@DomainModel(annotatedClasses = {
|
||||
BidirectionalOneToOneWithConverterLazyTest.FooEntity.class,
|
||||
BidirectionalOneToOneWithConverterLazyTest.BarEntity.class,
|
||||
|
@ -72,24 +70,17 @@ public class BidirectionalOneToOneWithConverterLazyTest {
|
|||
|
||||
@Test
|
||||
public void testBidirectionalFetch(SessionFactoryScope scope) {
|
||||
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
|
||||
scope.inTransaction( session -> {
|
||||
FooEntity foo = session.find( FooEntity.class, 1L );
|
||||
|
||||
final AtomicInteger queryExecutionCount = new AtomicInteger();
|
||||
session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
|
||||
@Override
|
||||
public void jdbcExecuteStatementStart() {
|
||||
super.jdbcExecuteStatementStart();
|
||||
queryExecutionCount.getAndIncrement();
|
||||
}
|
||||
} );
|
||||
statementInspector.clear();
|
||||
|
||||
BarEntity bar = foo.getBar();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 0 );
|
||||
assertEquals( 0.5, bar.getaDouble() );
|
||||
|
||||
FooEntity associatedFoo = bar.getFoo();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 0 );
|
||||
assertEquals( "foo_name", associatedFoo.getName() );
|
||||
assertEquals( foo, associatedFoo );
|
||||
|
||||
|
@ -99,24 +90,17 @@ public class BidirectionalOneToOneWithConverterLazyTest {
|
|||
|
||||
@Test
|
||||
public void testBidirectionalFetchInverse(SessionFactoryScope scope) {
|
||||
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
|
||||
scope.inTransaction( session -> {
|
||||
BarEntity bar = session.find( BarEntity.class, 1L );
|
||||
|
||||
final AtomicInteger queryExecutionCount = new AtomicInteger();
|
||||
session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
|
||||
@Override
|
||||
public void jdbcExecuteStatementStart() {
|
||||
super.jdbcExecuteStatementStart();
|
||||
queryExecutionCount.getAndIncrement();
|
||||
}
|
||||
} );
|
||||
statementInspector.clear();
|
||||
|
||||
FooEntity foo = bar.getFoo();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 0 );
|
||||
assertEquals( "foo_name", foo.getName() );
|
||||
|
||||
BarEntity associatedBar = foo.getBar();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 0 );
|
||||
assertEquals( 0.5, associatedBar.getaDouble() );
|
||||
assertEquals( bar, associatedBar );
|
||||
|
||||
|
|
|
@ -6,10 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.onetoone.bidirectional;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.hibernate.engine.internal.StatisticalLoggingSessionEventListener;
|
||||
|
||||
import org.hibernate.testing.jdbc.SQLStatementInspector;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
@ -31,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
/**
|
||||
* @author Marco Belladelli
|
||||
*/
|
||||
@SessionFactory
|
||||
@SessionFactory(useCollectingStatementInspector = true)
|
||||
@DomainModel(annotatedClasses = {
|
||||
BidirectionalOneToOneEagerFKTest.FooEntity.class,
|
||||
BidirectionalOneToOneEagerFKTest.BarEntity.class
|
||||
|
@ -66,24 +63,18 @@ public class BidirectionalOneToOneEagerFKTest {
|
|||
|
||||
@Test
|
||||
public void testBidirectionalFetchJoinColumnSide(SessionFactoryScope scope) {
|
||||
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
|
||||
statementInspector.clear();
|
||||
scope.inTransaction( session -> {
|
||||
final AtomicInteger queryExecutionCount = new AtomicInteger();
|
||||
session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
|
||||
@Override
|
||||
public void jdbcExecuteStatementStart() {
|
||||
super.jdbcExecuteStatementStart();
|
||||
queryExecutionCount.getAndIncrement();
|
||||
}
|
||||
} );
|
||||
|
||||
FooEntity foo = session.find( FooEntity.class, 1L );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
|
||||
BarEntity bar = foo.getBar();
|
||||
assertEquals( 1, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
assertEquals( 0.5, bar.getaDouble() );
|
||||
|
||||
FooEntity associatedFoo = bar.getFoo();
|
||||
assertEquals( 1, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
assertEquals( "foo_name", associatedFoo.getName() );
|
||||
assertEquals( foo, associatedFoo );
|
||||
|
||||
|
@ -93,25 +84,18 @@ public class BidirectionalOneToOneEagerFKTest {
|
|||
|
||||
@Test
|
||||
public void testBidirectionalFetchMappedBySide(SessionFactoryScope scope) {
|
||||
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
|
||||
statementInspector.clear();
|
||||
scope.inTransaction( session -> {
|
||||
final AtomicInteger queryExecutionCount = new AtomicInteger();
|
||||
session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
|
||||
@Override
|
||||
public void jdbcExecuteStatementStart() {
|
||||
super.jdbcExecuteStatementStart();
|
||||
queryExecutionCount.getAndIncrement();
|
||||
}
|
||||
} );
|
||||
|
||||
BarEntity bar = session.find( BarEntity.class, 1L );
|
||||
assertEquals( 1, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
|
||||
FooEntity foo = bar.getFoo();
|
||||
assertEquals( 1, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
assertEquals( "foo_name", foo.getName() );
|
||||
|
||||
BarEntity associatedBar = foo.getBar();
|
||||
assertEquals( 1, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
assertEquals( 0.5, associatedBar.getaDouble() );
|
||||
assertEquals( bar, associatedBar );
|
||||
|
||||
|
|
|
@ -6,10 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.onetoone.bidirectional;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.hibernate.engine.internal.StatisticalLoggingSessionEventListener;
|
||||
|
||||
import org.hibernate.testing.jdbc.SQLStatementInspector;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
@ -31,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
/**
|
||||
* @author Marco Belladelli
|
||||
*/
|
||||
@SessionFactory
|
||||
@SessionFactory(useCollectingStatementInspector = true)
|
||||
@DomainModel(annotatedClasses = {
|
||||
BidirectionalOneToOneLazyFKTest.FooEntity.class,
|
||||
BidirectionalOneToOneLazyFKTest.BarEntity.class
|
||||
|
@ -66,24 +63,17 @@ public class BidirectionalOneToOneLazyFKTest {
|
|||
|
||||
@Test
|
||||
public void testBidirectionalFetchJoinColumnSide(SessionFactoryScope scope) {
|
||||
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
|
||||
scope.inTransaction( session -> {
|
||||
FooEntity foo = session.find( FooEntity.class, 1L );
|
||||
|
||||
final AtomicInteger queryExecutionCount = new AtomicInteger();
|
||||
session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
|
||||
@Override
|
||||
public void jdbcExecuteStatementStart() {
|
||||
super.jdbcExecuteStatementStart();
|
||||
queryExecutionCount.getAndIncrement();
|
||||
}
|
||||
} );
|
||||
statementInspector.clear();
|
||||
|
||||
BarEntity bar = foo.getBar();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 0 );
|
||||
assertEquals( 0.5, bar.getaDouble() );
|
||||
|
||||
FooEntity associatedFoo = bar.getFoo();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 0 );
|
||||
assertEquals( "foo_name", associatedFoo.getName() );
|
||||
assertEquals( foo, associatedFoo );
|
||||
|
||||
|
@ -93,24 +83,17 @@ public class BidirectionalOneToOneLazyFKTest {
|
|||
|
||||
@Test
|
||||
public void testBidirectionalFetchMappedBySide(SessionFactoryScope scope) {
|
||||
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
|
||||
scope.inTransaction( session -> {
|
||||
BarEntity bar = session.find( BarEntity.class, 1L );
|
||||
|
||||
final AtomicInteger queryExecutionCount = new AtomicInteger();
|
||||
session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
|
||||
@Override
|
||||
public void jdbcExecuteStatementStart() {
|
||||
super.jdbcExecuteStatementStart();
|
||||
queryExecutionCount.getAndIncrement();
|
||||
}
|
||||
} );
|
||||
statementInspector.clear();
|
||||
|
||||
FooEntity foo = bar.getFoo();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 0 );
|
||||
assertEquals( "foo_name", foo.getName() );
|
||||
|
||||
BarEntity associatedBar = foo.getBar();
|
||||
assertEquals( 0, queryExecutionCount.get() );
|
||||
statementInspector.assertExecutedCount( 0 );
|
||||
assertEquals( 0.5, associatedBar.getaDouble() );
|
||||
assertEquals( bar, associatedBar );
|
||||
|
||||
|
|
Loading…
Reference in New Issue