diff options
author | Artur Signell <artur.signell@itmill.com> | 2011-02-21 13:52:58 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2011-02-21 13:52:58 +0000 |
commit | fd4bc348f11ebea00d46b1d2d39a305b0bc17d8e (patch) | |
tree | dc189cb32b861c5db9f3012121692335a1bc657e | |
parent | e2946ace866a459a5b4892a4201e2a236228536f (diff) | |
download | vaadin-framework-fd4bc348f11ebea00d46b1d2d39a305b0bc17d8e.tar.gz vaadin-framework-fd4bc348f11ebea00d46b1d2d39a305b0bc17d8e.zip |
Test for Table visible column API
svn changeset:17357/svn branch:6.5
-rw-r--r-- | tests/src/com/vaadin/tests/server/component/table/TableGenerator.java | 26 | ||||
-rw-r--r-- | tests/src/com/vaadin/tests/server/component/table/TableVisibleColumns.java | 75 |
2 files changed, 101 insertions, 0 deletions
diff --git a/tests/src/com/vaadin/tests/server/component/table/TableGenerator.java b/tests/src/com/vaadin/tests/server/component/table/TableGenerator.java new file mode 100644 index 0000000000..953682dcae --- /dev/null +++ b/tests/src/com/vaadin/tests/server/component/table/TableGenerator.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.server.component.table; + +import com.vaadin.data.Item; +import com.vaadin.ui.Table; + +public class TableGenerator { + public static Table createTableWithDefaultContainer(int properties, + int items) { + Table t = new Table(); + + for (int i = 0; i < properties; i++) { + t.addContainerProperty("Property " + i, String.class, null); + } + + for (int j = 0; j < items; j++) { + Item item = t.addItem("Item " + j); + for (int i = 0; i < properties; i++) { + item.getItemProperty("Property " + i).setValue( + "Item " + j + "/Property " + i); + } + } + + return t; + } + +} diff --git a/tests/src/com/vaadin/tests/server/component/table/TableVisibleColumns.java b/tests/src/com/vaadin/tests/server/component/table/TableVisibleColumns.java new file mode 100644 index 0000000000..be312044db --- /dev/null +++ b/tests/src/com/vaadin/tests/server/component/table/TableVisibleColumns.java @@ -0,0 +1,75 @@ +package com.vaadin.tests.server.component.table; + +import static org.junit.Assert.assertArrayEquals; + +import org.junit.Test; + +import com.vaadin.ui.Table; + +public class TableVisibleColumns { + + String[] defaultColumns3 = new String[] { "Property 0", "Property 1", + "Property 2" }; + + @Test + public void defaultVisibleColumns() { + for (int properties = 0; properties < 10; properties++) { + Table t = TableGenerator.createTableWithDefaultContainer( + properties, 10); + Object[] expected = new Object[properties]; + for (int i = 0; i < properties; i++) { + expected[i] = "Property " + i; + } + org.junit.Assert.assertArrayEquals("getVisibleColumns", expected, + t.getVisibleColumns()); + } + } + + @Test + public void explicitVisibleColumns() { + Table t = TableGenerator.createTableWithDefaultContainer(5, 10); + Object[] newVisibleColumns = new Object[] { "Property 1", "Property 2" }; + t.setVisibleColumns(newVisibleColumns); + assertArrayEquals("Explicit visible columns, 5 properties", + newVisibleColumns, t.getVisibleColumns()); + + } + + @Test + public void invalidVisibleColumnIds() { + Table t = TableGenerator.createTableWithDefaultContainer(3, 10); + + try { + t.setVisibleColumns(new Object[] { "a", "Property 2", "Property 3" }); + junit.framework.Assert.fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + // OK, expected + } + assertArrayEquals(defaultColumns3, t.getVisibleColumns()); + } + + @Test + public void duplicateVisibleColumnIds() { + Table t = TableGenerator.createTableWithDefaultContainer(3, 10); + try { + t.setVisibleColumns(new Object[] { "Property 0", "Property 1", + "Property 2", "Property 1" }); + // FIXME: Multiple properties in the Object array should be detected + // (#6476) + // junit.framework.Assert.fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + // OK, expected + } + // FIXME: Multiple properties in the Object array should be detected + // (#6476) + // assertArrayEquals(defaultColumns3, t.getVisibleColumns()); + } + + @Test + public void noVisibleColumns() { + Table t = TableGenerator.createTableWithDefaultContainer(3, 10); + t.setVisibleColumns(new Object[] {}); + assertArrayEquals(new Object[] {}, t.getVisibleColumns()); + + } +} |