From fd4bc348f11ebea00d46b1d2d39a305b0bc17d8e Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 21 Feb 2011 13:52:58 +0000 Subject: [PATCH] Test for Table visible column API svn changeset:17357/svn branch:6.5 --- .../component/table/TableGenerator.java | 26 +++++++ .../component/table/TableVisibleColumns.java | 75 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 tests/src/com/vaadin/tests/server/component/table/TableGenerator.java create mode 100644 tests/src/com/vaadin/tests/server/component/table/TableVisibleColumns.java 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()); + + } +} -- 2.39.5