From ed4bec15a1fbc53a1818192644cdb86e0e2e30ee Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Wed, 15 Apr 2015 13:36:18 +0300 Subject: Declarative read support for Table (#16367) Change-Id: I2327af18b2e1e4d31a057b110eee9495f16d9633 --- .../component/table/TableDeclarativeTest.java | 165 +++++++++++++++++++++ .../component/table/TableDeclarativeTestBase.java | 52 +++++++ 2 files changed, 217 insertions(+) create mode 100644 server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTestBase.java (limited to 'server/tests/src') diff --git a/server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTest.java new file mode 100644 index 0000000000..27888dee14 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTest.java @@ -0,0 +1,165 @@ +/* + * Copyright 2000-2014 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.server.component.table; + +import java.io.UnsupportedEncodingException; + +import org.junit.Test; + +import com.vaadin.server.ExternalResource; +import com.vaadin.shared.ui.MultiSelectMode; +import com.vaadin.ui.Table; +import com.vaadin.ui.Table.Align; +import com.vaadin.ui.Table.ColumnHeaderMode; +import com.vaadin.ui.Table.RowHeaderMode; +import com.vaadin.ui.Table.TableDragMode; + +/** + * Test declarative support for {@link Table}. + * + * @since + * @author Vaadin Ltd + */ +public class TableDeclarativeTest extends TableDeclarativeTestBase { + + @Test + public void testBasicAttributes() { + + String design = ""; + + Table table = new Table(); + table.setPageLength(30); + table.setCacheRate(3); + table.setSelectable(true); + table.setEditable(true); + table.setSortEnabled(false); + table.setDragMode(TableDragMode.ROW); + table.setMultiSelectMode(MultiSelectMode.SIMPLE); + table.setColumnHeaderMode(ColumnHeaderMode.ID); + table.setRowHeaderMode(RowHeaderMode.ID); + table.setColumnReorderingAllowed(true); + table.setColumnCollapsingAllowed(true); + table.setSortAscending(false); + table.setSortContainerPropertyId("foo"); + + testRead(design, table); + // testWrite(design, table); + } + + @Test + public void testColumns() { + String design = "" // + + " " // + + " " + + " " + + " " + + " " + + " " // + + "
" // + + "
"; + + Table table = new Table(); + table.setColumnCollapsingAllowed(true); + + table.addContainerProperty("foo", String.class, null); + table.setColumnAlignment("foo", Align.LEFT); + table.setColumnExpandRatio("foo", 0); + + table.addContainerProperty("bar", String.class, null); + table.setColumnAlignment("bar", Align.CENTER); + table.setColumnExpandRatio("bar", 1); + table.setColumnCollapsible("bar", false); + + table.addContainerProperty("baz", String.class, null); + table.setColumnAlignment("baz", Align.RIGHT); + table.setColumnExpandRatio("baz", 2); + table.setColumnCollapsed("baz", true); + + testRead(design, table); + // testWrite(design, table); + } + + @Test + public void testHeadersFooters() { + String design = "" // + + " " // + + " " // + + " " // + + " " // + + " " // + + " " // + + "
FOOBAR" // + + "
foobar" // + + "
" // + + "
"; + + Table table = new Table(); + table.setFooterVisible(true); + + table.addContainerProperty("foo", String.class, null); + table.setColumnHeader("foo", "FOO"); + table.setColumnIcon("foo", new ExternalResource( + "http://example.com/icon.png")); + table.setColumnFooter("foo", "foo"); + + table.addContainerProperty("bar", String.class, null); + table.setColumnHeader("bar", "BAR"); + table.setColumnFooter("bar", "bar"); + + testRead(design, table); + // testWrite(design, table); + } + + @Test + public void testInlineData() throws UnsupportedEncodingException { + String design = " "// + + " " // + + " " + + " " + + " " + + " " // + + " " + + " " + + " " + + " " + + " " + + " " // + + " " // + + " " // + + " " // + + " " // + + " " // + + "
DescriptionMilestoneStatus
r1c1r1c2r1c3
r2c1r2c2r2c3
F1F2F3
" // + + "
"; + Table table = new Table(); + table.addContainerProperty("foo", String.class, null); + table.addContainerProperty("bar", String.class, null); + table.addContainerProperty("baz", String.class, null); + table.setColumnHeaders("Description", "Milestone", "Status"); + table.setColumnFooter("foo", "F1"); + table.setColumnFooter("bar", "F2"); + table.setColumnFooter("baz", "F3"); + table.addItem(new Object[] { "r1c1", "r1c2", "r1c3" }, null); + table.addItem(new Object[] { "r2c1", "r2c2", "r2c3" }, null); + table.setFooterVisible(true); + testRead(design, table); + // testWrite(design, table); + + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTestBase.java b/server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTestBase.java new file mode 100644 index 0000000000..7f803c7f8b --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTestBase.java @@ -0,0 +1,52 @@ +/* + * Copyright 2000-2014 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.server.component.table; + +import static org.junit.Assert.assertTrue; + +import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.ui.Table; + +public class TableDeclarativeTestBase extends DeclarativeTestBase { + + @Override + public Table testRead(String design, Table expected) { + Table read = super.testRead(design, expected); + compareFooter(read, expected); + compareBody(read, expected); + return read; + } + + private void compareBody(Table read, Table expected) { + assertEquals(expected.getItemIds().size(), read.getItemIds().size()); + for (Object rowId : expected.getItemIds()) { + assertTrue(read.containsId(rowId)); + for (Object propertyId : read.getVisibleColumns()) { + Object expectedItem = expected.getContainerProperty(rowId, + propertyId); + Object readItem = read.getContainerProperty(rowId, propertyId); + assertEquals(expectedItem, readItem); + } + } + } + + private void compareFooter(Table read, Table expected) { + for (Object pid : expected.getVisibleColumns()) { + assertEquals(expected.getColumnFooter(pid), + read.getColumnFooter(pid)); + } + } +} -- cgit v1.2.3