diff options
author | Aleksi Hietanen <aleksi@vaadin.com> | 2017-05-16 11:57:02 +0300 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2017-05-16 11:57:02 +0300 |
commit | efa7f5a4d069556061ba4ceef4fb4d76dae84ef4 (patch) | |
tree | 767b0fdb3146930919cec37e5eaab75422b0867d /server/src/test | |
parent | eb743d965278d263a4c496bb4e39c067fe2b1a8c (diff) | |
download | vaadin-framework-efa7f5a4d069556061ba4ceef4fb4d76dae84ef4.tar.gz vaadin-framework-efa7f5a4d069556061ba4ceef4fb4d76dae84ef4.zip |
Refactor common methods in in-memory data providers (#9308)
* Refactor common methods of InMemoryHierarchicalDataProvider and ListDataProvider to a single interface
* Rename HierarchyData and InMemoryHierarchicalDataProvider, introduce HasHierarchicalDataProvider
* Additionally adds a helper method for recursive constructing
TreeData with a child item provider.
Diffstat (limited to 'server/src/test')
-rw-r--r-- | server/src/test/java/com/vaadin/data/provider/TreeDataProviderTest.java (renamed from server/src/test/java/com/vaadin/data/provider/InMemoryHierarchicalDataProviderTest.java) | 51 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/components/TreeTest.java | 14 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java | 14 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java | 1 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/treegrid/TreeGridDeclarativeTest.java | 8 |
5 files changed, 54 insertions, 34 deletions
diff --git a/server/src/test/java/com/vaadin/data/provider/InMemoryHierarchicalDataProviderTest.java b/server/src/test/java/com/vaadin/data/provider/TreeDataProviderTest.java index 99b7a04b19..3f9f1f6e94 100644 --- a/server/src/test/java/com/vaadin/data/provider/InMemoryHierarchicalDataProviderTest.java +++ b/server/src/test/java/com/vaadin/data/provider/TreeDataProviderTest.java @@ -1,6 +1,7 @@ package com.vaadin.data.provider; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -8,13 +9,13 @@ import java.util.stream.Collectors; import org.junit.Assert; import org.junit.Test; -import com.vaadin.data.HierarchyData; +import com.vaadin.data.TreeData; import com.vaadin.server.SerializablePredicate; -public class InMemoryHierarchicalDataProviderTest extends - DataProviderTestBase<InMemoryHierarchicalDataProvider<StrBean>> { +public class TreeDataProviderTest extends + DataProviderTestBase<TreeDataProvider<StrBean>> { - private HierarchyData<StrBean> data; + private TreeData<StrBean> data; private List<StrBean> flattenedData; private List<StrBean> rootData; @@ -24,7 +25,7 @@ public class InMemoryHierarchicalDataProviderTest extends flattenedData = new ArrayList<>(); rootData = new ArrayList<>(); - data = new HierarchyData<>(); + data = new TreeData<>(); data.addItems(null, randomBeans.subList(0, 5)); data.addItems(randomBeans.get(0), randomBeans.subList(5, 10)); data.addItems(randomBeans.get(5), randomBeans.subList(10, 15)); @@ -44,42 +45,60 @@ public class InMemoryHierarchicalDataProviderTest extends } @Test(expected = IllegalArgumentException.class) - public void hierarchyData_add_item_parent_not_in_hierarchy_throws() { - new HierarchyData<>().addItem(new StrBean("", 0, 0), + public void treeData_add_item_parent_not_in_hierarchy_throws() { + new TreeData<>().addItem(new StrBean("", 0, 0), new StrBean("", 0, 0)); } @Test(expected = NullPointerException.class) - public void hierarchyData_add_null_item_throws() { - new HierarchyData<>().addItem(null, null); + public void treeData_add_null_item_throws() { + new TreeData<>().addItem(null, null); } @Test(expected = IllegalArgumentException.class) - public void hierarchyData_add_item_already_in_hierarchy_throws() { + public void treeData_add_item_already_in_hierarchy_throws() { StrBean bean = new StrBean("", 0, 0); - new HierarchyData<>().addItem(null, bean).addItem(null, bean); + new TreeData<>().addItem(null, bean).addItem(null, bean); } @Test - public void hierarchyData_remove_root_item() { + public void treeData_remove_root_item() { data.removeItem(null); Assert.assertTrue(data.getChildren(null).isEmpty()); } @Test - public void hierarchyData_clear() { + public void treeData_clear() { data.clear(); Assert.assertTrue(data.getChildren(null).isEmpty()); } @Test - public void hierarchyData_re_add_removed_item() { + public void treeData_re_add_removed_item() { StrBean item = rootData.get(0); data.removeItem(item).addItem(null, item); Assert.assertTrue(data.getChildren(null).contains(item)); } @Test + public void populate_treeData_with_child_item_provider() { + TreeData<String> stringData = new TreeData<>(); + List<String> rootItems = Arrays.asList("a", "b", "c"); + stringData.addItems(rootItems, item -> { + if (item.length() >= 3 || item.startsWith("c")) { + return Arrays.asList(); + } + return Arrays.asList(item + "/a", item + "/b", item + "/c"); + }); + Assert.assertEquals(stringData.getChildren("a"), + Arrays.asList("a/a", "a/b", "a/c")); + Assert.assertEquals(stringData.getChildren("b"), + Arrays.asList("b/a", "b/b", "b/c")); + Assert.assertEquals(stringData.getChildren("c"), Arrays.asList()); + Assert.assertEquals(stringData.getChildren("a/b"), Arrays.asList()); + } + + @Test public void setFilter() { getDataProvider().setFilter(item -> item.getValue().equals("Xyz") || item.getValue().equals("Baz")); @@ -226,8 +245,8 @@ public class InMemoryHierarchicalDataProviderTest extends } @Override - protected InMemoryHierarchicalDataProvider<StrBean> createDataProvider() { - return new InMemoryHierarchicalDataProvider<>(data); + protected TreeDataProvider<StrBean> createDataProvider() { + return new TreeDataProvider<>(data); } @Override diff --git a/server/src/test/java/com/vaadin/tests/components/TreeTest.java b/server/src/test/java/com/vaadin/tests/components/TreeTest.java index 13ef0acc49..9224934a4c 100644 --- a/server/src/test/java/com/vaadin/tests/components/TreeTest.java +++ b/server/src/test/java/com/vaadin/tests/components/TreeTest.java @@ -3,8 +3,8 @@ package com.vaadin.tests.components; import org.junit.Assert; import org.junit.Test; -import com.vaadin.data.HierarchyData; -import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; +import com.vaadin.data.TreeData; +import com.vaadin.data.provider.TreeDataProvider; import com.vaadin.event.CollapseEvent; import com.vaadin.event.CollapseEvent.CollapseListener; import com.vaadin.event.ExpandEvent; @@ -52,12 +52,12 @@ public class TreeTest { @Test public void event_source_is_tree() { Tree<String> tree = new Tree<>(); - HierarchyData<String> hierarchyData = new HierarchyData<>(); - hierarchyData.addItem(null, "Foo"); - hierarchyData.addItem("Foo", "Bar"); - hierarchyData.addItem("Foo", "Baz"); + TreeData<String> treeData = new TreeData<>(); + treeData.addItem(null, "Foo"); + treeData.addItem("Foo", "Bar"); + treeData.addItem("Foo", "Baz"); tree.setDataProvider( - new InMemoryHierarchicalDataProvider<>(hierarchyData)); + new TreeDataProvider<>(treeData)); TreeCollapseExpandListener listener = new TreeCollapseExpandListener( tree); diff --git a/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java b/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java index 2e335f865e..1544a4f69d 100644 --- a/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java +++ b/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java @@ -3,8 +3,8 @@ package com.vaadin.tests.components.treegrid; import org.junit.Assert; import org.junit.Test; -import com.vaadin.data.HierarchyData; -import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; +import com.vaadin.data.TreeData; +import com.vaadin.data.provider.TreeDataProvider; import com.vaadin.ui.TreeGrid; import com.vaadin.ui.renderers.TextRenderer; @@ -24,12 +24,12 @@ public class TreeGridTest { @Test public void testExpandAndCollapseEvents() { - HierarchyData<String> hierarchyData = new HierarchyData<>(); - hierarchyData.addItem(null, "Foo"); - hierarchyData.addItem("Foo", "Bar"); - hierarchyData.addItem("Foo", "Baz"); + TreeData<String> treeData = new TreeData<>(); + treeData.addItem(null, "Foo"); + treeData.addItem("Foo", "Bar"); + treeData.addItem("Foo", "Baz"); treeGrid.setDataProvider( - new InMemoryHierarchicalDataProvider<>(hierarchyData)); + new TreeDataProvider<>(treeData)); treeGrid.addExpandListener(e -> expandEventFired = true); treeGrid.addCollapseListener(e -> collapseEventFired = true); diff --git a/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java b/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java index b4f9851867..d2d25b4777 100644 --- a/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java +++ b/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java @@ -76,6 +76,7 @@ public class ClassesSerializableTest { "com\\.vaadin\\.buildhelpers.*", // "com\\.vaadin\\.util\\.EncodeUtil.*", // "com\\.vaadin\\.util\\.ReflectTools.*", // + "com\\.vaadin\\.data\\.provider\\.InMemoryDataProviderHelpers", "com\\.vaadin\\.data\\.provider\\.HierarchyMapper\\$TreeLevelQuery", "com\\.vaadin\\.data\\.util\\.ReflectTools.*", // "com\\.vaadin\\.data\\.util\\.JsonUtil.*", // diff --git a/server/src/test/java/com/vaadin/tests/server/component/treegrid/TreeGridDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/treegrid/TreeGridDeclarativeTest.java index c8a51a1928..a13ba357ef 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/treegrid/TreeGridDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/treegrid/TreeGridDeclarativeTest.java @@ -4,9 +4,9 @@ import java.lang.reflect.InvocationTargetException; import org.junit.Assert; -import com.vaadin.data.HierarchyData; +import com.vaadin.data.TreeData; import com.vaadin.data.provider.HierarchicalQuery; -import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; +import com.vaadin.data.provider.TreeDataProvider; import com.vaadin.tests.data.bean.Person; import com.vaadin.tests.server.component.abstractlisting.AbstractListingDeclarativeTest; import com.vaadin.ui.TreeGrid; @@ -28,7 +28,7 @@ public class TreeGridDeclarativeTest Person person6 = createPerson("ca", "last-name"); Person person7 = createPerson("caa", "last-name"); - HierarchyData<Person> data = new HierarchyData<>(); + TreeData<Person> data = new TreeData<>(); data.addItems(null, person1, person4, person5); data.addItems(person1, person2, person3); data.addItem(person5, person6); @@ -38,7 +38,7 @@ public class TreeGridDeclarativeTest grid.addColumn(Person::getLastName).setId("id").setCaption("Id"); grid.setHierarchyColumn("id"); - grid.setDataProvider(new InMemoryHierarchicalDataProvider<>(data)); + grid.setDataProvider(new TreeDataProvider<>(data)); String design = String.format( "<%s hierarchy-column='id'><table><colgroup>" |