1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/tests/test/org/dbforms/config/TestTable.java,v 1.5 2004/08/18 12:26:11 hkollmann Exp $
3    * $Revision: 1.5 $
4    * $Date: 2004/08/18 12:26:11 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
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 }