diff options
author | Artur Signell <artur@vaadin.com> | 2012-08-30 17:24:36 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-08-30 17:24:36 +0300 |
commit | 7b25b3886ea95bc6495506fbe9472e45fcbde684 (patch) | |
tree | 0b93cb65dab437feb46720659a63b8f1ef48f7f4 /uitest/src/com/vaadin/tests/containers | |
parent | 8941056349e302e687e40e94c13709e75f256d73 (diff) | |
download | vaadin-framework-7b25b3886ea95bc6495506fbe9472e45fcbde684.tar.gz vaadin-framework-7b25b3886ea95bc6495506fbe9472e45fcbde684.zip |
Renamed tests -> uitest and tests/testbench -> uitest/src (#9299)
Diffstat (limited to 'uitest/src/com/vaadin/tests/containers')
12 files changed, 1285 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/containers/BeanItemContainerFilteringTest.java b/uitest/src/com/vaadin/tests/containers/BeanItemContainerFilteringTest.java new file mode 100644 index 0000000000..8b8ad4cf70 --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/BeanItemContainerFilteringTest.java @@ -0,0 +1,178 @@ +package com.vaadin.tests.containers; + +import com.vaadin.data.Item; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.server.Sizeable; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Label; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +public class BeanItemContainerFilteringTest extends TestBase { + + private Table table; + private BeanItemContainer<TestBean> container; + private TextField filterString; + private TextField position; + private int nextToAdd = 1; + private Label nextLabel; + + protected static class TestBean { + private String id; + private String value; + + public TestBean() { + } + + public TestBean(String id, String value) { + setId(id); + setValue(value); + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setValue(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + @Override + protected String getDescription() { + return "Test adding items in a filtered BeanItemContainer."; + } + + @Override + protected Integer getTicketNumber() { + return new Integer(1061); + } + + @Override + protected void setup() { + table = new Table(); + try { + container = new BeanItemContainer<TestBean>(TestBean.class); + table.setContainerDataSource(container); + + table.setWidth(300, Sizeable.UNITS_PIXELS); + table.setSelectable(true); + table.setMultiSelect(false); + table.setEditable(true); + table.setImmediate(true); + // table.addContainerProperty("column1", String.class, "test"); + + for (int i = 0; i < 25; ++i) { + container.addItem(new TestBean("Item " + i, "Value for " + i)); + } + + VerticalLayout vl = new VerticalLayout(); + + // activate & deactivate filtering + filterString = new TextField("Filter string:", "1"); + vl.addComponent(filterString); + + final CheckBox cb = new CheckBox("Filter on value"); + cb.addListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + container.removeAllContainerFilters(); + if (((CheckBox) event.getProperty()).getValue()) { + container.addContainerFilter("value", filterString + .getValue().toString(), false, false); + } + } + }); + cb.setImmediate(true); + vl.addComponent(cb); + + nextLabel = new Label(); + nextLabel.setCaption("Next id: " + nextToAdd); + vl.addComponent(nextLabel); + + // addItemAt(idx), addItemAfter(selection), addItem() + + final Button addItemButton = new Button("addItem()", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + container.addItem(new TestBean("addItem() " + + nextToAdd, "value " + nextToAdd)); + nextToAdd++; + nextLabel.setCaption("Next id: " + nextToAdd); + } + }); + addItemButton.setImmediate(true); + vl.addComponent(addItemButton); + + final Button addItemAfterButton = new Button("addItemAfter()", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + Object selection = table.getValue(); + if (selection == null) { + return; + } + TestBean bean = new TestBean("addItemAfter() " + + nextToAdd, "value " + nextToAdd); + Item item = container.addItemAfter(selection, bean); + if (item == null) { + getMainWindow().showNotification( + "Adding item after " + selection + + " failed"); + } + nextToAdd++; + nextLabel.setCaption("Next id: " + nextToAdd); + } + }); + addItemAfterButton.setImmediate(true); + vl.addComponent(addItemAfterButton); + + position = new TextField("Position:", "0"); + vl.addComponent(position); + + final Button addItemAtButton = new Button("addItemAt()", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + int index = Integer.parseInt(position.getValue() + .toString()); + TestBean bean = new TestBean("addItemAt() " + + nextToAdd, "value " + nextToAdd); + Item item = container.addItemAt(index, bean); + if (item == null) { + getMainWindow().showNotification( + "Adding item at index " + + position.getValue() + + " failed"); + } + nextToAdd++; + nextLabel.setCaption("Next id: " + nextToAdd); + } + }); + addItemAtButton.setImmediate(true); + vl.addComponent(addItemAtButton); + + getLayout().addComponent(table); + getLayout().addComponent(vl); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + +} diff --git a/uitest/src/com/vaadin/tests/containers/BeanItemContainerTest.java b/uitest/src/com/vaadin/tests/containers/BeanItemContainerTest.java new file mode 100644 index 0000000000..905ec2f9ff --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/BeanItemContainerTest.java @@ -0,0 +1,75 @@ +package com.vaadin.tests.containers; + +import java.util.Collection; +import java.util.LinkedList; + +import com.vaadin.data.util.BeanItemContainer; + +public class BeanItemContainerTest { + + /** + * Test class for BeanItemContainer + * + * @throws IllegalAccessException + * @throws InstantiationException + */ + public static void main(String[] args) throws InstantiationException, + IllegalAccessException { + BeanItemContainer<Hello> c = new BeanItemContainer<Hello>(Hello.class); + c.addItem(new Hello()); + + Collection<Hello> col = new LinkedList<Hello>(); + for (int i = 0; i < 100; i++) { + col.add(new Hello()); + } + col.add(new Hello2()); + + c = new BeanItemContainer<Hello>(col); + + System.out.println(c + " contains " + c.size() + " objects"); + + // test that subclass properties are handled correctly + System.out.println(c + " item 0 second = " + + c.getContainerProperty(c.getIdByIndex(0), "second")); + System.out.println(c + " item 100 second = " + + c.getContainerProperty(c.getIdByIndex(100), "second")); + + } + + public static class Hello { + + public String first; + public String second; + + public Hello() { + first = "f"; + second = "l"; + } + + public String getFirst() { + return first; + } + + public void setFirst(String first) { + this.first = first; + } + + public String getSecond() { + return second; + } + + public void setSecond(String second) { + this.second = second; + } + + } + + public static class Hello2 extends Hello { + + @Override + public String getSecond() { + return "second"; + } + + } +} diff --git a/uitest/src/com/vaadin/tests/containers/HierarchicalWrapperOrdering.java b/uitest/src/com/vaadin/tests/containers/HierarchicalWrapperOrdering.java new file mode 100644 index 0000000000..eba8ded705 --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/HierarchicalWrapperOrdering.java @@ -0,0 +1,129 @@ +package com.vaadin.tests.containers; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.Property; +import com.vaadin.data.util.ContainerHierarchicalWrapper; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Layout; +import com.vaadin.ui.Table; +import com.vaadin.ui.Tree; + +public class HierarchicalWrapperOrdering extends TestBase { + + private static final long serialVersionUID = 1L; + + IndexedContainer indexedContainer = new IndexedContainer(); + + Container.Hierarchical hier = new ContainerHierarchicalWrapper( + indexedContainer); + + Tree tree1; + + private static void sort(IndexedContainer container) { + Object[] properties = new Object[1]; + properties[0] = "name"; + + boolean[] ascending = new boolean[1]; + ascending[0] = true; + + container.sort(properties, ascending); + } + + private static void populateContainer(Container.Hierarchical container) { + container.addContainerProperty("name", String.class, null); + + addItem(container, "Games", null); + addItem(container, "Call of Duty", "Games"); + addItem(container, "Might and Magic", "Games"); + addItem(container, "Fallout", "Games"); + addItem(container, "Red Alert", "Games"); + + addItem(container, "Cars", null); + addItem(container, "Toyota", "Cars"); + addItem(container, "Volvo", "Cars"); + addItem(container, "Audi", "Cars"); + addItem(container, "Ford", "Cars"); + + addItem(container, "Natural languages", null); + addItem(container, "Swedish", "Natural languages"); + addItem(container, "English", "Natural languages"); + addItem(container, "Finnish", "Natural languages"); + + addItem(container, "Programming languages", null); + addItem(container, "C++", "Programming languages"); + addItem(container, "PHP", "Programming languages"); + addItem(container, "Java", "Programming languages"); + addItem(container, "Python", "Programming languages"); + + } + + public static void addItem(Container.Hierarchical container, String string, + String parent) { + Item item = container.addItem(string); + item.getItemProperty("name").setValue(string); + + if (parent != null) { + container.setParent(string, parent); + } + + } + + @Override + protected void setup() { + Layout l = getLayout(); + + populateContainer(hier); + + // sort(indexedContainer); + + tree1 = new Tree("Tree with wrapped IndexedContainer"); + tree1.setContainerDataSource(hier); + tree1.setItemCaptionPropertyId("name"); + for (Object id : hier.rootItemIds()) { + tree1.expandItemsRecursively(id); + } + l.addComponent(tree1); + + // This contains a bug, changes not reflected back to client + Button modify = new Button("Modify and sort (has a bug)", + new ClickListener() { + private static final long serialVersionUID = 1L; + + @Override + public void buttonClick(ClickEvent event) { + // Get first item + Object itemId = indexedContainer.getIdByIndex(0); + Item item = indexedContainer.getItem(itemId); + Property<String> property = (Property<String>) item + .getItemProperty("name"); + // Prepend with Z so item should get sorted later + property.setValue("Z " + property.getValue()); + // this does not work alone, requires extraneous + // setContainerDataSource for server-side changes to be + // reflected back to client-side + sort(indexedContainer); + } + }); + l.addComponent(modify); + + Table t = new Table("Table with indexed container", indexedContainer); + + l.addComponent(t); + } + + @Override + protected String getDescription() { + return "Items should be in same order as in wrapped container after sorting."; + } + + @Override + protected Integer getTicketNumber() { + return 3688; + } + +} diff --git a/uitest/src/com/vaadin/tests/containers/IndexedContainerFilteringTest.java b/uitest/src/com/vaadin/tests/containers/IndexedContainerFilteringTest.java new file mode 100644 index 0000000000..a1dba3eed8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/IndexedContainerFilteringTest.java @@ -0,0 +1,147 @@ +package com.vaadin.tests.containers; + +import com.vaadin.data.Item; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.server.Sizeable; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Label; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +public class IndexedContainerFilteringTest extends TestBase { + + private Table table; + private IndexedContainer container; + private TextField filterString; + private TextField position; + private int nextToAdd = 1; + private Label nextLabel; + + @Override + protected String getDescription() { + return "Adding items to a filtered IndexedContainer inserts the items at the wrong location."; + } + + @Override + protected Integer getTicketNumber() { + return new Integer(2809); + } + + @Override + protected void setup() { + table = new Table(); + container = (IndexedContainer) table.getContainerDataSource(); + + table.setWidth(300, Sizeable.UNITS_PIXELS); + table.setSelectable(true); + table.setMultiSelect(false); + table.addContainerProperty("column1", String.class, "test"); + + for (int i = 0; i < 25; ++i) { + table.addItem(new Object[] { "Item " + i }, "Item " + i); + } + + VerticalLayout vl = new VerticalLayout(); + + // activate & deactivate filtering + filterString = new TextField("Filter string:", "1"); + vl.addComponent(filterString); + + final CheckBox cb = new CheckBox("Filter"); + cb.addListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + container.removeAllContainerFilters(); + if (((CheckBox) event.getProperty()).getValue()) { + container.addContainerFilter("column1", filterString + .getValue().toString(), false, false); + } + } + }); + cb.setImmediate(true); + vl.addComponent(cb); + + nextLabel = new Label(); + nextLabel.setCaption("Next id: " + nextToAdd); + vl.addComponent(nextLabel); + + // addItemAt(idx), addItemAfter(selection), addItem() + + final Button addItemButton = new Button("addItem()", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + Item item = container.addItem("addItem() " + nextToAdd); + if (item != null) { + item.getItemProperty("column1").setValue( + "addItem() " + nextToAdd); + } + nextToAdd++; + nextLabel.setCaption("Next id: " + nextToAdd); + } + }); + addItemButton.setImmediate(true); + vl.addComponent(addItemButton); + + final Button addItemAfterButton = new Button("addItemAfter()", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + Object selection = table.getValue(); + if (selection == null) { + return; + } + String id = "addItemAfter() " + nextToAdd; + Item item = container.addItemAfter(selection, id); + if (item != null) { + item.getItemProperty("column1").setValue(id); + table.setValue(id); + } else { + getMainWindow().showNotification( + "Adding item after " + selection + + " failed"); + } + nextToAdd++; + nextLabel.setCaption("Next id: " + nextToAdd); + } + }); + addItemAfterButton.setImmediate(true); + vl.addComponent(addItemAfterButton); + + position = new TextField("Position:", "0"); + vl.addComponent(position); + + final Button addItemAtButton = new Button("addItemAt()", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + int index = Integer.parseInt(position.getValue() + .toString()); + String id = "addItemAt() " + nextToAdd; + Item item = container.addItemAt(index, id); + if (item != null) { + item.getItemProperty("column1").setValue(id); + table.setValue(id); + } else { + getMainWindow().showNotification( + "Adding item at index " + + position.getValue() + " failed"); + } + nextToAdd++; + nextLabel.setCaption("Next id: " + nextToAdd); + } + }); + addItemAtButton.setImmediate(true); + vl.addComponent(addItemAtButton); + + getLayout().addComponent(table); + getLayout().addComponent(vl); + } +} diff --git a/uitest/src/com/vaadin/tests/containers/TableWithFileSystemContainer.java b/uitest/src/com/vaadin/tests/containers/TableWithFileSystemContainer.java new file mode 100644 index 0000000000..25d0053fb2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/TableWithFileSystemContainer.java @@ -0,0 +1,31 @@ +package com.vaadin.tests.containers; + +import java.io.File; + +import com.vaadin.data.util.FilesystemContainer; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Table; + +public class TableWithFileSystemContainer extends TestBase { + + private String testPath = "C:/temp/img"; + + @Override + public void setup() { + Table table = new Table("Documents", new FilesystemContainer(new File( + testPath))); + table.setWidth("100%"); + getMainWindow().addComponent(table); + } + + @Override + protected String getDescription() { + return "The Table uses a FileSystemContainer as datasource. Scrolling to the end should show the last items, not throw an NPE."; + } + + @Override + protected Integer getTicketNumber() { + return 3864; + } + +} diff --git a/uitest/src/com/vaadin/tests/containers/TestItemSorter.java b/uitest/src/com/vaadin/tests/containers/TestItemSorter.java new file mode 100644 index 0000000000..46c4e004c1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/TestItemSorter.java @@ -0,0 +1,95 @@ +package com.vaadin.tests.containers; + +import java.util.Collection; +import java.util.Comparator; + +import com.vaadin.data.Item; +import com.vaadin.data.util.DefaultItemSorter; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Table; + +public class TestItemSorter extends TestBase { + + private static final Object BUTTON = "Button"; + private static final Object CHECKBOX = "CheckBox"; + private static final Object STRING = "String"; + + private Table table; + private IndexedContainer container; + + @Override + protected void setup() { + table = new Table("DefaultItemSorter with custom comparator"); + container = createContainer(); + populateContainer(container); + container.setItemSorter(new DefaultItemSorter(new Comparator<Object>() { + + @Override + public int compare(Object o1, Object o2) { + if (o1 instanceof CheckBox && o2 instanceof CheckBox) { + Boolean b1 = (Boolean) ((CheckBox) o1).getValue(); + return b1.compareTo((Boolean) ((CheckBox) o2).getValue()); + } else if (o1 instanceof Button && o2 instanceof Button) { + String caption1 = ((Button) o1).getCaption().toLowerCase(); + String caption2 = ((Button) o2).getCaption().toLowerCase(); + return caption1.compareTo(caption2); + + } else if (o1 instanceof String && o2 instanceof String) { + return ((String) o1).toLowerCase().compareTo( + ((String) o2).toLowerCase()); + } + + return 0; + + } + })); + table.setContainerDataSource(container); + + addComponent(table); + + } + + private static void populateContainer(IndexedContainer container) { + container.removeAllItems(); + String[] strings = new String[] { "Text 1", "Text 2", "true", "false", + "Caption 1", "Caption 2" }; + for (String s : strings) { + Object id = container.addItem(); + Item item = container.getItem(id); + item.getItemProperty(STRING).setValue(s); + item.getItemProperty(BUTTON).setValue(new Button(s)); + item.getItemProperty(CHECKBOX).setValue( + new CheckBox("", s.equals("true"))); + } + + } + + private static IndexedContainer createContainer() { + IndexedContainer ic = new IndexedContainer() { + @Override + public Collection<?> getSortableContainerPropertyIds() { + // Default implementation allows sorting only if the property + // type can be cast to Comparable + return getContainerPropertyIds(); + } + }; + ic.addContainerProperty(BUTTON, Button.class, null); + ic.addContainerProperty(CHECKBOX, CheckBox.class, null); + ic.addContainerProperty(STRING, String.class, null); + return ic; + } + + @Override + protected String getDescription() { + return "Test that uses a custom ItemSorter to allow sorting Property types that do not implement Comparable"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + +} diff --git a/uitest/src/com/vaadin/tests/containers/filesystemcontainer/FileSystemContainerInTreeTable.html b/uitest/src/com/vaadin/tests/containers/filesystemcontainer/FileSystemContainerInTreeTable.html new file mode 100644 index 0000000000..b5ccd53df0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/filesystemcontainer/FileSystemContainerInTreeTable.html @@ -0,0 +1,117 @@ +<?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>FileSystemContainerInTreeTable</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">FileSystemContainerInTreeTable</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.containers.filesystemcontainer.FileSystemContainerInTreeTable?restartApplication</td> + <td></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>initial</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VHorizontalLayout[0]/ChildComponentContainer[0]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>added_not_yet_visible</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]</td> + <td>30,8</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>added_dir2_expanded</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VHorizontalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[2]/domChild[0]/domChild[0]/domChild[0]</td> + <td>32,6</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>deleted_dir2_collapsed</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]</td> + <td>32,4</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>deleted_dir2_expanded</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VHorizontalLayout[0]/ChildComponentContainer[0]/VButton[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]</td> + <td>31,8</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>added_dir2_collapsed</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td> + <td>29,5</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>added_dir1_expanded</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VHorizontalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td> + <td>32,8</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>deleted_dir1_collapsed</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscontainersfilesystemcontainerFileSystemContainerInTreeTable::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VHorizontalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> + +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/containers/filesystemcontainer/FileSystemContainerInTreeTable.java b/uitest/src/com/vaadin/tests/containers/filesystemcontainer/FileSystemContainerInTreeTable.java new file mode 100644 index 0000000000..0afaf2c15f --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/filesystemcontainer/FileSystemContainerInTreeTable.java @@ -0,0 +1,146 @@ +package com.vaadin.tests.containers.filesystemcontainer; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import com.vaadin.data.Container; +import com.vaadin.data.Container.Ordered; +import com.vaadin.data.util.FilesystemContainer; +import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.util.Log; +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.Tree.CollapseEvent; +import com.vaadin.ui.Tree.CollapseListener; +import com.vaadin.ui.Tree.ExpandEvent; +import com.vaadin.ui.Tree.ExpandListener; +import com.vaadin.ui.TreeTable; + +public class FileSystemContainerInTreeTable extends TestBase { + + private Log log = new Log(5); + private TreeTable treeTable; + + @Override + protected void setup() { + setTheme("reindeer-tests"); + + final File folder; + try { + File tempFile = File.createTempFile("fsc-tt", ""); + tempFile.delete(); + folder = new File(tempFile.getParent(), tempFile.getName()); + folder.mkdir(); + System.out.println(folder.getPath()); + folder.deleteOnExit(); + + populate(folder, 3, 10); + + FilesystemContainer fsc = new FilesystemContainer(folder); + + treeTable = new TreeTable(); + treeTable.addStyleName("table-equal-rowheight"); + treeTable.setWidth("450px"); + treeTable.setHeight("550px"); + treeTable.setContainerDataSource(fsc); + treeTable.setItemIconPropertyId(FilesystemContainer.PROPERTY_ICON); + treeTable.setVisibleColumns(new String[] { "Name" }); + treeTable.setColumnWidth("Name", 400); + treeTable.addListener(new ExpandListener() { + + @Override + public void nodeExpand(ExpandEvent event) { + logExpandCollapse(event.getItemId(), "expanded"); + + } + }); + treeTable.addListener(new CollapseListener() { + + @Override + public void nodeCollapse(CollapseEvent event) { + logExpandCollapse(event.getItemId(), "collapsed"); + + } + }); + + addComponent(log); + addComponent(treeTable); + + HorizontalLayout buttonLayout = new HorizontalLayout(); + buttonLayout.setSpacing(true); + buttonLayout.addComponent(new Button("Create dir11", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + new File(folder, "dir11").mkdir(); + log.log("Row dir11 created"); + } + })); + buttonLayout.addComponent(new Button("Delete dir11", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + new File(folder, "dir11").delete(); + log.log("Row dir11 deleted"); + } + })); + // to clean up explicitly before ending an automated test + buttonLayout.addComponent(new Button("Clean all files", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + folder.delete(); + } + })); + addComponent(buttonLayout); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void populate(File folder, int subDirectories, int files) + throws IOException { + for (int i = 1; i <= files; i++) { + File f = new File(folder, "file" + i + ".txt"); + f.createNewFile(); + } + + for (int i = 1; i <= subDirectories; i++) { + File f = new File(folder, "dir" + i); + f.mkdir(); + populate(f, 0, 2); + } + } + + protected int indexOfId(Table source, Object itemId) { + Container.Ordered c = (Ordered) source.getContainerDataSource(); + if (c instanceof Container.Indexed) { + return ((Container.Indexed) source).indexOfId(itemId); + } else { + ArrayList<Object> list = new ArrayList<Object>(source.getItemIds()); + return list.indexOf(itemId); + } + } + + protected void logExpandCollapse(Object itemId, String operation) { + File file = (File) itemId; + // do not use the variable part (path) of file name + log.log("Row " + file.getName() + " " + operation + ". Row index: " + + indexOfId(treeTable, itemId)); + + } + + @Override + protected String getDescription() { + return "TreeTable partial updates can only be used with a container that notifies the TreeTable of item set changes"; + } + + @Override + protected Integer getTicketNumber() { + return 7837; + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java b/uitest/src/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java new file mode 100644 index 0000000000..0c1fdc23f6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java @@ -0,0 +1,114 @@ +package com.vaadin.tests.containers.sqlcontainer; + +import java.sql.SQLException; + +import com.vaadin.Application; +import com.vaadin.data.Container.ItemSetChangeEvent; +import com.vaadin.data.Container.ItemSetChangeListener; +import com.vaadin.data.Item; +import com.vaadin.data.Property; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Form; +import com.vaadin.ui.HorizontalSplitPanel; +import com.vaadin.ui.UI.LegacyWindow; +import com.vaadin.ui.Table; + +public class CheckboxUpdateProblem extends Application.LegacyApplication + implements Property.ValueChangeListener { + private final DatabaseHelper databaseHelper = new DatabaseHelper(); + private Table testList; + private final HorizontalSplitPanel horizontalSplit = new HorizontalSplitPanel(); + + private TestForm testForm = new TestForm(); + + @Override + public void init() { + setMainWindow(new LegacyWindow("Test window")); + horizontalSplit.setSizeFull(); + testList = new Table(); + + horizontalSplit.setFirstComponent(testList); + testList.setSizeFull(); + testList.setContainerDataSource(databaseHelper.getTestContainer()); + testList.setSelectable(true); + testList.setImmediate(true); + testList.addListener(this); + + databaseHelper.getTestContainer().addListener( + new ItemSetChangeListener() { + @Override + public void containerItemSetChange(ItemSetChangeEvent event) { + Object selected = testList.getValue(); + if (selected != null) { + testForm.setItemDataSource(testList + .getItem(selected)); + } + } + }); + + testForm = new TestForm(); + testForm.setItemDataSource(null); + + horizontalSplit.setSecondComponent(testForm); + + getMainWindow().setContent(horizontalSplit); + } + + @Override + public void valueChange(ValueChangeEvent event) { + + Property<?> property = event.getProperty(); + if (property == testList) { + Item item = testList.getItem(testList.getValue()); + + if (item != testForm.getItemDataSource()) { + testForm.setItemDataSource(item); + } + } + + } + + private class TestForm extends Form implements Button.ClickListener { + + private final Button save; + + private TestForm() { + setSizeFull(); + setBuffered(true); + setInvalidCommitted(false); + + save = new Button("Save", this); + getFooter().addComponent(save); + getFooter().setVisible(false); + } + + @Override + public void buttonClick(ClickEvent event) { + if (event.getSource() == save) { + super.commit(); + + try { + databaseHelper.getTestContainer().commit(); + getMainWindow().showNotification("Saved"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + @Override + public void setItemDataSource(Item newDataSource) { + super.setItemDataSource(newDataSource); + + if (newDataSource != null) { + getFooter().setVisible(true); + } else { + getFooter().setVisible(false); + } + } + + } + +} diff --git a/uitest/src/com/vaadin/tests/containers/sqlcontainer/ComboBoxUpdateProblem.java b/uitest/src/com/vaadin/tests/containers/sqlcontainer/ComboBoxUpdateProblem.java new file mode 100644 index 0000000000..aec0f0e28e --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/sqlcontainer/ComboBoxUpdateProblem.java @@ -0,0 +1,27 @@ +package com.vaadin.tests.containers.sqlcontainer; + +import com.vaadin.Application; +import com.vaadin.ui.AbstractSelect.Filtering; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.UI; + +/** + * See http://dev.vaadin.com/ticket/9155 . + */ +public class ComboBoxUpdateProblem extends Application.LegacyApplication { + private final DatabaseHelper databaseHelper = new DatabaseHelper(); + + @Override + public void init() { + setMainWindow(new UI.LegacyWindow("Test window")); + + ComboBox combo = new ComboBox("Names", + databaseHelper.getTestContainer()); + combo.setItemCaptionPropertyId("FIELD1"); + combo.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS); + combo.setImmediate(true); + + getMainWindow().addComponent(combo); + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/containers/sqlcontainer/DatabaseHelper.java b/uitest/src/com/vaadin/tests/containers/sqlcontainer/DatabaseHelper.java new file mode 100644 index 0000000000..b7b1e74eb0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/sqlcontainer/DatabaseHelper.java @@ -0,0 +1,91 @@ +package com.vaadin.tests.containers.sqlcontainer; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +import com.vaadin.data.util.sqlcontainer.AllTests; +import com.vaadin.data.util.sqlcontainer.SQLContainer; +import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool; +import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool; +import com.vaadin.data.util.sqlcontainer.query.TableQuery; + +class DatabaseHelper { + + private JDBCConnectionPool connectionPool = null; + private SQLContainer testContainer = null; + private static final String TABLENAME = "testtable"; + + public DatabaseHelper() { + initConnectionPool(); + initDatabase(); + initContainers(); + } + + private void initDatabase() { + try { + Connection conn = connectionPool.reserveConnection(); + Statement statement = conn.createStatement(); + try { + statement.execute("drop table " + TABLENAME); + } catch (SQLException e) { + // Will fail if table doesn't exist, which is OK. + conn.rollback(); + } + switch (AllTests.db) { + case HSQLDB: + statement + .execute("create table " + + TABLENAME + + " (id integer GENERATED BY DEFAULT AS IDENTITY, field1 varchar(100), field2 boolean, primary key(id))"); + break; + case MYSQL: + statement + .execute("create table " + + TABLENAME + + " (id integer auto_increment not null, field1 varchar(100), field2 boolean, primary key(id))"); + break; + case POSTGRESQL: + statement + .execute("create table " + + TABLENAME + + " (\"id\" serial primary key, \"field1\" varchar(100), \"field2\" boolean)"); + break; + } + statement.executeUpdate("insert into " + TABLENAME + + " values(default, 'Kalle', 'true')"); + statement.executeUpdate("insert into " + TABLENAME + + " values(default, 'Ville', 'true')"); + statement.executeUpdate("insert into " + TABLENAME + + " values(default, 'Jussi', 'true')"); + statement.close(); + conn.commit(); + connectionPool.releaseConnection(conn); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void initContainers() { + try { + TableQuery q1 = new TableQuery(TABLENAME, connectionPool); + q1.setVersionColumn("id"); + testContainer = new SQLContainer(q1); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void initConnectionPool() { + try { + connectionPool = new SimpleJDBCConnectionPool(AllTests.dbDriver, + AllTests.dbURL, AllTests.dbUser, AllTests.dbPwd, 2, 5); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public SQLContainer getTestContainer() { + return testContainer; + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/containers/sqlcontainer/MassInsertMemoryLeakTestApp.java b/uitest/src/com/vaadin/tests/containers/sqlcontainer/MassInsertMemoryLeakTestApp.java new file mode 100644 index 0000000000..8bb2ba1092 --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/sqlcontainer/MassInsertMemoryLeakTestApp.java @@ -0,0 +1,135 @@ +package com.vaadin.tests.containers.sqlcontainer; + +import java.sql.SQLException; + +import com.vaadin.Application; +import com.vaadin.data.util.sqlcontainer.SQLContainer; +import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool; +import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool; +import com.vaadin.data.util.sqlcontainer.query.TableQuery; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.ComponentContainer; +import com.vaadin.ui.ProgressIndicator; +import com.vaadin.ui.UI.LegacyWindow; +import com.vaadin.ui.VerticalLayout; + +// author table in testdb (MySQL) is set out as follows +// +-------------+-------------+------+-----+---------+----------------+ +// | Field | Type | Null | Key | Default | Extra | +// +-------------+-------------+------+-----+---------+----------------+ +// | id | int(11) | NO | PRI | NULL | auto_increment | +// | last_name | varchar(40) | NO | | NULL | | +// | first_names | varchar(80) | NO | | NULL | | +// +-------------+-------------+------+-----+---------+----------------+ + +@SuppressWarnings("serial") +public class MassInsertMemoryLeakTestApp extends Application.LegacyApplication { + + ProgressIndicator proggress = new ProgressIndicator(); + Button process = new Button("Mass insert"); + + @Override + public void init() { + setMainWindow(new LegacyWindow("SQLContainer Test", buildLayout())); + + process.addListener(new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + MassInsert mi = new MassInsert(); + mi.start(); + } + }); + } + + private class MassInsert extends Thread { + + @Override + public synchronized void start() { + proggress.setVisible(true); + proggress.setValue(new Float(0)); + proggress.setPollingInterval(100); + process.setEnabled(false); + proggress.setCaption(""); + super.start(); + } + + @Override + public void run() { + JDBCConnectionPool pool = getConnectionPool(); + if (pool != null) { + try { + int cents = 100; + for (int cent = 0; cent < cents; cent++) { + TableQuery q = new TableQuery("AUTHOR", pool); + q.setVersionColumn("ID"); + SQLContainer c = new SQLContainer(q); + for (int i = 0; i < 100; i++) { + Object id = c.addItem(); + c.getContainerProperty(id, "FIRST_NAMES").setValue( + getRandonName()); + c.getContainerProperty(id, "LAST_NAME").setValue( + getRandonName()); + } + c.commit(); + synchronized (MassInsertMemoryLeakTestApp.this) { + proggress + .setValue(new Float((1.0f * cent) / cents)); + proggress.setCaption("" + 100 * cent + + " rows inserted"); + } + } + } catch (SQLException e) { + getMainWindow().showNotification( + "SQLException while processing", + e.getLocalizedMessage()); + e.printStackTrace(); + } + } + synchronized (MassInsertMemoryLeakTestApp.this) { + proggress.setVisible(false); + proggress.setPollingInterval(0); + process.setEnabled(true); + } + } + } + + private ComponentContainer buildLayout() { + VerticalLayout lo = new VerticalLayout(); + lo.setSizeFull(); + lo.addComponent(proggress); + lo.addComponent(process); + lo.setComponentAlignment(proggress, Alignment.BOTTOM_CENTER); + lo.setComponentAlignment(process, Alignment.TOP_CENTER); + lo.setSpacing(true); + proggress.setIndeterminate(false); + proggress.setVisible(false); + return lo; + } + + private String getRandonName() { + final String[] tokens = new String[] { "sa", "len", "da", "vid", "ma", + "ry", "an", "na", "jo", "bri", "son", "mat", "e", "ric", "ge", + "eu", "han", "har", "ri", "ja", "lo" }; + StringBuffer sb = new StringBuffer(); + int len = (int) (Math.random() * 3 + 2); + while (len-- > 0) { + sb.append(tokens[(int) (Math.random() * tokens.length)]); + } + return Character.toUpperCase(sb.charAt(0)) + sb.toString().substring(1); + } + + private JDBCConnectionPool getConnectionPool() { + SimpleJDBCConnectionPool pool = null; + try { + pool = new SimpleJDBCConnectionPool("com.mysql.jdbc.Driver", + "jdbc:mysql://localhost:3306/sqlcontainer", "sqlcontainer", + "sqlcontainer"); + } catch (SQLException e) { + getMainWindow().showNotification("Error connecting to database"); + } + return pool; + } + +}
\ No newline at end of file |