01: /*
02: * {START_JAVA_COPYRIGHT_NOTICE
03: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
04: * Use is subject to license terms.
05: * END_COPYRIGHT_NOTICE}
06: */
07: package org.netbeans.modules.visualweb.dataprovider;
08:
09: import com.sun.data.provider.RowKey;
10: import com.sun.data.provider.SortCriteria;
11: import com.sun.data.provider.impl.BasicTableDataSorter;
12: import com.sun.data.provider.impl.FieldIdSortCriteria;
13: import com.sun.data.provider.impl.ObjectListDataProvider;
14: import org.netbeans.junit.NbTestCase;
15:
16: public class BasicTableDataSorterTest extends NbTestCase {
17:
18: private BasicTableDataSorter tds = null;
19: private ObjectListDataProvider tdp = null;
20:
21: public BasicTableDataSorterTest(String testName) {
22: super (testName);
23: }
24:
25: @Override
26: protected void setUp() throws Exception {
27: super .setUp();
28: /**@todo verify the constructors*/
29: tds = new BasicTableDataSorter();
30: tdp = new ObjectListDataProvider();
31: for (int x = 0; x < 10; x++) {
32: for (int i = 0; i < 20; i++) {
33: TestBean tb = new TestBean("TestBean" + i);
34: tb.setStringProperty(("TestBean:" + i) + tb.hashCode());
35: tb.setLongProperty(System.currentTimeMillis());
36: tb.setDoubleProperty(Math.random());
37: tb.setIntProperty((int) Math.round(tb
38: .getDoubleProperty() * 1000));
39: tdp.addObject(tb);
40: }
41: }
42: }
43:
44: @Override
45: protected void tearDown() throws Exception {
46: tds = null;
47: tdp = null;
48: super .tearDown();
49: }
50:
51: public void testSort() {
52: tds.setSortCriteria(new SortCriteria[] {
53: // new FieldIdSortCriteria("stringProperty", true),
54: new FieldIdSortCriteria("id", true),
55: new FieldIdSortCriteria("intProperty", false),
56: // new FieldIdSortCriteria("longProperty", true),
57: // new FieldIdSortCriteria("doubleProperty", true),
58: });
59: SortCriteria[] sca = tds.getSortCriteria();
60: // System.out.println("Sort Criteria:");
61: // for (int i = 0; i < sca.length; i++) {
62: // System.out.println(" [" + sca[i].getDisplayName() + "] " + (sca[i].isAscending() ? "ASC" : "DESC"));
63: // }
64: RowKey[] rows = tdp.getRowKeys(tdp.getRowCount(), null);
65: RowKey[] sort = tds.sort(tdp, rows);
66: // for (int i = 0; i < sort.length; i++) {
67: // System.out.println("sorted[" + i + "] row[" + sort[i] + "] id=\"" +
68: // tdp.getValue(tdp.getFieldKey("id"), sort[i]) + "\" int=" +
69: // tdp.getValue(tdp.getFieldKey("intProperty"), sort[i]) + " long=" +
70: // tdp.getValue(tdp.getFieldKey("longProperty"), sort[i]) + " double=" +
71: // tdp.getValue(tdp.getFieldKey("doubleProperty"), sort[i]) + " string=\"" +
72: // tdp.getValue(tdp.getFieldKey("stringProperty"), sort[i]) + "\"");
73: // }
74: }
75: }
|