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.

GridContainerNotSortableTest.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.vaadin.v7.tests.server.component.grid;
  2. import static org.junit.Assert.assertFalse;
  3. import java.util.Collection;
  4. import java.util.LinkedHashMap;
  5. import java.util.Map;
  6. import org.junit.Test;
  7. import com.vaadin.v7.data.Item;
  8. import com.vaadin.v7.data.Property;
  9. import com.vaadin.v7.data.util.AbstractInMemoryContainer;
  10. import com.vaadin.v7.ui.Grid;
  11. import com.vaadin.v7.ui.Grid.Column;
  12. public class GridContainerNotSortableTest {
  13. final AbstractInMemoryContainer<Object, Object, Item> notSortableDataSource = new AbstractInMemoryContainer<Object, Object, Item>() {
  14. private Map<Object, Property<?>> properties = new LinkedHashMap<Object, Property<?>>();
  15. {
  16. properties.put("Foo", new Property<String>() {
  17. @Override
  18. public String getValue() {
  19. return "foo";
  20. }
  21. @Override
  22. public void setValue(String newValue) throws ReadOnlyException {
  23. throw new ReadOnlyException();
  24. }
  25. @Override
  26. public Class<? extends String> getType() {
  27. return String.class;
  28. }
  29. @Override
  30. public boolean isReadOnly() {
  31. return true;
  32. }
  33. @Override
  34. public void setReadOnly(boolean newStatus) {
  35. throw new UnsupportedOperationException();
  36. }
  37. });
  38. }
  39. @Override
  40. public Collection<?> getContainerPropertyIds() {
  41. return properties.keySet();
  42. }
  43. @Override
  44. public Property getContainerProperty(Object itemId, Object propertyId) {
  45. return properties.get(propertyId);
  46. }
  47. @Override
  48. public Class<?> getType(Object propertyId) {
  49. return properties.get(propertyId).getType();
  50. }
  51. @Override
  52. protected Item getUnfilteredItem(Object itemId) {
  53. return null;
  54. }
  55. };
  56. @Test
  57. public void testGridWithNotSortableContainer() {
  58. new Grid(notSortableDataSource);
  59. }
  60. @Test(expected = IllegalStateException.class)
  61. public void testNotSortableGridSetColumnSortable() {
  62. Grid grid = new Grid();
  63. grid.setContainerDataSource(notSortableDataSource);
  64. Column column = grid.getColumn("Foo");
  65. assertFalse("Column should not be sortable initially.",
  66. column.isSortable());
  67. column.setSortable(true);
  68. }
  69. }