]> source.dussan.org Git - vaadin-framework.git/commitdiff
Test for Table visible column API
authorArtur Signell <artur.signell@itmill.com>
Mon, 21 Feb 2011 13:52:58 +0000 (13:52 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 21 Feb 2011 13:52:58 +0000 (13:52 +0000)
svn changeset:17357/svn branch:6.5

tests/src/com/vaadin/tests/server/component/table/TableGenerator.java [new file with mode: 0644]
tests/src/com/vaadin/tests/server/component/table/TableVisibleColumns.java [new file with mode: 0644]

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 (file)
index 0000000..953682d
--- /dev/null
@@ -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 (file)
index 0000000..be31204
--- /dev/null
@@ -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());
+
+    }
+}