diff options
3 files changed, 113 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.html b/server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.html new file mode 100644 index 0000000000..86c9c2a2da --- /dev/null +++ b/server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.html @@ -0,0 +1,5 @@ +<v-vertical-layout> + <v-text-field caption="First name" /> + <v-text-field caption="Last name" /> + <v-button>OK!</v-button> +</v-vertical-layout>
\ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.java b/server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.java new file mode 100644 index 0000000000..ce80d98324 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.java @@ -0,0 +1,31 @@ +/* + * 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 org.junit.Ignore; + +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.declarative.Design; + +@Ignore +public class DesignReadInConstructor extends CssLayout { + + public DesignReadInConstructor() { + Design.read( + getClass().getResourceAsStream("DesignReadInConstructor.html"), + this); + } +} diff --git a/server/tests/src/com/vaadin/tests/design/DesignReadInConstructorTest.java b/server/tests/src/com/vaadin/tests/design/DesignReadInConstructorTest.java new file mode 100644 index 0000000000..539595762d --- /dev/null +++ b/server/tests/src/com/vaadin/tests/design/DesignReadInConstructorTest.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.design; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Attribute; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +import com.vaadin.ui.declarative.Design; + +public class DesignReadInConstructorTest { + + @Test + public void useDesignReadInConstructor() { + DesignReadInConstructor dric = new DesignReadInConstructor(); + Assert.assertEquals(3, dric.getComponentCount()); + } + + @Test + @Ignore("Can't currently work. There is no way to write a custom component which manually reads its design in the constructor") + public void readAndWriteDesignReadInConstructor() throws IOException { + DesignReadInConstructor dric = new DesignReadInConstructor(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Design.write(dric, baos); + Document doc = Jsoup.parse(baos.toString("UTF-8")); + + Document d = Jsoup.parse( + getClass().getResourceAsStream("DesignReadInConstructor.html"), + "UTF-8", ""); + assertJsoupTreeEquals(d.body().child(0), doc.body().child(0)); + } + + private void assertJsoupTreeEquals(Element expected, Element actual) { + Assert.assertEquals(expected.tagName(), actual.tagName()); + + Set<String> keys = new HashSet<String>(); + + for (Attribute attr : expected.attributes().asList()) { + keys.add(attr.getKey()); + } + for (Attribute attr : actual.attributes().asList()) { + keys.add(attr.getKey()); + } + for (String attributeKey : keys) { + Assert.assertEquals(expected.attr(attributeKey), + actual.attr(attributeKey)); + } + + Assert.assertEquals(expected.children().size(), actual.children() + .size()); + for (int i = 0; i < expected.children().size(); i++) { + assertJsoupTreeEquals(expected.child(i), actual.child(i)); + } + } +} |