From caeb5347caef8723ba90cdfcc3db7b5a2883b122 Mon Sep 17 00:00:00 2001 From: Mika Murtojarvi Date: Tue, 14 Apr 2015 14:10:46 +0300 Subject: [PATCH] Refactor declarative tests. In addition, duplicate tests are removed. Change-Id: I01c681e82416ad408f616d61f9f5b4df81db2c08 --- .../AbstractFieldDeclarativeTest.java | 63 +++++-- .../abstractfield/ReadDesignTest.java | 71 ------- .../abstractfield/WriteDesignTest.java | 77 -------- .../AbstractOrderedLayoutDeclarativeTest.java | 178 ++++++++++++++++++ .../abstractorderedlayout/ReadDesignTest.java | 119 ------------ .../WriteDesignTest.java | 148 --------------- .../AbstractSplitPanelDeclarativeTest.java | 110 +++++++++++ .../abstractsplitpanel/ReadDesignTest.java | 158 ---------------- .../abstractsplitpanel/WriteDesignTest.java | 151 --------------- .../AbstractTextFieldDeclarativeTest.java | 52 +++++ .../abstracttextfield/ReadDesignTest.java | 73 ------- .../abstracttextfield/WriteDesignTest.java | 73 ------- .../button/ButtonDeclarativeTest.java | 106 ++++++++--- .../component/button/ReadDesignTest.java | 129 ------------- .../component/button/WriteDesignTest.java | 103 ---------- .../checkbox/CheckboxDeclarativeTest.java | 31 ++- .../component/checkbox/ReadDesignTest.java | 67 ------- .../component/checkbox/WriteDesignTest.java | 57 ------ .../csslayout/CssLayoutDeclarativeTest.java | 96 ++++++++++ .../component/csslayout/ReadDesignTest.java | 74 -------- .../component/csslayout/WriteDesignTest.java | 78 -------- .../component/label/LabelDeclarativeTest.java | 110 ++++++----- .../component/label/ReadDesignTest.java | 102 ---------- .../component/label/WriteDesignTest.java | 126 ------------- .../component/panel/PanelDeclarativeTest.java | 62 ++++++ .../component/panel/ReadDesignTest.java | 98 ---------- .../component/panel/WriteDesignTest.java | 71 ------- .../component/tabsheet/ReadDesignTest.java | 132 ------------- .../tabsheet/TabSheetDeclarativeTest.java | 98 ++++++++++ .../component/tabsheet/WriteDesignTest.java | 109 ----------- .../component/textarea/ReadDesignTest.java | 59 ------ .../textarea/TextAreaDeclarativeTest.java | 28 +-- .../component/textarea/WriteDesignTest.java | 60 ------ .../component/textfield/ReadDesignTest.java | 59 ------ .../textfield/TextFieldDeclarativeTest.java | 25 ++- .../component/textfield/WriteDesignTest.java | 59 ------ 36 files changed, 821 insertions(+), 2391 deletions(-) delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/WriteDesignTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/WriteDesignTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/AbstractSplitPanelDeclarativeTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/WriteDesignTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstracttextfield/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstracttextfield/WriteDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/button/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/button/WriteDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/checkbox/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/checkbox/WriteDesignTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/csslayout/CssLayoutDeclarativeTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/csslayout/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/csslayout/WriteDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/label/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/label/WriteDesignTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/panel/PanelDeclarativeTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/panel/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/panel/WriteDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/tabsheet/ReadDesignTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/tabsheet/TabSheetDeclarativeTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/tabsheet/WriteDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/textarea/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/textarea/WriteDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/textfield/ReadDesignTest.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/textfield/WriteDesignTest.java diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java index f415a5fd18..dbd945a3d8 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java @@ -15,11 +15,18 @@ */ package com.vaadin.tests.server.component.abstractfield; +import static org.junit.Assert.assertTrue; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; import org.junit.Test; +import com.vaadin.data.util.ObjectProperty; import com.vaadin.tests.design.DeclarativeTestBase; import com.vaadin.ui.AbstractField; import com.vaadin.ui.TextField; +import com.vaadin.ui.declarative.DesignContext; /** * Tests declarative support for implementations of {@link AbstractField}. @@ -31,23 +38,12 @@ public class AbstractFieldDeclarativeTest extends DeclarativeTestBase> { @Test - public void testPlainTextRead() { - testRead(getDesign(), getExpected()); - } - - @Test - public void testPlainTextWrite() { - testWrite(getDesign(), getExpected()); - } - - protected String getDesign() { - return ""; - } - - protected AbstractField getExpected() { - TextField tf = new TextField(); + AbstractField tf = new TextField(); + tf.setBuffered(true); tf.setBuffered(true); tf.setValidationVisible(false); tf.setInvalidCommitted(true); @@ -57,7 +53,40 @@ public class AbstractFieldDeclarativeTest extends tf.setConversionError("Input {0} cannot be parsed"); tf.setTabIndex(3); tf.setReadOnly(true); - return tf; - }; + testRead(design, tf); + testWrite(design, tf); + + // Test with readonly=false + design = design.replace("readonly='true'", ""); + tf.setReadOnly(false); + testRead(design, tf); + testWrite(design, tf); + } + + @Test + public void testWriteRemovesOldContent() { + Attributes attr = new Attributes(); + attr.put("should_be_removed", "foo"); + Element design = new Element(Tag.valueOf("v-text-field"), "", attr); + AbstractField component = new TextField(); + component.setReadOnly(true); + component.writeDesign(design, new DesignContext()); + // we only changed one of the attributes, others are at default values + assertEquals(1, design.attributes().size()); + assertTrue("Design must contain readonly", design.hasAttr("readonly")); + assertTrue("Readonly must be true", design.attr("readonly").equals("") + || design.attr("readonly").equals("true")); + } + @Test + public void testModelReadOnly() { + // Test that read only value coming from property data source is not + // written to design. + String design = ""; + AbstractField component = new TextField(); + ObjectProperty property = new ObjectProperty("test"); + property.setReadOnly(true); + component.setPropertyDataSource(property); + testWrite(design, component); + } } diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/ReadDesignTest.java deleted file mode 100644 index 4fa3400af5..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/ReadDesignTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.abstractfield; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.AbstractField; -import com.vaadin.ui.TextField; -import com.vaadin.ui.declarative.DesignContext; - -/** - * - * Test case for reading the attributes of the AbstractField from design - * - * @author Vaadin Ltd - */ -public class ReadDesignTest extends TestCase { - - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - public void testSynchronizeReadOnly() { - Element design = createDesign("readonly", ""); - AbstractField component = getComponent(); - component.readDesign(design, ctx); - assertEquals(true, component.isReadOnly()); - design = createDesign("readonly", "false"); - component.readDesign(design, ctx); - assertEquals(false, component.isReadOnly()); - } - - public void testSynchronizeTabIndex() { - Element design = createDesign("tabindex", "2"); - AbstractField component = getComponent(); - component.readDesign(design, ctx); - assertEquals("Tab index must be 2", 2, component.getTabIndex()); - } - - private AbstractField getComponent() { - return new TextField(); - } - - private Element createDesign(String key, String value) { - Attributes attributes = new Attributes(); - attributes.put(key, value); - Element node = new Element(Tag.valueOf("v-text-field"), "", attributes); - return node; - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/WriteDesignTest.java deleted file mode 100644 index 37ff8cf3aa..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/WriteDesignTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.abstractfield; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.data.util.ObjectProperty; -import com.vaadin.ui.AbstractField; -import com.vaadin.ui.TextField; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for writing the attributes of the AbstractField to design - * - * @author Vaadin Ltd - */ -public class WriteDesignTest extends TestCase { - - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - public void testSynchronizeReadOnly() { - Element design = createDesign(); - AbstractField component = getComponent(); - component.setReadOnly(true); - component.writeDesign(design, ctx); - // we only changed one of the attributes, others are at default values - assertEquals(1, design.attributes().size()); - assertTrue("Design must contain readonly", design.hasAttr("readonly")); - assertTrue("Readonly must be true", design.attr("readonly").equals("") - || design.attr("readonly").equals("true")); - } - - public void testSynchronizeModelReadOnly() { - Element design = createDesign(); - AbstractField component = getComponent(); - ObjectProperty property = new ObjectProperty("test"); - property.setReadOnly(true); - component.setPropertyDataSource(property); - component.writeDesign(design, ctx); - // make sure that property readonly is not written to design - assertFalse("Design must not contain readonly", - design.hasAttr("readonly")); - } - - private AbstractField getComponent() { - return new TextField(); - } - - private Element createDesign() { - Attributes attr = new Attributes(); - attr.put("should_be_removed", "foo"); - return new Element(Tag.valueOf("v-text-field"), "", attr); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java new file mode 100644 index 0000000000..192ea0f4f3 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java @@ -0,0 +1,178 @@ +/* + * 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.abstractorderedlayout; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; +import org.junit.Test; + +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.ui.AbstractOrderedLayout; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Tests declarative support for AbstractOrderedLayout. + * + * @since + * @author Vaadin Ltd + */ +public class AbstractOrderedLayoutDeclarativeTest extends + DeclarativeTestBase { + + private List defaultAlignments = Arrays.asList(new String[] { + ":top", ":left" }); + + @Test + public void testMargin() { + String design = getDesign(0, true); + AbstractOrderedLayout layout = getLayout(0, true, null); + testRead(design, layout); + testWrite(design, layout); + design = getDesign(0, false); + layout = getLayout(0, false, null); + testRead(design, layout); + testWrite(design, layout); + } + + @Test + public void testExpandRatio() { + String design = getDesign(1, false); + AbstractOrderedLayout layout = getLayout(1, false, null); + testRead(design, layout); + testWrite(design, layout); + design = getDesign(0.25f, false); + layout = getLayout(0.25f, false, null); + testRead(design, layout); + testWrite(design, layout); + } + + @Test + public void testAlignment() { + String design = getDesign(0, false, ":top", ":left"); + AbstractOrderedLayout layout = getLayout(0, false, Alignment.TOP_LEFT); + testRead(design, layout); + testWrite(design, layout); + design = getDesign(0, false, ":middle", ":center"); + layout = getLayout(0, false, Alignment.MIDDLE_CENTER); + testRead(design, layout); + testWrite(design, layout); + design = getDesign(0, false, ":bottom", ":right"); + layout = getLayout(0, false, Alignment.BOTTOM_RIGHT); + testRead(design, layout); + testWrite(design, layout); + } + + @Test + public void testWriteRemovesOldElementContent() { + // Create an element with some content + Attributes rootAttributes = new Attributes(); + rootAttributes.put("caption", "test-layout"); + Element design = new Element(Tag.valueOf("v-vertical-layout"), "", + rootAttributes); + Attributes firstChildAttributes = new Attributes(); + firstChildAttributes.put("caption", "test-label"); + Element firstChild = new Element(Tag.valueOf("v-label"), "", + firstChildAttributes); + design.appendChild(firstChild); + + Attributes secondChildAttributes = new Attributes(); + secondChildAttributes.put("caption", "test-button"); + Element secondChild = new Element(Tag.valueOf("v-button"), "", + secondChildAttributes); + design.appendChild(secondChild); + Attributes thirdChildAttributes = new Attributes(); + thirdChildAttributes.put("caption", "test-button-2"); + Element thirdChild = new Element(Tag.valueOf("v-button"), "", + thirdChildAttributes); + design.appendChild(thirdChild); + // Create and write a layout and check the new contents of the element + // node + VerticalLayout layout = new VerticalLayout(); + layout.addComponent(new Label("test-label")); + layout.getComponent(0).setCaption("test-caption"); + layout.setExpandRatio(layout.getComponent(0), 1.0f); + layout.addComponent(new Label("test-label-2")); + layout.writeDesign(design, new DesignContext()); + assertEquals(2, design.childNodes().size()); + assertEquals("v-label", ((Element) design.childNode(0)).tagName()); + assertEquals("test-caption", design.childNode(0).attr("caption")); + assertTrue(design.childNode(0).hasAttr(":expand")); + assertEquals("", design.childNode(0).attr(":expand")); + + } + + private String getDesign(float expandRatio, boolean margin, + String... alignments) { + String result = " { + + @Test + public void testWithBothChildren() { + String design = " " + + ""; + AbstractSplitPanel sp = new HorizontalSplitPanel(); + sp.setSplitPosition(20.5f, Unit.PERCENTAGE, true); + sp.setMinSplitPosition(20, Unit.PERCENTAGE); + sp.setMaxSplitPosition(50, Unit.PIXELS); + sp.setLocked(true); + sp.addComponent(new Table()); + sp.addComponent(new VerticalLayout()); + testRead(design, sp); + testWrite(design, sp); + } + + @Test + public void testWithFirstChild() { + String design = "" + + ""; + AbstractSplitPanel sp = new VerticalSplitPanel(); + Table t = new Table(); + t.setCaption("First slot"); + sp.addComponent(t); + testRead(design, sp); + testWrite(design, sp); + } + + @Test + public void testWithSecondChild() { + String design = "Second slot" + + ""; + AbstractSplitPanel sp = new HorizontalSplitPanel(); + Button b = new Button("Second slot"); + b.setCaptionAsHtml(true); + sp.setSecondComponent(b); + testRead(design, sp); + testWrite(design, sp); + } + + @Test + public void testEmpty() { + String design = ""; + AbstractSplitPanel sp = new HorizontalSplitPanel(); + testRead(design, sp); + testWrite(design, sp); + } + + @Test + public void testReSynchronize() { + // Test that old children and attributes are removed when an element is + // synchronized to a new component. + DesignContext ctx = new DesignContext(); + VerticalSplitPanel sp = new VerticalSplitPanel(); + sp.setMinSplitPosition(5.5f, Unit.PERCENTAGE); + sp.setMaxSplitPosition(95, Unit.PERCENTAGE); + sp.setFirstComponent(new Button("First slot")); + sp.setSecondComponent(new Label("Second slot")); + Element e = ctx.createElement(sp); + sp = new VerticalSplitPanel(); + sp.writeDesign(e, ctx); + assertTrue("There should be no attributes in the node.", e.attributes() + .size() == 0); + assertTrue("There should be no child elements.", + e.children().size() == 0); + } +} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/ReadDesignTest.java deleted file mode 100644 index f3a7e32e96..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/ReadDesignTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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.abstractsplitpanel; - -import java.lang.reflect.Method; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.server.Sizeable.Unit; -import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState.SplitterState; -import com.vaadin.ui.AbstractSplitPanel; -import com.vaadin.ui.HorizontalSplitPanel; -import com.vaadin.ui.Table; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.VerticalSplitPanel; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Tests synchronizing the attributes and children of horizontal and vertical - * split panels from a design. - * - * @author Vaadin Ltd - */ -public class ReadDesignTest extends TestCase { - DesignContext ctx; - - @Override - protected void setUp() { - ctx = new DesignContext(); - } - - public void testAttributes() throws Exception { - // Create a design with non-default attributes values. - Element design = createDesign(true, false, true, true); - HorizontalSplitPanel sp = new HorizontalSplitPanel(); - sp.readDesign(design, ctx); - // Check that the attributes are correctly parsed. - assertEquals(20.5f, sp.getSplitPosition()); - assertEquals(Unit.PERCENTAGE, sp.getSplitPositionUnit()); - assertEquals(20f, sp.getMinSplitPosition()); - assertEquals(Unit.PERCENTAGE, sp.getMinSplitPositionUnit()); - assertEquals(50f, sp.getMaxSplitPosition()); - assertEquals(Unit.PIXELS, sp.getMaxSplitPositionUnit()); - assertEquals(true, sp.isLocked()); - checkReversed(sp, true); - } - - public void testWithNoChildren() { - Element design = createDesign(true, false, false, false); - HorizontalSplitPanel sp = new HorizontalSplitPanel(); - sp.readDesign(design, ctx); - assertEquals("Unexpected child count for the split panel.", 0, - sp.getComponentCount()); - } - - public void testWithFirstChild() { - Element design = createDesign(false, false, true, false); - VerticalSplitPanel sp = new VerticalSplitPanel(); - sp.readDesign(design, ctx); - assertEquals("Unexpected child count for the split panel.", 1, - sp.getComponentCount()); - Object obj = sp.getFirstComponent(); - assertEquals("Wrong component in split panel.", Table.class, - obj.getClass()); - } - - public void testWithSecondChild() { - Element design = createDesign(true, false, false, true); - HorizontalSplitPanel sp = new HorizontalSplitPanel(); - sp.readDesign(design, ctx); - assertEquals("Unexpected child count for the split panel.", 1, - sp.getComponentCount()); - Object obj = sp.getSecondComponent(); - assertEquals("Wrong component in split panel.", VerticalLayout.class, - obj.getClass()); - } - - public void testWithBothChildren() { - Element design = createDesign(false, false, true, true); - VerticalSplitPanel sp = new VerticalSplitPanel(); - sp.readDesign(design, ctx); - assertEquals("Unexpected child count for the split panel.", 2, - sp.getComponentCount()); - Object first = sp.getFirstComponent(); - Object second = sp.getSecondComponent(); - assertEquals("Wrong first component in split panel.", Table.class, - first.getClass()); - assertEquals("Wrong second component in split panel.", - VerticalLayout.class, second.getClass()); - } - - /* - * Creates an html tree node structure representing a split panel and its - * contents. The parameters are used for controlling whether the split panel - * is horizontal or vertical, whether attributes are set for the design and - * whether the split panel should have the first and the second child - * component. - */ - private Element createDesign(boolean horizontal, - boolean useDefaultAttributes, boolean hasFirstChild, - boolean hasSecondChild) { - Attributes attributes = new Attributes(); - if (!useDefaultAttributes) { - attributes.put("split-position", "20.5%"); - // The unitless number should correspond to 20% - attributes.put("min-split-position", "20"); - attributes.put("max-split-position", "50px"); - attributes.put("locked", ""); - attributes.put("reversed", ""); - } - String tagName = horizontal ? "v-horizontal-split-panel" - : "v-vertical-split-panel"; - Element element = new Element(Tag.valueOf(tagName), "", attributes); - // Create the children - if (hasFirstChild) { - Element child = new Element(Tag.valueOf("v-table"), ""); - element.appendChild(child); - } - if (hasSecondChild) { - Element child = new Element(Tag.valueOf("v-vertical-layout"), ""); - if (!hasFirstChild) { - child.attr(":second", ""); - } - element.appendChild(child); - } - return element; - } - - /* - * Checks the reversed property of a split panel. - */ - private void checkReversed(AbstractSplitPanel sp, boolean expected) - throws Exception { - Method getter = AbstractSplitPanel.class - .getDeclaredMethod("getSplitterState"); - getter.setAccessible(true); - SplitterState state = (SplitterState) getter.invoke(sp); - assertEquals("Wrong value for split panel property reversed.", - expected, state.positionReversed); - } -} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/WriteDesignTest.java deleted file mode 100644 index a75fe911f8..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/WriteDesignTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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.abstractsplitpanel; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Element; - -import com.vaadin.server.Sizeable.Unit; -import com.vaadin.ui.Button; -import com.vaadin.ui.HorizontalSplitPanel; -import com.vaadin.ui.Label; -import com.vaadin.ui.VerticalSplitPanel; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Tests synchronizing the properties and child components of split panels to a - * design. - * - * @author Vaadin Ltd - */ -public class WriteDesignTest extends TestCase { - private DesignContext ctx; - - @Override - public void setUp() { - ctx = new DesignContext(); - } - - public void testHorizontalWithDefaultValues() { - // no attributes or child elements should appear - HorizontalSplitPanel sp = new HorizontalSplitPanel(); - Element e = ctx.createElement(sp); - assertEquals("Wrong tag name.", "v-horizontal-split-panel", - e.nodeName()); - assertEquals("The split panel should not have attributes.", 0, e - .attributes().size()); - assertEquals("The split panel should not have children.", 0, e - .children().size()); - } - - public void testVerticalWithAttributes() { - // All defined attributes should be output in the tree node. No child - // components are present in this test. - VerticalSplitPanel sp = new VerticalSplitPanel(); - sp.setSplitPosition(27f, Unit.PIXELS, true); - sp.setMinSplitPosition(5.5f, Unit.PERCENTAGE); - sp.setMaxSplitPosition(95, Unit.PERCENTAGE); - sp.setLocked(true); - Element e = ctx.createElement(sp); - assertEquals("Wrong tag name.", "v-vertical-split-panel", e.nodeName()); - assertEquals("Unexpected number of attributes.", 5, e.attributes() - .size()); - assertEquals("Wrong split position.", "27px", e.attr("split-position")); - assertEquals("Wrong minimum split position.", "5.5%", - e.attr("min-split-position")); - assertEquals("Wrong maximum split position.", "95%", - e.attr("max-split-position")); - assertTrue("Unexpected value for locked: " + e.attr("locked"), - "true".equals(e.attr("locked")) || "".equals(e.attr("locked"))); - assertTrue( - "Unexpected value for reversed: " + e.attr("reversed"), - "true".equals(e.attr("reversed")) - || "".equals(e.attr("reversed"))); - } - - public void testHorizontalWithFirstChild() { - // The split panel contains only the first child. - HorizontalSplitPanel sp = new HorizontalSplitPanel(); - sp.setSplitPosition(25f); - sp.setFirstComponent(new Button("First slot")); - Element e = ctx.createElement(sp); - assertEquals("Wrong split position.", "25%", e.attr("split-position")); - assertEquals("Wrong number of child elements.", 1, e.children().size()); - Element eb = e.children().get(0); - assertEquals("Wrong tag name of first child element.", "v-button", - eb.nodeName()); - assertEquals("Wrong text in the button element.", "First slot", - eb.html()); - } - - public void testVerticalWithSecondChild() { - // The split panel contains only the second child. - VerticalSplitPanel sp = new VerticalSplitPanel(); - sp.setMinSplitPosition(25f, Unit.PIXELS); - sp.setSecondComponent(new Label("Second slot")); - Element e = ctx.createElement(sp); - assertEquals("Wrong minimum split position.", "25px", - e.attr("min-split-position")); - assertEquals("Wrong number of child elements.", 1, e.children().size()); - Element el = e.children().get(0); - assertEquals("Wrong tag name of child element.", "v-label", - el.nodeName()); - assertEquals("Wrong text in the label element.", "Second slot", - el.html()); - assertTrue("Missing attribute :second in the label element.", - el.hasAttr(":second")); - } - - public void testVerticalWithBothChildren() { - // The split panel has both child components. - VerticalSplitPanel sp = new VerticalSplitPanel(); - sp.setFirstComponent(new Button("First slot")); - sp.setSecondComponent(new Label("Second slot")); - Element e = ctx.createElement(sp); - assertEquals("Wrong number of child elements.", 2, e.children().size()); - Element eb = e.children().get(0); - assertEquals("Wrong tag name of first child element.", "v-button", - eb.nodeName()); - assertEquals("Wrong text in the button element.", "First slot", - eb.html()); - Element el = e.children().get(1); - assertEquals("Wrong tag name of second child element.", "v-label", - el.nodeName()); - assertEquals("Wrong text in the label element.", "Second slot", - el.html()); - assertFalse( - "There should be no :second attribute when a split panel has both children.", - el.hasAttr(":second")); - } - - public void testReSynchronize() { - // Test that old children and attributes are removed when an element is - // synchronized to a new component. - VerticalSplitPanel sp = new VerticalSplitPanel(); - sp.setMinSplitPosition(5.5f, Unit.PERCENTAGE); - sp.setMaxSplitPosition(95, Unit.PERCENTAGE); - sp.setFirstComponent(new Button("First slot")); - sp.setSecondComponent(new Label("Second slot")); - Element e = ctx.createElement(sp); - sp = new VerticalSplitPanel(); - sp.writeDesign(e, ctx); - assertTrue("There should be no attributes in the node.", e.attributes() - .size() == 0); - assertTrue("There should be no child elements.", - e.children().size() == 0); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java new file mode 100644 index 0000000000..a3594b7159 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java @@ -0,0 +1,52 @@ +/* + * 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.abstracttextfield; + +import org.junit.Test; + +import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.ui.AbstractTextField; +import com.vaadin.ui.AbstractTextField.TextChangeEventMode; +import com.vaadin.ui.TextField; + +/** + * Tests declarative support for AbstractTextField. + * + * @since + * @author Vaadin Ltd + */ +public class AbstractTextFieldDeclarativeTest extends + DeclarativeTestBase { + + @Test + public void testAttributes() { + String design = ""; + AbstractTextField tf = new TextField(); + tf.setNullRepresentation("this-is-null"); + tf.setNullSettingAllowed(true); + tf.setMaxLength(5); + tf.setColumns(3); + tf.setInputPrompt("input"); + tf.setTextChangeEventMode(TextChangeEventMode.EAGER); + tf.setTextChangeTimeout(100); + testRead(design, tf); + testWrite(design, tf); + } + +} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/ReadDesignTest.java deleted file mode 100644 index 2645ce4255..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/ReadDesignTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.abstracttextfield; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.AbstractTextField; -import com.vaadin.ui.AbstractTextField.TextChangeEventMode; -import com.vaadin.ui.TextField; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for reading the attributes of the AbstractTextField from design - */ -public class ReadDesignTest extends TestCase { - - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - public void testAttributes() { - Element design = createDesign(); - AbstractTextField component = getComponent(); - component.readDesign(design, ctx); - assertEquals("this-is-null", component.getNullRepresentation()); - assertEquals(true, component.isNullSettingAllowed()); - assertEquals(5, component.getMaxLength()); - assertEquals(3, component.getColumns()); - assertEquals("input", component.getInputPrompt()); - assertEquals(TextChangeEventMode.EAGER, - component.getTextChangeEventMode()); - assertEquals(100, component.getTextChangeTimeout()); - } - - private AbstractTextField getComponent() { - return new TextField(); - } - - private Element createDesign() { - Attributes attributes = new Attributes(); - attributes.put("null-representation", "this-is-null"); - attributes.put("null-setting-allowed", "true"); - attributes.put("maxlength", "5"); - attributes.put("columns", "3"); - attributes.put("input-prompt", "input"); - attributes.put("text-change-event-mode", "eager"); - attributes.put("text-change-timeout", "100"); - Element node = new Element(Tag.valueOf("v-text-field"), "", attributes); - return node; - } - -} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/WriteDesignTest.java deleted file mode 100644 index 840de9e819..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/WriteDesignTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.abstracttextfield; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.AbstractTextField; -import com.vaadin.ui.AbstractTextField.TextChangeEventMode; -import com.vaadin.ui.TextField; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for writing the attributes of the AbstractTextField to design - * - * @author Vaadin Ltd - */ -public class WriteDesignTest extends TestCase { - - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - public void testSynchronizetestAttributes() { - Element design = createDesign(); - AbstractTextField component = getComponent(); - component.setNullRepresentation("this-is-null"); - component.setNullSettingAllowed(true); - component.setMaxLength(5); - component.setColumns(3); - component.setInputPrompt("input"); - component.setTextChangeEventMode(TextChangeEventMode.EAGER); - component.setTextChangeTimeout(100); - component.writeDesign(design, ctx); - assertEquals("this-is-null", design.attr("null-representation")); - assertEquals("true", design.attr("null-setting-allowed")); - assertEquals("5", design.attr("maxlength")); - assertEquals("3", design.attr("columns")); - assertEquals("input", design.attr("input-prompt")); - assertEquals("eager", design.attr("text-change-event-mode")); - assertEquals("100", design.attr("text-change-timeout")); - } - - private AbstractTextField getComponent() { - return new TextField(); - } - - private Element createDesign() { - Attributes attr = new Attributes(); - return new Element(Tag.valueOf("v-text-field"), "", attr); - } - -} diff --git a/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java index 2962620052..02dfa22671 100644 --- a/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java @@ -15,13 +15,23 @@ */ package com.vaadin.tests.server.component.button; +import static org.junit.Assert.assertTrue; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; import org.junit.Test; +import com.vaadin.event.ShortcutAction.KeyCode; +import com.vaadin.event.ShortcutAction.ModifierKey; import com.vaadin.tests.design.DeclarativeTestBase; import com.vaadin.ui.Button; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.declarative.DesignContext; /** - * Tests declarative support for implementations of {@link Button}. + * Tests declarative support for implementations of {@link Button} and + * {@link NativeButton}. * * @since 7.4 * @author Vaadin Ltd @@ -29,44 +39,90 @@ import com.vaadin.ui.Button; public class ButtonDeclarativeTest extends DeclarativeTestBase