HHH-10729 HHH-9021 HHH-10230 : Add more checks to test cases
This commit is contained in:
parent
597183a3b9
commit
13db8b95e3
|
@ -28,6 +28,7 @@ import org.junit.Test;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,6 +76,9 @@ public class CriteriaLiteralInSelectExpressionTest extends BaseEntityManagerFunc
|
||||||
final List<MyEntityDTO> dtos = entityManager.createQuery( query ).getResultList();
|
final List<MyEntityDTO> dtos = entityManager.createQuery( query ).getResultList();
|
||||||
|
|
||||||
assertThat( dtos.size(), is( 1 ) );
|
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();
|
entityManager.getTransaction().commit();
|
||||||
}
|
}
|
||||||
|
@ -105,6 +109,42 @@ public class CriteriaLiteralInSelectExpressionTest extends BaseEntityManagerFunc
|
||||||
final List<MyEntityDTO> dtos = entityManager.createQuery( query ).getResultList();
|
final List<MyEntityDTO> dtos = entityManager.createQuery( query ).getResultList();
|
||||||
|
|
||||||
assertThat( dtos.size(), is( 1 ) );
|
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();
|
entityManager.getTransaction().commit();
|
||||||
}
|
}
|
||||||
|
@ -135,6 +175,9 @@ public class CriteriaLiteralInSelectExpressionTest extends BaseEntityManagerFunc
|
||||||
final List<MyEntityDTO> dtos = entityManager.createQuery( query ).getResultList();
|
final List<MyEntityDTO> dtos = entityManager.createQuery( query ).getResultList();
|
||||||
|
|
||||||
assertThat( dtos.size(), is( 1 ) );
|
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();
|
entityManager.getTransaction().commit();
|
||||||
}
|
}
|
||||||
|
@ -164,6 +207,8 @@ public class CriteriaLiteralInSelectExpressionTest extends BaseEntityManagerFunc
|
||||||
final List<Tuple> results = typedQuery.getResultList();
|
final List<Tuple> results = typedQuery.getResultList();
|
||||||
|
|
||||||
assertThat( results.size(), is( 1 ) );
|
assertThat( results.size(), is( 1 ) );
|
||||||
|
assertThat( results.get( 0 ).getElements().size(), is( 1 ) );
|
||||||
|
assertThat( results.get( 0 ).get( 0 ), is( false ) );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
entityManager.close();
|
entityManager.close();
|
||||||
|
|
|
@ -62,6 +62,10 @@ public class QueryWithLiteralsInSelectExpressionTest extends BaseEntityManagerFu
|
||||||
Object[].class
|
Object[].class
|
||||||
).getResultList();
|
).getResultList();
|
||||||
Assert.assertEquals( 1, elements.size() );
|
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 {
|
finally {
|
||||||
entityManager.close();
|
entityManager.close();
|
||||||
|
@ -78,6 +82,10 @@ public class QueryWithLiteralsInSelectExpressionTest extends BaseEntityManagerFu
|
||||||
Object[].class
|
Object[].class
|
||||||
).getResultList();
|
).getResultList();
|
||||||
Assert.assertEquals( 1, elements.size() );
|
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 {
|
finally {
|
||||||
entityManager.close();
|
entityManager.close();
|
||||||
|
|
Loading…
Reference in New Issue