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.

GridStaticSectionTest.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package com.vaadin.v7.tests.server.component.grid;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertNotNull;
  4. import static org.junit.Assert.assertNull;
  5. import java.lang.reflect.Method;
  6. import org.junit.Before;
  7. import org.junit.Test;
  8. import com.vaadin.v7.data.Container.Indexed;
  9. import com.vaadin.v7.data.util.IndexedContainer;
  10. import com.vaadin.v7.ui.Grid;
  11. public class GridStaticSectionTest extends Grid {
  12. private Indexed dataSource = new IndexedContainer();
  13. @Before
  14. public void setUp() {
  15. dataSource.addContainerProperty("firstName", String.class, "");
  16. dataSource.addContainerProperty("lastName", String.class, "");
  17. dataSource.addContainerProperty("streetAddress", String.class, "");
  18. dataSource.addContainerProperty("zipCode", Integer.class, null);
  19. setContainerDataSource(dataSource);
  20. }
  21. @Test
  22. public void testAddAndRemoveHeaders() {
  23. assertEquals(1, getHeaderRowCount());
  24. prependHeaderRow();
  25. assertEquals(2, getHeaderRowCount());
  26. removeHeaderRow(0);
  27. assertEquals(1, getHeaderRowCount());
  28. removeHeaderRow(0);
  29. assertEquals(0, getHeaderRowCount());
  30. assertEquals(null, getDefaultHeaderRow());
  31. HeaderRow row = appendHeaderRow();
  32. assertEquals(1, getHeaderRowCount());
  33. assertEquals(null, getDefaultHeaderRow());
  34. setDefaultHeaderRow(row);
  35. assertEquals(row, getDefaultHeaderRow());
  36. }
  37. @Test
  38. public void testAddAndRemoveFooters() {
  39. // By default there are no footer rows
  40. assertEquals(0, getFooterRowCount());
  41. FooterRow row = appendFooterRow();
  42. assertEquals(1, getFooterRowCount());
  43. prependFooterRow();
  44. assertEquals(2, getFooterRowCount());
  45. assertEquals(row, getFooterRow(1));
  46. removeFooterRow(0);
  47. assertEquals(1, getFooterRowCount());
  48. removeFooterRow(0);
  49. assertEquals(0, getFooterRowCount());
  50. }
  51. @Test
  52. public void testUnusedPropertyNotInCells() {
  53. removeColumn("firstName");
  54. assertNull("firstName cell was not removed from existing row",
  55. getDefaultHeaderRow().getCell("firstName"));
  56. HeaderRow newRow = appendHeaderRow();
  57. assertNull("firstName cell was created when it should not.",
  58. newRow.getCell("firstName"));
  59. addColumn("firstName");
  60. assertNotNull(
  61. "firstName cell was not created for default row when added again",
  62. getDefaultHeaderRow().getCell("firstName"));
  63. assertNotNull(
  64. "firstName cell was not created for new row when added again",
  65. newRow.getCell("firstName"));
  66. }
  67. @Test
  68. public void testJoinHeaderCells() {
  69. HeaderRow mergeRow = prependHeaderRow();
  70. mergeRow.join("firstName", "lastName").setText("Name");
  71. mergeRow.join(mergeRow.getCell("streetAddress"),
  72. mergeRow.getCell("zipCode"));
  73. }
  74. @Test(expected = IllegalStateException.class)
  75. public void testJoinHeaderCellsIncorrectly() throws Throwable {
  76. HeaderRow mergeRow = prependHeaderRow();
  77. mergeRow.join("firstName", "zipCode").setText("Name");
  78. sanityCheck();
  79. }
  80. @Test
  81. public void testJoinAllFooterCells() {
  82. FooterRow mergeRow = prependFooterRow();
  83. mergeRow.join(dataSource.getContainerPropertyIds().toArray())
  84. .setText("All the stuff.");
  85. }
  86. private void sanityCheck() throws Throwable {
  87. Method sanityCheckHeader;
  88. try {
  89. sanityCheckHeader = Grid.Header.class
  90. .getDeclaredMethod("sanityCheck");
  91. sanityCheckHeader.setAccessible(true);
  92. Method sanityCheckFooter = Grid.Footer.class
  93. .getDeclaredMethod("sanityCheck");
  94. sanityCheckFooter.setAccessible(true);
  95. sanityCheckHeader.invoke(getHeader());
  96. sanityCheckFooter.invoke(getFooter());
  97. } catch (Exception e) {
  98. throw e.getCause();
  99. }
  100. }
  101. }