return new FunctionalTestClassTestSuite( CriteriaClassicAggregationReturnTest.class );
}
public void testClassicHQLAggregationReturnTypes() {
// EJB3: COUNT returns Long
QueryTranslatorImpl translator = createNewQueryTranslator( "select count(*) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.INTEGER, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select count(h.heightInches) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.INTEGER, translator.getReturnTypes()[0] );
// MAX, MIN return the type of the state-field to which they are applied.
translator = createNewQueryTranslator( "select max(h.heightInches) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select max(h.id) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
// AVG returns Float integrals, and otherwise the field type.
translator = createNewQueryTranslator( "select avg(h.heightInches) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select avg(h.id) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.FLOAT, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select avg(h.bigIntegerValue) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.BIG_INTEGER, translator.getReturnTypes()[0] );
// SUM returns underlying type sum
translator = createNewQueryTranslator( "select sum(h.id) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select sum(h.intValue) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.INTEGER, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select sum(h.heightInches) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select sum(h.floatValue) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.FLOAT, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select sum(h.bigIntegerValue) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.BIG_INTEGER, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select sum(h.bigDecimalValue) from Human h", sfi() );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.BIG_DECIMAL, translator.getReturnTypes()[0] );
// special case to test classicquery special case handling of count(*)
QueryTranslator oldQueryTranslator = null;
String hql = "select count(*) from Human h";
QueryTranslatorFactory classic = new ClassicQueryTranslatorFactory();