summaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
authorMika Murtojarvi <mika@vaadin.com>2014-12-17 18:10:09 +0200
committerVaadin Code Review <review@vaadin.com>2014-12-18 16:35:13 +0000
commitbedbe2bf818385bb2356224a40c49de8f8056749 (patch)
treeb0af334ef885d733eb38b19a231494549c0e9563 /server/tests
parent68eec666b55c42b4a55235c00bc78f6212eb2062 (diff)
downloadvaadin-framework-bedbe2bf818385bb2356224a40c49de8f8056749.tar.gz
vaadin-framework-bedbe2bf818385bb2356224a40c49de8f8056749.zip
Allow reading and writing empty designs (#7749).
Change-Id: Id66201d040d07f0e0d731418624c9b702b2d0d3b
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/TestReadEmptyDesign.java78
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/TestWriteEmptyDesign.java58
2 files changed, 136 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/server/component/TestReadEmptyDesign.java b/server/tests/src/com/vaadin/tests/server/component/TestReadEmptyDesign.java
new file mode 100644
index 0000000000..ecd303b678
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/TestReadEmptyDesign.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;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.DocumentType;
+import org.jsoup.nodes.Element;
+
+import com.vaadin.ui.Component;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.declarative.Design;
+import com.vaadin.ui.declarative.DesignContext;
+import com.vaadin.ui.declarative.DesignException;
+
+/**
+ * Test cases for checking that reading a design with no elements in the html
+ * body produces null as the root component.
+ */
+public class TestReadEmptyDesign extends TestCase {
+ InputStream is;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ String html = createDesign().toString();
+ is = new ByteArrayInputStream(html.getBytes());
+ }
+
+ public void testReadComponent() {
+ Component root = Design.read(is);
+ assertNull("The root component should be null.", root);
+ }
+
+ public void testReadContext() {
+ DesignContext ctx = Design.read(is, null);
+ assertNotNull("The design context should not be null.", ctx);
+ assertNull("The root component should be null.", ctx.getRootComponent());
+ }
+
+ public void testReadContextWithRootParameter() {
+ try {
+ Component rootComponent = new VerticalLayout();
+ DesignContext ctx = Design.read(is, rootComponent);
+ fail("Reading a design with no elements should fail when a non-null root Component is specified.");
+ } catch (DesignException e) {
+ // This is the expected outcome, nothing to do.
+ }
+ }
+
+ private Document createDesign() {
+ Document doc = new Document("");
+ DocumentType docType = new DocumentType("html", "", "", "");
+ doc.appendChild(docType);
+ Element html = doc.createElement("html");
+ doc.appendChild(html);
+ html.appendChild(doc.createElement("head"));
+ html.appendChild(doc.createElement("body"));
+ return doc;
+ }
+} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/TestWriteEmptyDesign.java b/server/tests/src/com/vaadin/tests/server/component/TestWriteEmptyDesign.java
new file mode 100644
index 0000000000..b50915f1fd
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/TestWriteEmptyDesign.java
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+
+import com.vaadin.ui.Component;
+import com.vaadin.ui.declarative.Design;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Test cases for checking that writing a component hierarchy with null root
+ * produces an html document that has no elements in the html body.
+ */
+public class TestWriteEmptyDesign extends TestCase {
+
+ public void testWriteComponent() throws IOException {
+ OutputStream os = new ByteArrayOutputStream();
+ Design.write((Component) null, os);
+ checkHtml(os.toString());
+ }
+
+ public void testWriteContext() throws IOException {
+ OutputStream os = new ByteArrayOutputStream();
+ DesignContext ctx = new DesignContext();
+ ctx.setRootComponent(null);
+ Design.write(ctx, os);
+ checkHtml(os.toString());
+ }
+
+ private void checkHtml(String html) {
+ Document doc = Jsoup.parse(html);
+ Element body = doc.body();
+ assertEquals("There should be no elements in the html body.", "",
+ body.html());
+ }
+} \ No newline at end of file