You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridInlineDataDeclarativeTest.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2000-2014 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.tests.server.component.grid.declarative;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import com.vaadin.data.Container;
  20. import com.vaadin.ui.Grid;
  21. public class GridInlineDataDeclarativeTest extends GridDeclarativeTestBase {
  22. @Test
  23. public void testSimpleInlineData() {
  24. String design = "<vaadin-grid><table>"//
  25. + "<colgroup>"
  26. + " <col sortable property-id='Col1' />"
  27. + "</colgroup>" //
  28. + "<thead />" // No headers read or written
  29. + "<tbody>" //
  30. + "<tr><td>Foo</tr>" //
  31. + "<tr><td>Bar</tr>" //
  32. + "<tr><td>Baz</tr>" //
  33. + "</tbody>" //
  34. + "</table></vaadin-grid>";
  35. Grid grid = new Grid();
  36. grid.addColumn("Col1", String.class);
  37. grid.addRow("Foo");
  38. grid.addRow("Bar");
  39. grid.addRow("Baz");
  40. // Remove default header
  41. grid.removeHeaderRow(grid.getDefaultHeaderRow());
  42. testWrite(design, grid, true);
  43. testRead(design, grid, true, true);
  44. }
  45. @Test
  46. public void testMultipleColumnsInlineData() {
  47. String design = "<vaadin-grid><table>"//
  48. + "<colgroup>"
  49. + " <col sortable property-id='Col1' />"
  50. + " <col sortable property-id='Col2' />"
  51. + " <col sortable property-id='Col3' />" //
  52. + "</colgroup>" //
  53. + "<thead />" // No headers read or written
  54. + "<tbody>" //
  55. + "<tr><td>Foo<td>Bar<td>Baz</tr>" //
  56. + "<tr><td>My<td>Summer<td>Car</tr>" //
  57. + "</tbody>" //
  58. + "</table></vaadin-grid>";
  59. Grid grid = new Grid();
  60. grid.addColumn("Col1", String.class);
  61. grid.addColumn("Col2", String.class);
  62. grid.addColumn("Col3", String.class);
  63. grid.addRow("Foo", "Bar", "Baz");
  64. grid.addRow("My", "Summer", "Car");
  65. // Remove default header
  66. grid.removeHeaderRow(grid.getDefaultHeaderRow());
  67. testWrite(design, grid, true);
  68. testRead(design, grid, true, true);
  69. }
  70. @Test
  71. public void testMultipleColumnsInlineDataReordered() {
  72. String design = "<vaadin-grid><table>"//
  73. + "<colgroup>"
  74. + " <col sortable property-id='Col2' />"
  75. + " <col sortable property-id='Col3' />"
  76. + " <col sortable property-id='Col1' />" //
  77. + "</colgroup>" //
  78. + "<thead />" // No headers read or written
  79. + "<tbody>" //
  80. + "<tr><td>Bar<td>Baz<td>Foo</tr>" //
  81. + "<tr><td>Summer<td>Car<td>My</tr>" //
  82. + "</tbody>" //
  83. + "</table></vaadin-grid>";
  84. Grid grid = new Grid();
  85. grid.addColumn("Col1", String.class);
  86. grid.addColumn("Col2", String.class);
  87. grid.addColumn("Col3", String.class);
  88. grid.addRow("Foo", "Bar", "Baz");
  89. grid.addRow("My", "Summer", "Car");
  90. grid.setColumnOrder("Col2", "Col3", "Col1");
  91. // Remove default header
  92. grid.removeHeaderRow(grid.getDefaultHeaderRow());
  93. testWrite(design, grid, true);
  94. testRead(design, grid, true, true);
  95. }
  96. @Test
  97. public void testHtmlEntities() {
  98. String design = "<vaadin-grid><table>"//
  99. + "<colgroup>"
  100. + " <col property-id='test' />"
  101. + "</colgroup>" //
  102. + "<thead />" // No headers read or written
  103. + "<tbody>" //
  104. + " <tr><td>&amp;Test</tr></td>"
  105. + "</tbody>"
  106. + "</table></vaadin-grid>";
  107. Grid read = read(design);
  108. Container cds = read.getContainerDataSource();
  109. Assert.assertEquals("&amp;Test",
  110. cds.getItem(cds.getItemIds().iterator().next())
  111. .getItemProperty("test").getValue());
  112. }
  113. }