1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/tests/test/org/dbforms/config/TestFieldValue.java,v 1.6 2004/08/18 12:26:11 hkollmann Exp $
3    * $Revision: 1.6 $
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  import org.dbforms.util.AbstractTestCase;
31  
32  import java.util.Locale;
33  
34  
35  
36  /***
37   *  Description of the Class
38   *
39   * @author     epugh
40   * @created    May 3, 2002
41   */
42  public class TestFieldValue extends AbstractTestCase {
43     Field      fAuthorId             = null;
44     Field      fBookId               = null;
45     FieldValue fvLogicalOR           = null;
46     FieldValue fvLogicalORLikeFilter = null;
47     FieldValue fvNotLogicalOR        = null;
48  
49     /***
50      * DOCUMENT ME!
51      *
52      * @throws Exception DOCUMENT ME!
53      */
54     public void setUp() throws Exception {
55        super.setUp();
56        fAuthorId = new Field();
57        fAuthorId.setName("AUTHOR_ID");
58        fBookId = new Field();
59        fBookId.setName("BOOK_ID");
60  
61        fvLogicalOR = new FieldValue(fAuthorId, "10");
62        fvLogicalOR.setOperator(Constants.FILTER_EQUAL);
63        fvLogicalOR.setLogicalOR(true);
64        fvNotLogicalOR = new FieldValue(fBookId, "10");
65        fvNotLogicalOR.setOperator(Constants.FILTER_EQUAL);
66        fvNotLogicalOR.setLogicalOR(false);
67        fvLogicalORLikeFilter = new FieldValue(fAuthorId, "10");
68        fvLogicalORLikeFilter.setOperator(Constants.FILTER_LIKE);
69        fvLogicalORLikeFilter.setLogicalOR(true);
70     }
71  
72  
73     /***
74      * DOCUMENT ME!
75      *
76      * @throws Exception DOCUMENT ME!
77      */
78     public void testClone() throws Exception {
79        FieldValue fv = new FieldValue(fAuthorId, "10");
80  
81        FieldValue fvClone = (FieldValue) fv.clone();
82        assertTrue("Make sure toStrings match",
83                   fv.toString().equals(fvClone.toString()));
84     }
85  
86  
87     /***
88      * DOCUMENT ME!
89      *
90      * @throws Exception DOCUMENT ME!
91      */
92     public void testCon() throws Exception {
93        FieldValue fv = new FieldValue(fAuthorId, "10");
94        assertTrue("make sure we get our field back.",
95                   fv.getField().equals(fAuthorId));
96        assertTrue("make sure we get our field value.",
97                   fv.getFieldValue().equals("10"));
98     }
99  
100 
101    /***
102     * DOCUMENT ME!
103     *
104     * @throws Exception DOCUMENT ME!
105     */
106    public void testInvert() throws Exception {
107       fvLogicalOR.setSortDirection(Constants.ORDER_ASCENDING);
108       fvNotLogicalOR.setSortDirection(Constants.ORDER_ASCENDING);
109       fvLogicalORLikeFilter.setSortDirection(Constants.ORDER_ASCENDING);
110 
111       FieldValue fvLogicalOROrig           = (FieldValue) fvLogicalOR.clone();
112       FieldValue fvNotLogicalOROrig        = (FieldValue) fvNotLogicalOR.clone();
113       FieldValue fvLogicalORLikeFilterOrig = (FieldValue) fvLogicalORLikeFilter
114                                              .clone();
115 
116       FieldValue[] fvs = {
117                             fvLogicalOR,
118                             fvNotLogicalOR,
119                             fvLogicalORLikeFilter
120                          };
121 
122       FieldValue.invert(fvs);
123       assertTrue("fv was flipped",
124                  fvLogicalOR.getSortDirection() != fvLogicalOROrig
125                                                    .getSortDirection());
126       assertTrue("fv was flipped",
127                  fvNotLogicalOR.getSortDirection() != fvNotLogicalOROrig
128                                                       .getSortDirection());
129       assertTrue("fv was flipped",
130                  fvLogicalORLikeFilter.getSortDirection() != fvLogicalORLikeFilterOrig
131                                                              .getSortDirection());
132    }
133 
134 
135    /***
136     * DOCUMENT ME!
137     *
138     * @throws Exception DOCUMENT ME!
139     */
140    public void testLogicalOr() throws Exception {
141       FieldValue fv = new FieldValue(fAuthorId, "10");
142       assertTrue("Make sure this is not a logical OR.", !fv.getLogicalOR());
143       fv.setLogicalOR(true);
144       assertTrue("make sure this is a logical OR.", fv.getLogicalOR());
145    }
146 
147 
148    /***
149     * DOCUMENT ME!
150     */
151    public void testNull() {
152       Field f = new Field();
153       f.setName("TESTINT");
154       f.setFieldType("int");
155 
156       FieldValue fv = new FieldValue(f, "");
157       fv.setLocale(Locale.ENGLISH);
158 
159       Integer i = (Integer) fv.getFieldValueAsObject();
160       assertTrue(i == null);
161    }
162 }