]> source.dussan.org Git - vaadin-framework.git/commitdiff
TestBench test case for #8291
authorJohannes Dahlström <johannes.dahlstrom@vaadin.com>
Mon, 3 Sep 2012 12:31:35 +0000 (12:31 +0000)
committerJohannes Dahlström <johannes.dahlstrom@vaadin.com>
Mon, 3 Sep 2012 12:31:35 +0000 (12:31 +0000)
svn changeset:24289/svn branch:6.8

tests/testbench/com/vaadin/tests/components/table/TableReduceContainerSize.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/table/TableReduceContainerSize.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/tickets/Ticket8291.java [deleted file]

diff --git a/tests/testbench/com/vaadin/tests/components/table/TableReduceContainerSize.html b/tests/testbench/com/vaadin/tests/components/table/TableReduceContainerSize.html
new file mode 100644 (file)
index 0000000..9bd0149
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>TableReduceContainerSize</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">TableReduceContainerSize</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/TableReduceContainerSize?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>scroll</td>
+       <td>vaadin=runTableReduceContainerSize::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]</td>
+       <td>19700</td>
+</tr>
+<tr>
+       <td>pause</td>
+       <td>300</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runTableReduceContainerSize::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runTableReduceContainerSize::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VLabel[0]</td>
+       <td>Index: *</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runTableReduceContainerSize::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>scroll</td>
+       <td>vaadin=runTableReduceContainerSize::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]</td>
+       <td>19700</td>
+</tr>
+<tr>
+       <td>pause</td>
+       <td>300</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runTableReduceContainerSize::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runTableReduceContainerSize::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VLabel[0]</td>
+       <td>Index: *</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/testbench/com/vaadin/tests/components/table/TableReduceContainerSize.java b/tests/testbench/com/vaadin/tests/components/table/TableReduceContainerSize.java
new file mode 100644 (file)
index 0000000..bc729ef
--- /dev/null
@@ -0,0 +1,147 @@
+package com.vaadin.tests.components.table;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import com.vaadin.data.Container.Filter;
+import com.vaadin.data.Item;
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+
+/**
+ * Test for #8291 and #7666: NegativeArraySizeException when Table scrolled to
+ * the end and its size reduced.
+ */
+public class TableReduceContainerSize extends TestBase {
+
+    @Override
+    protected void setup() {
+        addComponent(new TestView());
+    }
+
+    private static class DecimateFilter implements Filter {
+        public boolean passesFilter(Object itemId, Item item)
+                throws UnsupportedOperationException {
+            return ((((TestObject) itemId).property3 % 10) == 0);
+        }
+
+        public boolean appliesToProperty(Object propertyId) {
+            return true;
+        }
+    }
+
+    private static class TestView extends HorizontalLayout {
+
+        private Filter filter = null;
+
+        private boolean reduceData;
+
+        private TestView() {
+            final Table table = new Table();
+            List<TestObject> data = createData(1000);
+            final BeanItemContainer<TestObject> container = new BeanItemContainer<TestObject>(
+                    TestObject.class, data) {
+
+                @Override
+                public int size() {
+                    if (reduceData) {
+                        return 100;
+                    } else {
+                        return super.size();
+                    }
+                }
+            };
+            table.setContainerDataSource(container);
+            addComponent(table);
+            final Label label = new Label();
+            addComponent(label);
+            Button button = new Button("Click");
+            button.addListener(new Button.ClickListener() {
+                public void buttonClick(ClickEvent event) {
+                    try {
+                        reduceData = !reduceData;
+                        table.refreshRowCache();
+                        label.setValue("Index: "
+                                + table.getCurrentPageFirstItemIndex());
+                    } catch (Exception e) {
+                        label.setValue("Exception: "
+                                + e.getClass().getSimpleName());
+                    }
+                }
+            });
+            addComponent(button);
+            Button button2 = new Button("Filter");
+            button2.addListener(new Button.ClickListener() {
+                public void buttonClick(ClickEvent event) {
+                    try {
+                        if (filter != null) {
+                            container.removeAllContainerFilters();
+                            filter = null;
+                        } else {
+                            filter = new DecimateFilter();
+                            container.addContainerFilter(filter);
+                        }
+                        table.refreshRowCache();
+                        label.setValue("Index: "
+                                + table.getCurrentPageFirstItemIndex());
+                    } catch (Exception e) {
+                        label.setValue("Exception: "
+                                + e.getClass().getSimpleName());
+                    }
+                }
+            });
+            addComponent(button2);
+        }
+    }
+
+    private static List<TestObject> createData(int count) {
+        ArrayList<TestObject> data = new ArrayList<TestObject>(count);
+        for (int i = 0; i < count; i++) {
+            data.add(new TestObject("string-" + i, new Date(), i));
+        }
+        return data;
+    }
+
+    public static class TestObject {
+
+        private String property1;
+        private Date property2;
+        private Integer property3;
+
+        public TestObject(String property1, Date property2, Integer property3) {
+            this.property1 = property1;
+            this.property2 = property2;
+            this.property3 = property3;
+        }
+
+        public String getProperty1() {
+            return property1;
+        }
+
+        public Date getProperty2() {
+            return property2;
+        }
+
+        public Integer getProperty3() {
+            return property3;
+        }
+
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Table throws NegativeArraySizeException if container size is reduced to less than current scroll position";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 8291;
+    }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket8291.java b/tests/testbench/com/vaadin/tests/tickets/Ticket8291.java
deleted file mode 100644 (file)
index 86b5db9..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-package com.vaadin.tests.tickets;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import com.vaadin.Application;
-import com.vaadin.data.Container.Filter;
-import com.vaadin.data.Item;
-import com.vaadin.data.util.BeanItemContainer;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Button.ClickEvent;
-import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.ui.Table;
-import com.vaadin.ui.Window;
-
-/**
- * Test for #8291 and #7666: NegativeArraySizeException when Table scrolled to
- * the end and its size reduced.
- */
-public class Ticket8291 extends Application {
-
-    @Override
-    public void init() {
-        setMainWindow(new Window("", new TestView()));
-    }
-
-    private static class DecimateFilter implements Filter {
-        public boolean passesFilter(Object itemId, Item item)
-                throws UnsupportedOperationException {
-            return ((((TestObject) itemId).property3 % 10) == 0);
-        }
-
-        public boolean appliesToProperty(Object propertyId) {
-            return true;
-        }
-    }
-
-    private static class TestView extends HorizontalLayout {
-
-        private Filter filter = null;
-
-        private boolean reduceData;
-
-        private TestView() {
-            final Table table = new Table();
-            List<TestObject> data = createData(1000);
-            final BeanItemContainer<TestObject> container = new BeanItemContainer<TestObject>(
-                    TestObject.class, data) {
-
-                @Override
-                public int size() {
-                    if (reduceData) {
-                        return 100;
-                    } else {
-                        return super.size();
-                    }
-                }
-            };
-            table.setContainerDataSource(container);
-            addComponent(table);
-            Button button = new Button("Click");
-            button.addListener(new Button.ClickListener() {
-                public void buttonClick(ClickEvent event) {
-                    reduceData = !reduceData;
-                    table.refreshRowCache();
-                }
-            });
-            addComponent(button);
-            Button button2 = new Button("Filter");
-            button2.addListener(new Button.ClickListener() {
-                public void buttonClick(ClickEvent event) {
-                    if (filter != null) {
-                        container.removeAllContainerFilters();
-                        filter = null;
-                    } else {
-                        filter = new DecimateFilter();
-                        container.addContainerFilter(filter);
-                    }
-                    table.refreshRowCache();
-                }
-            });
-            addComponent(button2);
-        }
-    }
-
-    private static List<TestObject> createData(int count) {
-        ArrayList<TestObject> data = new ArrayList<TestObject>(count);
-        for (int i = 0; i < count; i++) {
-            data.add(new TestObject("string-" + i, new Date(), i));
-        }
-        return data;
-    }
-
-    public static class TestObject {
-
-        private String property1;
-        private Date property2;
-        private Integer property3;
-
-        public TestObject(String property1, Date property2, Integer property3) {
-            this.property1 = property1;
-            this.property2 = property2;
-            this.property3 = property3;
-        }
-
-        public String getProperty1() {
-            return property1;
-        }
-
-        public Date getProperty2() {
-            return property2;
-        }
-
-        public Integer getProperty3() {
-            return property3;
-        }
-
-    }
-
-}