summaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2015-04-15 13:36:18 +0300
committerVaadin Code Review <review@vaadin.com>2015-04-17 14:31:32 +0000
commited4bec15a1fbc53a1818192644cdb86e0e2e30ee (patch)
treeccb65d62e45ef155bfdfcc25908c76ff546bd99c /server/tests
parent2d3ed921065acd7761df07b9b403d111bedf33d9 (diff)
downloadvaadin-framework-ed4bec15a1fbc53a1818192644cdb86e0e2e30ee.tar.gz
vaadin-framework-ed4bec15a1fbc53a1818192644cdb86e0e2e30ee.zip
Declarative read support for Table (#16367)
Change-Id: I2327af18b2e1e4d31a057b110eee9495f16d9633
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTest.java165
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTestBase.java52
2 files changed, 217 insertions, 0 deletions
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 = "<v-table page-length=30 cache-rate=3 selectable editable sortable=false "
+ + "drag-mode=row multi-select-mode=simple column-header-mode=id "
+ + "column-reordering-allowed column-collapsing-allowed sort-ascending=false "
+ + "row-header-mode=id sort-container-property-id=foo />";
+
+ 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 = "<v-table column-collapsing-allowed=true>" //
+ + " <table>" //
+ + " <colgroup>"
+ + " <col property-id='foo'>"
+ + " <col property-id='bar' center expand=1 collapsible=false>"
+ + " <col property-id='baz' right expand=2 collapsed=true>"
+ + " </colgroup>" //
+ + " </table>" //
+ + "</v-table>";
+
+ 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 = "<v-table>" //
+ + " <table>" //
+ + " <colgroup><col property-id=foo><col property-id=bar></colgroup>" //
+ + " <thead>" //
+ + " <tr><th icon='http://example.com/icon.png'>FOO<th>BAR" //
+ + " </thead>" //
+ + " <tfoot>" //
+ + " <tr><td>foo<td>bar" //
+ + " </tfoot>" //
+ + " </table>" //
+ + "</v-table>";
+
+ 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 = "<v-table footer-visible=true> "//
+ + " <table>" //
+ + " <colgroup>"
+ + " <col property-id='foo' width=150 />"
+ + " <col property-id='bar' />"
+ + " <col property-id='baz' />" //
+ + " </colgroup>"
+ + " <thead>"
+ + " <tr><th>Description<th>Milestone<th>Status</tr>"
+ + " </thead>"
+ + " <tbody>"
+ + " <tr><td>r1c1</td><td>r1c2</td><td>r1c3</td>" //
+ + " <tr><td>r2c1</td><td>r2c2</td><td>r2c3</td>" //
+ + " </tbody>" //
+ + " <tfoot>" //
+ + " <tr><td>F1<td>F2<td>F3</tr>" //
+ + " </tfoot>" //
+ + " </table>" //
+ + "</v-table>";
+ 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<Table> {
+
+ @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));
+ }
+ }
+}