aboutsummaryrefslogtreecommitdiffstats
path: root/server/tests/src/com/vaadin
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2014-12-15 23:02:22 +0200
committerArtur Signell <artur@vaadin.com>2014-12-15 23:04:41 +0200
commit353206974a542d0aadc278dea4adeff226fb3a9e (patch)
treebd6511b2d62cefaaa88f5131abf69f11a1cd12e5 /server/tests/src/com/vaadin
parent8eafe7aee31b3e2f80c87b39c4e42e260a86a5eb (diff)
downloadvaadin-framework-353206974a542d0aadc278dea4adeff226fb3a9e.tar.gz
vaadin-framework-353206974a542d0aadc278dea4adeff226fb3a9e.zip
Fix writing issues (#7749)
* A root component with @DesignRoot must always use its superclass for default values. Otherwise the written design will be empty as the design is read in the constructor. * A component which is not the root must not write its component tree if the component tree is generated in the constructor. This is a simplification which should be good enough for most cases (can't add children in constructor and also using addComponent - in this case the component added with addComponent will not be written). * Test cases for nested templates Change-Id: I3a384d1d8654b9865a3a790ebeb055a300a62135
Diffstat (limited to 'server/tests/src/com/vaadin')
-rw-r--r--server/tests/src/com/vaadin/tests/design/nested/MyChildDesign.java40
-rw-r--r--server/tests/src/com/vaadin/tests/design/nested/MyChildDesignCustomComponent.java25
-rw-r--r--server/tests/src/com/vaadin/tests/design/nested/MyDesignRoot.java38
-rw-r--r--server/tests/src/com/vaadin/tests/design/nested/MyExtendedChildDesign.java25
-rw-r--r--server/tests/src/com/vaadin/tests/design/nested/TestReadNestedTemplates.java62
-rw-r--r--server/tests/src/com/vaadin/tests/design/nested/TestWriteNestedTemplates.java89
-rw-r--r--server/tests/src/com/vaadin/tests/design/nested/mychilddesign.html12
-rw-r--r--server/tests/src/com/vaadin/tests/design/nested/mydesignroot.html10
8 files changed, 301 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/design/nested/MyChildDesign.java b/server/tests/src/com/vaadin/tests/design/nested/MyChildDesign.java
new file mode 100644
index 0000000000..e85c0aca5f
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/design/nested/MyChildDesign.java
@@ -0,0 +1,40 @@
+/*
+ * 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.design.nested;
+
+import org.junit.Ignore;
+
+import com.vaadin.annotations.DesignRoot;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.declarative.Design;
+
+/**
+ * Child design component
+ *
+ * @author Vaadin Ltd
+ */
+@Ignore
+@DesignRoot("mychilddesign.html")
+public class MyChildDesign extends HorizontalLayout {
+ public Label childLabel;
+ public MyChildDesignCustomComponent childCustomComponent;
+
+ public MyChildDesign() {
+ Design.read(this);
+ childLabel.setDescription("added in constructor");
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/design/nested/MyChildDesignCustomComponent.java b/server/tests/src/com/vaadin/tests/design/nested/MyChildDesignCustomComponent.java
new file mode 100644
index 0000000000..94e34baea2
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/design/nested/MyChildDesignCustomComponent.java
@@ -0,0 +1,25 @@
+/*
+ * 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.design.nested;
+
+import org.junit.Ignore;
+
+import com.vaadin.ui.Button;
+
+@Ignore
+public class MyChildDesignCustomComponent extends Button {
+
+}
diff --git a/server/tests/src/com/vaadin/tests/design/nested/MyDesignRoot.java b/server/tests/src/com/vaadin/tests/design/nested/MyDesignRoot.java
new file mode 100644
index 0000000000..5727322ce3
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/design/nested/MyDesignRoot.java
@@ -0,0 +1,38 @@
+/*
+ * 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.design.nested;
+
+import org.junit.Ignore;
+
+import com.vaadin.annotations.DesignRoot;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.declarative.Design;
+
+/**
+ * Root design component
+ *
+ * @author Vaadin Ltd
+ */
+@Ignore
+@DesignRoot("mydesignroot.html")
+public class MyDesignRoot extends VerticalLayout {
+ // should be assigned automatically
+ public MyExtendedChildDesign childDesign;
+
+ public MyDesignRoot() {
+ Design.read(this);
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/design/nested/MyExtendedChildDesign.java b/server/tests/src/com/vaadin/tests/design/nested/MyExtendedChildDesign.java
new file mode 100644
index 0000000000..2012e4ec14
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/design/nested/MyExtendedChildDesign.java
@@ -0,0 +1,25 @@
+/*
+ * 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.design.nested;
+
+import org.junit.Ignore;
+
+@Ignore
+public class MyExtendedChildDesign extends MyChildDesign {
+ public MyExtendedChildDesign() {
+ super();
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/design/nested/TestReadNestedTemplates.java b/server/tests/src/com/vaadin/tests/design/nested/TestReadNestedTemplates.java
new file mode 100644
index 0000000000..c1483adc8a
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/design/nested/TestReadNestedTemplates.java
@@ -0,0 +1,62 @@
+/*
+ * 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.design.nested;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for reading nested templates
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class TestReadNestedTemplates extends TestCase {
+
+ private MyDesignRoot root;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ root = new MyDesignRoot();
+ }
+
+ public void testChildren() {
+ assertEquals("The root layout must contain one child", 1,
+ root.getComponentCount());
+ assertTrue(root.iterator().next() instanceof MyExtendedChildDesign);
+ }
+
+ public void testGrandChildren() {
+ assertEquals("The root layout must have two grandchildren", 2,
+ root.childDesign.getComponentCount());
+ }
+
+ public void testRootComponentFields() {
+ assertNotNull("The child component must not be null", root.childDesign);
+ }
+
+ public void testChildComponentFields() {
+ assertNotNull("Grandchildren must not be null",
+ root.childDesign.childLabel);
+ assertNotNull("Grandchildren must not be null",
+ root.childDesign.childCustomComponent);
+ assertEquals("child label caption must be read", "test content",
+ root.childDesign.childLabel.getValue());
+ assertEquals("child custom component caption must be read",
+ "custom content",
+ root.childDesign.childCustomComponent.getCaption());
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/design/nested/TestWriteNestedTemplates.java b/server/tests/src/com/vaadin/tests/design/nested/TestWriteNestedTemplates.java
new file mode 100644
index 0000000000..7fe63baa73
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/design/nested/TestWriteNestedTemplates.java
@@ -0,0 +1,89 @@
+/*
+ * 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.design.nested;
+
+import junit.framework.TestCase;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ *
+ * Test case for writing nested templates
+ *
+ * @author Vaadin Ltd
+ */
+public class TestWriteNestedTemplates extends TestCase {
+
+ private MyDesignRoot root;
+ private Element design;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ root = new MyDesignRoot();
+ design = createDesign();
+ DesignContext designContext = new DesignContext();
+ designContext.setRootComponent(root);
+ root.writeDesign(design, designContext);
+ }
+
+ public void testChildRendered() {
+ assertEquals("Root layout must have one child", 1, design.children()
+ .size());
+ assertEquals("com_vaadin_tests_design_nested-my-extended-child-design",
+ design.child(0).tagName());
+ }
+
+ public void testRootCaptionWritten() {
+ assertTrue("Root layout caption must be written",
+ design.hasAttr("caption"));
+ assertEquals("Root layout caption must be written", "root caption",
+ design.attr("caption"));
+ }
+
+ public void testChildCaptionWritten() {
+ assertTrue("Child design caption must be written", design.child(0)
+ .hasAttr("caption"));
+ assertEquals("Child design caption must be written", "child caption",
+ design.child(0).attr("caption"));
+ }
+
+ // The default caption is read from child template
+ public void testDefaultCaptionShouldNotBeWritten() {
+ design = createDesign();
+ root.childDesign.setCaption("Default caption for child design");
+ DesignContext designContext = new DesignContext();
+ designContext.setRootComponent(root);
+ root.writeDesign(design, designContext);
+ assertFalse("Default caption must not be written", design.child(0)
+ .hasAttr("caption"));
+ }
+
+ public void testChildDesignChildrenNotWrittenInRootTemplate() {
+ assertEquals(
+ "Children of the child template must not be written to root template",
+ 0, design.child(0).children().size());
+ }
+
+ private Element createDesign() {
+ return new Element(Tag.valueOf("v-vertical-layout"), "",
+ new Attributes());
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/design/nested/mychilddesign.html b/server/tests/src/com/vaadin/tests/design/nested/mychilddesign.html
new file mode 100644
index 0000000000..c636033d2d
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/design/nested/mychilddesign.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta name="package-mapping" content="x:com.vaadin.tests.design.nested"/>
+ </head>
+ <body>
+ <v-horizontal-layout caption="Default caption for child design">
+ <v-label _id="childLabel">test content</v-label>
+ <!-- Test some custom component in child template -->
+ <x-my-child-design-custom-component _id="childCustomComponent">custom content</x-my-child-design-custom-component>
+ </v-horizontal-layout>
+</body> \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/design/nested/mydesignroot.html b/server/tests/src/com/vaadin/tests/design/nested/mydesignroot.html
new file mode 100644
index 0000000000..55ac27c194
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/design/nested/mydesignroot.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta name="package-mapping" content="x:com.vaadin.tests.design.nested"/>
+ </head>
+ <body>
+ <v-vertical-layout caption="root caption">
+ <x-my-extended-child-design _id="childDesign" caption="child caption"/>
+ </v-vertical-layout>
+ </body> \ No newline at end of file