]> source.dussan.org Git - vaadin-framework.git/blob
d5ac086d4698afe2df469bfbfa7cf95f4b83645e
[vaadin-framework.git] /
1 /*
2  * Copyright 2000-2016 Vaadin Ltd.
3  *
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
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
14  * the License.
15  */
16 package com.vaadin.v7.tests.server.component.grid.declarative;
17
18 import org.junit.Assert;
19 import org.junit.Test;
20
21 import com.vaadin.v7.data.Container;
22 import com.vaadin.v7.ui.Grid;
23
24 public class GridInlineDataDeclarativeTest extends GridDeclarativeTestBase {
25
26     @Test
27     public void testSimpleInlineData() {
28         String design = "<vaadin7-grid><table>"//
29                 + "<colgroup>" + "   <col sortable property-id='Col1' />"
30                 + "</colgroup>" //
31                 + "<thead />" // No headers read or written
32                 + "<tbody>" //
33                 + "<tr><td>Foo</tr>" //
34                 + "<tr><td>Bar</tr>" //
35                 + "<tr><td>Baz</tr>" //
36                 + "</tbody>" //
37                 + "</table></vaadin7-grid>";
38
39         Grid grid = new Grid();
40         grid.addColumn("Col1", String.class);
41         grid.addRow("Foo");
42         grid.addRow("Bar");
43         grid.addRow("Baz");
44
45         // Remove default header
46         grid.removeHeaderRow(grid.getDefaultHeaderRow());
47
48         testWrite(design, grid, true);
49         testRead(design, grid, true, true);
50     }
51
52     @Test
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' />" //
58                 + "</colgroup>" //
59                 + "<thead />" // No headers read or written
60                 + "<tbody>" //
61                 + "<tr><td>Foo<td>Bar<td>Baz</tr>" //
62                 + "<tr><td>My<td>Summer<td>Car</tr>" //
63                 + "</tbody>" //
64                 + "</table></vaadin7-grid>";
65
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");
72
73         // Remove default header
74         grid.removeHeaderRow(grid.getDefaultHeaderRow());
75
76         testWrite(design, grid, true);
77         testRead(design, grid, true, true);
78     }
79
80     @Test
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' />" //
86                 + "</colgroup>" //
87                 + "<thead />" // No headers read or written
88                 + "<tbody>" //
89                 + "<tr><td>Bar<td>Baz<td>Foo</tr>" //
90                 + "<tr><td>Summer<td>Car<td>My</tr>" //
91                 + "</tbody>" //
92                 + "</table></vaadin7-grid>";
93
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");
101
102         // Remove default header
103         grid.removeHeaderRow(grid.getDefaultHeaderRow());
104
105         testWrite(design, grid, true);
106         testRead(design, grid, true, true);
107     }
108
109     @Test
110     public void testHtmlEntities() {
111         String design = "<vaadin7-grid><table>"//
112                 + "<colgroup>" + "   <col property-id='test' />" + "</colgroup>" //
113                 + "<thead />" // No headers read or written
114                 + "<tbody>" //
115                 + "  <tr><td>&amp;Test</tr></td>" + "</tbody>"
116                 + "</table></vaadin7-grid>";
117
118         Grid read = read(design);
119         Container cds = read.getContainerDataSource();
120         assertEquals("&amp;Test",
121                 cds.getItem(cds.getItemIds().iterator().next())
122                         .getItemProperty("test").getValue());
123     }
124 }