db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Poeschl <mpoes...@marmot.at>
Subject Re: Test failure on Torque HEAD
Date Thu, 10 Apr 2003 16:01:18 GMT
i replace HashSet with UniqueList .. maybe we can switch to OrderedSet when it is release as
part of 
commons-collections

martin

Henning P. Schmiedehausen wrote:
> The current HEAD fails the SqlExpression test on
> 
> testBuildInStringObjectSqlEnumbooleanDB
> 
> because it assumes that a HashSet returns its objects in the same
> sequence as they were put in. Which it does not:
> 
> junit.framework.ComparisonFailure: expected:<...2','43','44...> but was:<...3','44','42...>
>         at org.apache.torque.util.SqlExpressionTest.testBuildInStringObjectSqlEnumbooleanDB(SqlExpressionTest.java:124)
> 
> (BTW: The "expected" and result parameters of the assertEquals calls
> are all the wrong way round).
> 
> This happened because of the change from StringStack to HashSet which
> was checked in by Martin on March 20th.
> 
> You need (just like I do for the module lists of Turbine), a data
> structure which is a set but keeps the sequence of the added
> objects. It is called "OrderedSet" and attached to Bugzilla #18006 for
> inclusion into commons collections.
> 
> I'd be happy if you would help me lobbying this class into the next
> c-c release. =:-)
> 
> You can get the source from ftp://ftp.hometree.net/pub/java/orderedset/OrderedSet.java
> 
> A patch which uses this (and passes the SQL tests) is attached
> 
> --- cut ---
> Index: src/java/org/apache/torque/util/SqlExpression.java
> ===================================================================
> RCS file: /home/cvs/db-torque/src/java/org/apache/torque/util/SqlExpression.java,v
> retrieving revision 1.22
> diff -u -b -r1.22 SqlExpression.java
> --- src/java/org/apache/torque/util/SqlExpression.java	20 Mar 2003 20:34:42 -0000	1.22
> +++ src/java/org/apache/torque/util/SqlExpression.java	10 Apr 2003 10:40:00 -0000
> @@ -55,19 +55,22 @@
>   */
>  
>  import java.lang.reflect.Array;
> +
>  import java.util.Date;
> -import java.util.HashSet;
>  import java.util.Iterator;
>  import java.util.List;
> +import java.util.Set;
> +
> +import org.apache.commons.collections.OrderedSet;
>  
>  import org.apache.commons.lang.StringUtils;
> +
>  import org.apache.torque.TorqueException;
>  import org.apache.torque.adapter.DB;
>  import org.apache.torque.om.DateKey;
>  import org.apache.torque.om.ObjectKey;
>  import org.apache.torque.om.StringKey;
>  
> -
>  /**
>   * This class represents a part of an SQL query found in the <code>WHERE</code>
>   * section.  For example:
> @@ -510,7 +513,7 @@
>          }
>  
>          whereClause.append(comparison);
> -        HashSet inClause = new HashSet();
> +        Set inClause = new OrderedSet();
>          if (criteria instanceof List)
>          {
>              Iterator iter = ((List) criteria).iterator();
> Index: src/test/org/apache/torque/util/SqlExpressionTest.java
> ===================================================================
> RCS file: /home/cvs/db-torque/src/test/org/apache/torque/util/SqlExpressionTest.java,v
> retrieving revision 1.1
> diff -u -b -r1.1 SqlExpressionTest.java
> --- src/test/org/apache/torque/util/SqlExpressionTest.java	19 Mar 2003 06:53:16 -0000
1.1
> +++ src/test/org/apache/torque/util/SqlExpressionTest.java	10 Apr 2003 10:40:00 -0000
> @@ -100,7 +100,7 @@
>  	public void testBuildInnerJoinStringString()
>  	{
>          String result = SqlExpression.buildInnerJoin("TA.COLA", "TB.COLB");
> -        assertEquals(result, "TA.COLA=TB.COLB");
> +        assertEquals("TA.COLA=TB.COLB", result);
>  	}
>  
>  	/**
> @@ -110,7 +110,7 @@
>  	{
>          String result = SqlExpression.buildInnerJoin("TA.COLA", "TB.COLB", 
>                  true, db);
> -        assertEquals(result, "TA.COLA=TB.COLB");
> +        assertEquals("TA.COLA=TB.COLB", result);
>  	}
>  
>  	/**
> @@ -121,6 +121,17 @@
>          String[] values = new String[] { "42", "43", "44" };
>          String result = SqlExpression.buildIn("COL", values, SqlEnum.IN, 
>                  true, db);
> -        assertEquals(result, "COL IN ('42','43','44')");
> +        assertEquals("COL IN ('42','43','44')", result);
> +	}
> +
> +	/**
> +	 * Test for String buildIn(String, Object, SqlEnum, boolean, DB)
> +	 */
> +	public void testBuildInStringObjectSqlEnumbooleanDB2()
> +	{
> +        String[] values = new String[] { "42", "43", "44", "43", "42", "1" };
> +        String result = SqlExpression.buildIn("COL", values, SqlEnum.IN, 
> +                true, db);
> +        assertEquals("COL IN ('42','43','44','1')", result);
>  	}
>  }
> --- cut ---
> 
> 	Regards
> 		Henning
> 
> 



Mime
View raw message