KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > util > QueryTest


1 package org.apache.torque.util;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements. See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership. The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied. See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */

21
22 import junit.framework.TestCase;
23
24 /**
25  * Tests for Query
26  *
27  * @author <a HREF="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
28  * @author <a HREF="mailto:fischer@seitenbau.de">Thomas Fischer</a>
29  * @version $Id: QueryTest.java 473821 2006-11-11 22:37:25Z tv $
30  */

31 public class QueryTest extends TestCase
32 {
33
34     /**
35      * Constructor for QueryTest.
36      * @param arg0
37      */

38     public QueryTest(String JavaDoc arg0)
39     {
40         super(arg0);
41     }
42
43     /**
44      * Test for String toString()
45      */

46     public void testColumns()
47     {
48         String JavaDoc expected
49                 = "SELECT tableA.column1, tableA.column2, tableB.column1 FROM ";
50         Query query = new Query();
51
52         UniqueList columns = new UniqueList();
53         columns.add("tableA.column1");
54         columns.add("tableA.column2");
55         columns.add("tableB.column1");
56         query.setSelectClause(columns);
57
58         assertEquals(expected, query.toString());
59     }
60
61     /**
62      * Test for String toString()
63      */

64     public void testToString()
65     {
66         String JavaDoc expected = "SELECT tableA.column1, tableA.column2, "
67                 + "tableB.column1 FROM tableA, tableB WHERE tableA.A = tableB.A"
68                 + " AND tableA.B = 1234";
69         Query query = new Query();
70
71         UniqueList columns = new UniqueList();
72         columns.add("tableA.column1");
73         columns.add("tableA.column2");
74         columns.add("tableB.column1");
75         query.setSelectClause(columns);
76
77         UniqueList tables = new UniqueList();
78         tables.add(new Query.FromElement("tableA", null, null));
79         tables.add(new Query.FromElement("tableB", null, null));
80         query.setFromClause(tables);
81
82         UniqueList where = new UniqueList();
83         where.add("tableA.A = tableB.A");
84         where.add("tableA.B = 1234");
85         query.setWhereClause(where);
86
87         assertEquals(expected, query.toString());
88     }
89 }
90
Popular Tags