@Test public void testExpandedRowsAccessors() { WTable table = new WTable(); table.setTableModel(createModel(new String[10][1])); Set<Object> rows1 = new HashSet<Object>(Arrays.asList(Arrays.asList(0), Arrays.asList(1), Arrays.asList(2))); Set<Object> rows2 = new HashSet<Object>(Arrays.asList(Arrays.asList(3), Arrays.asList(4), Arrays.asList(5))); assertAccessorsCorrect(table, "expandedRows", Collections.EMPTY_SET, rows1, rows2); }
@Test public void testSelectModeAccessors() { assertAccessorsCorrect(new WTable(), "selectMode", SelectMode.NONE, SelectMode.SINGLE, SelectMode.MULTIPLE); }
@Test public void testStripingTypeAccessors() { assertAccessorsCorrect(new WTable(), "stripingType", StripingType.NONE, StripingType.ROWS, StripingType.COLUMNS); }
@Test public void testToggleSubRowSelectionAccessors() { assertAccessorsCorrect(new WTable(), "toggleSubRowSelection", false, true, false); }
@Test public void testRowHeadersAccessors() { assertAccessorsCorrect(new WTable(), "rowHeaders", false, true, false); }
@Test(expected = IllegalArgumentException.class) public void testCurrentPageInvalidNegative() { new WTable().setCurrentPage(-123); }
@Test public void testSelectAllTypeAccessors() { assertAccessorsCorrect(new WTable(), "selectAllMode", SelectAllType.TEXT, SelectAllType.CONTROL, SelectAllType.TEXT); }
/** * Test setSortMode. */ @Test public void testSetSortMode() { WTable table = new WTable(); table.setSortMode(WTable.SortMode.DYNAMIC); Assert.assertEquals("should return SortMode set", WTable.SortMode.DYNAMIC, table. getSortMode()); }
@Test public void testNamingContextIdAccessor() { String id = "test"; NamingContextable naming = new WTable(); naming.setIdName(id); Assert.assertEquals("Incorrect component id", id, naming.getId()); Assert.assertEquals("Naming context should match component id", id, naming. getNamingContextId()); }
@Test public void testSelectionChangeActionAccessors() { assertAccessorsCorrect(new WTable(), "selectionChangeAction", null, new TestAction(), new TestAction()); }
@Test(expected = IllegalArgumentException.class) public void testColumnOrderInvalidColumnIndex() { WTable table = new WTable(); table.addColumn(new WTableColumn("col1", WText.class)); table.setColumnOrder(new int[]{1}); }
@Test public void testMarginAccessors() { assertAccessorsCorrect(new WTable(), "margin", null, new Margin(1), new Margin(2)); }
@Test(expected = IllegalArgumentException.class) public void testSetColumnOrderTooHigh() { WTable table = new WTable(); table.addColumn(new WTableColumn("col1", WText.class)); table.setColumnOrder(new int[]{1, 2}); }
@Test public void testCurrentPageLogicWithNoPagination() { WTable table = new WTable(); table.setPaginationMode(PaginationMode.NONE); table.setTableModel(createModel(new String[100][1])); table.setRowsPerPage(10); table.setCurrentPage(50); Assert.assertEquals("Current page should alway be zero for a table with no pagination", 0, table.getCurrentPage()); }
/** * Create example. */ public TableContentExample() { table = new WTable(); table.setPaginationMode(WTable.PaginationMode.CLIENT); table.setRowsPerPage(5); table.addColumn(new WTableColumn("Name (text)", new WText())); table.addColumn(new WTableColumn("Name (image)", new DynamicWImage())); add(table); }
@Test public void testCurrentPageAccessors() { WTable table = new WTable(); table.setTableModel(createModel(new String[100][1])); table.setPaginationMode(PaginationMode.CLIENT); table.setRowsPerPage(10); assertAccessorsCorrect(table, "currentPage", 0, 5, 7); }
@Test public void testColumnOrderAccessors() { WTable table = new WTable(); table.addColumn(new WTableColumn("col1", WText.class)); table.addColumn(new WTableColumn("col2", WText.class)); int[] order1 = new int[]{0, 1}; int[] order2 = new int[]{1}; assertAccessorsCorrect(table, "columnOrder", null, order1, order2); }
@Test public void testDoPaintSelectModeSingle() throws IOException, SAXException, XpathException { WTable component = new WTable(); component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class)); component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class)); component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class)); TableModel tableModel = createTableModel(); component.setTableModel(tableModel); component.setVisible(true); component.setSelectMode(WTable.SelectMode.SINGLE); assertXpathExists("//ui:table/ui:rowselection", component); }
@Test public void testDoPaintExpandModeDynamic() throws IOException, SAXException, XpathException { WTable component = new WTable(); component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class)); component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class)); component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class)); TableModel tableModel = createTableModel(); component.setTableModel(tableModel); component.setVisible(true); component.setExpandMode(ExpandMode.DYNAMIC); assertXpathEvaluatesTo("dynamic", "//ui:table/ui:rowexpansion/@mode", component); }