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.grid.declarative;
18 import org.junit.Assert;
19 import org.junit.Test;
21 import com.vaadin.v7.data.Container;
22 import com.vaadin.v7.ui.Grid;
24 public class GridInlineDataDeclarativeTest extends GridDeclarativeTestBase {
27 public void testSimpleInlineData() {
28 String design = "<vaadin7-grid><table>"//
29 + "<colgroup>" + " <col sortable property-id='Col1' />"
31 + "<thead />" // No headers read or written
33 + "<tr><td>Foo</tr>" //
34 + "<tr><td>Bar</tr>" //
35 + "<tr><td>Baz</tr>" //
37 + "</table></vaadin7-grid>";
39 Grid grid = new Grid();
40 grid.addColumn("Col1", String.class);
45 // Remove default header
46 grid.removeHeaderRow(grid.getDefaultHeaderRow());
48 testWrite(design, grid, true);
49 testRead(design, grid, true, true);
53 public void testMultipleColumnsInlineData() {
54 String design = "<vaadin7-grid><table>"//
55 + "<colgroup>" + " <col sortable property-id='Col1' />"
56 + " <col sortable property-id='Col2' />"
57 + " <col sortable property-id='Col3' />" //
59 + "<thead />" // No headers read or written
61 + "<tr><td>Foo<td>Bar<td>Baz</tr>" //
62 + "<tr><td>My<td>Summer<td>Car</tr>" //
64 + "</table></vaadin7-grid>";
66 Grid grid = new Grid();
67 grid.addColumn("Col1", String.class);
68 grid.addColumn("Col2", String.class);
69 grid.addColumn("Col3", String.class);
70 grid.addRow("Foo", "Bar", "Baz");
71 grid.addRow("My", "Summer", "Car");
73 // Remove default header
74 grid.removeHeaderRow(grid.getDefaultHeaderRow());
76 testWrite(design, grid, true);
77 testRead(design, grid, true, true);
81 public void testMultipleColumnsInlineDataReordered() {
82 String design = "<vaadin7-grid><table>"//
83 + "<colgroup>" + " <col sortable property-id='Col2' />"
84 + " <col sortable property-id='Col3' />"
85 + " <col sortable property-id='Col1' />" //
87 + "<thead />" // No headers read or written
89 + "<tr><td>Bar<td>Baz<td>Foo</tr>" //
90 + "<tr><td>Summer<td>Car<td>My</tr>" //
92 + "</table></vaadin7-grid>";
94 Grid grid = new Grid();
95 grid.addColumn("Col1", String.class);
96 grid.addColumn("Col2", String.class);
97 grid.addColumn("Col3", String.class);
98 grid.addRow("Foo", "Bar", "Baz");
99 grid.addRow("My", "Summer", "Car");
100 grid.setColumnOrder("Col2", "Col3", "Col1");
102 // Remove default header
103 grid.removeHeaderRow(grid.getDefaultHeaderRow());
105 testWrite(design, grid, true);
106 testRead(design, grid, true, true);
110 public void testHtmlEntities() {
111 String design = "<vaadin7-grid><table>"//
112 + "<colgroup>" + " <col property-id='test' />" + "</colgroup>" //
113 + "<thead />" // No headers read or written
115 + " <tr><td>&Test</tr></td>" + "</tbody>"
116 + "</table></vaadin7-grid>";
118 Grid read = read(design);
119 Container cds = read.getContainerDataSource();
120 assertEquals("&Test",
121 cds.getItem(cds.getItemIds().iterator().next())
122 .getItemProperty("test").getValue());