aboutsummaryrefslogtreecommitdiffstats
path: root/server/tests/src/com
diff options
context:
space:
mode:
authorMatti Hosio <mhosio@vaadin.com>2014-12-05 11:27:29 +0200
committerVaadin Code Review <review@vaadin.com>2014-12-08 18:19:47 +0000
commit18b333ee3dfd171956829e97a32baa8069346c65 (patch)
treed02139df7b7843b06b70629c35c7954d689826af /server/tests/src/com
parentbd78a4c8b2eb84cbba3bc686bcb40b19fd847640 (diff)
downloadvaadin-framework-18b333ee3dfd171956829e97a32baa8069346c65.tar.gz
vaadin-framework-18b333ee3dfd171956829e97a32baa8069346c65.zip
Support for automatic binding of the fields of the root layout (#7749)
The fields are bound to the components generated when parsing the design. The binding is done based on localId, id or caption. Change-Id: I32ecac3cb76737c9d9d05a123db85fe65d55369c
Diffstat (limited to 'server/tests/src/com')
-rw-r--r--server/tests/src/com/vaadin/tests/layoutparser/InvalidLayoutTemplate.java55
-rw-r--r--server/tests/src/com/vaadin/tests/layoutparser/LayoutTemplate.java49
-rw-r--r--server/tests/src/com/vaadin/tests/layoutparser/ParseLayoutTest.java40
3 files changed, 144 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/layoutparser/InvalidLayoutTemplate.java b/server/tests/src/com/vaadin/tests/layoutparser/InvalidLayoutTemplate.java
new file mode 100644
index 0000000000..9447acb37e
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/layoutparser/InvalidLayoutTemplate.java
@@ -0,0 +1,55 @@
+/*
+ * 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.layoutparser;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.NativeButton;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class InvalidLayoutTemplate extends VerticalLayout {
+ private NativeButton firstButton;
+ private NativeButton secondButton;
+ private NativeButton yetanotherbutton; // generated based on caption
+ private Button clickme; // generated based on caption
+ private TextField shouldNotBeMapped;
+
+ public NativeButton getFirstButton() {
+ return firstButton;
+ }
+
+ public NativeButton getSecondButton() {
+ return secondButton;
+ }
+
+ public NativeButton getYetanotherbutton() {
+ return yetanotherbutton;
+ }
+
+ public Button getClickme() {
+ return clickme;
+ }
+
+ public TextField getShouldNotBeMapped() {
+ return shouldNotBeMapped;
+ }
+
+}
diff --git a/server/tests/src/com/vaadin/tests/layoutparser/LayoutTemplate.java b/server/tests/src/com/vaadin/tests/layoutparser/LayoutTemplate.java
new file mode 100644
index 0000000000..72131826ba
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/layoutparser/LayoutTemplate.java
@@ -0,0 +1,49 @@
+/*
+ * 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.layoutparser;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.NativeButton;
+import com.vaadin.ui.VerticalLayout;
+
+/**
+ * Template to be populated in the tests
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class LayoutTemplate extends VerticalLayout {
+ private NativeButton firstButton; // assigned based on local id
+ private NativeButton secondButton; // assigned based on id
+ private NativeButton yetanotherbutton; // assigned based on caption
+ private Button clickme; // assigned based on caption
+
+ public NativeButton getFirstButton() {
+ return firstButton;
+ }
+
+ public NativeButton getSecondButton() {
+ return secondButton;
+ }
+
+ public NativeButton getYetanotherbutton() {
+ return yetanotherbutton;
+ }
+
+ public Button getClickme() {
+ return clickme;
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/layoutparser/ParseLayoutTest.java b/server/tests/src/com/vaadin/tests/layoutparser/ParseLayoutTest.java
index adba5e57b9..1c4d50cc55 100644
--- a/server/tests/src/com/vaadin/tests/layoutparser/ParseLayoutTest.java
+++ b/server/tests/src/com/vaadin/tests/layoutparser/ParseLayoutTest.java
@@ -18,6 +18,7 @@ package com.vaadin.tests.layoutparser;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import junit.framework.TestCase;
@@ -35,6 +36,7 @@ import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.declarative.DesignContext;
+import com.vaadin.ui.declarative.DesignException;
import com.vaadin.ui.declarative.LayoutHandler;
/**
@@ -106,6 +108,43 @@ public class ParseLayoutTest extends TestCase {
}
/*
+ * Check that the field binding works if root instance with member fields is
+ * passed to the LayoutHandler
+ *
+ * @throws IOException
+ */
+ public void testFieldBinding() throws IOException {
+ LayoutTemplate template = new LayoutTemplate();
+ InputStream htmlFile = new FileInputStream(
+ "server/tests/src/com/vaadin/tests/layoutparser/testFile.html");
+ LayoutHandler.parse(htmlFile, template);
+ assertNotNull(template.getFirstButton());
+ assertNotNull(template.getSecondButton());
+ assertNotNull(template.getYetanotherbutton());
+ assertNotNull(template.getClickme());
+ assertEquals("Native click me", template.getFirstButton().getCaption());
+ }
+
+ /*
+ * Check that the field binding fails if some of the fields in the root
+ * instance were not bound
+ *
+ * @throws IOException
+ */
+ public void testUnboundFields() throws IOException {
+ InvalidLayoutTemplate template = new InvalidLayoutTemplate();
+ InputStream htmlFile = new FileInputStream(
+ "server/tests/src/com/vaadin/tests/layoutparser/testFile.html");
+ try {
+ LayoutHandler.parse(htmlFile, template);
+ // we are expecting an exception
+ fail();
+ } catch (DesignException e) {
+ // expected
+ }
+ }
+
+ /*
* Checks that the correct components occur in the correct order in the
* component hierarchy rooted at context.getComponentRoot().
*/
@@ -173,4 +212,5 @@ public class ParseLayoutTest extends TestCase {
assertTrue("The found button is incorrect.", thirdButton.getCaption()
.equals("Yet another button"));
}
+
}