diff options
author | Artur Signell <artur@vaadin.com> | 2015-10-01 21:05:29 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-10-01 22:43:32 +0300 |
commit | 6d47320640275234a736ab29979a0dfd8eba4084 (patch) | |
tree | 2df6909ef68c4ebd1d288f50cbb116c61d23156e /server/tests | |
parent | 00dc7ab85e8fd533854ccc50b788012cf1450342 (diff) | |
download | vaadin-framework-6d47320640275234a736ab29979a0dfd8eba4084.tar.gz vaadin-framework-6d47320640275234a736ab29979a0dfd8eba4084.zip |
Do not use getters/setters when mapping designer fields (#17388)
Change-Id: I5c03beca2b5f00c6efb32980e5e5ddf36cc4f16a
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/src/com/vaadin/tests/design/FieldNameWhichConflictsWithGettersTest.java | 82 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/design/MyVerticalLayout.html | 4 |
2 files changed, 86 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/design/FieldNameWhichConflictsWithGettersTest.java b/server/tests/src/com/vaadin/tests/design/FieldNameWhichConflictsWithGettersTest.java new file mode 100644 index 0000000000..8c8d7b78b1 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/design/FieldNameWhichConflictsWithGettersTest.java @@ -0,0 +1,82 @@ +/* + * 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; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.annotations.DesignRoot; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.Design; +import com.vaadin.ui.declarative.DesignContext; + +public class FieldNameWhichConflictsWithGettersTest { + + @DesignRoot("MyVerticalLayout.html") + public static class MyVerticalLayout extends VerticalLayout { + private Label caption; + private TextField description; + + public MyVerticalLayout() { + Design.read(this); + } + } + + @Test + public void readWithConflictingFields() { + MyVerticalLayout v = new MyVerticalLayout(); + Assert.assertNotNull(v.caption); + Assert.assertNotNull(v.description); + } + + @Test + public void writeWithConflictingFields() throws IOException { + VerticalLayout v = new VerticalLayout(); + Label l = new Label(); + l.setId("caption"); + TextField tf = new TextField(); + v.addComponents(l, tf); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + DesignContext context = new DesignContext(); + context.setComponentLocalId(tf, "description"); + context.setRootComponent(v); + + Design.write(context, baos); + String str = baos.toString("UTF-8"); + + Document doc = Jsoup.parse(str); + Element body = doc.body(); + Element captionElement = body.getElementById("caption"); + Assert.assertNotNull(captionElement); + Assert.assertEquals("vaadin-label", captionElement.tagName()); + + Element descriptionElement = captionElement.nextElementSibling(); + Assert.assertNotNull(descriptionElement); + Assert.assertEquals("vaadin-text-field", descriptionElement.tagName()); + Assert.assertEquals("description", descriptionElement.attr("_id")); + + } +} diff --git a/server/tests/src/com/vaadin/tests/design/MyVerticalLayout.html b/server/tests/src/com/vaadin/tests/design/MyVerticalLayout.html new file mode 100644 index 0000000000..f6f4d98259 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/design/MyVerticalLayout.html @@ -0,0 +1,4 @@ +<v-vertical-layout> + <v-label _id="caption" /> + <v-text-field id="description" /> +</v-vertical-layout>
\ No newline at end of file |