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.

GridDeclarativeTestBase.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package com.vaadin.v7.tests.server.component.grid.declarative;
  2. import java.util.List;
  3. import com.vaadin.tests.design.DeclarativeTestBase;
  4. import com.vaadin.v7.ui.Grid;
  5. import com.vaadin.v7.ui.Grid.Column;
  6. import com.vaadin.v7.ui.Grid.FooterCell;
  7. import com.vaadin.v7.ui.Grid.FooterRow;
  8. import com.vaadin.v7.ui.Grid.HeaderCell;
  9. import com.vaadin.v7.ui.Grid.HeaderRow;
  10. public class GridDeclarativeTestBase extends DeclarativeTestBase<Grid> {
  11. @Override
  12. public Grid testRead(String design, Grid expected) {
  13. return testRead(design, expected, false);
  14. }
  15. public Grid testRead(String design, Grid expected, boolean retestWrite) {
  16. return testRead(design, expected, retestWrite, false);
  17. }
  18. public Grid testRead(String design, Grid expected, boolean retestWrite,
  19. boolean writeData) {
  20. Grid actual = super.testRead(design, expected);
  21. compareGridColumns(expected, actual);
  22. compareHeaders(expected, actual);
  23. compareFooters(expected, actual);
  24. if (retestWrite) {
  25. testWrite(design, actual, writeData);
  26. }
  27. return actual;
  28. }
  29. private void compareHeaders(Grid expected, Grid actual) {
  30. assertEquals("Different header row count", expected.getHeaderRowCount(),
  31. actual.getHeaderRowCount());
  32. for (int i = 0; i < expected.getHeaderRowCount(); ++i) {
  33. HeaderRow expectedRow = expected.getHeaderRow(i);
  34. HeaderRow actualRow = actual.getHeaderRow(i);
  35. if (expectedRow.equals(expected.getDefaultHeaderRow())) {
  36. assertEquals("Different index for default header row",
  37. actual.getDefaultHeaderRow(), actualRow);
  38. }
  39. for (Column c : expected.getColumns()) {
  40. String baseError = "Difference when comparing cell for " + c
  41. + " on header row " + i + ": ";
  42. Object propertyId = c.getPropertyId();
  43. HeaderCell expectedCell = expectedRow.getCell(propertyId);
  44. HeaderCell actualCell = actualRow.getCell(propertyId);
  45. switch (expectedCell.getCellType()) {
  46. case TEXT:
  47. assertEquals(baseError + "Text content",
  48. expectedCell.getText(), actualCell.getText());
  49. break;
  50. case HTML:
  51. assertEquals(baseError + "HTML content",
  52. expectedCell.getHtml(), actualCell.getHtml());
  53. break;
  54. case WIDGET:
  55. assertEquals(baseError + "Component content",
  56. expectedCell.getComponent(),
  57. actualCell.getComponent());
  58. break;
  59. }
  60. }
  61. }
  62. }
  63. private void compareFooters(Grid expected, Grid actual) {
  64. assertEquals("Different footer row count", expected.getFooterRowCount(),
  65. actual.getFooterRowCount());
  66. for (int i = 0; i < expected.getFooterRowCount(); ++i) {
  67. FooterRow expectedRow = expected.getFooterRow(i);
  68. FooterRow actualRow = actual.getFooterRow(i);
  69. for (Column c : expected.getColumns()) {
  70. String baseError = "Difference when comparing cell for " + c
  71. + " on footer row " + i + ": ";
  72. Object propertyId = c.getPropertyId();
  73. FooterCell expectedCell = expectedRow.getCell(propertyId);
  74. FooterCell actualCell = actualRow.getCell(propertyId);
  75. switch (expectedCell.getCellType()) {
  76. case TEXT:
  77. assertEquals(baseError + "Text content",
  78. expectedCell.getText(), actualCell.getText());
  79. break;
  80. case HTML:
  81. assertEquals(baseError + "HTML content",
  82. expectedCell.getHtml(), actualCell.getHtml());
  83. break;
  84. case WIDGET:
  85. assertEquals(baseError + "Component content",
  86. expectedCell.getComponent(),
  87. actualCell.getComponent());
  88. break;
  89. }
  90. }
  91. }
  92. }
  93. private void compareGridColumns(Grid expected, Grid actual) {
  94. List<Column> columns = expected.getColumns();
  95. List<Column> actualColumns = actual.getColumns();
  96. assertEquals("Different amount of columns", columns.size(),
  97. actualColumns.size());
  98. for (int i = 0; i < columns.size(); ++i) {
  99. Column col1 = columns.get(i);
  100. Column col2 = actualColumns.get(i);
  101. String baseError = "Error when comparing columns for property "
  102. + col1.getPropertyId() + ": ";
  103. assertEquals(baseError + "Property id", col1.getPropertyId(),
  104. col2.getPropertyId());
  105. assertEquals(baseError + "Width", col1.getWidth(), col2.getWidth());
  106. assertEquals(baseError + "Maximum width", col1.getMaximumWidth(),
  107. col2.getMaximumWidth());
  108. assertEquals(baseError + "Minimum width", col1.getMinimumWidth(),
  109. col2.getMinimumWidth());
  110. assertEquals(baseError + "Expand ratio", col1.getExpandRatio(),
  111. col2.getExpandRatio());
  112. assertEquals(baseError + "Sortable", col1.isSortable(),
  113. col2.isSortable());
  114. assertEquals(baseError + "Editable", col1.isEditable(),
  115. col2.isEditable());
  116. assertEquals(baseError + "Hidable", col1.isHidable(),
  117. col2.isHidable());
  118. assertEquals(baseError + "Hidden", col1.isHidden(),
  119. col2.isHidden());
  120. assertEquals(baseError + "HidingToggleCaption",
  121. col1.getHidingToggleCaption(),
  122. col2.getHidingToggleCaption());
  123. }
  124. }
  125. }