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 TestTable 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 Table 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 Table();
73 table.setName("td");
74 }
75
76
77 /***
78 * DOCUMENT ME!
79 *
80 * @throws Exception DOCUMENT ME!
81 */
82 public void testGetSelectQuery() throws Exception {
83 FieldValue[] fvs = {
84 fvLogicalOR,
85 fvNotLogicalOR
86 };
87 String s = table.getSelectQuery(null, null, null, "f1 >= ?",
88 Constants.COMPARE_NONE);
89 assertTrue("Test fvs Where clause equals:" + s,
90 s.indexOf("SELECT * FROM td WHERE ( f1 >= ? )") >= 0);
91
92 s = table.getSelectQuery(null, fvs, null, "f1 >= ?",
93 Constants.COMPARE_NONE);
94 assertTrue("Test fvs Where clause equals:" + s,
95 s.indexOf("SELECT * FROM td WHERE ( f1 >= ? ) AND ( ( ( AUTHOR_ID = ? ) AND ( BOOK_ID = ? ) ) )") >= 0);
96 }
97
98
99 /***
100 * DOCUMENT ME!
101 *
102 * @throws Exception DOCUMENT ME!
103 */
104 public void testGetWhereClause() throws Exception {
105 FieldValue[] fvs = {
106 fvLogicalOR,
107 fvNotLogicalOR
108 };
109 String s = table.getWhereClause(fvs);
110 assertTrue("Test fvs Where clause equals: (AUTHOR_ID = ?) AND (BOOK_ID = ?):"
111 + s,
112 s.indexOf("( AUTHOR_ID = ? ) AND ( BOOK_ID = ? )") >= 0);
113
114 FieldValue[] fvs2 = {
115 fvLogicalOR,
116 fvLogicalOR
117 };
118 assertTrue("Test fvs2 Where clause equals:" + table.getWhereClause(fvs2),
119 table.getWhereClause(fvs2).indexOf("AUTHOR_ID = ? OR AUTHOR_ID = ?") >= 0);
120
121 FieldValue[] fvs3 = {
122 fvLogicalORLikeFilter,
123 fvLogicalOR
124 };
125 s = table.getWhereClause(fvs3);
126 assertTrue("Test fvs3 Where clause equals:" + s,
127 s.indexOf("AUTHOR_ID LIKE ? OR AUTHOR_ID = ?") >= 0);
128 }
129 }