Fixed test

This commit is contained in:
Steve Ebersole 2019-10-15 14:06:33 -05:00
parent 6ea723ddc5
commit a5fe864295
1 changed files with 23 additions and 19 deletions

View File

@ -59,25 +59,13 @@ public class SmokeTests {
public void setUp(SessionFactoryScope scope) { public void setUp(SessionFactoryScope scope) {
scope.inTransaction( scope.inTransaction(
session -> { session -> {
{ SimpleEntity simpleEntity = new SimpleEntity();
SimpleEntity simpleEntity = new SimpleEntity(); simpleEntity.setId( 1 );
simpleEntity.setId( 1 ); simpleEntity.setGender( FEMALE );
simpleEntity.setGender( FEMALE ); simpleEntity.setName( "Fab" );
simpleEntity.setName( "Fab" ); simpleEntity.setGender2( MALE );
simpleEntity.setGender2( MALE ); simpleEntity.setComponent( new Component( "a1", "a2" ) );
simpleEntity.setComponent( new Component( "a1", "a2" ) ); session.save( simpleEntity );
session.save( simpleEntity );
}
{
SimpleEntity simpleEntity = new SimpleEntity();
simpleEntity.setId( 2 );
simpleEntity.setGender( MALE );
simpleEntity.setName( "Andrea" );
simpleEntity.setGender2( FEMALE );
simpleEntity.setComponent( new Component( "b1", "b2" ) );
session.save( simpleEntity );
}
} }
); );
} }
@ -212,14 +200,29 @@ public class SmokeTests {
@Test @Test
public void testHqlQueryReuseWithDiffParameterBinds(SessionFactoryScope scope) { public void testHqlQueryReuseWithDiffParameterBinds(SessionFactoryScope scope) {
// first, let's create a second entity
scope.inTransaction( scope.inTransaction(
session -> { session -> {
SimpleEntity simpleEntity = new SimpleEntity();
simpleEntity.setId( 2 );
simpleEntity.setGender( MALE );
simpleEntity.setName( "Andrea" );
simpleEntity.setGender2( FEMALE );
simpleEntity.setComponent( new Component( "b1", "b2" ) );
session.save( simpleEntity );
}
);
scope.inTransaction(
session -> {
// create a Query ref that we will use to query for each entity individually through a parameter
final QueryImplementor<Component> query = session.createQuery( final QueryImplementor<Component> query = session.createQuery(
"select e.component from SimpleEntity e where e.component.attribute1 = :param", "select e.component from SimpleEntity e where e.component.attribute1 = :param",
Component.class Component.class
); );
{ {
// first query execution searching for the standard entity created in set-up
final Component component = query.setParameter( "param", "a1" ).uniqueResult(); final Component component = query.setParameter( "param", "a1" ).uniqueResult();
assertThat( component, notNullValue() ); assertThat( component, notNullValue() );
assertThat( component.getAttribute1(), is( "a1" ) ); assertThat( component.getAttribute1(), is( "a1" ) );
@ -227,6 +230,7 @@ public class SmokeTests {
} }
{ {
// second query execution searching for the second entity created locally
final Component component = query.setParameter( "param", "b1" ).uniqueResult(); final Component component = query.setParameter( "param", "b1" ).uniqueResult();
assertThat( component, notNullValue() ); assertThat( component, notNullValue() );
assertThat( component.getAttribute1(), is( "b1" ) ); assertThat( component.getAttribute1(), is( "b1" ) );