1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.config;
25
26 import org.dbforms.config.Constants;
27 import org.dbforms.config.Field;
28 import org.dbforms.config.FieldValue;
29
30
31
32 /***
33 * Description of the Class
34 *
35 * @author epugh
36 * @created May 3, 2002
37 */
38 public class TestQuery extends org.dbforms.util.AbstractTestCase {
39 Field fAuthorId = null;
40 Field fBookId = null;
41 FieldValue fvLogicalOR = null;
42 FieldValue fvLogicalORLikeFilter = null;
43 FieldValue fvNotLogicalOR = null;
44 Query table = null;
45
46 /***
47 * DOCUMENT ME!
48 *
49 * @throws Exception DOCUMENT ME!
50 */
51 public void setUp() throws Exception {
52 super.setUp();
53 fAuthorId = new Field();
54 fAuthorId.setName("AUTHOR_ID");
55 fAuthorId.setFieldType("char");
56
57 fBookId = new Field();
58 fBookId.setName("BOOK_ID");
59
60 fvLogicalOR = new FieldValue(fAuthorId, "10");
61 fvLogicalOR.setOperator(Constants.FILTER_EQUAL);
62 fvLogicalOR.setLogicalOR(true);
63
64 fvNotLogicalOR = new FieldValue(fBookId, "10");
65 fvNotLogicalOR.setOperator(Constants.FILTER_EQUAL);
66 fvNotLogicalOR.setLogicalOR(false);
67
68 fvLogicalORLikeFilter = new FieldValue(fAuthorId, "10");
69 fvLogicalORLikeFilter.setOperator(Constants.FILTER_LIKE);
70 fvLogicalORLikeFilter.setLogicalOR(true);
71
72 table = new Query();
73 table.setWhere("td.id = td1.id and td.id1 = td1.id1");
74 table.setFollowAfterWhere("AND");
75 table.setFrom("td");
76 }
77
78
79 /***
80 * DOCUMENT ME!
81 *
82 * @throws Exception DOCUMENT ME!
83 */
84 public void testGetSelectQuery() throws Exception {
85 FieldValue[] fvs = {
86 fvLogicalOR,
87 fvNotLogicalOR
88 };
89 String s = table.getSelectQuery(null, null, null, "f1 >= ?",
90 Constants.COMPARE_NONE);
91 assertTrue("Test fvs Where clause equals:" + s,
92 s.indexOf("SELECT * FROM td WHERE ( td.id = td1.id and td.id1 = td1.id1 ) AND ( f1 >= ? )") >= 0);
93
94 s = table.getSelectQuery(null, fvs, null, "f1 >= ?",
95 Constants.COMPARE_NONE);
96 assertTrue("Test fvs Where clause equals:" + s,
97 s.indexOf("SELECT * FROM td WHERE ( td.id = td1.id and td.id1 = td1.id1 ) AND ( f1 >= ? ) AND ( ( ( AUTHOR_ID = ? ) AND ( BOOK_ID = ? ) ) )") >= 0);
98 }
99
100
101 /***
102 * DOCUMENT ME!
103 *
104 * @throws Exception DOCUMENT ME!
105 */
106 public void testGetWhereClause() throws Exception {
107 FieldValue[] fvs = {
108 fvLogicalOR,
109 fvNotLogicalOR
110 };
111 String s = table.getWhereClause(fvs);
112 assertTrue("Test fvs Where clause equals: (AUTHOR_ID = ?) AND (BOOK_ID = ?):"
113 + s,
114 s.indexOf("( AUTHOR_ID = ? ) AND ( BOOK_ID = ? )") >= 0);
115
116 FieldValue[] fvs2 = {
117 fvLogicalOR,
118 fvLogicalOR
119 };
120 assertTrue("Test fvs2 Where clause equals:" + table.getWhereClause(fvs2),
121 table.getWhereClause(fvs2).indexOf("AUTHOR_ID = ? OR AUTHOR_ID = ?") >= 0);
122
123 FieldValue[] fvs3 = {
124 fvLogicalORLikeFilter,
125 fvLogicalOR
126 };
127 s = table.getWhereClause(fvs3);
128 assertTrue("Test fvs3 Where clause equals:" + s,
129 s.indexOf("AUTHOR_ID LIKE ? OR AUTHOR_ID = ?") >= 0);
130 }
131 }