diff options
author | Juuso Valli <juuso@vaadin.com> | 2014-05-07 09:39:14 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-05-15 09:30:56 +0000 |
commit | 40a80c51803a109083d3949039448beeefd7f9da (patch) | |
tree | ad7a5d74eb4b8d02cc64bbaa018373911e41b75f /uitest | |
parent | 023568931d8eca775a9f6ab2e584e7ccfae83bd4 (diff) | |
download | vaadin-framework-40a80c51803a109083d3949039448beeefd7f9da.tar.gz vaadin-framework-40a80c51803a109083d3949039448beeefd7f9da.zip |
Fix Push inserts producing duplicate rows in Table (#13562)
Change-Id: I050553b233fb7024049c31d9495d90f4d88239c8
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/table/AsyncPushUpdates.java | 126 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/table/AsyncPushUpdatesTest.java | 46 |
2 files changed, 172 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/table/AsyncPushUpdates.java b/uitest/src/com/vaadin/tests/components/table/AsyncPushUpdates.java new file mode 100644 index 0000000000..fcbfe1e0b0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/AsyncPushUpdates.java @@ -0,0 +1,126 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.table; + +import javax.servlet.annotation.WebServlet; + +import com.vaadin.annotations.Push; +import com.vaadin.annotations.VaadinServletConfiguration; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinServlet; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Table; + +/** + * Test to see if VScrollTable handles Push updates correctly. + * + * @author Vaadin Ltd + */ +@Push +public class AsyncPushUpdates extends AbstractTestUI { + + public int clickCount = 0; + + @WebServlet(value = "/*", asyncSupported = true) + @VaadinServletConfiguration(productionMode = false, ui = AsyncPushUpdates.class) + public static class Servlet extends VaadinServlet { + } + + public static final String VALUE_PROPERTY_ID = "value"; + + private final IndexedContainer container = createContainer(); + private final Table table = new Table(); + + @Override + public void setup(VaadinRequest request) { + table.setWidth("100%"); + table.setContainerDataSource(container); + + Button button = new Button("START"); + button.addClickListener(new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + ++clickCount; + + container.removeAllItems(); + for (int i = 0; i < 100; i++) { + container.getContainerProperty(container.addItem(), + VALUE_PROPERTY_ID).setValue("A" + i); + } + + Runnable generateNewRows = new Runnable() { + public int id = 0; + + @Override + public void run() { + getSession().lock(); + try { + Thread.sleep(500); + ++id; + container.removeAllItems(); + for (int i = 0; i < 11; i++) { + container.getContainerProperty( + container.addItem(), VALUE_PROPERTY_ID) + .setValue( + clickCount + " - " + id + " - " + + i); + } + + } catch (InterruptedException e) { + // NOOP + } finally { + getSession().unlock(); + } + } + }; + new Thread(generateNewRows).start(); + } + }); + addComponent(table); + addComponent(button); + } + + private static IndexedContainer createContainer() { + IndexedContainer container = new IndexedContainer(); + container.addContainerProperty(VALUE_PROPERTY_ID, String.class, ""); + return container; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() + */ + @Override + protected String getTestDescription() { + return "Make sure there are no duplicates on the table."; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() + */ + @Override + protected Integer getTicketNumber() { + return 13562; + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/table/AsyncPushUpdatesTest.java b/uitest/src/com/vaadin/tests/components/table/AsyncPushUpdatesTest.java new file mode 100644 index 0000000000..b33204cc44 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/AsyncPushUpdatesTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.table; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test to see if VScrollTable handles Push updates correctly. + * + * @author Vaadin Ltd + */ +public class AsyncPushUpdatesTest extends MultiBrowserTest { + + @Test(expected = NoSuchElementException.class) + public void InsertedRowsAreNotDuplicated() { + openTestURL(); + + WebElement button = $(ButtonElement.class).first(); + + button.click(); + + $(TableElement.class).first().getCell(12, 0); + Assert.fail("Duplicates are present."); + } + +} |