1 package org.apache.torque.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import junit.framework.TestCase;
20
21 /***
22 * Tests for Query
23 *
24 * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
25 * @version $Id: QueryTest.java,v 1.4.2.2 2004/05/20 04:36:06 seade Exp $
26 */
27 public class QueryTest extends TestCase
28 {
29
30 /***
31 * Constructor for QueryTest.
32 * @param arg0
33 */
34 public QueryTest(String arg0)
35 {
36 super(arg0);
37 }
38
39 /***
40 * Test for String toString()
41 */
42 public void testColumns()
43 {
44 String expected
45 = "SELECT tableA.column1, tableA.column2, tableB.column1 FROM ";
46 Query query = new Query();
47
48 UniqueList columns = new UniqueList();
49 columns.add("tableA.column1");
50 columns.add("tableA.column2");
51 columns.add("tableB.column1");
52 query.setSelectClause(columns);
53
54 assertEquals(expected, query.toString());
55 }
56
57 /***
58 * Test for String toString()
59 */
60 public void testToString()
61 {
62 String expected = "SELECT tableA.column1, tableA.column2, "
63 + "tableB.column1 FROM tableA, tableB WHERE tableA.A = tableB.A"
64 + " AND tableA.B = 1234";
65 Query query = new Query();
66
67 UniqueList columns = new UniqueList();
68 columns.add("tableA.column1");
69 columns.add("tableA.column2");
70 columns.add("tableB.column1");
71 query.setSelectClause(columns);
72
73 UniqueList tables = new UniqueList();
74 tables.add("tableA");
75 tables.add("tableB");
76 query.setFromClause(tables);
77
78 UniqueList where = new UniqueList();
79 where.add("tableA.A = tableB.A");
80 where.add("tableA.B = 1234");
81 query.setWhereClause(where);
82
83 assertEquals(expected, query.toString());
84 }
85 }