HHH-10729 HHH-9021 HHH-10230 : Add more checks to test cases

(cherry picked from commit 13db8b95e3)
This commit is contained in:
Gail Badner 2016-06-28 17:11:26 -07:00
parent 6ecd2bd472
commit 31fc318585
2 changed files with 53 additions and 0 deletions

View File

@ -28,6 +28,7 @@ import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
/**
@ -75,6 +76,9 @@ public class CriteriaLiteralInSelectExpressionTest extends BaseEntityManagerFunc
final List<MyEntityDTO> dtos = entityManager.createQuery( query ).getResultList();
assertThat( dtos.size(), is( 1 ) );
assertThat( dtos.get( 0 ).active, is( false ) );
assertThat( dtos.get( 0 ).name, is( "Fab" ) );
assertThat( dtos.get( 0 ).surname, nullValue() );
entityManager.getTransaction().commit();
}
@ -105,6 +109,42 @@ public class CriteriaLiteralInSelectExpressionTest extends BaseEntityManagerFunc
final List<MyEntityDTO> dtos = entityManager.createQuery( query ).getResultList();
assertThat( dtos.size(), is( 1 ) );
assertThat( dtos.get( 0 ).active, is( false ) );
assertThat( dtos.get( 0 ).name, nullValue() );
assertThat( dtos.get( 0 ).surname, nullValue() );
entityManager.getTransaction().commit();
}
catch (Exception e) {
if ( entityManager.getTransaction().isActive() ) {
entityManager.getTransaction().rollback();
}
throw e;
}
finally {
entityManager.close();
}
}
@Test
@TestForIssue(jiraKey = "HHH-10861")
public void testNullLiteralFirst() throws Exception {
final EntityManager entityManager = getOrCreateEntityManager();
try {
entityManager.getTransaction().begin();
final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
final CriteriaQuery<MyEntityDTO> query = criteriaBuilder.createQuery( MyEntityDTO.class );
final Root<MyEntity> entity = query.from( MyEntity.class );
query.multiselect( criteriaBuilder.nullLiteral( String.class ), entity.get( "surname" ) );
final List<MyEntityDTO> dtos = entityManager.createQuery( query ).getResultList();
assertThat( dtos.size(), is( 1 ) );
assertThat( dtos.get( 0 ).name, nullValue() );
assertThat( dtos.get( 0 ).surname, is( "A" ) );
assertThat( dtos.get( 0 ).active, is( false ) );
entityManager.getTransaction().commit();
}
@ -135,6 +175,9 @@ public class CriteriaLiteralInSelectExpressionTest extends BaseEntityManagerFunc
final List<MyEntityDTO> dtos = entityManager.createQuery( query ).getResultList();
assertThat( dtos.size(), is( 1 ) );
assertThat( dtos.get( 0 ).name, is( "Leo" ) );
assertThat( dtos.get( 0 ).surname, is( "A" ) );
assertThat( dtos.get( 0 ).active, is( false ) );
entityManager.getTransaction().commit();
}
@ -164,6 +207,8 @@ public class CriteriaLiteralInSelectExpressionTest extends BaseEntityManagerFunc
final List<Tuple> results = typedQuery.getResultList();
assertThat( results.size(), is( 1 ) );
assertThat( results.get( 0 ).getElements().size(), is( 1 ) );
assertThat( results.get( 0 ).get( 0 ), is( false ) );
}
finally {
entityManager.close();

View File

@ -62,6 +62,10 @@ public class QueryWithLiteralsInSelectExpressionTest extends BaseEntityManagerFu
Object[].class
).getResultList();
Assert.assertEquals( 1, elements.size() );
Assert.assertEquals( 3, elements.get( 0 ).length );
Assert.assertEquals( true, elements.get( 0 )[ 0 ] );
Assert.assertEquals( false, elements.get( 0 )[ 1 ] );
Assert.assertEquals( "Fab", elements.get( 0 )[ 2 ] );
}
finally {
entityManager.close();
@ -78,6 +82,10 @@ public class QueryWithLiteralsInSelectExpressionTest extends BaseEntityManagerFu
Object[].class
).getResultList();
Assert.assertEquals( 1, elements.size() );
Assert.assertEquals( 3, elements.get( 0 ).length );
Assert.assertEquals( null, elements.get( 0 )[ 0 ] );
Assert.assertEquals( false, elements.get( 0 )[ 1 ] );
Assert.assertEquals( "Fab", elements.get( 0 )[ 2 ] );
}
finally {
entityManager.close();