KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > dataset > DataColumnTest


1 /*
2  * $Id: DataColumnTest.java,v 1.2 2005/02/25 19:46:07 rbair Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.dataset;
9 import junit.framework.*;
10
11
12 /**
13  *
14  * @author rbair
15  */

16 public class DataColumnTest extends TestCase {
17     
18     public DataColumnTest(String JavaDoc testName) {
19         super(testName);
20     }
21     
22     // TODO add test methods here. The name must begin with 'test'. For example:
23
// public void testHello() {}
24

25     protected void setUp() throws Exception JavaDoc {
26     }
27
28     protected void tearDown() throws Exception JavaDoc {
29     }
30
31     public static Test suite() {
32         TestSuite suite = new TestSuite(DataColumnTest.class);
33         
34         return suite;
35     }
36
37     /**
38      * Test of getTable method, of class org.jdesktop.dataset.DataColumn.
39      */

40     public void testGetTable() {
41         System.out.println("testGetTable");
42         //Test table is null by default
43
DataTable table = new DataTable(new DataSet());
44         DataColumn col = new DataColumn(table);
45         assertEquals(table, col.getTable());
46     }
47
48     /**
49      * Test of getName method, of class org.jdesktop.dataset.DataColumn.
50      * Also tests the name auto generation.
51      */

52     public void testGetName() {
53         System.out.println("testGetName");
54         
55         //test that the name can be set
56
DataSet ds = new DataSet();
57         DataTable table = ds.createTable();
58         DataColumn col1 = table.createColumn();
59         col1.setName("column_1");
60         assertEquals(col1.getName(), "column_1");
61         
62         //test that the name cannot be set to null
63
try {
64             col1.setName(null);
65             assertTrue(false);
66         } catch (Error JavaDoc e) {
67             assertTrue(true);
68         }
69         
70         //test that the name cannot be set to empty string
71
try {
72             col1.setName("");
73             assertTrue(false);
74         } catch (Error JavaDoc e) {
75             assertTrue(true);
76         }
77         
78         
79         //test that the name cannot be set to empty string with spaces
80
try {
81             col1.setName(" ");
82             assertTrue(false);
83         } catch (Error JavaDoc e) {
84             assertTrue(true);
85         }
86     }
87
88     /**
89      * Test of getType method, of class org.jdesktop.dataset.DataColumn.
90      */

91     public void testGetType() {
92         System.out.println("testGetType");
93        
94         //test that the type is Object.class by default
95
DataSet ds = new DataSet();
96         DataTable table = ds.createTable();
97         DataColumn col = table.createColumn();
98         assertEquals(col.getType(), Object JavaDoc.class);
99         
100         //set the type
101
col.setType(String JavaDoc.class);
102         assertEquals(col.getType(), String JavaDoc.class);
103         
104         //nullify the type (should revert to Object.class)
105
col.setType(null);
106         assertEquals(col.getType(), Object JavaDoc.class);
107     }
108
109     /**
110      * Test of isReadOnly method, of class org.jdesktop.dataset.DataColumn.
111      */

112     public void testIsReadOnly() {
113         System.out.println("testIsReadOnly");
114         
115         //test that readonly is false to begin with
116
DataSet ds = new DataSet();
117         DataTable table = ds.createTable();
118         DataColumn col = table.createColumn();
119         assertFalse(col.isReadOnly());
120         
121         //set to true
122
col.setReadOnly(true);
123         assertTrue(col.isReadOnly());
124         
125         //set to false
126
col.setReadOnly(false);
127         assertFalse(col.isReadOnly());
128     }
129
130     /**
131      * Test of isRequired method, of class org.jdesktop.dataset.DataColumn.
132      */

133     public void testIsRequired() {
134         System.out.println("testIsRequired");
135         
136         //test that is required is false to begin with
137
DataSet ds = new DataSet();
138         DataTable table = ds.createTable();
139         DataColumn col = table.createColumn();
140         assertFalse(col.isRequired());
141         
142         //set to true
143
col.setRequired(true);
144         assertTrue(col.isRequired());
145         
146         //set to false
147
col.setRequired(false);
148         assertFalse(col.isRequired());
149     }
150
151     public void testGetDefaultValue() {
152         System.out.println("testGetDefaultValue");
153         
154         //test that the default value is null to begin with
155
DataSet ds = new DataSet();
156         DataTable table = ds.createTable();
157         DataColumn col = table.createColumn();
158         assertNull(col.getDefaultValue());
159         
160         //set a value
161
col.setDefaultValue("blar");
162         assertEquals(col.getDefaultValue(), "blar");
163         
164         //clear
165
col.setDefaultValue(null);
166         assertNull(col.getDefaultValue());
167     }
168 }
Popular Tags