2 * Copyright 2000-2016 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.v7.tests.server.component.table;
18 import org.junit.Assert;
19 import org.junit.Test;
21 import com.vaadin.server.ExternalResource;
22 import com.vaadin.shared.ui.MultiSelectMode;
23 import com.vaadin.v7.ui.Table;
24 import com.vaadin.v7.ui.Table.Align;
25 import com.vaadin.v7.ui.Table.ColumnHeaderMode;
26 import com.vaadin.v7.ui.Table.RowHeaderMode;
27 import com.vaadin.v7.ui.Table.TableDragMode;
30 * Test declarative support for {@link Table}.
35 public class TableDeclarativeTest extends TableDeclarativeTestBase {
38 public void testBasicAttributes() {
40 String design = "<" + getTag()
41 + " page-length=30 cache-rate=3 selectable editable "
42 + "sortable=false sort-ascending=false sort-container-property-id=foo "
43 + "drag-mode=row multi-select-mode=simple column-header-mode=id row-header-mode=id "
44 + "column-reordering-allowed column-collapsing-allowed />";
46 Table table = getTable();
47 table.setPageLength(30);
48 table.setCacheRate(3);
49 table.setSelectable(true);
50 table.setEditable(true);
52 table.setSortEnabled(false);
53 table.setSortAscending(false);
54 table.setSortContainerPropertyId("foo");
56 table.setDragMode(TableDragMode.ROW);
57 table.setMultiSelectMode(MultiSelectMode.SIMPLE);
58 table.setColumnHeaderMode(ColumnHeaderMode.ID);
59 table.setRowHeaderMode(RowHeaderMode.ID);
61 table.setColumnReorderingAllowed(true);
62 table.setColumnCollapsingAllowed(true);
64 testRead(design, table);
65 testWrite(design, table);
69 public void testColumns() {
70 String design = "<" + getTag() + " column-collapsing-allowed>" //
72 + " <colgroup>" + " <col property-id='foo' width=300>"
73 + " <col property-id='bar' center expand=1 collapsible=false>"
74 + " <col property-id='baz' right expand=2 collapsed>"
78 Table table = getTable();
79 table.setColumnCollapsingAllowed(true);
81 table.addContainerProperty("foo", String.class, null);
82 table.setColumnAlignment("foo", Align.LEFT);
83 table.setColumnWidth("foo", 300);
85 table.addContainerProperty("bar", String.class, null);
86 table.setColumnAlignment("bar", Align.CENTER);
87 table.setColumnExpandRatio("bar", 1);
88 table.setColumnCollapsible("bar", false);
90 table.addContainerProperty("baz", String.class, null);
91 table.setColumnAlignment("baz", Align.RIGHT);
92 table.setColumnExpandRatio("baz", 2);
93 table.setColumnCollapsed("baz", true);
95 testRead(design, table);
96 testWrite(design, table);
100 public void testHeadersFooters() {
101 String design = "<" + getTag() + ">" //
103 + " <colgroup><col property-id=foo><col property-id=bar></colgroup>" //
105 + " <tr><th icon='http://example.com/icon.png'>FOO<th>BAR" //
108 + " <tr><td>foo<td>bar" //
112 Table table = getTable();
113 table.setFooterVisible(true);
115 table.addContainerProperty("foo", String.class, null);
116 table.setColumnHeader("foo", "FOO");
117 table.setColumnIcon("foo",
118 new ExternalResource("http://example.com/icon.png"));
119 table.setColumnFooter("foo", "foo");
121 table.addContainerProperty("bar", String.class, null);
122 table.setColumnHeader("bar", "BAR");
123 table.setColumnFooter("bar", "bar");
125 testRead(design, table);
126 testWrite(design, table);
130 public void testInlineData() {
131 String design = "<" + getTag() + ">" //
133 + " <colgroup>" + " <col property-id='foo' />"
134 + " <col property-id='bar' />"
135 + " <col property-id='baz' />" //
136 + " </colgroup>" + " <thead>"
137 + " <tr><th>Description<th>Milestone<th>Status</tr>"
138 + " </thead>" + " <tbody>"
139 + " <tr item-id=1><td>r1c1</td><td>r1c2</td><td>r1c3</td>" //
140 + " <tr item-id=2><td>r2c1</td><td>r2c2</td><td>r2c3</td>" //
143 + " <tr><td>F1<td>F2<td>F3</tr>" //
147 Table table = getTable();
148 table.addContainerProperty("foo", String.class, null);
149 table.addContainerProperty("bar", String.class, null);
150 table.addContainerProperty("baz", String.class, null);
151 table.setColumnHeaders("Description", "Milestone", "Status");
152 table.setColumnFooter("foo", "F1");
153 table.setColumnFooter("bar", "F2");
154 table.setColumnFooter("baz", "F3");
155 table.addItem(new Object[] { "r1c1", "r1c2", "r1c3" }, "1");
156 table.addItem(new Object[] { "r2c1", "r2c2", "r2c3" }, "2");
157 table.setFooterVisible(true);
159 testRead(design, table);
160 testWrite(design, table, true);
164 public void testHtmlEntities() {
165 String design = "<vaadin7-table>" + "<table>" + " <colgroup>"
166 + " <col property-id=\"test\"" + " </colgroup>"
167 + " <thead>" + " <tr><th>& Test</th></tr>"
168 + " </thead>" + " <tbody>"
169 + " <tr item-id=\"test\"><td>& Test</tr>" + " </tbody>"
170 + " <tfoot>" + " <tr><td>& Test</td></tr>"
171 + " </tfoot>" + "</table>" + "</vaadin7-table>";
172 Table read = read(design);
174 assertEquals("& Test",
175 read.getContainerProperty("test", "test").getValue());
176 assertEquals("& Test", read.getColumnHeader("test"));
177 assertEquals("& Test", read.getColumnFooter("test"));