[hibernate-commits] Hibernate SVN: r11360 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Mar 29 08:47:49 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-03-29 08:47:49 -0400 (Thu, 29 Mar 2007)
New Revision: 11360

Modified:
   branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
   branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
Log:
test suite fixes : postgresql (boolean handling)

Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java	2007-03-29 12:35:51 UTC (rev 11359)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java	2007-03-29 12:47:49 UTC (rev 11360)
@@ -11,7 +11,6 @@
 
 import antlr.RecognitionException;
 import junit.framework.Test;
-import junit.framework.TestSuite;
 
 import org.hibernate.Hibernate;
 import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -516,8 +515,7 @@
 	}
 
 	public void testSubstitutions() throws Exception {
-		HashMap replacements = new HashMap();
-		replacements.put("true", "1");
+		Map replacements = buildTrueFalseReplacementMapForDialect();
 		replacements.put("yes", "'Y'");
 		assertTranslation( "from Human h where h.pregnant = true", replacements );
 		assertTranslation( "from Human h where h.pregnant = yes", replacements );
@@ -663,27 +661,35 @@
 
 
 	public void testPolymorphism() throws Exception {
-		HashMap replacements = new HashMap();
-		replacements.put( "false", "0" );
-		replacements.put( "true", "1" );
+		Map replacements = buildTrueFalseReplacementMapForDialect();
 		assertTranslation( "from Mammal" );
 		assertTranslation( "from Dog" );
 		assertTranslation( "from Mammal m where m.pregnant = false and m.bodyWeight > 10", replacements );
 		assertTranslation( "from Dog d where d.pregnant = false and d.bodyWeight > 10", replacements );
 	}
 
-	public void testTokenReplacement() throws Exception {
+	private Map buildTrueFalseReplacementMapForDialect() {
 		HashMap replacements = new HashMap();
-		replacements.put( "false", "0" );
-		replacements.put( "true", "1" );
-		assertTranslation( "from Mammal m where m.pregnant = false and m.bodyWeight > 10",
-				replacements );
+		try {
+			String dialectTrueRepresentation = getDialect().toBooleanValueString( true );
+			// if this call succeeds, then the dialect is saying to represent true/false as int values...
+			Integer.parseInt( dialectTrueRepresentation );
+			replacements.put( "true", "1" );
+			replacements.put( "false", "0" );
+		}
+		catch( NumberFormatException nfe ) {
+			// the Integer#parseInt call failed...
+		}
+		return replacements;
 	}
 
+	public void testTokenReplacement() throws Exception {
+		Map replacements = buildTrueFalseReplacementMapForDialect();
+		assertTranslation( "from Mammal m where m.pregnant = false and m.bodyWeight > 10", replacements );
+	}
+
 	public void testProduct() throws Exception {
-		HashMap replacements = new HashMap();
-		replacements.put( "false", "0" );
-		replacements.put( "true", "1" );
+		Map replacements = buildTrueFalseReplacementMapForDialect();
 		assertTranslation( "from Animal, Animal" );
 		assertTranslation( "from Animal x, Animal y where x.bodyWeight = y.bodyWeight" );
 		assertTranslation( "from Animal x, Mammal y where x.bodyWeight = y.bodyWeight and not y.pregnant = true", replacements );
@@ -747,9 +753,7 @@
 	}
 
 	public void testExplicitJoins() throws Exception {
-		HashMap replacements = new HashMap();
-		replacements.put( "false", "0" );
-		replacements.put( "true", "1" );
+		Map replacements = buildTrueFalseReplacementMapForDialect();
 		assertTranslation( "from Zoo zoo join zoo.mammals mam where mam.pregnant = true and mam.description like '%white%'", replacements );
 		assertTranslation( "from Zoo zoo join zoo.animals an where an.description like '%white%'" );
 	}

Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java	2007-03-29 12:35:51 UTC (rev 11359)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java	2007-03-29 12:47:49 UTC (rev 11360)
@@ -106,7 +106,7 @@
 		assertTranslation( hql, null, scalar, null );
 	}
 
-	protected void assertTranslation(String hql, HashMap replacements) {
+	protected void assertTranslation(String hql, Map replacements) {
 		ComparisonFailure cf = null;
 		try {
 			assertTranslation( hql, replacements, false, null );
@@ -141,7 +141,7 @@
 		System.out.println( "OLD SQL: " + oldsql );
 	}
 
-	protected void assertTranslation(String hql, HashMap replacements, boolean scalar, String sql) {
+	protected void assertTranslation(String hql, Map replacements, boolean scalar, String sql) {
 		SessionFactoryImplementor factory = getSessionFactoryImplementor();
 
 		// Create an empty replacements map if we don't have one.
@@ -198,12 +198,12 @@
 
 	}
 
-	protected QueryTranslatorImpl createNewQueryTranslator(String hql, HashMap replacements, boolean scalar) {
+	protected QueryTranslatorImpl createNewQueryTranslator(String hql, Map replacements, boolean scalar) {
 		SessionFactoryImplementor factory = getSessionFactoryImplementor();
 		return createNewQueryTranslator( hql, replacements, scalar, factory );
 	}
 
-	private QueryTranslatorImpl createNewQueryTranslator(String hql, HashMap replacements, boolean scalar, SessionFactoryImplementor factory) {
+	private QueryTranslatorImpl createNewQueryTranslator(String hql, Map replacements, boolean scalar, SessionFactoryImplementor factory) {
 		QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
 		QueryTranslatorImpl newQueryTranslator = ( QueryTranslatorImpl ) ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, factory );
 		newQueryTranslator.compile( replacements, scalar );




More information about the hibernate-commits mailing list