Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

GridStaticSectionTest.java 4.6KB

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