1   package org.apache.torque.util;
2   
3   /*
4    * Copyright 2001-2005 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   * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
26   * @version $Id: QueryTest.java 239630 2005-08-24 12:25:32Z henning $
27   */
28  public class QueryTest extends TestCase
29  {
30  
31      /***
32       * Constructor for QueryTest.
33       * @param arg0
34       */
35      public QueryTest(String arg0)
36      {
37          super(arg0);
38      }
39  
40      /***
41       * Test for String toString()
42       */
43      public void testColumns()
44      {
45          String expected
46                  = "SELECT tableA.column1, tableA.column2, tableB.column1 FROM ";
47          Query query = new Query();
48  
49          UniqueList columns = new UniqueList();
50          columns.add("tableA.column1");
51          columns.add("tableA.column2");
52          columns.add("tableB.column1");
53          query.setSelectClause(columns);
54  
55          assertEquals(expected, query.toString());
56      }
57  
58      /***
59       * Test for String toString()
60       */
61      public void testToString()
62      {
63          String expected = "SELECT tableA.column1, tableA.column2, "
64                  + "tableB.column1 FROM tableA, tableB WHERE tableA.A = tableB.A"
65                  + " AND tableA.B = 1234";
66          Query query = new Query();
67  
68          UniqueList columns = new UniqueList();
69          columns.add("tableA.column1");
70          columns.add("tableA.column2");
71          columns.add("tableB.column1");
72          query.setSelectClause(columns);
73  
74          UniqueList tables = new UniqueList();
75          tables.add(new Query.FromElement("tableA", null, null));
76          tables.add(new Query.FromElement("tableB", null, null));
77          query.setFromClause(tables);
78  
79          UniqueList where = new UniqueList();
80          where.add("tableA.A = tableB.A");
81          where.add("tableA.B = 1234");
82          query.setWhereClause(where);
83  
84          assertEquals(expected, query.toString());
85      }
86  }