01: package org.apache.torque.util;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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: * Constructor for QueryTest.
35: * @param arg0
36: */
37: public QueryTest(String arg0) {
38: super (arg0);
39: }
40:
41: /**
42: * Test for String toString()
43: */
44: public void testColumns() {
45: String expected = "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: String expected = "SELECT tableA.column1, tableA.column2, "
62: + "tableB.column1 FROM tableA, tableB WHERE tableA.A = tableB.A"
63: + " AND tableA.B = 1234";
64: Query query = new Query();
65:
66: UniqueList columns = new UniqueList();
67: columns.add("tableA.column1");
68: columns.add("tableA.column2");
69: columns.add("tableB.column1");
70: query.setSelectClause(columns);
71:
72: UniqueList tables = new UniqueList();
73: tables.add(new Query.FromElement("tableA", null, null));
74: tables.add(new Query.FromElement("tableB", null, null));
75: query.setFromClause(tables);
76:
77: UniqueList where = new UniqueList();
78: where.add("tableA.A = tableB.A");
79: where.add("tableA.B = 1234");
80: query.setWhereClause(where);
81:
82: assertEquals(expected, query.toString());
83: }
84: }
|