From 9298d87e5c0c2fd14278e96af3d49a7a7a092dd2 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Mon, 13 Apr 2015 10:56:53 +0300 Subject: Fix Grid Columns declarative support (#16596) Change-Id: I62e06ca7be62d81f8cca619775e150250a478b39 --- .../declarative/GridColumnDeclarativeTest.java | 91 ++++++++++++++++++++++ .../grid/declarative/GridDeclarativeTestBase.java | 71 +++++++++++++++++ .../declarative/GridStructureDeclarativeTest.java | 50 ++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridStructureDeclarativeTest.java (limited to 'server/tests') diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java new file mode 100644 index 0000000000..735a1ab502 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java @@ -0,0 +1,91 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.grid.declarative; + +import org.junit.Test; + +import com.vaadin.ui.Grid; + +public class GridColumnDeclarativeTest extends GridDeclarativeTestBase { + + @Test + public void testSimpleGridColumns() { + String design = ""// + + "" + + " " + + " " + + " " + + "" // + + "
"; + Grid grid = new Grid(); + grid.addColumn("Column1", String.class).setWidth(100); + grid.addColumn("Column2", String.class).setMaximumWidth(200) + .setExpandRatio(2).setSortable(false); + grid.addColumn("Column3", String.class).setMinimumWidth(15) + .setExpandRatio(1).setEditable(false); + + // Use the read grid component to do another pass on write. + testRead(design, grid, true); + testWrite(design, grid); + } + + @Test + public void testReadColumnsWithoutPropertyId() { + String design = ""// + + "" + + " " + + " " // property-id="property-1" + + " " + + "" // + + "
"; + Grid grid = new Grid(); + grid.addColumn("Column1", String.class).setWidth(100); + grid.addColumn("property-1", String.class).setMaximumWidth(200) + .setExpandRatio(2); + grid.addColumn("Column3", String.class).setMinimumWidth(15) + .setExpandRatio(1); + + testRead(design, grid); + } + + @Test + public void testReadEmptyExpand() { + String design = ""// + + "" + + " " + + "" // + + "
"; + + Grid grid = new Grid(); + grid.addColumn("property-0", String.class).setExpandRatio(1); + + testRead(design, grid); + } + + @Test + public void testReadColumnWithNoAttributes() { + String design = ""// + + "" // + + " " // + + "" // + + "
"; + + Grid grid = new Grid(); + grid.addColumn("property-0", String.class); + + testRead(design, grid); + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java new file mode 100644 index 0000000000..56f4647e90 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java @@ -0,0 +1,71 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.grid.declarative; + +import java.util.List; + +import org.junit.Assert; + +import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; + +public class GridDeclarativeTestBase extends DeclarativeTestBase { + + @Override + public Grid testRead(String design, Grid expected) { + return testRead(design, expected, false); + } + + public Grid testRead(String design, Grid expected, boolean retestWrite) { + Grid readGrid = super.testRead(design, expected); + + compareGridColumns(expected, readGrid); + + if (retestWrite) { + testWrite(design, readGrid); + } + + return readGrid; + } + + private void compareGridColumns(Grid expected, Grid actual) { + List columns = expected.getColumns(); + List actualColumns = actual.getColumns(); + Assert.assertEquals("Different amount of columns", columns.size(), + actualColumns.size()); + for (int i = 0; i < columns.size(); ++i) { + Column col1 = columns.get(i); + Column col2 = actualColumns.get(i); + String baseError = "Error when comparing columns for property " + + col1.getPropertyId() + ": "; + assertEquals(baseError + "Property id", col1.getPropertyId(), + col2.getPropertyId()); + assertEquals(baseError + "Width", col1.getWidth(), col2.getWidth()); + assertEquals(baseError + "Maximum width", col1.getMaximumWidth(), + col2.getMaximumWidth()); + assertEquals(baseError + "Minimum width", col1.getMinimumWidth(), + col2.getMinimumWidth()); + assertEquals(baseError + "Expand ratio", col1.getExpandRatio(), + col2.getExpandRatio()); + assertEquals(baseError + "Sortable", col1.isSortable(), + col2.isSortable()); + assertEquals(baseError + "Editable", col1.isEditable(), + col2.isEditable()); + + } + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridStructureDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridStructureDeclarativeTest.java new file mode 100644 index 0000000000..dc74f46d4d --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridStructureDeclarativeTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.grid.declarative; + +import org.junit.Test; + +import com.vaadin.ui.Grid; +import com.vaadin.ui.declarative.DesignException; + +public class GridStructureDeclarativeTest extends GridDeclarativeTestBase { + + @Test + public void testReadEmptyGrid() { + String design = ""; + testRead(design, new Grid(), false); + } + + @Test + public void testEmptyGrid() { + String design = ""; + Grid expected = new Grid(); + testWrite(design, expected); + testRead(design, expected, true); + } + + @Test(expected = DesignException.class) + public void testMalformedGrid() { + String design = ""; + testRead(design, new Grid()); + } + + @Test(expected = DesignException.class) + public void testGridWithNoColGroup() { + String design = "
Foo
"; + testRead(design, new Grid()); + } +} -- cgit v1.2.3