From 3b75f2b14833f78c00d0032cbd76b09fca058100 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Sun, 14 Dec 2014 21:34:01 +0200 Subject: SynchronizeFrom/ToDesign -> read/writeDesign (#7749) Change-Id: Ie5e420ac5d62a2aa3206051888e6dd0f8f30df11 --- .../component/absolutelayout/TestReadDesign.java | 110 +++++++++ .../absolutelayout/TestSynchronizeFromDesign.java | 110 --------- .../absolutelayout/TestSynchronizeToDesign.java | 100 -------- .../component/absolutelayout/TestWriteDesign.java | 100 ++++++++ .../abstractcomponent/TestReadDesign.java | 256 ++++++++++++++++++++ .../TestSynchronizeFromDesign.java | 256 -------------------- .../abstractcomponent/TestSynchronizeToDesign.java | 266 --------------------- .../abstractcomponent/TestWriteDesign.java | 266 +++++++++++++++++++++ .../component/abstractfield/TestReadDesign.java | 71 ++++++ .../abstractfield/TestSynchronizeFromDesign.java | 71 ------ .../abstractfield/TestSynchronizeToDesign.java | 77 ------ .../component/abstractfield/TestWriteDesign.java | 77 ++++++ .../abstractorderedlayout/TestReadDesign.java | 119 +++++++++ .../TestSynchronizeFromDesign.java | 119 --------- .../TestSynchronizeToDesign.java | 148 ------------ .../abstractorderedlayout/TestWriteDesign.java | 148 ++++++++++++ .../abstractsplitpanel/TestReadDesign.java | 173 ++++++++++++++ .../TestSynchronizeFromDesign.java | 173 -------------- .../TestSynchronizeToDesign.java | 151 ------------ .../abstractsplitpanel/TestWriteDesign.java | 151 ++++++++++++ .../abstracttextfield/TestReadDesign.java | 73 ++++++ .../TestSynchronizeFromDesign.java | 73 ------ .../abstracttextfield/TestSynchronizeToDesign.java | 73 ------ .../abstracttextfield/TestWriteDesign.java | 73 ++++++ .../server/component/button/TestReadDesign.java | 129 ++++++++++ .../button/TestSynchronizeFromDesign.java | 129 ---------- .../component/button/TestSynchronizeToDesign.java | 103 -------- .../server/component/button/TestWriteDesign.java | 103 ++++++++ .../server/component/csslayout/TestReadDesign.java | 74 ++++++ .../csslayout/TestSynchronizeFromDesign.java | 74 ------ .../csslayout/TestSynchronizeToDesign.java | 78 ------ .../component/csslayout/TestWriteDesign.java | 78 ++++++ .../server/component/label/TestReadDesign.java | 102 ++++++++ .../component/label/TestSynchronizeFromDesign.java | 102 -------- .../component/label/TestSynchronizeToDesign.java | 126 ---------- .../server/component/label/TestWriteDesign.java | 126 ++++++++++ .../server/component/panel/TestReadDesign.java | 98 ++++++++ .../component/panel/TestSynchronizeFromDesign.java | 98 -------- .../component/panel/TestSynchronizeToDesign.java | 71 ------ .../server/component/panel/TestWriteDesign.java | 71 ++++++ .../server/component/tabsheet/TestReadDesign.java | 136 +++++++++++ .../tabsheet/TestSynchronizeFromDesign.java | 137 ----------- .../tabsheet/TestSynchronizeToDesign.java | 109 --------- .../server/component/tabsheet/TestWriteDesign.java | 109 +++++++++ .../server/component/textarea/TestReadDesign.java | 59 +++++ .../textarea/TestSynchronizeFromDesign.java | 59 ----- .../textarea/TestSynchronizeToDesign.java | 60 ----- .../server/component/textarea/TestWriteDesign.java | 60 +++++ .../server/component/textfield/TestReadDesign.java | 59 +++++ .../textfield/TestSynchronizeFromDesign.java | 59 ----- .../textfield/TestSynchronizeToDesign.java | 59 ----- .../component/textfield/TestWriteDesign.java | 59 +++++ 52 files changed, 2880 insertions(+), 2881 deletions(-) create mode 100644 server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/button/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/button/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/csslayout/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/csslayout/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/label/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/label/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/panel/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/panel/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/panel/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/panel/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/tabsheet/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/tabsheet/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/tabsheet/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/tabsheet/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/textarea/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/textarea/TestWriteDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/textfield/TestReadDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeFromDesign.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeToDesign.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/textfield/TestWriteDesign.java (limited to 'server/tests') diff --git a/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestReadDesign.java new file mode 100644 index 0000000000..5f9674e554 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestReadDesign.java @@ -0,0 +1,110 @@ +/* + * 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.absolutelayout; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.server.Sizeable; +import com.vaadin.ui.AbsoluteLayout; +import com.vaadin.ui.AbsoluteLayout.ComponentPosition; +import com.vaadin.ui.Component; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for reading AbsoluteLayout from design + * + * @since + * @author Vaadin Ltd + */ +public class TestReadDesign extends TestCase { + + private AbsoluteLayout root; + + @Override + public void setUp() throws Exception { + super.setUp(); + root = createLayout(); + } + + public void testAttributes() { + assertEquals("test-layout", root.getCaption()); + Iterator children = root.iterator(); + assertEquals("test-label", children.next().getCaption()); + assertEquals("test-button", children.next().getCaption()); + } + + public void testTopLeftPosition() { + ComponentPosition position = root.getPosition(root.iterator().next()); + assertEquals(Sizeable.Unit.PIXELS, position.getTopUnits()); + assertEquals(100.0f, position.getTopValue()); + assertEquals(Sizeable.Unit.PERCENTAGE, position.getLeftUnits()); + assertEquals(50.0f, position.getLeftValue()); + } + + public void testBottomRightPosition() { + Iterator children = root.iterator(); + children.next(); + ComponentPosition position = root.getPosition(children.next()); + assertEquals(Sizeable.Unit.PIXELS, position.getBottomUnits()); + assertEquals(100.0f, position.getBottomValue()); + assertEquals(Sizeable.Unit.PERCENTAGE, position.getRightUnits()); + assertEquals(50.0f, position.getRightValue()); + } + + public void testZIndex() { + ComponentPosition position = root.getPosition(root.iterator().next()); + assertEquals(2, position.getZIndex()); + } + + private AbsoluteLayout createLayout() { + DesignContext ctx = new DesignContext(); + Element design = createDesign(); + Component child = ctx.createChild(design); + return (AbsoluteLayout) child; + } + + private Element createDesign() { + + Attributes rootAttributes = new Attributes(); + rootAttributes.put("caption", "test-layout"); + Element node = new Element(Tag.valueOf("v-absolute-layout"), "", + rootAttributes); + + Attributes firstChildAttributes = new Attributes(); + firstChildAttributes.put("caption", "test-label"); + firstChildAttributes.put(":top", "100px"); + firstChildAttributes.put(":left", "50%"); + firstChildAttributes.put(":z-index", "2"); + Element firstChild = new Element(Tag.valueOf("v-label"), "", + firstChildAttributes); + node.appendChild(firstChild); + + Attributes secondChildAttributes = new Attributes(); + secondChildAttributes.put(":bottom", "100px"); + secondChildAttributes.put(":right", "50%"); + Element secondChild = new Element(Tag.valueOf("v-button"), "", + secondChildAttributes); + secondChild.html("test-button"); + node.appendChild(secondChild); + return node; + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeFromDesign.java deleted file mode 100644 index ce054007a6..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,110 +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.absolutelayout; - -import java.util.Iterator; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.server.Sizeable; -import com.vaadin.ui.AbsoluteLayout; -import com.vaadin.ui.AbsoluteLayout.ComponentPosition; -import com.vaadin.ui.Component; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for reading AbsoluteLayout from design - * - * @since - * @author Vaadin Ltd - */ -public class TestSynchronizeFromDesign extends TestCase { - - private AbsoluteLayout root; - - @Override - public void setUp() throws Exception { - super.setUp(); - root = createLayout(); - } - - public void testAttributes() { - assertEquals("test-layout", root.getCaption()); - Iterator children = root.iterator(); - assertEquals("test-label", children.next().getCaption()); - assertEquals("test-button", children.next().getCaption()); - } - - public void testTopLeftPosition() { - ComponentPosition position = root.getPosition(root.iterator().next()); - assertEquals(Sizeable.Unit.PIXELS, position.getTopUnits()); - assertEquals(100.0f, position.getTopValue()); - assertEquals(Sizeable.Unit.PERCENTAGE, position.getLeftUnits()); - assertEquals(50.0f, position.getLeftValue()); - } - - public void testBottomRightPosition() { - Iterator children = root.iterator(); - children.next(); - ComponentPosition position = root.getPosition(children.next()); - assertEquals(Sizeable.Unit.PIXELS, position.getBottomUnits()); - assertEquals(100.0f, position.getBottomValue()); - assertEquals(Sizeable.Unit.PERCENTAGE, position.getRightUnits()); - assertEquals(50.0f, position.getRightValue()); - } - - public void testZIndex() { - ComponentPosition position = root.getPosition(root.iterator().next()); - assertEquals(2, position.getZIndex()); - } - - private AbsoluteLayout createLayout() { - DesignContext ctx = new DesignContext(); - Element design = createDesign(); - Component child = ctx.createChild(design); - return (AbsoluteLayout) child; - } - - private Element createDesign() { - - Attributes rootAttributes = new Attributes(); - rootAttributes.put("caption", "test-layout"); - Element node = new Element(Tag.valueOf("v-absolute-layout"), "", - rootAttributes); - - Attributes firstChildAttributes = new Attributes(); - firstChildAttributes.put("caption", "test-label"); - firstChildAttributes.put(":top", "100px"); - firstChildAttributes.put(":left", "50%"); - firstChildAttributes.put(":z-index", "2"); - Element firstChild = new Element(Tag.valueOf("v-label"), "", - firstChildAttributes); - node.appendChild(firstChild); - - Attributes secondChildAttributes = new Attributes(); - secondChildAttributes.put(":bottom", "100px"); - secondChildAttributes.put(":right", "50%"); - Element secondChild = new Element(Tag.valueOf("v-button"), "", - secondChildAttributes); - secondChild.html("test-button"); - node.appendChild(secondChild); - return node; - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeToDesign.java deleted file mode 100644 index eb61d13684..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeToDesign.java +++ /dev/null @@ -1,100 +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.absolutelayout; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.AbsoluteLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for writing AbsoluteLayout to design - * - * @since - * @author Vaadin Ltd - */ -public class TestSynchronizeToDesign extends TestCase { - - public void testSynchronizeEmptyLayout() { - AbsoluteLayout layout = createTestLayout(); - layout.removeAllComponents(); - Element design = createDesign(); - layout.synchronizeToDesign(design, createDesignContext()); - assertEquals(0, design.childNodes().size()); - assertEquals("changed-caption", design.attr("caption")); - } - - public void testSynchronizeLayoutWithChildren() { - AbsoluteLayout layout = createTestLayout(); - Element design = createDesign(); - layout.synchronizeToDesign(design, createDesignContext()); - assertEquals(2, design.childNodes().size()); - assertEquals("v-label", ((Element) design.childNode(0)).tagName()); - assertEquals("v-label", ((Element) design.childNode(1)).tagName()); - } - - public void testSynchronizePosition() { - AbsoluteLayout layout = createTestLayout(); - Element design = createDesign(); - layout.synchronizeToDesign(design, createDesignContext()); - Attributes attributes = design.childNode(0).attributes(); - assertEquals("50px", attributes.get(":top")); - assertEquals("50%", attributes.get(":left")); - assertEquals("2", attributes.get(":z-index")); - attributes = design.childNode(1).attributes(); - assertEquals("50px", attributes.get(":bottom")); - assertEquals("50%", attributes.get(":right")); - } - - private AbsoluteLayout createTestLayout() { - AbsoluteLayout layout = new AbsoluteLayout(); - layout.setCaption("changed-caption"); - layout.addComponent(new Label("test-label"), - "top:50px;left:50%;z-index:2"); - layout.addComponent(new Label("test-label-2"), - "bottom:50px;right:50%;z-index:3"); - return layout; - } - - private Element createDesign() { - // make sure that the design node has old content that should be removed - Attributes rootAttributes = new Attributes(); - rootAttributes.put("caption", "test-layout"); - Element node = new Element(Tag.valueOf("v-absolute-layout"), "", - rootAttributes); - Attributes firstChildAttributes = new Attributes(); - firstChildAttributes.put("caption", "test-label"); - Element firstChild = new Element(Tag.valueOf("v-label"), "", - firstChildAttributes); - node.appendChild(firstChild); - - Attributes secondChildAttributes = new Attributes(); - secondChildAttributes.put("caption", "test-button"); - Element secondChild = new Element(Tag.valueOf("v-button"), "", - secondChildAttributes); - node.appendChild(secondChild); - return node; - } - - private DesignContext createDesignContext() { - return new DesignContext(); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestWriteDesign.java new file mode 100644 index 0000000000..5f42b1fa81 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestWriteDesign.java @@ -0,0 +1,100 @@ +/* + * 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.absolutelayout; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.AbsoluteLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for writing AbsoluteLayout to design + * + * @since + * @author Vaadin Ltd + */ +public class TestWriteDesign extends TestCase { + + public void testSynchronizeEmptyLayout() { + AbsoluteLayout layout = createTestLayout(); + layout.removeAllComponents(); + Element design = createDesign(); + layout.writeDesign(design, createDesignContext()); + assertEquals(0, design.childNodes().size()); + assertEquals("changed-caption", design.attr("caption")); + } + + public void testSynchronizeLayoutWithChildren() { + AbsoluteLayout layout = createTestLayout(); + Element design = createDesign(); + layout.writeDesign(design, createDesignContext()); + assertEquals(2, design.childNodes().size()); + assertEquals("v-label", ((Element) design.childNode(0)).tagName()); + assertEquals("v-label", ((Element) design.childNode(1)).tagName()); + } + + public void testSynchronizePosition() { + AbsoluteLayout layout = createTestLayout(); + Element design = createDesign(); + layout.writeDesign(design, createDesignContext()); + Attributes attributes = design.childNode(0).attributes(); + assertEquals("50px", attributes.get(":top")); + assertEquals("50%", attributes.get(":left")); + assertEquals("2", attributes.get(":z-index")); + attributes = design.childNode(1).attributes(); + assertEquals("50px", attributes.get(":bottom")); + assertEquals("50%", attributes.get(":right")); + } + + private AbsoluteLayout createTestLayout() { + AbsoluteLayout layout = new AbsoluteLayout(); + layout.setCaption("changed-caption"); + layout.addComponent(new Label("test-label"), + "top:50px;left:50%;z-index:2"); + layout.addComponent(new Label("test-label-2"), + "bottom:50px;right:50%;z-index:3"); + return layout; + } + + private Element createDesign() { + // make sure that the design node has old content that should be removed + Attributes rootAttributes = new Attributes(); + rootAttributes.put("caption", "test-layout"); + Element node = new Element(Tag.valueOf("v-absolute-layout"), "", + rootAttributes); + Attributes firstChildAttributes = new Attributes(); + firstChildAttributes.put("caption", "test-label"); + Element firstChild = new Element(Tag.valueOf("v-label"), "", + firstChildAttributes); + node.appendChild(firstChild); + + Attributes secondChildAttributes = new Attributes(); + secondChildAttributes.put("caption", "test-button"); + Element secondChild = new Element(Tag.valueOf("v-button"), "", + secondChildAttributes); + node.appendChild(secondChild); + return node; + } + + private DesignContext createDesignContext() { + return new DesignContext(); + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestReadDesign.java new file mode 100644 index 0000000000..760f1ca422 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestReadDesign.java @@ -0,0 +1,256 @@ +/* + * 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.abstractcomponent; + +import java.lang.reflect.Field; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.server.ExternalResource; +import com.vaadin.server.FileResource; +import com.vaadin.server.Responsive; +import com.vaadin.server.ThemeResource; +import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.Label; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for reading the attributes of the AbstractComponent from design + * + * @author Vaadin Ltd + */ +public class TestReadDesign extends TestCase { + + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + public void testSynchronizeId() { + Element design = createDesign("id", "testId"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals("testId", component.getId()); + } + + public void testSynchronizePrimaryStyleName() { + Element design = createDesign("primary-style-name", "test-style"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals("test-style", component.getPrimaryStyleName()); + } + + public void testSynchronizeCaption() { + Element design = createDesign("caption", "test-caption"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals("test-caption", component.getCaption()); + } + + public void testSynchronizeLocale() { + Element design = createDesign("locale", "fi_FI"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals("fi", component.getLocale().getLanguage()); + assertEquals("FI", component.getLocale().getCountry()); + } + + public void testSynchronizeExternalIcon() { + Element design = createDesign("icon", "http://example.com/example.gif"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertTrue("Incorrect resource type returned", component.getIcon() + .getClass().isAssignableFrom(ExternalResource.class)); + assertEquals("http://example.com/example.gif", + ((ExternalResource) component.getIcon()).getURL()); + } + + public void testSynchronizeThemeIcon() { + Element design = createDesign("icon", "theme://example.gif"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertTrue("Incorrect resource type returned", component.getIcon() + .getClass().isAssignableFrom(ThemeResource.class)); + } + + public void testSynchronizeFileResource() { + Element design = createDesign("icon", "img/example.gif"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertTrue("Incorrect resource type returned", component.getIcon() + .getClass().isAssignableFrom(FileResource.class)); + } + + public void testSynchronizeImmediate() { + Element design = createDesign("immediate", "true"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals(true, component.isImmediate()); + assertEquals(Boolean.TRUE, getExplicitImmediate(component)); + // Synchronize with a design having no immediate attribute - + // explicitImmediate should then be null. + design = createDesign("description", "test-description"); + component.readDesign(design, ctx); + assertEquals(null, getExplicitImmediate(component)); + // Synchronize with a design having immediate = false + design = createDesign("immediate", "false"); + component.readDesign(design, ctx); + assertEquals(false, component.isImmediate()); + assertEquals(Boolean.FALSE, getExplicitImmediate(component)); + // Synchronize with a design having immediate = "" - should correspond + // to + // true. + design = createDesign("immediate", ""); + component.readDesign(design, ctx); + assertEquals(true, component.isImmediate()); + assertEquals(Boolean.TRUE, getExplicitImmediate(component)); + } + + public void testSynchronizeDescription() { + Element design = createDesign("description", "test-description"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals("test-description", component.getDescription()); + } + + public void testSynchronizeComponentError() { + Element design = createDesign("error", "
test-error
"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals("
test-error
", component.getComponentError() + .getFormattedHtmlMessage()); + } + + public void testSynchronizeSizeFull() { + Element design = createDesign("size-full", ""); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals(100, component.getWidth(), 0.1f); + assertEquals(100, component.getHeight(), 0.1f); + } + + public void testSynchronizeSizeAuto() { + Element design = createDesign("size-auto", ""); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals(-1, component.getWidth(), 0.1f); + assertEquals(-1, component.getHeight(), 0.1f); + } + + public void testSynchronizeHeightFull() { + Element design = createDesign("height-full", ""); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals(100, component.getHeight(), 0.1f); + } + + public void testSynchronizeHeightAuto() { + Element design = createDesign("height-auto", ""); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals(-1, component.getHeight(), 0.1f); + } + + public void testSynchronizeWidthFull() { + Element design = createDesign("width-full", ""); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals(100, component.getWidth(), 0.1f); + } + + public void testSynchronizeWidthAuto() { + Element design = createDesign("width-auto", ""); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals(-1, component.getWidth(), 0.1f); + } + + public void testSynchronizeWidth() { + Element design = createDesign("width", "12px"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals(12, component.getWidth(), 0.1f); + assertEquals(com.vaadin.server.Sizeable.Unit.PIXELS, + component.getWidthUnits()); + } + + public void testSynchronizeHeight() { + Element design = createDesign("height", "12px"); + AbstractComponent component = getComponent(); + component.readDesign(design, ctx); + assertEquals(12, component.getHeight(), 0.1f); + assertEquals(com.vaadin.server.Sizeable.Unit.PIXELS, + component.getHeightUnits()); + } + + public void testSynchronizeNotResponsive() { + AbstractComponent component = getComponent(); + Responsive.makeResponsive(component); + Element design = createDesign("responsive", "false"); + component.readDesign(design, ctx); + assertEquals("Component should not have extensions", 0, component + .getExtensions().size()); + } + + public void testSynchronizeResponsive() { + AbstractComponent component = getComponent(); + Element design = createDesign("responsive", ""); + component.readDesign(design, ctx); + assertEquals("Component should have one extension", 1, component + .getExtensions().size()); + assertTrue("Extension should be responsive", component.getExtensions() + .iterator().next() instanceof Responsive); + } + + public void testSynchronizeAlreadyResponsive() { + AbstractComponent component = getComponent(); + Responsive.makeResponsive(component); + Element design = createDesign("responsive", ""); + component.readDesign(design, ctx); + assertEquals("Component should have only one extension", 1, component + .getExtensions().size()); + } + + private AbstractComponent getComponent() { + return new Label(); + } + + private Element createDesign(String key, String value) { + Attributes attributes = new Attributes(); + attributes.put(key, value); + Element node = new Element(Tag.valueOf("v-label"), "", attributes); + return node; + } + + private Boolean getExplicitImmediate(AbstractComponent component) { + try { + Field immediate = AbstractComponent.class + .getDeclaredField("explicitImmediateValue"); + immediate.setAccessible(true); + return (Boolean) immediate.get(component); + } catch (Exception e) { + throw new RuntimeException( + "Getting the field explicitImmediateValue failed."); + } + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeFromDesign.java deleted file mode 100644 index df6fb47bf2..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,256 +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.abstractcomponent; - -import java.lang.reflect.Field; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.server.ExternalResource; -import com.vaadin.server.FileResource; -import com.vaadin.server.Responsive; -import com.vaadin.server.ThemeResource; -import com.vaadin.ui.AbstractComponent; -import com.vaadin.ui.Label; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for reading the attributes of the AbstractComponent from design - * - * @author Vaadin Ltd - */ -public class TestSynchronizeFromDesign extends TestCase { - - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - public void testSynchronizeId() { - Element design = createDesign("id", "testId"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals("testId", component.getId()); - } - - public void testSynchronizePrimaryStyleName() { - Element design = createDesign("primary-style-name", "test-style"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals("test-style", component.getPrimaryStyleName()); - } - - public void testSynchronizeCaption() { - Element design = createDesign("caption", "test-caption"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals("test-caption", component.getCaption()); - } - - public void testSynchronizeLocale() { - Element design = createDesign("locale", "fi_FI"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals("fi", component.getLocale().getLanguage()); - assertEquals("FI", component.getLocale().getCountry()); - } - - public void testSynchronizeExternalIcon() { - Element design = createDesign("icon", "http://example.com/example.gif"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertTrue("Incorrect resource type returned", component.getIcon() - .getClass().isAssignableFrom(ExternalResource.class)); - assertEquals("http://example.com/example.gif", - ((ExternalResource) component.getIcon()).getURL()); - } - - public void testSynchronizeThemeIcon() { - Element design = createDesign("icon", "theme://example.gif"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertTrue("Incorrect resource type returned", component.getIcon() - .getClass().isAssignableFrom(ThemeResource.class)); - } - - public void testSynchronizeFileResource() { - Element design = createDesign("icon", "img/example.gif"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertTrue("Incorrect resource type returned", component.getIcon() - .getClass().isAssignableFrom(FileResource.class)); - } - - public void testSynchronizeImmediate() { - Element design = createDesign("immediate", "true"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals(true, component.isImmediate()); - assertEquals(Boolean.TRUE, getExplicitImmediate(component)); - // Synchronize with a design having no immediate attribute - - // explicitImmediate should then be null. - design = createDesign("description", "test-description"); - component.synchronizeFromDesign(design, ctx); - assertEquals(null, getExplicitImmediate(component)); - // Synchronize with a design having immediate = false - design = createDesign("immediate", "false"); - component.synchronizeFromDesign(design, ctx); - assertEquals(false, component.isImmediate()); - assertEquals(Boolean.FALSE, getExplicitImmediate(component)); - // Synchronize with a design having immediate = "" - should correspond - // to - // true. - design = createDesign("immediate", ""); - component.synchronizeFromDesign(design, ctx); - assertEquals(true, component.isImmediate()); - assertEquals(Boolean.TRUE, getExplicitImmediate(component)); - } - - public void testSynchronizeDescription() { - Element design = createDesign("description", "test-description"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals("test-description", component.getDescription()); - } - - public void testSynchronizeComponentError() { - Element design = createDesign("error", "
test-error
"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals("
test-error
", component.getComponentError() - .getFormattedHtmlMessage()); - } - - public void testSynchronizeSizeFull() { - Element design = createDesign("size-full", ""); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals(100, component.getWidth(), 0.1f); - assertEquals(100, component.getHeight(), 0.1f); - } - - public void testSynchronizeSizeAuto() { - Element design = createDesign("size-auto", ""); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals(-1, component.getWidth(), 0.1f); - assertEquals(-1, component.getHeight(), 0.1f); - } - - public void testSynchronizeHeightFull() { - Element design = createDesign("height-full", ""); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals(100, component.getHeight(), 0.1f); - } - - public void testSynchronizeHeightAuto() { - Element design = createDesign("height-auto", ""); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals(-1, component.getHeight(), 0.1f); - } - - public void testSynchronizeWidthFull() { - Element design = createDesign("width-full", ""); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals(100, component.getWidth(), 0.1f); - } - - public void testSynchronizeWidthAuto() { - Element design = createDesign("width-auto", ""); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals(-1, component.getWidth(), 0.1f); - } - - public void testSynchronizeWidth() { - Element design = createDesign("width", "12px"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals(12, component.getWidth(), 0.1f); - assertEquals(com.vaadin.server.Sizeable.Unit.PIXELS, - component.getWidthUnits()); - } - - public void testSynchronizeHeight() { - Element design = createDesign("height", "12px"); - AbstractComponent component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals(12, component.getHeight(), 0.1f); - assertEquals(com.vaadin.server.Sizeable.Unit.PIXELS, - component.getHeightUnits()); - } - - public void testSynchronizeNotResponsive() { - AbstractComponent component = getComponent(); - Responsive.makeResponsive(component); - Element design = createDesign("responsive", "false"); - component.synchronizeFromDesign(design, ctx); - assertEquals("Component should not have extensions", 0, component - .getExtensions().size()); - } - - public void testSynchronizeResponsive() { - AbstractComponent component = getComponent(); - Element design = createDesign("responsive", ""); - component.synchronizeFromDesign(design, ctx); - assertEquals("Component should have one extension", 1, component - .getExtensions().size()); - assertTrue("Extension should be responsive", component.getExtensions() - .iterator().next() instanceof Responsive); - } - - public void testSynchronizeAlreadyResponsive() { - AbstractComponent component = getComponent(); - Responsive.makeResponsive(component); - Element design = createDesign("responsive", ""); - component.synchronizeFromDesign(design, ctx); - assertEquals("Component should have only one extension", 1, component - .getExtensions().size()); - } - - private AbstractComponent getComponent() { - return new Label(); - } - - private Element createDesign(String key, String value) { - Attributes attributes = new Attributes(); - attributes.put(key, value); - Element node = new Element(Tag.valueOf("v-label"), "", attributes); - return node; - } - - private Boolean getExplicitImmediate(AbstractComponent component) { - try { - Field immediate = AbstractComponent.class - .getDeclaredField("explicitImmediateValue"); - immediate.setAccessible(true); - return (Boolean) immediate.get(component); - } catch (Exception e) { - throw new RuntimeException( - "Getting the field explicitImmediateValue failed."); - } - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeToDesign.java deleted file mode 100644 index 349598ec8f..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeToDesign.java +++ /dev/null @@ -1,266 +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.abstractcomponent; - -import java.io.File; -import java.util.Locale; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.server.AbstractErrorMessage.ContentMode; -import com.vaadin.server.ErrorMessage.ErrorLevel; -import com.vaadin.server.ExternalResource; -import com.vaadin.server.FileResource; -import com.vaadin.server.Responsive; -import com.vaadin.server.ThemeResource; -import com.vaadin.server.UserError; -import com.vaadin.ui.AbstractComponent; -import com.vaadin.ui.Button; -import com.vaadin.ui.HorizontalSplitPanel; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for writing the attributes of the AbstractComponent to design - * - * @author Vaadin Ltd - */ -public class TestSynchronizeToDesign extends TestCase { - - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - public void testSynchronizeId() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setId("testId"); - component.synchronizeToDesign(design, ctx); - // we only changed one of the attributes, others are at default values - assertEquals(1, design.attributes().size()); - assertEquals("testId", design.attr("id")); - } - - public void testSynchronizePrimaryStyleName() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setPrimaryStyleName("test-style"); - component.synchronizeToDesign(design, ctx); - // we only changed one of the attributes, others are at default values - assertEquals(1, design.attributes().size()); - assertEquals("test-style", design.attr("primary-style-name")); - } - - public void testSynchronizeCaption() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setCaption("test-caption"); - component.synchronizeToDesign(design, ctx); - // We only changed the caption, which is not - // an attribute. - assertEquals(0, design.attributes().size()); - assertEquals("test-caption", design.html()); - } - - public void testSynchronizeLocale() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setLocale(new Locale("fi", "FI")); - component.synchronizeToDesign(design, ctx); - // we only changed one of the attributes, others are at default values - assertEquals(1, design.attributes().size()); - assertEquals("fi_FI", design.attr("locale")); - } - - public void testSynchronizeExternalIcon() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component - .setIcon(new ExternalResource("http://example.com/example.gif")); - component.synchronizeToDesign(design, ctx); - // we only changed one of the attributes, others are at default values - assertEquals(1, design.attributes().size()); - assertEquals("http://example.com/example.gif", design.attr("icon")); - } - - public void testSynchronizeThemeIcon() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setIcon(new ThemeResource("example.gif")); - component.synchronizeToDesign(design, ctx); - // we only changed one of the attributes, others are at default values - assertEquals(1, design.attributes().size()); - assertEquals("theme://example.gif", design.attr("icon")); - } - - public void testSynchronizeFileResource() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setIcon(new FileResource(new File("img/example.gif"))); - component.synchronizeToDesign(design, ctx); - // we only changed one of the attributes, others are at default values - assertEquals(1, design.attributes().size()); - assertEquals("img/example.gif", design.attr("icon")); - } - - public void testSynchronizeImmediate() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - // no immediate attribute should be written before setting immediate to - // some value - component.synchronizeToDesign(design, ctx); - assertFalse(design.hasAttr("immediate")); - component.setImmediate(true); - component.synchronizeToDesign(design, ctx); - // we only changed one of the attributes, others are at default values - assertEquals(1, design.attributes().size()); - assertEquals("true", design.attr("immediate")); - } - - public void testSynchronizeDescription() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setDescription("test-description"); - component.synchronizeToDesign(design, ctx); - // we only changed one of the attributes, others are at default values - assertEquals(1, design.attributes().size()); - assertEquals("test-description", design.attr("description")); - } - - public void testSynchronizeComponentError() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setComponentError(new UserError("
test-error
", - ContentMode.HTML, ErrorLevel.ERROR)); - component.synchronizeToDesign(design, ctx); - // we only changed one of the attributes, others are at default values - assertEquals(1, design.attributes().size()); - assertEquals("
test-error
", design.attr("error")); - } - - public void testSynchronizeSizeFull() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setSizeFull(); - component.synchronizeToDesign(design, ctx); - // there should be only size full - assertEquals(1, design.attributes().size()); - assertEquals("true", design.attr("size-full")); - } - - public void testSynchronizeSizeAuto() { - Element design = createDesign(); - AbstractComponent component = getPanel(); - component.setSizeUndefined(); - component.synchronizeToDesign(design, ctx); - // there should be only size auto - assertEquals(1, design.attributes().size()); - assertEquals("true", design.attr("size-auto")); - } - - public void testSynchronizeHeightFull() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setHeight("100%"); - component.setWidth("20px"); - component.synchronizeToDesign(design, ctx); - assertEquals("true", design.attr("height-full")); - } - - public void testSynchronizeHeightAuto() { - Element design = createDesign(); - // we need to have default height of 100% -> use split panel - AbstractComponent component = getPanel(); - component.setHeight(null); - component.setWidth("20px"); - component.synchronizeToDesign(design, ctx); - assertEquals("true", design.attr("height-auto")); - } - - public void testSynchronizeWidthFull() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setHeight("20px"); - component.setWidth("100%"); - component.synchronizeToDesign(design, ctx); - assertEquals("true", design.attr("width-full")); - } - - public void testSynchronizeWidthAuto() { - Element design = createDesign(); - // need to get label, otherwise the default would be auto - AbstractComponent component = getPanel(); - component.setHeight("20px"); - component.setWidth(null); - component.synchronizeToDesign(design, ctx); - assertEquals("true", design.attr("width-auto")); - } - - public void testSynchronizeWidth() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setHeight("20px"); - component.setWidth("70%"); - component.synchronizeToDesign(design, ctx); - assertEquals("70%", design.attr("width")); - } - - public void testSynchronizeHeight() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - component.setHeight("20px"); - component.setWidth("70%"); - component.synchronizeToDesign(design, ctx); - assertEquals("20px", design.attr("height")); - } - - public void testSynchronizeResponsive() { - Element design = createDesign(); - AbstractComponent component = getComponent(); - Responsive.makeResponsive(component); - component.synchronizeToDesign(design, ctx); - assertTrue("Design attributes should have key 'responsive'", design - .attributes().hasKey("responsive")); - assertFalse("Responsive attribute should not be 'false'", - design.attr("responsive").equalsIgnoreCase("false")); - } - - private AbstractComponent getComponent() { - Button button = new Button(); - button.setHtmlContentAllowed(true); - return button; - } - - private AbstractComponent getPanel() { - return new HorizontalSplitPanel(); - } - - private Element createDesign() { - Attributes attr = new Attributes(); - attr.put("should_be_removed", "foo"); - Element node = new Element(Tag.valueOf("v-button"), "", attr); - Element child = new Element(Tag.valueOf("to-be-removed"), "foo", attr); - node.appendChild(child); - return node; - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestWriteDesign.java new file mode 100644 index 0000000000..44c0e0b063 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestWriteDesign.java @@ -0,0 +1,266 @@ +/* + * 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.abstractcomponent; + +import java.io.File; +import java.util.Locale; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.server.AbstractErrorMessage.ContentMode; +import com.vaadin.server.ErrorMessage.ErrorLevel; +import com.vaadin.server.ExternalResource; +import com.vaadin.server.FileResource; +import com.vaadin.server.Responsive; +import com.vaadin.server.ThemeResource; +import com.vaadin.server.UserError; +import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.Button; +import com.vaadin.ui.HorizontalSplitPanel; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for writing the attributes of the AbstractComponent to design + * + * @author Vaadin Ltd + */ +public class TestWriteDesign extends TestCase { + + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + public void testSynchronizeId() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setId("testId"); + component.writeDesign(design, ctx); + // we only changed one of the attributes, others are at default values + assertEquals(1, design.attributes().size()); + assertEquals("testId", design.attr("id")); + } + + public void testSynchronizePrimaryStyleName() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setPrimaryStyleName("test-style"); + component.writeDesign(design, ctx); + // we only changed one of the attributes, others are at default values + assertEquals(1, design.attributes().size()); + assertEquals("test-style", design.attr("primary-style-name")); + } + + public void testSynchronizeCaption() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setCaption("test-caption"); + component.writeDesign(design, ctx); + // We only changed the caption, which is not + // an attribute. + assertEquals(0, design.attributes().size()); + assertEquals("test-caption", design.html()); + } + + public void testSynchronizeLocale() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setLocale(new Locale("fi", "FI")); + component.writeDesign(design, ctx); + // we only changed one of the attributes, others are at default values + assertEquals(1, design.attributes().size()); + assertEquals("fi_FI", design.attr("locale")); + } + + public void testSynchronizeExternalIcon() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component + .setIcon(new ExternalResource("http://example.com/example.gif")); + component.writeDesign(design, ctx); + // we only changed one of the attributes, others are at default values + assertEquals(1, design.attributes().size()); + assertEquals("http://example.com/example.gif", design.attr("icon")); + } + + public void testSynchronizeThemeIcon() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setIcon(new ThemeResource("example.gif")); + component.writeDesign(design, ctx); + // we only changed one of the attributes, others are at default values + assertEquals(1, design.attributes().size()); + assertEquals("theme://example.gif", design.attr("icon")); + } + + public void testSynchronizeFileResource() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setIcon(new FileResource(new File("img/example.gif"))); + component.writeDesign(design, ctx); + // we only changed one of the attributes, others are at default values + assertEquals(1, design.attributes().size()); + assertEquals("img/example.gif", design.attr("icon")); + } + + public void testSynchronizeImmediate() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + // no immediate attribute should be written before setting immediate to + // some value + component.writeDesign(design, ctx); + assertFalse(design.hasAttr("immediate")); + component.setImmediate(true); + component.writeDesign(design, ctx); + // we only changed one of the attributes, others are at default values + assertEquals(1, design.attributes().size()); + assertEquals("true", design.attr("immediate")); + } + + public void testSynchronizeDescription() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setDescription("test-description"); + component.writeDesign(design, ctx); + // we only changed one of the attributes, others are at default values + assertEquals(1, design.attributes().size()); + assertEquals("test-description", design.attr("description")); + } + + public void testSynchronizeComponentError() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setComponentError(new UserError("
test-error
", + ContentMode.HTML, ErrorLevel.ERROR)); + component.writeDesign(design, ctx); + // we only changed one of the attributes, others are at default values + assertEquals(1, design.attributes().size()); + assertEquals("
test-error
", design.attr("error")); + } + + public void testSynchronizeSizeFull() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setSizeFull(); + component.writeDesign(design, ctx); + // there should be only size full + assertEquals(1, design.attributes().size()); + assertEquals("true", design.attr("size-full")); + } + + public void testSynchronizeSizeAuto() { + Element design = createDesign(); + AbstractComponent component = getPanel(); + component.setSizeUndefined(); + component.writeDesign(design, ctx); + // there should be only size auto + assertEquals(1, design.attributes().size()); + assertEquals("true", design.attr("size-auto")); + } + + public void testSynchronizeHeightFull() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setHeight("100%"); + component.setWidth("20px"); + component.writeDesign(design, ctx); + assertEquals("true", design.attr("height-full")); + } + + public void testSynchronizeHeightAuto() { + Element design = createDesign(); + // we need to have default height of 100% -> use split panel + AbstractComponent component = getPanel(); + component.setHeight(null); + component.setWidth("20px"); + component.writeDesign(design, ctx); + assertEquals("true", design.attr("height-auto")); + } + + public void testSynchronizeWidthFull() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setHeight("20px"); + component.setWidth("100%"); + component.writeDesign(design, ctx); + assertEquals("true", design.attr("width-full")); + } + + public void testSynchronizeWidthAuto() { + Element design = createDesign(); + // need to get label, otherwise the default would be auto + AbstractComponent component = getPanel(); + component.setHeight("20px"); + component.setWidth(null); + component.writeDesign(design, ctx); + assertEquals("true", design.attr("width-auto")); + } + + public void testSynchronizeWidth() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setHeight("20px"); + component.setWidth("70%"); + component.writeDesign(design, ctx); + assertEquals("70%", design.attr("width")); + } + + public void testSynchronizeHeight() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + component.setHeight("20px"); + component.setWidth("70%"); + component.writeDesign(design, ctx); + assertEquals("20px", design.attr("height")); + } + + public void testSynchronizeResponsive() { + Element design = createDesign(); + AbstractComponent component = getComponent(); + Responsive.makeResponsive(component); + component.writeDesign(design, ctx); + assertTrue("Design attributes should have key 'responsive'", design + .attributes().hasKey("responsive")); + assertFalse("Responsive attribute should not be 'false'", + design.attr("responsive").equalsIgnoreCase("false")); + } + + private AbstractComponent getComponent() { + Button button = new Button(); + button.setHtmlContentAllowed(true); + return button; + } + + private AbstractComponent getPanel() { + return new HorizontalSplitPanel(); + } + + private Element createDesign() { + Attributes attr = new Attributes(); + attr.put("should_be_removed", "foo"); + Element node = new Element(Tag.valueOf("v-button"), "", attr); + Element child = new Element(Tag.valueOf("to-be-removed"), "foo", attr); + node.appendChild(child); + return node; + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/TestReadDesign.java new file mode 100644 index 0000000000..dd0e629199 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/TestReadDesign.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.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 TestReadDesign 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/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/TestSynchronizeFromDesign.java deleted file mode 100644 index 6a2c194978..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/TestSynchronizeFromDesign.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 TestSynchronizeFromDesign 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.synchronizeFromDesign(design, ctx); - assertEquals(true, component.isReadOnly()); - design = createDesign("readonly", "false"); - component.synchronizeFromDesign(design, ctx); - assertEquals(false, component.isReadOnly()); - } - - public void testSynchronizeTabIndex() { - Element design = createDesign("tabindex", "2"); - AbstractField component = getComponent(); - component.synchronizeFromDesign(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/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/TestSynchronizeToDesign.java deleted file mode 100644 index 26f64f9199..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/TestSynchronizeToDesign.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 TestSynchronizeToDesign 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.synchronizeToDesign(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.synchronizeToDesign(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/abstractfield/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/TestWriteDesign.java new file mode 100644 index 0000000000..969713abe6 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/TestWriteDesign.java @@ -0,0 +1,77 @@ +/* + * 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 TestWriteDesign 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/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestReadDesign.java new file mode 100644 index 0000000000..f52a04496a --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestReadDesign.java @@ -0,0 +1,119 @@ +/* + * 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 junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Component; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case from reading AbstractOrdered layouts from design + * + * @since + * @author Vaadin Ltd + */ +public class TestReadDesign extends TestCase { + + public void testChildCount() { + VerticalLayout root = createLayout(0f, false); + assertEquals(2, root.getComponentCount()); + } + + public void testMargin() { + VerticalLayout root = createLayout(0f, true); + assertTrue(root.getMargin().getBitMask() != 0); + root = createLayout(0f, false); + assertTrue(root.getMargin().getBitMask() == 0); + } + + public void testAttributes() { + VerticalLayout root = createLayout(0f, false); + assertEquals("test-layout", root.getCaption()); + assertEquals("test-label", root.getComponent(0).getCaption()); + assertEquals("test-button", root.getComponent(1).getCaption()); + } + + public void testExpandRatio() { + VerticalLayout root = createLayout(1f, false); + assertEquals(1f, root.getExpandRatio(root.getComponent(0))); + assertEquals(1f, root.getExpandRatio(root.getComponent(1))); + + root = createLayout(0f, false); + assertEquals(0f, root.getExpandRatio(root.getComponent(0))); + assertEquals(0f, root.getExpandRatio(root.getComponent(1))); + } + + public void testAlignment() { + VerticalLayout root = createLayout(0f, false, ":top", ":left"); + assertEquals(Alignment.TOP_LEFT, + root.getComponentAlignment(root.getComponent(0))); + root = createLayout(0f, false, ":middle", ":center"); + assertEquals(Alignment.MIDDLE_CENTER, + root.getComponentAlignment(root.getComponent(0))); + root = createLayout(0f, false, ":bottom", ":right"); + assertEquals(Alignment.BOTTOM_RIGHT, + root.getComponentAlignment(root.getComponent(0))); + + } + + private VerticalLayout createLayout(float expandRatio, boolean margin, + String... alignments) { + DesignContext ctx = new DesignContext(); + Element design = createDesign(expandRatio, margin, alignments); + Component child = ctx.createChild(design); + return (VerticalLayout) child; + } + + private Element createDesign(float expandRatio, boolean margin, + String... alignments) { + + Attributes rootAttributes = new Attributes(); + rootAttributes.put("caption", "test-layout"); + if (margin) { + rootAttributes.put("margin", ""); + } + Element node = new Element(Tag.valueOf("v-vertical-layout"), "", + rootAttributes); + + Attributes firstChildAttributes = new Attributes(); + firstChildAttributes.put("caption", "test-label"); + firstChildAttributes.put(":expand", String.valueOf(expandRatio)); + for (String alignment : alignments) { + firstChildAttributes.put(alignment, ""); + } + Element firstChild = new Element(Tag.valueOf("v-label"), "", + firstChildAttributes); + node.appendChild(firstChild); + + Attributes secondChildAttributes = new Attributes(); + secondChildAttributes.put(":expand", String.valueOf(expandRatio)); + for (String alignment : alignments) { + secondChildAttributes.put(alignment, ""); + } + Element secondChild = new Element(Tag.valueOf("v-button"), "", + secondChildAttributes); + secondChild.html("test-button"); + node.appendChild(secondChild); + return node; + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java deleted file mode 100644 index 2b3d4cbdac..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,119 +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.abstractorderedlayout; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Component; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case from reading AbstractOrdered layouts from design - * - * @since - * @author Vaadin Ltd - */ -public class TestSynchronizeFromDesign extends TestCase { - - public void testChildCount() { - VerticalLayout root = createLayout(0f, false); - assertEquals(2, root.getComponentCount()); - } - - public void testMargin() { - VerticalLayout root = createLayout(0f, true); - assertTrue(root.getMargin().getBitMask() != 0); - root = createLayout(0f, false); - assertTrue(root.getMargin().getBitMask() == 0); - } - - public void testAttributes() { - VerticalLayout root = createLayout(0f, false); - assertEquals("test-layout", root.getCaption()); - assertEquals("test-label", root.getComponent(0).getCaption()); - assertEquals("test-button", root.getComponent(1).getCaption()); - } - - public void testExpandRatio() { - VerticalLayout root = createLayout(1f, false); - assertEquals(1f, root.getExpandRatio(root.getComponent(0))); - assertEquals(1f, root.getExpandRatio(root.getComponent(1))); - - root = createLayout(0f, false); - assertEquals(0f, root.getExpandRatio(root.getComponent(0))); - assertEquals(0f, root.getExpandRatio(root.getComponent(1))); - } - - public void testAlignment() { - VerticalLayout root = createLayout(0f, false, ":top", ":left"); - assertEquals(Alignment.TOP_LEFT, - root.getComponentAlignment(root.getComponent(0))); - root = createLayout(0f, false, ":middle", ":center"); - assertEquals(Alignment.MIDDLE_CENTER, - root.getComponentAlignment(root.getComponent(0))); - root = createLayout(0f, false, ":bottom", ":right"); - assertEquals(Alignment.BOTTOM_RIGHT, - root.getComponentAlignment(root.getComponent(0))); - - } - - private VerticalLayout createLayout(float expandRatio, boolean margin, - String... alignments) { - DesignContext ctx = new DesignContext(); - Element design = createDesign(expandRatio, margin, alignments); - Component child = ctx.createChild(design); - return (VerticalLayout) child; - } - - private Element createDesign(float expandRatio, boolean margin, - String... alignments) { - - Attributes rootAttributes = new Attributes(); - rootAttributes.put("caption", "test-layout"); - if (margin) { - rootAttributes.put("margin", ""); - } - Element node = new Element(Tag.valueOf("v-vertical-layout"), "", - rootAttributes); - - Attributes firstChildAttributes = new Attributes(); - firstChildAttributes.put("caption", "test-label"); - firstChildAttributes.put(":expand", String.valueOf(expandRatio)); - for (String alignment : alignments) { - firstChildAttributes.put(alignment, ""); - } - Element firstChild = new Element(Tag.valueOf("v-label"), "", - firstChildAttributes); - node.appendChild(firstChild); - - Attributes secondChildAttributes = new Attributes(); - secondChildAttributes.put(":expand", String.valueOf(expandRatio)); - for (String alignment : alignments) { - secondChildAttributes.put(alignment, ""); - } - Element secondChild = new Element(Tag.valueOf("v-button"), "", - secondChildAttributes); - secondChild.html("test-button"); - node.appendChild(secondChild); - return node; - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeToDesign.java deleted file mode 100644 index 23cf15cd13..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeToDesign.java +++ /dev/null @@ -1,148 +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.abstractorderedlayout; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Label; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for writing abstract ordered layout to design - * - * @since - * @author Vaadin Ltd - */ -public class TestSynchronizeToDesign extends TestCase { - - public void testSynchronizeMargin() { - VerticalLayout layout = new VerticalLayout(); - layout.setMargin(true); - Element design = createDesign(); - layout.synchronizeToDesign(design, createDesignContext()); - assertTrue("The margin must be written", design.hasAttr("margin")); - assertTrue("The margin must be empty or true", design.attr("margin") - .equals("") || design.attr("margin").equalsIgnoreCase("true")); - } - - public void testSynchronizeEmptyLayout() { - VerticalLayout layout = new VerticalLayout(); - layout.setCaption("changed-caption"); - Element design = createDesign(); - layout.synchronizeToDesign(design, createDesignContext()); - assertEquals(0, design.childNodes().size()); - assertEquals("changed-caption", design.attr("caption")); - } - - public void testSynchronizeLayoutWithChildren() { - VerticalLayout layout = new VerticalLayout(); - layout.addComponent(new Label("test-label")); - layout.getComponent(0).setCaption("test-caption"); - layout.addComponent(new Label("test-label-2")); - Element design = createDesign(); - layout.synchronizeToDesign(design, createDesignContext()); - assertEquals(2, design.childNodes().size()); - assertEquals("v-label", ((Element) design.childNode(0)).tagName()); - assertEquals("test-caption", design.childNode(0).attr("caption")); - } - - public void testSynchronizeUnitExpandRatio() { - VerticalLayout layout = new VerticalLayout(); - layout.addComponent(new Label("test-label")); - layout.setExpandRatio(layout.getComponent(0), 1.0f); - Element design = createDesign(); - layout.synchronizeToDesign(design, createDesignContext()); - assertTrue(design.childNode(0).hasAttr(":expand")); - assertEquals("", design.childNode(0).attr(":expand")); - } - - public void testSynchronizeArbitraryExpandRatio() { - VerticalLayout layout = new VerticalLayout(); - layout.addComponent(new Label("test-label")); - layout.setExpandRatio(layout.getComponent(0), 2.40f); - Element design = createDesign(); - layout.synchronizeToDesign(design, createDesignContext()); - assertTrue(design.childNode(0).hasAttr(":expand")); - assertEquals("2.4", design.childNode(0).attr(":expand")); - } - - public void testSynchronizeDefaultAlignment() { - Element design = createDesign(); - VerticalLayout layout = createLayoutWithAlignment(design, null); - layout.synchronizeToDesign(design, createDesignContext()); - assertFalse(design.childNode(0).hasAttr(":top")); - assertFalse(design.childNode(0).hasAttr(":left")); - } - - public void testSynchronizeMiddleCenter() { - Element design = createDesign(); - VerticalLayout layout = createLayoutWithAlignment(design, - Alignment.MIDDLE_CENTER); - layout.synchronizeToDesign(design, createDesignContext()); - assertTrue(design.childNode(0).hasAttr(":middle")); - assertTrue(design.childNode(0).hasAttr(":center")); - } - - public void testSynchronizeBottomRight() { - Element design = createDesign(); - VerticalLayout layout = createLayoutWithAlignment(design, - Alignment.BOTTOM_RIGHT); - layout.synchronizeToDesign(design, createDesignContext()); - assertTrue(design.childNode(0).hasAttr(":bottom")); - assertTrue(design.childNode(0).hasAttr(":right")); - } - - private VerticalLayout createLayoutWithAlignment(Element design, - Alignment alignment) { - VerticalLayout layout = new VerticalLayout(); - layout.addComponent(new Label("test-label")); - if (alignment != null) { - layout.setComponentAlignment(layout.getComponent(0), alignment); - } - layout.synchronizeToDesign(design, createDesignContext()); - return layout; - } - - private Element createDesign() { - // make sure that the design node has old content that should be removed - Attributes rootAttributes = new Attributes(); - rootAttributes.put("caption", "test-layout"); - Element node = 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); - node.appendChild(firstChild); - - Attributes secondChildAttributes = new Attributes(); - secondChildAttributes.put("caption", "test-button"); - Element secondChild = new Element(Tag.valueOf("v-button"), "", - secondChildAttributes); - node.appendChild(secondChild); - return node; - } - - private DesignContext createDesignContext() { - return new DesignContext(); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestWriteDesign.java new file mode 100644 index 0000000000..302cf985bd --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestWriteDesign.java @@ -0,0 +1,148 @@ +/* + * 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 junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for writing abstract ordered layout to design + * + * @since + * @author Vaadin Ltd + */ +public class TestWriteDesign extends TestCase { + + public void testSynchronizeMargin() { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + Element design = createDesign(); + layout.writeDesign(design, createDesignContext()); + assertTrue("The margin must be written", design.hasAttr("margin")); + assertTrue("The margin must be empty or true", design.attr("margin") + .equals("") || design.attr("margin").equalsIgnoreCase("true")); + } + + public void testSynchronizeEmptyLayout() { + VerticalLayout layout = new VerticalLayout(); + layout.setCaption("changed-caption"); + Element design = createDesign(); + layout.writeDesign(design, createDesignContext()); + assertEquals(0, design.childNodes().size()); + assertEquals("changed-caption", design.attr("caption")); + } + + public void testSynchronizeLayoutWithChildren() { + VerticalLayout layout = new VerticalLayout(); + layout.addComponent(new Label("test-label")); + layout.getComponent(0).setCaption("test-caption"); + layout.addComponent(new Label("test-label-2")); + Element design = createDesign(); + layout.writeDesign(design, createDesignContext()); + assertEquals(2, design.childNodes().size()); + assertEquals("v-label", ((Element) design.childNode(0)).tagName()); + assertEquals("test-caption", design.childNode(0).attr("caption")); + } + + public void testSynchronizeUnitExpandRatio() { + VerticalLayout layout = new VerticalLayout(); + layout.addComponent(new Label("test-label")); + layout.setExpandRatio(layout.getComponent(0), 1.0f); + Element design = createDesign(); + layout.writeDesign(design, createDesignContext()); + assertTrue(design.childNode(0).hasAttr(":expand")); + assertEquals("", design.childNode(0).attr(":expand")); + } + + public void testSynchronizeArbitraryExpandRatio() { + VerticalLayout layout = new VerticalLayout(); + layout.addComponent(new Label("test-label")); + layout.setExpandRatio(layout.getComponent(0), 2.40f); + Element design = createDesign(); + layout.writeDesign(design, createDesignContext()); + assertTrue(design.childNode(0).hasAttr(":expand")); + assertEquals("2.4", design.childNode(0).attr(":expand")); + } + + public void testSynchronizeDefaultAlignment() { + Element design = createDesign(); + VerticalLayout layout = createLayoutWithAlignment(design, null); + layout.writeDesign(design, createDesignContext()); + assertFalse(design.childNode(0).hasAttr(":top")); + assertFalse(design.childNode(0).hasAttr(":left")); + } + + public void testSynchronizeMiddleCenter() { + Element design = createDesign(); + VerticalLayout layout = createLayoutWithAlignment(design, + Alignment.MIDDLE_CENTER); + layout.writeDesign(design, createDesignContext()); + assertTrue(design.childNode(0).hasAttr(":middle")); + assertTrue(design.childNode(0).hasAttr(":center")); + } + + public void testSynchronizeBottomRight() { + Element design = createDesign(); + VerticalLayout layout = createLayoutWithAlignment(design, + Alignment.BOTTOM_RIGHT); + layout.writeDesign(design, createDesignContext()); + assertTrue(design.childNode(0).hasAttr(":bottom")); + assertTrue(design.childNode(0).hasAttr(":right")); + } + + private VerticalLayout createLayoutWithAlignment(Element design, + Alignment alignment) { + VerticalLayout layout = new VerticalLayout(); + layout.addComponent(new Label("test-label")); + if (alignment != null) { + layout.setComponentAlignment(layout.getComponent(0), alignment); + } + layout.writeDesign(design, createDesignContext()); + return layout; + } + + private Element createDesign() { + // make sure that the design node has old content that should be removed + Attributes rootAttributes = new Attributes(); + rootAttributes.put("caption", "test-layout"); + Element node = 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); + node.appendChild(firstChild); + + Attributes secondChildAttributes = new Attributes(); + secondChildAttributes.put("caption", "test-button"); + Element secondChild = new Element(Tag.valueOf("v-button"), "", + secondChildAttributes); + node.appendChild(secondChild); + return node; + } + + private DesignContext createDesignContext() { + return new DesignContext(); + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestReadDesign.java new file mode 100644 index 0000000000..c57f18cbf9 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestReadDesign.java @@ -0,0 +1,173 @@ +/* + * 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 TestReadDesign 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); + // check that the properties get the default values if the design + // does not have attributes corresponding to those properties + design = createDesign(true, true, true, true); + sp.readDesign(design, ctx); + HorizontalSplitPanel def = new HorizontalSplitPanel(); + assertEquals(def.getSplitPosition(), sp.getSplitPosition()); + assertEquals(def.getSplitPositionUnit(), sp.getSplitPositionUnit()); + assertEquals(def.getMinSplitPosition(), sp.getMinSplitPosition()); + assertEquals(def.getMinSplitPositionUnit(), + sp.getMinSplitPositionUnit()); + assertEquals(def.getMaxSplitPosition(), sp.getMaxSplitPosition()); + assertEquals(def.getMaxSplitPositionUnit(), + sp.getMaxSplitPositionUnit()); + assertEquals(def.isLocked(), sp.isLocked()); + checkReversed(sp, false); + } + + 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/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestSynchronizeFromDesign.java deleted file mode 100644 index b34e8fc3f0..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,173 +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 TestSynchronizeFromDesign 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.synchronizeFromDesign(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); - // check that the properties get the default values if the design - // does not have attributes corresponding to those properties - design = createDesign(true, true, true, true); - sp.synchronizeFromDesign(design, ctx); - HorizontalSplitPanel def = new HorizontalSplitPanel(); - assertEquals(def.getSplitPosition(), sp.getSplitPosition()); - assertEquals(def.getSplitPositionUnit(), sp.getSplitPositionUnit()); - assertEquals(def.getMinSplitPosition(), sp.getMinSplitPosition()); - assertEquals(def.getMinSplitPositionUnit(), - sp.getMinSplitPositionUnit()); - assertEquals(def.getMaxSplitPosition(), sp.getMaxSplitPosition()); - assertEquals(def.getMaxSplitPositionUnit(), - sp.getMaxSplitPositionUnit()); - assertEquals(def.isLocked(), sp.isLocked()); - checkReversed(sp, false); - } - - public void testWithNoChildren() { - Element design = createDesign(true, false, false, false); - HorizontalSplitPanel sp = new HorizontalSplitPanel(); - sp.synchronizeFromDesign(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.synchronizeFromDesign(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.synchronizeFromDesign(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.synchronizeFromDesign(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/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestSynchronizeToDesign.java deleted file mode 100644 index 3e342a0c89..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestSynchronizeToDesign.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 TestSynchronizeToDesign 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.createNode(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.createNode(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.createNode(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.createNode(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.createNode(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.createNode(sp); - sp = new VerticalSplitPanel(); - sp.synchronizeToDesign(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/abstractsplitpanel/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestWriteDesign.java new file mode 100644 index 0000000000..1027414c2d --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/TestWriteDesign.java @@ -0,0 +1,151 @@ +/* + * 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 TestWriteDesign 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.createNode(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.createNode(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.createNode(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.createNode(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.createNode(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.createNode(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/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestReadDesign.java new file mode 100644 index 0000000000..3b4b6f1f03 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestReadDesign.java @@ -0,0 +1,73 @@ +/* + * 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 TestReadDesign 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/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestSynchronizeFromDesign.java deleted file mode 100644 index f7ba67f506..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestSynchronizeFromDesign.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 TestSynchronizeFromDesign 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.synchronizeFromDesign(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/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestSynchronizeToDesign.java deleted file mode 100644 index b8f29b0ac9..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestSynchronizeToDesign.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 TestSynchronizeToDesign 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.synchronizeToDesign(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/abstracttextfield/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestWriteDesign.java new file mode 100644 index 0000000000..be5c384d3b --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/TestWriteDesign.java @@ -0,0 +1,73 @@ +/* + * 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 TestWriteDesign 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/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/button/TestReadDesign.java new file mode 100644 index 0000000000..48b228a35a --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/button/TestReadDesign.java @@ -0,0 +1,129 @@ +/* + * 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.button; + +import java.lang.reflect.Field; + +import junit.framework.TestCase; + +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.ui.Button; +import com.vaadin.ui.Button.ClickShortcut; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.declarative.DesignContext; + +/** + * + * Test cases for reading the contents of a Button and a NativeButton from a + * design. + * + */ +public class TestReadDesign extends TestCase { + + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + @Test + public void testWithContent() { + createAndTestButtons("Click", null); + } + + @Test + public void testWithHtmlCaption() { + createAndTestButtons("Click me", null); + } + + @Test + public void testWithContentAndCaption() { + createAndTestButtons("Click me", "caption"); + } + + @Test + public void testWithCaption() { + createAndTestButtons(null, "Click me"); + } + + @Test + public void testAttributes() throws IllegalArgumentException, + SecurityException, IllegalAccessException, NoSuchFieldException { + Attributes attributes = new Attributes(); + attributes.put("tabindex", "3"); + attributes.put("plain-text", ""); + attributes.put("icon-alt", "OK"); + attributes.put("click-shortcut", "ctrl-shift-o"); + Button button = (Button) ctx + .createChild(createButtonWithAttributes(attributes)); + assertEquals(3, button.getTabIndex()); + assertEquals(false, button.isHtmlContentAllowed()); + assertEquals("OK", button.getIconAlternateText()); + Field field = Button.class.getDeclaredField("clickShortcut"); + field.setAccessible(true); + ClickShortcut value = (ClickShortcut) field.get(button); + assertEquals(KeyCode.O, value.getKeyCode()); + assertEquals(ModifierKey.CTRL, value.getModifiers()[0]); + assertEquals(ModifierKey.SHIFT, value.getModifiers()[1]); + } + + /* + * Test both Button and NativeButton. Caption should always be ignored. If + * content is null, the created button should have empty content. + */ + private void createAndTestButtons(String content, String caption) { + Element e1 = createElement("v-button", content, caption); + Button b1 = (Button) ctx.createChild(e1); + Element e2 = createElement("v-native-button", content, caption); + NativeButton b2 = (NativeButton) ctx.createChild(e2); + if (content != null) { + assertEquals("The button has the wrong text content.", content, + b1.getCaption()); + assertEquals("The button has the wrong text content.", content, + b2.getCaption()); + } else { + assertTrue("The button has the wrong content.", + b1.getCaption() == null || "".equals(b1.getCaption())); + assertTrue("The button has the wrong content.", + b2.getCaption() == null || "".equals(b2.getCaption())); + } + } + + private Element createButtonWithAttributes(Attributes attributes) { + return new Element(Tag.valueOf("v-button"), "", attributes); + } + + private Element createElement(String elementName, String content, + String caption) { + Attributes attributes = new Attributes(); + if (caption != null) { + attributes.put("caption", caption); + } + Element node = new Element(Tag.valueOf(elementName), "", attributes); + if (content != null) { + node.html(content); + } + return node; + } +} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeFromDesign.java deleted file mode 100644 index 704192fb04..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,129 +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.button; - -import java.lang.reflect.Field; - -import junit.framework.TestCase; - -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.ui.Button; -import com.vaadin.ui.Button.ClickShortcut; -import com.vaadin.ui.NativeButton; -import com.vaadin.ui.declarative.DesignContext; - -/** - * - * Test cases for reading the contents of a Button and a NativeButton from a - * design. - * - */ -public class TestSynchronizeFromDesign extends TestCase { - - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - @Test - public void testWithContent() { - createAndTestButtons("Click", null); - } - - @Test - public void testWithHtmlCaption() { - createAndTestButtons("Click me", null); - } - - @Test - public void testWithContentAndCaption() { - createAndTestButtons("Click me", "caption"); - } - - @Test - public void testWithCaption() { - createAndTestButtons(null, "Click me"); - } - - @Test - public void testAttributes() throws IllegalArgumentException, - SecurityException, IllegalAccessException, NoSuchFieldException { - Attributes attributes = new Attributes(); - attributes.put("tabindex", "3"); - attributes.put("plain-text", ""); - attributes.put("icon-alt", "OK"); - attributes.put("click-shortcut", "ctrl-shift-o"); - Button button = (Button) ctx - .createChild(createButtonWithAttributes(attributes)); - assertEquals(3, button.getTabIndex()); - assertEquals(false, button.isHtmlContentAllowed()); - assertEquals("OK", button.getIconAlternateText()); - Field field = Button.class.getDeclaredField("clickShortcut"); - field.setAccessible(true); - ClickShortcut value = (ClickShortcut) field.get(button); - assertEquals(KeyCode.O, value.getKeyCode()); - assertEquals(ModifierKey.CTRL, value.getModifiers()[0]); - assertEquals(ModifierKey.SHIFT, value.getModifiers()[1]); - } - - /* - * Test both Button and NativeButton. Caption should always be ignored. If - * content is null, the created button should have empty content. - */ - private void createAndTestButtons(String content, String caption) { - Element e1 = createElement("v-button", content, caption); - Button b1 = (Button) ctx.createChild(e1); - Element e2 = createElement("v-native-button", content, caption); - NativeButton b2 = (NativeButton) ctx.createChild(e2); - if (content != null) { - assertEquals("The button has the wrong text content.", content, - b1.getCaption()); - assertEquals("The button has the wrong text content.", content, - b2.getCaption()); - } else { - assertTrue("The button has the wrong content.", - b1.getCaption() == null || "".equals(b1.getCaption())); - assertTrue("The button has the wrong content.", - b2.getCaption() == null || "".equals(b2.getCaption())); - } - } - - private Element createButtonWithAttributes(Attributes attributes) { - return new Element(Tag.valueOf("v-button"), "", attributes); - } - - private Element createElement(String elementName, String content, - String caption) { - Attributes attributes = new Attributes(); - if (caption != null) { - attributes.put("caption", caption); - } - Element node = new Element(Tag.valueOf(elementName), "", attributes); - if (content != null) { - node.html(content); - } - return node; - } -} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeToDesign.java deleted file mode 100644 index c96fd36d5d..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeToDesign.java +++ /dev/null @@ -1,103 +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.button; - -import junit.framework.TestCase; - -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.ui.Button; -import com.vaadin.ui.NativeButton; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Tests generating html tree nodes corresponding to the contents of a Button - * and a NativeButton. - */ -public class TestSynchronizeToDesign extends TestCase { - - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - @Test - public void testWithTextContent() { - createAndTestButtons("Click me"); - } - - @Test - public void testWithHtmlContent() { - createAndTestButtons("Click"); - } - - @Test - public void testAttributes() { - Button button = new Button(); - button.setTabIndex(3); - button.setIconAlternateText("OK"); - button.setClickShortcut(KeyCode.O, ModifierKey.CTRL, ModifierKey.SHIFT); - Element e = new Element(Tag.valueOf("v-button"), "", new Attributes()); - button.synchronizeToDesign(e, ctx); - assertEquals("3", e.attr("tabindex")); - assertTrue("Button is plain text by default", e.hasAttr("plain-text")); - assertEquals("OK", e.attr("icon-alt")); - assertEquals("ctrl-shift-o", e.attr("click-shortcut")); - } - - @Test - public void testUpdateContentMode() { - Button button = new Button("OK"); - Element e = new Element(Tag.valueOf("v-button"), "", new Attributes()); - button.synchronizeToDesign(e, ctx); - assertTrue("Button is plain text by default", e.hasAttr("plain-text")); - - button.setHtmlContentAllowed(true); - button.synchronizeToDesign(e, ctx); - assertTrue("Button is updated to HTML", !e.hasAttr("plain-text")); - - } - - private void createAndTestButtons(String content) { - Button b1 = new Button(content); - // we need to set this on, since the plain-text attribute will appear - // otherwise - b1.setHtmlContentAllowed(true); - Element e1 = ctx.createNode(b1); - assertEquals("Wrong tag name for button.", "v-button", e1.tagName()); - assertEquals("Unexpected content in the v-button element.", content, - e1.html()); - assertTrue("The v-button element should not have attributes.", e1 - .attributes().size() == 0); - NativeButton b2 = new NativeButton(content); - b2.setHtmlContentAllowed(true); - Element e2 = ctx.createNode(b2); - assertEquals("Wrong tag name for button.", "v-native-button", - e2.tagName()); - assertEquals("Unexpected content in the v-button element.", content, - e2.html()); - assertTrue("The v-button element should not have attributes.", e2 - .attributes().size() == 0); - } -} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/button/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/button/TestWriteDesign.java new file mode 100644 index 0000000000..a8cf83522c --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/button/TestWriteDesign.java @@ -0,0 +1,103 @@ +/* + * 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.button; + +import junit.framework.TestCase; + +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.ui.Button; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Tests generating html tree nodes corresponding to the contents of a Button + * and a NativeButton. + */ +public class TestWriteDesign extends TestCase { + + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + @Test + public void testWithTextContent() { + createAndTestButtons("Click me"); + } + + @Test + public void testWithHtmlContent() { + createAndTestButtons("Click"); + } + + @Test + public void testAttributes() { + Button button = new Button(); + button.setTabIndex(3); + button.setIconAlternateText("OK"); + button.setClickShortcut(KeyCode.O, ModifierKey.CTRL, ModifierKey.SHIFT); + Element e = new Element(Tag.valueOf("v-button"), "", new Attributes()); + button.writeDesign(e, ctx); + assertEquals("3", e.attr("tabindex")); + assertTrue("Button is plain text by default", e.hasAttr("plain-text")); + assertEquals("OK", e.attr("icon-alt")); + assertEquals("ctrl-shift-o", e.attr("click-shortcut")); + } + + @Test + public void testUpdateContentMode() { + Button button = new Button("OK"); + Element e = new Element(Tag.valueOf("v-button"), "", new Attributes()); + button.writeDesign(e, ctx); + assertTrue("Button is plain text by default", e.hasAttr("plain-text")); + + button.setHtmlContentAllowed(true); + button.writeDesign(e, ctx); + assertTrue("Button is updated to HTML", !e.hasAttr("plain-text")); + + } + + private void createAndTestButtons(String content) { + Button b1 = new Button(content); + // we need to set this on, since the plain-text attribute will appear + // otherwise + b1.setHtmlContentAllowed(true); + Element e1 = ctx.createNode(b1); + assertEquals("Wrong tag name for button.", "v-button", e1.tagName()); + assertEquals("Unexpected content in the v-button element.", content, + e1.html()); + assertTrue("The v-button element should not have attributes.", e1 + .attributes().size() == 0); + NativeButton b2 = new NativeButton(content); + b2.setHtmlContentAllowed(true); + Element e2 = ctx.createNode(b2); + assertEquals("Wrong tag name for button.", "v-native-button", + e2.tagName()); + assertEquals("Unexpected content in the v-button element.", content, + e2.html()); + assertTrue("The v-button element should not have attributes.", e2 + .attributes().size() == 0); + } +} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/csslayout/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/csslayout/TestReadDesign.java new file mode 100644 index 0000000000..51f763bf14 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/csslayout/TestReadDesign.java @@ -0,0 +1,74 @@ +/* + * 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.csslayout; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.Component; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for reading CssLayout from design + * + * @author Vaadin Ltd + */ +public class TestReadDesign extends TestCase { + + public void testChildCount() { + CssLayout root = createLayout(); + assertEquals(2, root.getComponentCount()); + } + + public void testAttributes() { + CssLayout root = createLayout(); + assertEquals("test-layout", root.getCaption()); + assertEquals("test-label", root.getComponent(0).getCaption()); + assertEquals("test-button", root.getComponent(1).getCaption()); + } + + private CssLayout createLayout() { + DesignContext ctx = new DesignContext(); + Element design = createDesign(); + Component child = ctx.createChild(design); + return (CssLayout) child; + } + + private Element createDesign() { + + Attributes rootAttributes = new Attributes(); + rootAttributes.put("caption", "test-layout"); + Element node = new Element(Tag.valueOf("v-css-layout"), "", + rootAttributes); + + Attributes firstChildAttributes = new Attributes(); + firstChildAttributes.put("caption", "test-label"); + Element firstChild = new Element(Tag.valueOf("v-label"), "", + firstChildAttributes); + node.appendChild(firstChild); + + Attributes secondChildAttributes = new Attributes(); + Element secondChild = new Element(Tag.valueOf("v-button"), "", + secondChildAttributes); + secondChild.html("test-button"); + node.appendChild(secondChild); + return node; + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeFromDesign.java deleted file mode 100644 index e9694f0170..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,74 +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.csslayout; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.Component; -import com.vaadin.ui.CssLayout; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for reading CssLayout from design - * - * @author Vaadin Ltd - */ -public class TestSynchronizeFromDesign extends TestCase { - - public void testChildCount() { - CssLayout root = createLayout(); - assertEquals(2, root.getComponentCount()); - } - - public void testAttributes() { - CssLayout root = createLayout(); - assertEquals("test-layout", root.getCaption()); - assertEquals("test-label", root.getComponent(0).getCaption()); - assertEquals("test-button", root.getComponent(1).getCaption()); - } - - private CssLayout createLayout() { - DesignContext ctx = new DesignContext(); - Element design = createDesign(); - Component child = ctx.createChild(design); - return (CssLayout) child; - } - - private Element createDesign() { - - Attributes rootAttributes = new Attributes(); - rootAttributes.put("caption", "test-layout"); - Element node = new Element(Tag.valueOf("v-css-layout"), "", - rootAttributes); - - Attributes firstChildAttributes = new Attributes(); - firstChildAttributes.put("caption", "test-label"); - Element firstChild = new Element(Tag.valueOf("v-label"), "", - firstChildAttributes); - node.appendChild(firstChild); - - Attributes secondChildAttributes = new Attributes(); - Element secondChild = new Element(Tag.valueOf("v-button"), "", - secondChildAttributes); - secondChild.html("test-button"); - node.appendChild(secondChild); - return node; - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeToDesign.java deleted file mode 100644 index 2dfd560c8c..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeToDesign.java +++ /dev/null @@ -1,78 +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.csslayout; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.CssLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for writing CssLayout to design - * - * @author Vaadin Ltd - */ -public class TestSynchronizeToDesign extends TestCase { - - public void testSynchronizeEmptyLayout() { - CssLayout layout = new CssLayout(); - layout.setCaption("changed-caption"); - Element design = createDesign(); - layout.synchronizeToDesign(design, createDesignContext()); - assertEquals(0, design.childNodes().size()); - assertEquals("changed-caption", design.attr("caption")); - } - - public void testSynchronizeLayoutWithChildren() { - CssLayout layout = new CssLayout(); - layout.addComponent(new Label("test-label")); - layout.getComponent(0).setCaption("test-caption"); - layout.addComponent(new Label("test-label-2")); - Element design = createDesign(); - layout.synchronizeToDesign(design, createDesignContext()); - assertEquals(2, design.childNodes().size()); - assertEquals("v-label", ((Element) design.childNode(0)).tagName()); - assertEquals("test-caption", design.childNode(0).attr("caption")); - } - - private Element createDesign() { - // make sure that the design node has old content that should be removed - Attributes rootAttributes = new Attributes(); - rootAttributes.put("caption", "test-layout"); - Element node = 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); - node.appendChild(firstChild); - - Element secondChild = new Element(Tag.valueOf("v-button"), "", - new Attributes()); - secondChild.html("test-button"); - node.appendChild(secondChild); - return node; - } - - private DesignContext createDesignContext() { - return new DesignContext(); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/csslayout/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/csslayout/TestWriteDesign.java new file mode 100644 index 0000000000..d660eb77ec --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/csslayout/TestWriteDesign.java @@ -0,0 +1,78 @@ +/* + * 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.csslayout; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for writing CssLayout to design + * + * @author Vaadin Ltd + */ +public class TestWriteDesign extends TestCase { + + public void testSynchronizeEmptyLayout() { + CssLayout layout = new CssLayout(); + layout.setCaption("changed-caption"); + Element design = createDesign(); + layout.writeDesign(design, createDesignContext()); + assertEquals(0, design.childNodes().size()); + assertEquals("changed-caption", design.attr("caption")); + } + + public void testSynchronizeLayoutWithChildren() { + CssLayout layout = new CssLayout(); + layout.addComponent(new Label("test-label")); + layout.getComponent(0).setCaption("test-caption"); + layout.addComponent(new Label("test-label-2")); + Element design = createDesign(); + layout.writeDesign(design, createDesignContext()); + assertEquals(2, design.childNodes().size()); + assertEquals("v-label", ((Element) design.childNode(0)).tagName()); + assertEquals("test-caption", design.childNode(0).attr("caption")); + } + + private Element createDesign() { + // make sure that the design node has old content that should be removed + Attributes rootAttributes = new Attributes(); + rootAttributes.put("caption", "test-layout"); + Element node = 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); + node.appendChild(firstChild); + + Element secondChild = new Element(Tag.valueOf("v-button"), "", + new Attributes()); + secondChild.html("test-button"); + node.appendChild(secondChild); + return node; + } + + private DesignContext createDesignContext() { + return new DesignContext(); + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/label/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/label/TestReadDesign.java new file mode 100644 index 0000000000..1a02ed98cc --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/label/TestReadDesign.java @@ -0,0 +1,102 @@ +/* + * 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.label; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; +import org.junit.Test; + +import com.vaadin.ui.Label; +import com.vaadin.ui.declarative.DesignContext; + +/** + * + * Test case for reading the contents of a Label from a design. + * + */ +public class TestReadDesign extends TestCase { + + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + @Test + public void testWithContent() { + createAndTestLabel("A label", null); + } + + @Test + public void testWithHtmlContent() { + createAndTestLabel("A label", null); + } + + @Test + public void testWithContentAndCaption() { + createAndTestLabel("A label", "This is a label"); + } + + @Test + public void testWithCaption() { + createAndTestLabel(null, "This is a label"); + } + + @Test + public void testWithoutContentAndCaption() { + createAndTestLabel(null, null); + } + + /* + * Test creating a Label. A Label can have both caption and content. + */ + private void createAndTestLabel(String content, String caption) { + Element e = createElement("v-label", content, caption); + Label l = (Label) ctx.createChild(e); + if (content != null) { + assertEquals("The label has wrong text content.", content, + l.getValue()); + } else { + assertTrue("The label has wrong text content.", + l.getValue() == null || "".equals(l.getValue())); + } + if (caption != null) { + assertEquals("The label has wrong caption.", caption, + l.getCaption()); + } else { + assertTrue("The label has wrong caption.", l.getCaption() == null + || "".equals(l.getCaption())); + } + } + + private Element createElement(String elementName, String content, + String caption) { + Attributes attributes = new Attributes(); + if (caption != null) { + attributes.put("caption", caption); + } + Element node = new Element(Tag.valueOf(elementName), "", attributes); + if (content != null) { + node.html(content); + } + return node; + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeFromDesign.java deleted file mode 100644 index 168c44cb90..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,102 +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.label; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; -import org.junit.Test; - -import com.vaadin.ui.Label; -import com.vaadin.ui.declarative.DesignContext; - -/** - * - * Test case for reading the contents of a Label from a design. - * - */ -public class TestSynchronizeFromDesign extends TestCase { - - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - @Test - public void testWithContent() { - createAndTestLabel("A label", null); - } - - @Test - public void testWithHtmlContent() { - createAndTestLabel("A label", null); - } - - @Test - public void testWithContentAndCaption() { - createAndTestLabel("A label", "This is a label"); - } - - @Test - public void testWithCaption() { - createAndTestLabel(null, "This is a label"); - } - - @Test - public void testWithoutContentAndCaption() { - createAndTestLabel(null, null); - } - - /* - * Test creating a Label. A Label can have both caption and content. - */ - private void createAndTestLabel(String content, String caption) { - Element e = createElement("v-label", content, caption); - Label l = (Label) ctx.createChild(e); - if (content != null) { - assertEquals("The label has wrong text content.", content, - l.getValue()); - } else { - assertTrue("The label has wrong text content.", - l.getValue() == null || "".equals(l.getValue())); - } - if (caption != null) { - assertEquals("The label has wrong caption.", caption, - l.getCaption()); - } else { - assertTrue("The label has wrong caption.", l.getCaption() == null - || "".equals(l.getCaption())); - } - } - - private Element createElement(String elementName, String content, - String caption) { - Attributes attributes = new Attributes(); - if (caption != null) { - attributes.put("caption", caption); - } - Element node = new Element(Tag.valueOf(elementName), "", attributes); - if (content != null) { - node.html(content); - } - return node; - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeToDesign.java deleted file mode 100644 index 869546ac3d..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeToDesign.java +++ /dev/null @@ -1,126 +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.label; - -import junit.framework.TestCase; - -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.ui.Label; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Tests generating an html tree node corresponding to a Label. - */ -public class TestSynchronizeToDesign extends TestCase { - - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - @Test - public void testWithContent() { - createAndTestLabel("A label", null); - } - - @Test - public void testWithHtmlContent() { - createAndTestLabel("A label", null); - } - - @Test - public void testWithCaption() { - createAndTestLabel(null, "Label caption"); - } - - @Test - public void testWithContentAndCaption() { - createAndTestLabel("A label", "Label caption"); - } - - @Test - public void testContentModeText() { - Label l = new Label("plain text label"); - Element e = new Element(Tag.valueOf("v-label"), "", new Attributes()); - l.synchronizeToDesign(e, ctx); - assertTrue("Label should be marked as plain text", - e.hasAttr("plain-text")); - } - - @Test - public void testContentModeHtml() { - Label l = new Label("html label"); - l.setContentMode(ContentMode.HTML); - - Element e = new Element(Tag.valueOf("v-label"), "", new Attributes()); - l.synchronizeToDesign(e, ctx); - assertFalse("Label should not be marked as plain text", - e.hasAttr("plain-text")); - } - - @Test - public void testChangeContentMode() { - Label l = new Label("html label"); - l.setContentMode(ContentMode.HTML); - - Element e = new Element(Tag.valueOf("v-label"), "", new Attributes()); - l.synchronizeToDesign(e, ctx); - - assertFalse("Label should not be marked as plain text", - e.hasAttr("plain-text")); - l.setContentMode(ContentMode.TEXT); - l.synchronizeToDesign(e, ctx); - - assertTrue("Label should be marked as plain text", - e.hasAttr("plain-text")); - } - - @Test - public void testWithoutContentAndCaption() { - createAndTestLabel(null, null); - } - - private void createAndTestLabel(String content, String caption) { - Label l = new Label(content); - if (caption != null) { - l.setCaption(caption); - } - Element e = ctx.createNode(l); - assertEquals("Wrong tag name for label.", "v-label", e.tagName()); - if (content != null) { - assertEquals("Unexpected content in the v-label element.", content, - e.html()); - } else { - assertTrue("Unexpected content in the v-label element.", - e.html() == null || "".equals(e.html())); - } - if (caption != null) { - assertEquals("Wrong caption in the v-label element.", caption, - e.attr("caption")); - } else { - assertTrue("Unexpected caption in the v-label element.", - e.attr("caption") == null || "".equals(e.attr("caption"))); - } - } -} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/label/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/label/TestWriteDesign.java new file mode 100644 index 0000000000..fab7c1d8eb --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/label/TestWriteDesign.java @@ -0,0 +1,126 @@ +/* + * 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.label; + +import junit.framework.TestCase; + +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.ui.Label; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Tests generating an html tree node corresponding to a Label. + */ +public class TestWriteDesign extends TestCase { + + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + @Test + public void testWithContent() { + createAndTestLabel("A label", null); + } + + @Test + public void testWithHtmlContent() { + createAndTestLabel("A label", null); + } + + @Test + public void testWithCaption() { + createAndTestLabel(null, "Label caption"); + } + + @Test + public void testWithContentAndCaption() { + createAndTestLabel("A label", "Label caption"); + } + + @Test + public void testContentModeText() { + Label l = new Label("plain text label"); + Element e = new Element(Tag.valueOf("v-label"), "", new Attributes()); + l.writeDesign(e, ctx); + assertTrue("Label should be marked as plain text", + e.hasAttr("plain-text")); + } + + @Test + public void testContentModeHtml() { + Label l = new Label("html label"); + l.setContentMode(ContentMode.HTML); + + Element e = new Element(Tag.valueOf("v-label"), "", new Attributes()); + l.writeDesign(e, ctx); + assertFalse("Label should not be marked as plain text", + e.hasAttr("plain-text")); + } + + @Test + public void testChangeContentMode() { + Label l = new Label("html label"); + l.setContentMode(ContentMode.HTML); + + Element e = new Element(Tag.valueOf("v-label"), "", new Attributes()); + l.writeDesign(e, ctx); + + assertFalse("Label should not be marked as plain text", + e.hasAttr("plain-text")); + l.setContentMode(ContentMode.TEXT); + l.writeDesign(e, ctx); + + assertTrue("Label should be marked as plain text", + e.hasAttr("plain-text")); + } + + @Test + public void testWithoutContentAndCaption() { + createAndTestLabel(null, null); + } + + private void createAndTestLabel(String content, String caption) { + Label l = new Label(content); + if (caption != null) { + l.setCaption(caption); + } + Element e = ctx.createNode(l); + assertEquals("Wrong tag name for label.", "v-label", e.tagName()); + if (content != null) { + assertEquals("Unexpected content in the v-label element.", content, + e.html()); + } else { + assertTrue("Unexpected content in the v-label element.", + e.html() == null || "".equals(e.html())); + } + if (caption != null) { + assertEquals("Wrong caption in the v-label element.", caption, + e.attr("caption")); + } else { + assertTrue("Unexpected caption in the v-label element.", + e.attr("caption") == null || "".equals(e.attr("caption"))); + } + } +} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/panel/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/panel/TestReadDesign.java new file mode 100644 index 0000000000..3eb52309a8 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/panel/TestReadDesign.java @@ -0,0 +1,98 @@ +/* + * 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.panel; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.Panel; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.DesignContext; +import com.vaadin.ui.declarative.DesignException; + +/** + * Test case for reading the attributes of a Panel from design. + * + * @author Vaadin Ltd + */ +public class TestReadDesign extends TestCase { + DesignContext ctx; + + @Override + public void setUp() { + ctx = new DesignContext(); + } + + public void testAttributes() { + Element design = createDesign(); + Panel panel = new Panel(); + panel.readDesign(design, ctx); + assertEquals("A panel", panel.getCaption()); + assertEquals(2, panel.getTabIndex()); + assertEquals(10, panel.getScrollLeft()); + assertEquals(20, panel.getScrollTop()); + assertEquals(200f, panel.getWidth()); + assertEquals(150f, panel.getHeight()); + } + + public void testChild() { + Element design = createDesign(); + Panel panel = new Panel(); + panel.readDesign(design, ctx); + VerticalLayout vLayout = (VerticalLayout) panel.getContent(); + assertEquals(300f, vLayout.getWidth()); + assertEquals(400f, vLayout.getHeight()); + } + + public void testWithMoreThanOneChild() { + Element design = createDesign(); + // Add a new child to the panel element. An exception should be + // thrown when parsing the design. + Element newChild = new Element(Tag.valueOf("v-horizontal-layout"), ""); + design.appendChild(newChild); + Panel panel = new Panel(); + try { + panel.readDesign(design, ctx); + fail("Parsing a design containing a Panel with more than one child component should have failed."); + } catch (DesignException e) { + // Nothing needs to be done, this is the expected case. + } + } + + /* + * Creates an html document that can be parsed into a valid component + * hierarchy. + */ + private Element createDesign() { + // Create a node defining a Panel + Element panelElement = new Element(Tag.valueOf("v-panel"), ""); + panelElement.attr("caption", "A panel"); + panelElement.attr("tabindex", "2"); + panelElement.attr("scroll-left", "10"); + panelElement.attr("scroll-top", "20"); + panelElement.attr("width", "200px"); + panelElement.attr("height", "150px"); + // Add some content to the panel + Element layoutElement = new Element(Tag.valueOf("v-vertical-layout"), + ""); + layoutElement.attr("width", "300px"); + layoutElement.attr("height", "400px"); + panelElement.appendChild(layoutElement); + return panelElement; + } +} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/panel/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/panel/TestSynchronizeFromDesign.java deleted file mode 100644 index bc4a597a4e..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/panel/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,98 +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.panel; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.Panel; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.declarative.DesignContext; -import com.vaadin.ui.declarative.DesignException; - -/** - * Test case for reading the attributes of a Panel from design. - * - * @author Vaadin Ltd - */ -public class TestSynchronizeFromDesign extends TestCase { - DesignContext ctx; - - @Override - public void setUp() { - ctx = new DesignContext(); - } - - public void testAttributes() { - Element design = createDesign(); - Panel panel = new Panel(); - panel.synchronizeFromDesign(design, ctx); - assertEquals("A panel", panel.getCaption()); - assertEquals(2, panel.getTabIndex()); - assertEquals(10, panel.getScrollLeft()); - assertEquals(20, panel.getScrollTop()); - assertEquals(200f, panel.getWidth()); - assertEquals(150f, panel.getHeight()); - } - - public void testChild() { - Element design = createDesign(); - Panel panel = new Panel(); - panel.synchronizeFromDesign(design, ctx); - VerticalLayout vLayout = (VerticalLayout) panel.getContent(); - assertEquals(300f, vLayout.getWidth()); - assertEquals(400f, vLayout.getHeight()); - } - - public void testWithMoreThanOneChild() { - Element design = createDesign(); - // Add a new child to the panel element. An exception should be - // thrown when parsing the design. - Element newChild = new Element(Tag.valueOf("v-horizontal-layout"), ""); - design.appendChild(newChild); - Panel panel = new Panel(); - try { - panel.synchronizeFromDesign(design, ctx); - fail("Parsing a design containing a Panel with more than one child component should have failed."); - } catch (DesignException e) { - // Nothing needs to be done, this is the expected case. - } - } - - /* - * Creates an html document that can be parsed into a valid component - * hierarchy. - */ - private Element createDesign() { - // Create a node defining a Panel - Element panelElement = new Element(Tag.valueOf("v-panel"), ""); - panelElement.attr("caption", "A panel"); - panelElement.attr("tabindex", "2"); - panelElement.attr("scroll-left", "10"); - panelElement.attr("scroll-top", "20"); - panelElement.attr("width", "200px"); - panelElement.attr("height", "150px"); - // Add some content to the panel - Element layoutElement = new Element(Tag.valueOf("v-vertical-layout"), - ""); - layoutElement.attr("width", "300px"); - layoutElement.attr("height", "400px"); - panelElement.appendChild(layoutElement); - return panelElement; - } -} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/panel/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/panel/TestSynchronizeToDesign.java deleted file mode 100644 index 56ff155612..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/panel/TestSynchronizeToDesign.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.panel; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.Panel; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for writing the attributes and the child element of a Panel to a - * design. - * - * @author Vaadin Ltd - */ -public class TestSynchronizeToDesign extends TestCase { - Element panelElement; - - @Override - public void setUp() { - // create a component hierarchy - Panel panel = new Panel("A panel"); - panel.setId("panelId"); - panel.setHeight("250px"); - panel.setScrollTop(50); - panel.setTabIndex(4); - VerticalLayout vLayout = new VerticalLayout(); - vLayout.setWidth("500px"); - panel.setContent(vLayout); - // synchronize to design - DesignContext ctx = new DesignContext(); - panelElement = new Element(Tag.valueOf("div"), ""); - panel.synchronizeToDesign(panelElement, ctx); - } - - public void testAttributes() { - // should have caption, id, height, scroll top and tab index - assertEquals(5, panelElement.attributes().size()); - // check the values of the attributes - assertEquals("A panel", panelElement.attr("caption")); - assertEquals("panelId", panelElement.attr("id")); - assertEquals("250px", panelElement.attr("height")); - assertEquals("50", panelElement.attr("scroll-top")); - assertEquals("4", panelElement.attr("tabindex")); - } - - public void testChild() { - // the panel element should have exactly one child, a v-vertical-layout - assertEquals(1, panelElement.childNodes().size()); - Element vLayoutElement = panelElement.child(0); - assertEquals("v-vertical-layout", vLayoutElement.nodeName()); - assertEquals("500px", vLayoutElement.attr("width")); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/panel/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/panel/TestWriteDesign.java new file mode 100644 index 0000000000..f81193d511 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/panel/TestWriteDesign.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.panel; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.Panel; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for writing the attributes and the child element of a Panel to a + * design. + * + * @author Vaadin Ltd + */ +public class TestWriteDesign extends TestCase { + Element panelElement; + + @Override + public void setUp() { + // create a component hierarchy + Panel panel = new Panel("A panel"); + panel.setId("panelId"); + panel.setHeight("250px"); + panel.setScrollTop(50); + panel.setTabIndex(4); + VerticalLayout vLayout = new VerticalLayout(); + vLayout.setWidth("500px"); + panel.setContent(vLayout); + // synchronize to design + DesignContext ctx = new DesignContext(); + panelElement = new Element(Tag.valueOf("div"), ""); + panel.writeDesign(panelElement, ctx); + } + + public void testAttributes() { + // should have caption, id, height, scroll top and tab index + assertEquals(5, panelElement.attributes().size()); + // check the values of the attributes + assertEquals("A panel", panelElement.attr("caption")); + assertEquals("panelId", panelElement.attr("id")); + assertEquals("250px", panelElement.attr("height")); + assertEquals("50", panelElement.attr("scroll-top")); + assertEquals("4", panelElement.attr("tabindex")); + } + + public void testChild() { + // the panel element should have exactly one child, a v-vertical-layout + assertEquals(1, panelElement.childNodes().size()); + Element vLayoutElement = panelElement.child(0); + assertEquals("v-vertical-layout", vLayoutElement.nodeName()); + assertEquals("500px", vLayoutElement.attr("width")); + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestReadDesign.java new file mode 100644 index 0000000000..6a34d6584a --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestReadDesign.java @@ -0,0 +1,136 @@ +/* + * 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.tabsheet; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.server.ExternalResource; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.TabSheet.Tab; +import com.vaadin.ui.TextField; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case from reading TabSheet from design + * + * @since + * @author Vaadin Ltd + */ +public class TestReadDesign extends TestCase { + + private TabSheet sheet; + + @Override + protected void setUp() throws Exception { + super.setUp(); + sheet = createTabSheet(); + } + + public void testChildCount() { + assertEquals(1, sheet.getComponentCount()); + } + + public void testTabIndex() { + assertEquals(5, sheet.getTabIndex()); + } + + public void testTabAttributes() { + Tab tab = sheet.getTab(0); + assertEquals("test-caption", tab.getCaption()); + assertEquals(false, tab.isVisible()); + assertEquals(false, tab.isClosable()); + assertEquals(false, tab.isEnabled()); + assertEquals("http://www.vaadin.com/test.png", + ((ExternalResource) tab.getIcon()).getURL()); + assertEquals("OK", tab.getIconAlternateText()); + assertEquals("test-desc", tab.getDescription()); + assertEquals("test-style", tab.getStyleName()); + assertEquals("test-id", tab.getId()); + } + + public void testSelectedComponent() { + TabSheet tabSheet = new TabSheet(); + tabSheet.readDesign(createFirstTabSelectedDesign(), new DesignContext()); + assertEquals(tabSheet.getTab(0).getComponent(), + tabSheet.getSelectedTab()); + } + + public void testTabContent() { + assertTrue("The child for the tabsheet should be textfield", sheet + .getTab(0).getComponent() instanceof TextField); + } + + private TabSheet createTabSheet() { + TabSheet tabSheet = new TabSheet(); + // add some tabs that should be cleared on sync + tabSheet.addComponent(new Label("tab1")); + tabSheet.addComponent(new Label("tab2")); + DesignContext ctx = new DesignContext(); + Element design = createDesign(); + tabSheet.readDesign(design, ctx); + return tabSheet; + } + + private Element createDesign() { + // create root design + Attributes rootAttributes = new Attributes(); + rootAttributes.put("tabindex", "5"); + Element node = new Element(Tag.valueOf("v-tab-sheet"), "", + rootAttributes); + // create tab design + Attributes tabAttributes = new Attributes(); + tabAttributes.put("caption", "test-caption"); + tabAttributes.put("visible", "false"); + tabAttributes.put("closable", "false"); + tabAttributes.put("enabled", "false"); + tabAttributes.put("icon", "http://www.vaadin.com/test.png"); + tabAttributes.put("icon-alt", "OK"); + tabAttributes.put("description", "test-desc"); + tabAttributes.put("style-name", "test-style"); + tabAttributes.put("id", "test-id"); + Element tab = new Element(Tag.valueOf("tab"), "", tabAttributes); + // add child component to tab + tab.appendChild(new Element(Tag.valueOf("v-text-field"), "", + new Attributes())); + // add tab to root design + node.appendChild(tab); + return node; + } + + private Element createFirstTabSelectedDesign() { + // create root design + Attributes rootAttributes = new Attributes(); + Element node = new Element(Tag.valueOf("v-tab-sheet"), "", + rootAttributes); + // create tab design + Attributes tabAttributes = new Attributes(); + tabAttributes.put("selected", ""); + tabAttributes.put("caption", "test-caption"); + Element tab = new Element(Tag.valueOf("tab"), "", tabAttributes); + // add child component to tab + tab.appendChild(new Element(Tag.valueOf("v-text-field"), "", + new Attributes())); + // add tab to root design + node.appendChild(tab); + return node; + + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestSynchronizeFromDesign.java deleted file mode 100644 index 4c0a2863f0..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,137 +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.tabsheet; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.server.ExternalResource; -import com.vaadin.ui.Label; -import com.vaadin.ui.TabSheet; -import com.vaadin.ui.TabSheet.Tab; -import com.vaadin.ui.TextField; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case from reading TabSheet from design - * - * @since - * @author Vaadin Ltd - */ -public class TestSynchronizeFromDesign extends TestCase { - - private TabSheet sheet; - - @Override - protected void setUp() throws Exception { - super.setUp(); - sheet = createTabSheet(); - } - - public void testChildCount() { - assertEquals(1, sheet.getComponentCount()); - } - - public void testTabIndex() { - assertEquals(5, sheet.getTabIndex()); - } - - public void testTabAttributes() { - Tab tab = sheet.getTab(0); - assertEquals("test-caption", tab.getCaption()); - assertEquals(false, tab.isVisible()); - assertEquals(false, tab.isClosable()); - assertEquals(false, tab.isEnabled()); - assertEquals("http://www.vaadin.com/test.png", - ((ExternalResource) tab.getIcon()).getURL()); - assertEquals("OK", tab.getIconAlternateText()); - assertEquals("test-desc", tab.getDescription()); - assertEquals("test-style", tab.getStyleName()); - assertEquals("test-id", tab.getId()); - } - - public void testSelectedComponent() { - TabSheet tabSheet = new TabSheet(); - tabSheet.synchronizeFromDesign(createFirstTabSelectedDesign(), - new DesignContext()); - assertEquals(tabSheet.getTab(0).getComponent(), - tabSheet.getSelectedTab()); - } - - public void testTabContent() { - assertTrue("The child for the tabsheet should be textfield", sheet - .getTab(0).getComponent() instanceof TextField); - } - - private TabSheet createTabSheet() { - TabSheet tabSheet = new TabSheet(); - // add some tabs that should be cleared on sync - tabSheet.addComponent(new Label("tab1")); - tabSheet.addComponent(new Label("tab2")); - DesignContext ctx = new DesignContext(); - Element design = createDesign(); - tabSheet.synchronizeFromDesign(design, ctx); - return tabSheet; - } - - private Element createDesign() { - // create root design - Attributes rootAttributes = new Attributes(); - rootAttributes.put("tabindex", "5"); - Element node = new Element(Tag.valueOf("v-tab-sheet"), "", - rootAttributes); - // create tab design - Attributes tabAttributes = new Attributes(); - tabAttributes.put("caption", "test-caption"); - tabAttributes.put("visible", "false"); - tabAttributes.put("closable", "false"); - tabAttributes.put("enabled", "false"); - tabAttributes.put("icon", "http://www.vaadin.com/test.png"); - tabAttributes.put("icon-alt", "OK"); - tabAttributes.put("description", "test-desc"); - tabAttributes.put("style-name", "test-style"); - tabAttributes.put("id", "test-id"); - Element tab = new Element(Tag.valueOf("tab"), "", tabAttributes); - // add child component to tab - tab.appendChild(new Element(Tag.valueOf("v-text-field"), "", - new Attributes())); - // add tab to root design - node.appendChild(tab); - return node; - } - - private Element createFirstTabSelectedDesign() { - // create root design - Attributes rootAttributes = new Attributes(); - Element node = new Element(Tag.valueOf("v-tab-sheet"), "", - rootAttributes); - // create tab design - Attributes tabAttributes = new Attributes(); - tabAttributes.put("selected", ""); - tabAttributes.put("caption", "test-caption"); - Element tab = new Element(Tag.valueOf("tab"), "", tabAttributes); - // add child component to tab - tab.appendChild(new Element(Tag.valueOf("v-text-field"), "", - new Attributes())); - // add tab to root design - node.appendChild(tab); - return node; - - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestSynchronizeToDesign.java deleted file mode 100644 index c33a1da4d7..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestSynchronizeToDesign.java +++ /dev/null @@ -1,109 +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.tabsheet; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.server.ExternalResource; -import com.vaadin.ui.TabSheet; -import com.vaadin.ui.TabSheet.Tab; -import com.vaadin.ui.TextField; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for writing TabSheet to design - * - * @since - * @author Vaadin Ltd - */ -public class TestSynchronizeToDesign extends TestCase { - - private TabSheet sheet; - private Element design; - - @Override - protected void setUp() throws Exception { - super.setUp(); - sheet = createTabSheet(); - design = createDesign(); - sheet.synchronizeToDesign(design, createDesignContext()); - } - - public void testOnlyOneTab() { - assertEquals("There should be only one child", 1, design.children() - .size()); - } - - public void testAttributes() { - Element tabDesign = design.child(0); - assertEquals("5", design.attr("tabindex")); - assertEquals("test-caption", tabDesign.attr("caption")); - assertEquals("false", tabDesign.attr("visible")); - assertTrue(tabDesign.hasAttr("closable")); - assertTrue(tabDesign.attr("closable").equals("true") - || tabDesign.attr("closable").equals("")); - assertEquals("false", tabDesign.attr("enabled")); - assertEquals("http://www.vaadin.com/test.png", tabDesign.attr("icon")); - assertEquals("OK", tabDesign.attr("icon-alt")); - assertEquals("test-desc", tabDesign.attr("description")); - assertEquals("test-style", tabDesign.attr("style-name")); - assertEquals("test-id", tabDesign.attr("id")); - } - - public void testContent() { - Element tabDesign = design.child(0); - Element content = tabDesign.child(0); - assertEquals("Tab must have only one child", 1, tabDesign.children() - .size()); - assertEquals("v-text-field", content.tagName()); - } - - private Element createDesign() { - // make sure that the design node has old content that should be removed - Element node = new Element(Tag.valueOf("v-tab-sheet"), "", - new Attributes()); - node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); - node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); - node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); - return node; - } - - private DesignContext createDesignContext() { - return new DesignContext(); - } - - private TabSheet createTabSheet() { - TabSheet sheet = new TabSheet(); - sheet.setTabIndex(5); - sheet.addTab(new TextField()); - Tab tab = sheet.getTab(0); - tab.setCaption("test-caption"); - tab.setVisible(false); - tab.setClosable(true); - tab.setEnabled(false); - tab.setIcon(new ExternalResource("http://www.vaadin.com/test.png")); - tab.setIconAlternateText("OK"); - tab.setDescription("test-desc"); - tab.setStyleName("test-style"); - tab.setId("test-id"); - return sheet; - } - -} diff --git a/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestWriteDesign.java new file mode 100644 index 0000000000..a46b33e2d6 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/tabsheet/TestWriteDesign.java @@ -0,0 +1,109 @@ +/* + * 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.tabsheet; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.server.ExternalResource; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.TabSheet.Tab; +import com.vaadin.ui.TextField; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for writing TabSheet to design + * + * @since + * @author Vaadin Ltd + */ +public class TestWriteDesign extends TestCase { + + private TabSheet sheet; + private Element design; + + @Override + protected void setUp() throws Exception { + super.setUp(); + sheet = createTabSheet(); + design = createDesign(); + sheet.writeDesign(design, createDesignContext()); + } + + public void testOnlyOneTab() { + assertEquals("There should be only one child", 1, design.children() + .size()); + } + + public void testAttributes() { + Element tabDesign = design.child(0); + assertEquals("5", design.attr("tabindex")); + assertEquals("test-caption", tabDesign.attr("caption")); + assertEquals("false", tabDesign.attr("visible")); + assertTrue(tabDesign.hasAttr("closable")); + assertTrue(tabDesign.attr("closable").equals("true") + || tabDesign.attr("closable").equals("")); + assertEquals("false", tabDesign.attr("enabled")); + assertEquals("http://www.vaadin.com/test.png", tabDesign.attr("icon")); + assertEquals("OK", tabDesign.attr("icon-alt")); + assertEquals("test-desc", tabDesign.attr("description")); + assertEquals("test-style", tabDesign.attr("style-name")); + assertEquals("test-id", tabDesign.attr("id")); + } + + public void testContent() { + Element tabDesign = design.child(0); + Element content = tabDesign.child(0); + assertEquals("Tab must have only one child", 1, tabDesign.children() + .size()); + assertEquals("v-text-field", content.tagName()); + } + + private Element createDesign() { + // make sure that the design node has old content that should be removed + Element node = new Element(Tag.valueOf("v-tab-sheet"), "", + new Attributes()); + node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); + node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); + node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); + return node; + } + + private DesignContext createDesignContext() { + return new DesignContext(); + } + + private TabSheet createTabSheet() { + TabSheet sheet = new TabSheet(); + sheet.setTabIndex(5); + sheet.addTab(new TextField()); + Tab tab = sheet.getTab(0); + tab.setCaption("test-caption"); + tab.setVisible(false); + tab.setClosable(true); + tab.setEnabled(false); + tab.setIcon(new ExternalResource("http://www.vaadin.com/test.png")); + tab.setIconAlternateText("OK"); + tab.setDescription("test-desc"); + tab.setStyleName("test-style"); + tab.setId("test-id"); + return sheet; + } + +} diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/textarea/TestReadDesign.java new file mode 100644 index 0000000000..a31367008a --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/textarea/TestReadDesign.java @@ -0,0 +1,59 @@ +/* + * 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.textarea; + +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.TextArea; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for reading the value of the TextField from design + * + * @author Vaadin Ltd + */ +public class TestReadDesign extends TestCase { + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + public void testValue() { + Element design = createDesign(); + AbstractTextField component = getComponent(); + component.readDesign(design, ctx); + assertEquals("test value", component.getValue()); + } + + private AbstractTextField getComponent() { + return new TextArea(); + } + + private Element createDesign() { + Attributes attributes = new Attributes(); + Element node = new Element(Tag.valueOf("v-text-area"), "", attributes); + node.html("test value"); + return node; + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeFromDesign.java deleted file mode 100644 index 787eac0a03..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,59 +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.textarea; - -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.TextArea; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for reading the value of the TextField from design - * - * @author Vaadin Ltd - */ -public class TestSynchronizeFromDesign extends TestCase { - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - public void testValue() { - Element design = createDesign(); - AbstractTextField component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals("test value", component.getValue()); - } - - private AbstractTextField getComponent() { - return new TextArea(); - } - - private Element createDesign() { - Attributes attributes = new Attributes(); - Element node = new Element(Tag.valueOf("v-text-area"), "", attributes); - node.html("test value"); - return node; - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeToDesign.java deleted file mode 100644 index a316b02ddc..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeToDesign.java +++ /dev/null @@ -1,60 +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.textarea; - -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.TextArea; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for writing the value of the TextField to design - * - * @author Vaadin Ltd - */ -public class TestSynchronizeToDesign extends TestCase { - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - public void testSynchronizeValue() { - Element design = createDesign(); - AbstractTextField component = getComponent(); - component.setValue("test value"); - component.synchronizeToDesign(design, ctx); - assertEquals("test value", design.html()); - assertFalse(design.hasAttr("value")); - } - - private AbstractTextField getComponent() { - return new TextArea(); - } - - private Element createDesign() { - Attributes attr = new Attributes(); - return new Element(Tag.valueOf("v-text-area"), "", attr); - } - -} diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/textarea/TestWriteDesign.java new file mode 100644 index 0000000000..01b0095fe9 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/textarea/TestWriteDesign.java @@ -0,0 +1,60 @@ +/* + * 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.textarea; + +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.TextArea; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for writing the value of the TextField to design + * + * @author Vaadin Ltd + */ +public class TestWriteDesign extends TestCase { + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + public void testSynchronizeValue() { + Element design = createDesign(); + AbstractTextField component = getComponent(); + component.setValue("test value"); + component.writeDesign(design, ctx); + assertEquals("test value", design.html()); + assertFalse(design.hasAttr("value")); + } + + private AbstractTextField getComponent() { + return new TextArea(); + } + + private Element createDesign() { + Attributes attr = new Attributes(); + return new Element(Tag.valueOf("v-text-area"), "", attr); + } + +} diff --git a/server/tests/src/com/vaadin/tests/server/component/textfield/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/textfield/TestReadDesign.java new file mode 100644 index 0000000000..62cb1a53bc --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/textfield/TestReadDesign.java @@ -0,0 +1,59 @@ +/* + * 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.textfield; + +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.TextField; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for reading the value of the TextField from design + * + * @author Vaadin Ltd + */ +public class TestReadDesign extends TestCase { + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + public void testValue() { + Element design = createDesign(); + AbstractTextField component = getComponent(); + component.readDesign(design, ctx); + assertEquals("test value", component.getValue()); + } + + private AbstractTextField getComponent() { + return new TextField(); + } + + private Element createDesign() { + Attributes attributes = new Attributes(); + attributes.put("value", "test value"); + Element node = new Element(Tag.valueOf("v-text-field"), "", attributes); + return node; + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeFromDesign.java deleted file mode 100644 index 2df0ab4855..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeFromDesign.java +++ /dev/null @@ -1,59 +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.textfield; - -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.TextField; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for reading the value of the TextField from design - * - * @author Vaadin Ltd - */ -public class TestSynchronizeFromDesign extends TestCase { - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - public void testValue() { - Element design = createDesign(); - AbstractTextField component = getComponent(); - component.synchronizeFromDesign(design, ctx); - assertEquals("test value", component.getValue()); - } - - private AbstractTextField getComponent() { - return new TextField(); - } - - private Element createDesign() { - Attributes attributes = new Attributes(); - attributes.put("value", "test value"); - Element node = new Element(Tag.valueOf("v-text-field"), "", attributes); - return node; - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeToDesign.java deleted file mode 100644 index 58d361e683..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeToDesign.java +++ /dev/null @@ -1,59 +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.textfield; - -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.TextField; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Test case for writing the value of the TextField to design - * - * @author Vaadin Ltd - */ -public class TestSynchronizeToDesign extends TestCase { - private DesignContext ctx; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ctx = new DesignContext(); - } - - public void testSynchronizeValue() { - Element design = createDesign(); - AbstractTextField component = getComponent(); - component.setValue("test value"); - component.synchronizeToDesign(design, ctx); - assertEquals("test value", design.attr("value")); - } - - 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/textfield/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/textfield/TestWriteDesign.java new file mode 100644 index 0000000000..479c94f6a8 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/textfield/TestWriteDesign.java @@ -0,0 +1,59 @@ +/* + * 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.textfield; + +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.TextField; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for writing the value of the TextField to design + * + * @author Vaadin Ltd + */ +public class TestWriteDesign extends TestCase { + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + public void testSynchronizeValue() { + Element design = createDesign(); + AbstractTextField component = getComponent(); + component.setValue("test value"); + component.writeDesign(design, ctx); + assertEquals("test value", design.attr("value")); + } + + private AbstractTextField getComponent() { + return new TextField(); + } + + private Element createDesign() { + Attributes attr = new Attributes(); + return new Element(Tag.valueOf("v-text-field"), "", attr); + } + +} -- cgit v1.2.3