KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > TableTest


1 /*
2  * $Id: TableTest.java,v 1.3 2004/09/02 00:50:36 aim 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.jdnc.markup;
9
10 import java.net.URL JavaDoc;
11 import java.net.MalformedURLException JavaDoc;
12
13 import javax.swing.SwingConstants JavaDoc;
14
15 import junit.framework.TestCase;
16
17 import net.openmarkup.ObjectRealizer;
18
19 import org.jdesktop.jdnc.markup.ElementTypes;
20
21 import org.jdesktop.jdnc.JNTable;
22
23 /**
24  * Unit test for table element
25  */

26 public class TableTest extends TestCase {
27
28     private ObjectRealizer realizer;
29
30     protected void setUp() {
31         realizer = RealizerUnitTest.createObjectRealizer();
32         realizer.add(ElementTypes.get());
33     }
34
35     protected void tearDown() {
36         realizer = null;
37     }
38
39     /**
40      * Simple utility to verify the URL and table object.
41      */

42     private JNTable getTable(String JavaDoc resource) throws Exception JavaDoc {
43         URL JavaDoc url = RealizerUnitTest.class.getResource(resource);
44         assertNotNull(url);
45
46         Object JavaDoc obj = realizer.getObject(url);
47         assertNotNull(obj);
48         assertTrue(obj.getClass().toString() + " is not a JNTable",
49                    obj instanceof JNTable);
50
51         return (JNTable) obj;
52     }
53
54     /**
55      * Verify that the basic test data will create tables. All new table test cases
56      * should be placed here.
57      */

58     public void testTable() throws Exception JavaDoc {
59         getTable("resources/table1.xml");
60         getTable("resources/table2.xml");
61         getTable("resources/table2-1.xml");
62         getTable("resources/table2-2.xml");
63         getTable("resources/table2.xml");
64         getTable("resources/table3.xml");
65         getTable("resources/table4.xml");
66         getTable("resources/table4-1.xml");
67         getTable("resources/table5.xml");
68     }
69
70     public void testTableData() throws Exception JavaDoc {
71         JNTable table = getTable("resources/table2.xml");
72
73         // how do we verify that the table model has been initialized with
74
// the data in bugs.txt
75
}
76
77     /**
78      * Use a non-default delimiter.
79      */

80     public void testDataDelimeter() throws Exception JavaDoc {
81         JNTable table = getTable("resources/table2-1.xml");
82
83         /* The rows are loaded on the EDT. How do we get the row count?
84              assertTrue("Row count should not be zero: " + table.getModel().getRowCount(),
85                0 != table.getModel().getRowCount());
86          */

87     }
88
89     public void testTableDataMetaData() throws Exception JavaDoc {
90         JNTable table = getTable("resources/table2-2.xml");
91     }
92
93     /**
94      * The following test verifies that the table column alignments
95      * are corectly set.
96      */

97     public void testTableColumnAlignment() throws Exception JavaDoc {
98         JNTable table = getTable("resources/table4-1.xml");
99         assertEquals(SwingConstants.RIGHT, table.getColumnHorizontalAlignment("synopsis"));
100         assertEquals(SwingConstants.TRAILING, table.getColumnHorizontalAlignment("state"));
101         assertEquals(SwingConstants.TRAILING, table.getColumnHorizontalAlignment("bugid"));
102         assertEquals(SwingConstants.CENTER, table.getColumnHorizontalAlignment("priority"));
103         assertEquals(SwingConstants.LEFT, table.getColumnHorizontalAlignment("severity"));
104         //LEADING is currently broken because JLabel doesn't fire a propertyChangeEvent when
105
// horizontalAlignment is set to it since its teh default value; need to re-think
106
// the way LabelProperties tracks changes.
107
//assertEquals(SwingConstants.LEADING, table.getColumnHorizontalAlignment("engineer"));
108
//assertEquals(SwingConstants.LEADING, table.getColumnHorizontalAlignment("dispatchdate"));
109
assertEquals(-1, table.getColumnHorizontalAlignment("jdcvotes"));
110     }
111 }
Popular Tags