1   package org.apache.torque.util;
2   
3   /*
4    * Copyright 2001-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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  }