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 java.lang.reflect.Array;
20
21 import junit.framework.TestCase;
22
23 import org.apache.torque.adapter.DB;
24 import org.apache.torque.adapter.DBFactory;
25
26 /***
27 * Tests for SqlExpression
28 *
29 * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
30 * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
31 * @version $Id: SqlExpressionTest.java 239636 2005-08-24 12:38:09Z henning $
32 */
33 public class SqlExpressionTest extends TestCase
34 {
35 private DB db = null;
36
37
38 /***
39 * Constructor for SqlExpressionTest.
40 * @param arg0
41 */
42 public SqlExpressionTest(String arg0)
43 {
44 super(arg0);
45 }
46
47 /***
48 * set up environment
49 */
50 public void setUp()
51 {
52 try
53 {
54 db = DBFactory.create("mysql");
55 }
56 catch (Exception ex)
57 {
58 ex.printStackTrace();
59 }
60 }
61
62 /***
63 * Test for String buildInnerJoin(String, String)
64 */
65 public void testBuildInnerJoinStringString()
66 {
67 String result = SqlExpression.buildInnerJoin("TA.COLA", "TB.COLB");
68 assertEquals(result, "TA.COLA=TB.COLB");
69 }
70
71 /***
72 * Test for String buildInnerJoin(String, String, boolean, DB)
73 */
74 public void testBuildInnerJoinStringStringbooleanDB()
75 {
76 String result = SqlExpression.buildInnerJoin("TA.COLA", "TB.COLB",
77 true, db);
78 assertEquals(result, "TA.COLA=TB.COLB");
79 }
80
81 /***
82 * Test for String buildIn(String, Object, SqlEnum, boolean, DB)
83 */
84 public void testBuildInStringObjectSqlEnumbooleanDB()
85 {
86 String[] values = new String[] { "42", "43", "44" };
87 String result = SqlExpression.buildIn("COL", values, SqlEnum.IN,
88 true, db);
89
90
91 if (result.equals("COL IN ('42','43','44')"))
92 {
93
94 assertEquals(result, "COL IN ('42','43','44')");
95 }
96 else
97 {
98
99 assertEquals(result, "COL IN ('43','44','42')");
100 }
101 }
102
103 public void testLargeBuildInStringObjectSqlEnumbooleanDB()
104 {
105 int size = 10000;
106 String[] values = new String[size];
107 for (int i = 0; i < size; i++)
108 {
109 Array.set(values, i, String.valueOf(i));
110 }
111 long start = System.currentTimeMillis();
112 String result = SqlExpression.buildIn("COL", values, SqlEnum.IN,
113 true, db);
114 long end = System.currentTimeMillis();
115 System.out.println("large buildIn took " + (end - start) + " milliseconds");
116 }
117
118 }