summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/navigator/Navigator.java11
-rw-r--r--server/src/com/vaadin/server/VaadinServlet.java4
-rw-r--r--server/src/com/vaadin/ui/Grid.java10
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java63
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractfield/ReadDesignTest.java71
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractfield/WriteDesignTest.java77
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java178
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/ReadDesignTest.java119
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/WriteDesignTest.java148
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/AbstractSplitPanelDeclarativeTest.java110
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/ReadDesignTest.java158
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/WriteDesignTest.java151
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java52
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstracttextfield/ReadDesignTest.java73
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstracttextfield/WriteDesignTest.java73
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java106
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/button/ReadDesignTest.java129
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/button/WriteDesignTest.java103
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java31
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/checkbox/ReadDesignTest.java67
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/checkbox/WriteDesignTest.java57
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/csslayout/CssLayoutDeclarativeTest.java96
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/csslayout/ReadDesignTest.java74
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/csslayout/WriteDesignTest.java78
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeAttributeTest.java14
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java110
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/label/ReadDesignTest.java102
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/label/WriteDesignTest.java126
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/panel/PanelDeclarativeTest.java62
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/panel/ReadDesignTest.java98
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/panel/WriteDesignTest.java71
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/tabsheet/ReadDesignTest.java132
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/tabsheet/TabSheetDeclarativeTest.java98
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/tabsheet/WriteDesignTest.java109
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/textarea/ReadDesignTest.java59
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java28
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/textarea/WriteDesignTest.java60
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/textfield/ReadDesignTest.java59
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java25
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/textfield/WriteDesignTest.java59
40 files changed, 852 insertions, 2399 deletions
diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java
index ef5c61a294..65b3fec488 100644
--- a/server/src/com/vaadin/navigator/Navigator.java
+++ b/server/src/com/vaadin/navigator/Navigator.java
@@ -32,6 +32,7 @@ package com.vaadin.navigator;
*/
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -597,7 +598,10 @@ public class Navigator implements Serializable {
* block the navigation operation
*/
protected boolean fireBeforeViewChange(ViewChangeEvent event) {
- for (ViewChangeListener l : listeners) {
+ // a copy of the listener list is needed to avoid
+ // ConcurrentModificationException as a listener can add/remove
+ // listeners
+ for (ViewChangeListener l : new ArrayList<ViewChangeListener>(listeners)) {
if (!l.beforeViewChange(event)) {
return false;
}
@@ -647,7 +651,10 @@ public class Navigator implements Serializable {
* view change event (not null)
*/
protected void fireAfterViewChange(ViewChangeEvent event) {
- for (ViewChangeListener l : listeners) {
+ // a copy of the listener list is needed to avoid
+ // ConcurrentModificationException as a listener can add/remove
+ // listeners
+ for (ViewChangeListener l : new ArrayList<ViewChangeListener>(listeners)) {
l.afterViewChange(event);
}
}
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java
index aa76dc8e08..3eb2ce24c1 100644
--- a/server/src/com/vaadin/server/VaadinServlet.java
+++ b/server/src/com/vaadin/server/VaadinServlet.java
@@ -336,11 +336,11 @@ public class VaadinServlet extends HttpServlet implements Constants {
return;
}
- if (isStaticResourceRequest(request)) {
+ if (isStaticResourceRequest(vaadinRequest)) {
// Define current servlet and service, but no request and response
getService().setCurrentInstances(null, null);
try {
- serveStaticResources(request, response);
+ serveStaticResources(vaadinRequest, vaadinResponse);
return;
} finally {
CurrentInstance.clearAll();
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index a7ff15c8dd..504e0e6eae 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -5985,10 +5985,6 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
setEditorEnabled(DesignAttributeHandler.readAttribute("editable",
attrs, boolean.class));
}
- if (attrs.hasKey("frozen-columns")) {
- setFrozenColumnCount(DesignAttributeHandler.readAttribute(
- "frozen-columns", attrs, int.class));
- }
if (attrs.hasKey("rows")) {
setHeightByRows(DesignAttributeHandler.readAttribute("rows", attrs,
double.class));
@@ -6045,6 +6041,12 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
}
}
}
+
+ // Read frozen columns after columns are read.
+ if (attrs.hasKey("frozen-columns")) {
+ setFrozenColumnCount(DesignAttributeHandler.readAttribute(
+ "frozen-columns", attrs, int.class));
+ }
}
@Override
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java
index f415a5fd18..dbd945a3d8 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java
@@ -15,11 +15,18 @@
*/
package com.vaadin.tests.server.component.abstractfield;
+import static org.junit.Assert.assertTrue;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
import org.junit.Test;
+import com.vaadin.data.util.ObjectProperty;
import com.vaadin.tests.design.DeclarativeTestBase;
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.TextField;
+import com.vaadin.ui.declarative.DesignContext;
/**
* Tests declarative support for implementations of {@link AbstractField}.
@@ -31,23 +38,12 @@ public class AbstractFieldDeclarativeTest extends
DeclarativeTestBase<AbstractField<?>> {
@Test
- public void testPlainTextRead() {
- testRead(getDesign(), getExpected());
- }
-
- @Test
- public void testPlainTextWrite() {
- testWrite(getDesign(), getExpected());
- }
-
- protected String getDesign() {
- return "<v-text-field buffered='true' validation-visible='false' invalid-committed='true'"
+ public void testPlainText() {
+ String design = "<v-text-field buffered='true' validation-visible='false' invalid-committed='true'"
+ " invalid-allowed='false' required='true' required-error='This is a required field'"
+ " conversion-error='Input {0} cannot be parsed' tabindex=3 readonly='true'/>";
- }
-
- protected AbstractField getExpected() {
- TextField tf = new TextField();
+ AbstractField tf = new TextField();
+ tf.setBuffered(true);
tf.setBuffered(true);
tf.setValidationVisible(false);
tf.setInvalidCommitted(true);
@@ -57,7 +53,40 @@ public class AbstractFieldDeclarativeTest extends
tf.setConversionError("Input {0} cannot be parsed");
tf.setTabIndex(3);
tf.setReadOnly(true);
- return tf;
- };
+ testRead(design, tf);
+ testWrite(design, tf);
+
+ // Test with readonly=false
+ design = design.replace("readonly='true'", "");
+ tf.setReadOnly(false);
+ testRead(design, tf);
+ testWrite(design, tf);
+ }
+
+ @Test
+ public void testWriteRemovesOldContent() {
+ Attributes attr = new Attributes();
+ attr.put("should_be_removed", "foo");
+ Element design = new Element(Tag.valueOf("v-text-field"), "", attr);
+ AbstractField component = new TextField();
+ component.setReadOnly(true);
+ component.writeDesign(design, new DesignContext());
+ // we only changed one of the attributes, others are at default values
+ assertEquals(1, design.attributes().size());
+ assertTrue("Design must contain readonly", design.hasAttr("readonly"));
+ assertTrue("Readonly must be true", design.attr("readonly").equals("")
+ || design.attr("readonly").equals("true"));
+ }
+ @Test
+ public void testModelReadOnly() {
+ // Test that read only value coming from property data source is not
+ // written to design.
+ String design = "<v-text-field value=test></v-text-field>";
+ AbstractField component = new TextField();
+ ObjectProperty<String> property = new ObjectProperty<String>("test");
+ property.setReadOnly(true);
+ component.setPropertyDataSource(property);
+ testWrite(design, component);
+ }
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/ReadDesignTest.java
deleted file mode 100644
index 4fa3400af5..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/ReadDesignTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.abstractfield;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.AbstractField;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- *
- * Test case for reading the attributes of the AbstractField from design
- *
- * @author Vaadin Ltd
- */
-public class ReadDesignTest extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- public void testSynchronizeReadOnly() {
- Element design = createDesign("readonly", "");
- AbstractField component = getComponent();
- component.readDesign(design, ctx);
- assertEquals(true, component.isReadOnly());
- design = createDesign("readonly", "false");
- component.readDesign(design, ctx);
- assertEquals(false, component.isReadOnly());
- }
-
- public void testSynchronizeTabIndex() {
- Element design = createDesign("tabindex", "2");
- AbstractField component = getComponent();
- component.readDesign(design, ctx);
- assertEquals("Tab index must be 2", 2, component.getTabIndex());
- }
-
- private AbstractField getComponent() {
- return new TextField();
- }
-
- private Element createDesign(String key, String value) {
- Attributes attributes = new Attributes();
- attributes.put(key, value);
- Element node = new Element(Tag.valueOf("v-text-field"), "", attributes);
- return node;
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/WriteDesignTest.java
deleted file mode 100644
index 37ff8cf3aa..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/WriteDesignTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.abstractfield;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.data.util.ObjectProperty;
-import com.vaadin.ui.AbstractField;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for writing the attributes of the AbstractField to design
- *
- * @author Vaadin Ltd
- */
-public class WriteDesignTest extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- public void testSynchronizeReadOnly() {
- Element design = createDesign();
- AbstractField component = getComponent();
- component.setReadOnly(true);
- component.writeDesign(design, ctx);
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertTrue("Design must contain readonly", design.hasAttr("readonly"));
- assertTrue("Readonly must be true", design.attr("readonly").equals("")
- || design.attr("readonly").equals("true"));
- }
-
- public void testSynchronizeModelReadOnly() {
- Element design = createDesign();
- AbstractField component = getComponent();
- ObjectProperty property = new ObjectProperty<String>("test");
- property.setReadOnly(true);
- component.setPropertyDataSource(property);
- component.writeDesign(design, ctx);
- // make sure that property readonly is not written to design
- assertFalse("Design must not contain readonly",
- design.hasAttr("readonly"));
- }
-
- private AbstractField getComponent() {
- return new TextField();
- }
-
- private Element createDesign() {
- Attributes attr = new Attributes();
- attr.put("should_be_removed", "foo");
- return new Element(Tag.valueOf("v-text-field"), "", attr);
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java
new file mode 100644
index 0000000000..192ea0f4f3
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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.abstractorderedlayout;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+import org.junit.Test;
+
+import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.AbstractOrderedLayout;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Tests declarative support for AbstractOrderedLayout.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class AbstractOrderedLayoutDeclarativeTest extends
+ DeclarativeTestBase<AbstractOrderedLayout> {
+
+ private List<String> defaultAlignments = Arrays.asList(new String[] {
+ ":top", ":left" });
+
+ @Test
+ public void testMargin() {
+ String design = getDesign(0, true);
+ AbstractOrderedLayout layout = getLayout(0, true, null);
+ testRead(design, layout);
+ testWrite(design, layout);
+ design = getDesign(0, false);
+ layout = getLayout(0, false, null);
+ testRead(design, layout);
+ testWrite(design, layout);
+ }
+
+ @Test
+ public void testExpandRatio() {
+ String design = getDesign(1, false);
+ AbstractOrderedLayout layout = getLayout(1, false, null);
+ testRead(design, layout);
+ testWrite(design, layout);
+ design = getDesign(0.25f, false);
+ layout = getLayout(0.25f, false, null);
+ testRead(design, layout);
+ testWrite(design, layout);
+ }
+
+ @Test
+ public void testAlignment() {
+ String design = getDesign(0, false, ":top", ":left");
+ AbstractOrderedLayout layout = getLayout(0, false, Alignment.TOP_LEFT);
+ testRead(design, layout);
+ testWrite(design, layout);
+ design = getDesign(0, false, ":middle", ":center");
+ layout = getLayout(0, false, Alignment.MIDDLE_CENTER);
+ testRead(design, layout);
+ testWrite(design, layout);
+ design = getDesign(0, false, ":bottom", ":right");
+ layout = getLayout(0, false, Alignment.BOTTOM_RIGHT);
+ testRead(design, layout);
+ testWrite(design, layout);
+ }
+
+ @Test
+ public void testWriteRemovesOldElementContent() {
+ // Create an element with some content
+ Attributes rootAttributes = new Attributes();
+ rootAttributes.put("caption", "test-layout");
+ Element design = new Element(Tag.valueOf("v-vertical-layout"), "",
+ rootAttributes);
+ Attributes firstChildAttributes = new Attributes();
+ firstChildAttributes.put("caption", "test-label");
+ Element firstChild = new Element(Tag.valueOf("v-label"), "",
+ firstChildAttributes);
+ design.appendChild(firstChild);
+
+ Attributes secondChildAttributes = new Attributes();
+ secondChildAttributes.put("caption", "test-button");
+ Element secondChild = new Element(Tag.valueOf("v-button"), "",
+ secondChildAttributes);
+ design.appendChild(secondChild);
+ Attributes thirdChildAttributes = new Attributes();
+ thirdChildAttributes.put("caption", "test-button-2");
+ Element thirdChild = new Element(Tag.valueOf("v-button"), "",
+ thirdChildAttributes);
+ design.appendChild(thirdChild);
+ // Create and write a layout and check the new contents of the element
+ // node
+ VerticalLayout layout = new VerticalLayout();
+ layout.addComponent(new Label("test-label"));
+ layout.getComponent(0).setCaption("test-caption");
+ layout.setExpandRatio(layout.getComponent(0), 1.0f);
+ layout.addComponent(new Label("test-label-2"));
+ layout.writeDesign(design, new DesignContext());
+ assertEquals(2, design.childNodes().size());
+ assertEquals("v-label", ((Element) design.childNode(0)).tagName());
+ assertEquals("test-caption", design.childNode(0).attr("caption"));
+ assertTrue(design.childNode(0).hasAttr(":expand"));
+ assertEquals("", design.childNode(0).attr(":expand"));
+
+ }
+
+ private String getDesign(float expandRatio, boolean margin,
+ String... alignments) {
+ String result = "<v-vertical-layout caption=test-layout";
+ if (margin) {
+ result += " margin=true";
+ }
+ result += "><v-label caption=test-label ";
+ String ratioString = expandRatio == 1.0f ? "\"\"" : String
+ .valueOf(expandRatio);
+ if (expandRatio != 0) {
+ result += ":expand=" + ratioString;
+ }
+ for (String alignment : alignments) {
+ if (!defaultAlignments.contains(alignment)) {
+ result += " " + alignment + "=\"\"";
+ }
+ }
+ result += "></v-label><v-button ";
+ if (expandRatio != 0) {
+ result += ":expand=" + ratioString;
+ }
+ for (String alignment : alignments) {
+ if (!defaultAlignments.contains(alignment)) {
+ result += " " + alignment + "=\"\"";
+ }
+ }
+ result += "></v-button></v-vertical-layout>";
+ return result;
+ }
+
+ private AbstractOrderedLayout getLayout(float expandRatio, boolean margin,
+ Alignment alignment) {
+ VerticalLayout layout = new VerticalLayout();
+ layout.setMargin(margin);
+ layout.setCaption("test-layout");
+ Label l = new Label();
+ l.setCaption("test-label");
+ l.setContentMode(ContentMode.HTML);
+ layout.addComponent(l);
+ layout.setExpandRatio(l, expandRatio);
+ Button b = new Button();
+ b.setCaptionAsHtml(true);
+ layout.addComponent(b);
+ layout.setExpandRatio(b, expandRatio);
+ if (alignment != null) {
+ layout.setComponentAlignment(l, alignment);
+ layout.setComponentAlignment(b, alignment);
+ }
+ return layout;
+ }
+} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/ReadDesignTest.java
deleted file mode 100644
index b0a2e678c2..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/ReadDesignTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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.abstractorderedlayout;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.Alignment;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case from reading AbstractOrdered layouts from design
- *
- * @since
- * @author Vaadin Ltd
- */
-public class ReadDesignTest extends TestCase {
-
- public void testChildCount() {
- VerticalLayout root = createLayout(0f, false);
- assertEquals(2, root.getComponentCount());
- }
-
- public void testMargin() {
- VerticalLayout root = createLayout(0f, true);
- assertTrue(root.getMargin().getBitMask() != 0);
- root = createLayout(0f, false);
- assertTrue(root.getMargin().getBitMask() == 0);
- }
-
- public void testAttributes() {
- VerticalLayout root = createLayout(0f, false);
- assertEquals("test-layout", root.getCaption());
- assertEquals("test-label", root.getComponent(0).getCaption());
- assertEquals("test-button", root.getComponent(1).getCaption());
- }
-
- public void testExpandRatio() {
- VerticalLayout root = createLayout(1f, false);
- assertEquals(1f, root.getExpandRatio(root.getComponent(0)));
- assertEquals(1f, root.getExpandRatio(root.getComponent(1)));
-
- root = createLayout(0f, false);
- assertEquals(0f, root.getExpandRatio(root.getComponent(0)));
- assertEquals(0f, root.getExpandRatio(root.getComponent(1)));
- }
-
- public void testAlignment() {
- VerticalLayout root = createLayout(0f, false, ":top", ":left");
- assertEquals(Alignment.TOP_LEFT,
- root.getComponentAlignment(root.getComponent(0)));
- root = createLayout(0f, false, ":middle", ":center");
- assertEquals(Alignment.MIDDLE_CENTER,
- root.getComponentAlignment(root.getComponent(0)));
- root = createLayout(0f, false, ":bottom", ":right");
- assertEquals(Alignment.BOTTOM_RIGHT,
- root.getComponentAlignment(root.getComponent(0)));
-
- }
-
- private VerticalLayout createLayout(float expandRatio, boolean margin,
- String... alignments) {
- DesignContext ctx = new DesignContext();
- Element design = createDesign(expandRatio, margin, alignments);
- Component child = ctx.readDesign(design);
- return (VerticalLayout) child;
- }
-
- private Element createDesign(float expandRatio, boolean margin,
- String... alignments) {
-
- Attributes rootAttributes = new Attributes();
- rootAttributes.put("caption", "test-layout");
- if (margin) {
- rootAttributes.put("margin", "");
- }
- Element node = new Element(Tag.valueOf("v-vertical-layout"), "",
- rootAttributes);
-
- Attributes firstChildAttributes = new Attributes();
- firstChildAttributes.put("caption", "test-label");
- firstChildAttributes.put(":expand", String.valueOf(expandRatio));
- for (String alignment : alignments) {
- firstChildAttributes.put(alignment, "");
- }
- Element firstChild = new Element(Tag.valueOf("v-label"), "",
- firstChildAttributes);
- node.appendChild(firstChild);
-
- Attributes secondChildAttributes = new Attributes();
- secondChildAttributes.put(":expand", String.valueOf(expandRatio));
- for (String alignment : alignments) {
- secondChildAttributes.put(alignment, "");
- }
- Element secondChild = new Element(Tag.valueOf("v-button"), "",
- secondChildAttributes);
- secondChild.html("test-button");
- node.appendChild(secondChild);
- return node;
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/WriteDesignTest.java
deleted file mode 100644
index 96697af3cd..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/WriteDesignTest.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * 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.abstractorderedlayout;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.Alignment;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for writing abstract ordered layout to design
- *
- * @since
- * @author Vaadin Ltd
- */
-public class WriteDesignTest extends TestCase {
-
- public void testSynchronizeMargin() {
- VerticalLayout layout = new VerticalLayout();
- layout.setMargin(true);
- Element design = createDesign();
- layout.writeDesign(design, createDesignContext());
- assertTrue("The margin must be written", design.hasAttr("margin"));
- assertTrue("The margin must be empty or true", design.attr("margin")
- .equals("") || design.attr("margin").equalsIgnoreCase("true"));
- }
-
- public void testSynchronizeEmptyLayout() {
- VerticalLayout layout = new VerticalLayout();
- layout.setCaption("changed-caption");
- Element design = createDesign();
- layout.writeDesign(design, createDesignContext());
- assertEquals(0, design.childNodes().size());
- assertEquals("changed-caption", design.attr("caption"));
- }
-
- public void testSynchronizeLayoutWithChildren() {
- VerticalLayout layout = new VerticalLayout();
- layout.addComponent(new Label("test-label"));
- layout.getComponent(0).setCaption("test-caption");
- layout.addComponent(new Label("test-label-2"));
- Element design = createDesign();
- layout.writeDesign(design, createDesignContext());
- assertEquals(2, design.childNodes().size());
- assertEquals("v-label", ((Element) design.childNode(0)).tagName());
- assertEquals("test-caption", design.childNode(0).attr("caption"));
- }
-
- public void testSynchronizeUnitExpandRatio() {
- VerticalLayout layout = new VerticalLayout();
- layout.addComponent(new Label("test-label"));
- layout.setExpandRatio(layout.getComponent(0), 1.0f);
- Element design = createDesign();
- layout.writeDesign(design, createDesignContext());
- assertTrue(design.childNode(0).hasAttr(":expand"));
- assertEquals("", design.childNode(0).attr(":expand"));
- }
-
- public void testSynchronizeArbitraryExpandRatio() {
- VerticalLayout layout = new VerticalLayout();
- layout.addComponent(new Label("test-label"));
- layout.setExpandRatio(layout.getComponent(0), 2.40f);
- Element design = createDesign();
- layout.writeDesign(design, createDesignContext());
- assertTrue(design.childNode(0).hasAttr(":expand"));
- assertEquals("2.4", design.childNode(0).attr(":expand"));
- }
-
- public void testSynchronizeDefaultAlignment() {
- Element design = createDesign();
- VerticalLayout layout = createLayoutWithAlignment(design, null);
- layout.writeDesign(design, createDesignContext());
- assertFalse(design.childNode(0).hasAttr(":top"));
- assertFalse(design.childNode(0).hasAttr(":left"));
- }
-
- public void testSynchronizeMiddleCenter() {
- Element design = createDesign();
- VerticalLayout layout = createLayoutWithAlignment(design,
- Alignment.MIDDLE_CENTER);
- layout.writeDesign(design, createDesignContext());
- assertTrue(design.childNode(0).hasAttr(":middle"));
- assertTrue(design.childNode(0).hasAttr(":center"));
- }
-
- public void testSynchronizeBottomRight() {
- Element design = createDesign();
- VerticalLayout layout = createLayoutWithAlignment(design,
- Alignment.BOTTOM_RIGHT);
- layout.writeDesign(design, createDesignContext());
- assertTrue(design.childNode(0).hasAttr(":bottom"));
- assertTrue(design.childNode(0).hasAttr(":right"));
- }
-
- private VerticalLayout createLayoutWithAlignment(Element design,
- Alignment alignment) {
- VerticalLayout layout = new VerticalLayout();
- layout.addComponent(new Label("test-label"));
- if (alignment != null) {
- layout.setComponentAlignment(layout.getComponent(0), alignment);
- }
- layout.writeDesign(design, createDesignContext());
- return layout;
- }
-
- private Element createDesign() {
- // make sure that the design node has old content that should be removed
- Attributes rootAttributes = new Attributes();
- rootAttributes.put("caption", "test-layout");
- Element node = new Element(Tag.valueOf("v-vertical-layout"), "",
- rootAttributes);
- Attributes firstChildAttributes = new Attributes();
- firstChildAttributes.put("caption", "test-label");
- Element firstChild = new Element(Tag.valueOf("v-label"), "",
- firstChildAttributes);
- node.appendChild(firstChild);
-
- Attributes secondChildAttributes = new Attributes();
- secondChildAttributes.put("caption", "test-button");
- Element secondChild = new Element(Tag.valueOf("v-button"), "",
- secondChildAttributes);
- node.appendChild(secondChild);
- return node;
- }
-
- private DesignContext createDesignContext() {
- return new DesignContext();
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/AbstractSplitPanelDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/AbstractSplitPanelDeclarativeTest.java
new file mode 100644
index 0000000000..1f2113fabc
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/AbstractSplitPanelDeclarativeTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.abstractsplitpanel;
+
+import static junit.framework.TestCase.assertTrue;
+
+import org.jsoup.nodes.Element;
+import org.junit.Test;
+
+import com.vaadin.server.Sizeable.Unit;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.AbstractSplitPanel;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalSplitPanel;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.VerticalSplitPanel;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Tests declarative support for AbstractSplitPanel.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class AbstractSplitPanelDeclarativeTest extends
+ DeclarativeTestBase<AbstractSplitPanel> {
+
+ @Test
+ public void testWithBothChildren() {
+ String design = "<v-horizontal-split-panel split-position=20.5% "
+ + "min-split-position=20% max-split-position=50px locked=true "
+ + "reversed=\"\"> <v-table /> <v-vertical-layout />"
+ + "</v-horizontal-split-panel>";
+ AbstractSplitPanel sp = new HorizontalSplitPanel();
+ sp.setSplitPosition(20.5f, Unit.PERCENTAGE, true);
+ sp.setMinSplitPosition(20, Unit.PERCENTAGE);
+ sp.setMaxSplitPosition(50, Unit.PIXELS);
+ sp.setLocked(true);
+ sp.addComponent(new Table());
+ sp.addComponent(new VerticalLayout());
+ testRead(design, sp);
+ testWrite(design, sp);
+ }
+
+ @Test
+ public void testWithFirstChild() {
+ String design = "<v-vertical-split-panel><v-table caption=\"First slot\"/>"
+ + "</v-vertical-split-panel>";
+ AbstractSplitPanel sp = new VerticalSplitPanel();
+ Table t = new Table();
+ t.setCaption("First slot");
+ sp.addComponent(t);
+ testRead(design, sp);
+ testWrite(design, sp);
+ }
+
+ @Test
+ public void testWithSecondChild() {
+ String design = "<v-horizontal-split-panel><v-button :second>Second slot</v-button>"
+ + "</v-vertical-split-panel>";
+ AbstractSplitPanel sp = new HorizontalSplitPanel();
+ Button b = new Button("Second slot");
+ b.setCaptionAsHtml(true);
+ sp.setSecondComponent(b);
+ testRead(design, sp);
+ testWrite(design, sp);
+ }
+
+ @Test
+ public void testEmpty() {
+ String design = "<v-horizontal-split-panel/>";
+ AbstractSplitPanel sp = new HorizontalSplitPanel();
+ testRead(design, sp);
+ testWrite(design, sp);
+ }
+
+ @Test
+ public void testReSynchronize() {
+ // Test that old children and attributes are removed when an element is
+ // synchronized to a new component.
+ DesignContext ctx = new DesignContext();
+ VerticalSplitPanel sp = new VerticalSplitPanel();
+ sp.setMinSplitPosition(5.5f, Unit.PERCENTAGE);
+ sp.setMaxSplitPosition(95, Unit.PERCENTAGE);
+ sp.setFirstComponent(new Button("First slot"));
+ sp.setSecondComponent(new Label("Second slot"));
+ Element e = ctx.createElement(sp);
+ sp = new VerticalSplitPanel();
+ sp.writeDesign(e, ctx);
+ assertTrue("There should be no attributes in the node.", e.attributes()
+ .size() == 0);
+ assertTrue("There should be no child elements.",
+ e.children().size() == 0);
+ }
+} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/ReadDesignTest.java
deleted file mode 100644
index f3a7e32e96..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/ReadDesignTest.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * 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.abstractsplitpanel;
-
-import java.lang.reflect.Method;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.server.Sizeable.Unit;
-import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState.SplitterState;
-import com.vaadin.ui.AbstractSplitPanel;
-import com.vaadin.ui.HorizontalSplitPanel;
-import com.vaadin.ui.Table;
-import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.VerticalSplitPanel;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Tests synchronizing the attributes and children of horizontal and vertical
- * split panels from a design.
- *
- * @author Vaadin Ltd
- */
-public class ReadDesignTest extends TestCase {
- DesignContext ctx;
-
- @Override
- protected void setUp() {
- ctx = new DesignContext();
- }
-
- public void testAttributes() throws Exception {
- // Create a design with non-default attributes values.
- Element design = createDesign(true, false, true, true);
- HorizontalSplitPanel sp = new HorizontalSplitPanel();
- sp.readDesign(design, ctx);
- // Check that the attributes are correctly parsed.
- assertEquals(20.5f, sp.getSplitPosition());
- assertEquals(Unit.PERCENTAGE, sp.getSplitPositionUnit());
- assertEquals(20f, sp.getMinSplitPosition());
- assertEquals(Unit.PERCENTAGE, sp.getMinSplitPositionUnit());
- assertEquals(50f, sp.getMaxSplitPosition());
- assertEquals(Unit.PIXELS, sp.getMaxSplitPositionUnit());
- assertEquals(true, sp.isLocked());
- checkReversed(sp, true);
- }
-
- public void testWithNoChildren() {
- Element design = createDesign(true, false, false, false);
- HorizontalSplitPanel sp = new HorizontalSplitPanel();
- sp.readDesign(design, ctx);
- assertEquals("Unexpected child count for the split panel.", 0,
- sp.getComponentCount());
- }
-
- public void testWithFirstChild() {
- Element design = createDesign(false, false, true, false);
- VerticalSplitPanel sp = new VerticalSplitPanel();
- sp.readDesign(design, ctx);
- assertEquals("Unexpected child count for the split panel.", 1,
- sp.getComponentCount());
- Object obj = sp.getFirstComponent();
- assertEquals("Wrong component in split panel.", Table.class,
- obj.getClass());
- }
-
- public void testWithSecondChild() {
- Element design = createDesign(true, false, false, true);
- HorizontalSplitPanel sp = new HorizontalSplitPanel();
- sp.readDesign(design, ctx);
- assertEquals("Unexpected child count for the split panel.", 1,
- sp.getComponentCount());
- Object obj = sp.getSecondComponent();
- assertEquals("Wrong component in split panel.", VerticalLayout.class,
- obj.getClass());
- }
-
- public void testWithBothChildren() {
- Element design = createDesign(false, false, true, true);
- VerticalSplitPanel sp = new VerticalSplitPanel();
- sp.readDesign(design, ctx);
- assertEquals("Unexpected child count for the split panel.", 2,
- sp.getComponentCount());
- Object first = sp.getFirstComponent();
- Object second = sp.getSecondComponent();
- assertEquals("Wrong first component in split panel.", Table.class,
- first.getClass());
- assertEquals("Wrong second component in split panel.",
- VerticalLayout.class, second.getClass());
- }
-
- /*
- * Creates an html tree node structure representing a split panel and its
- * contents. The parameters are used for controlling whether the split panel
- * is horizontal or vertical, whether attributes are set for the design and
- * whether the split panel should have the first and the second child
- * component.
- */
- private Element createDesign(boolean horizontal,
- boolean useDefaultAttributes, boolean hasFirstChild,
- boolean hasSecondChild) {
- Attributes attributes = new Attributes();
- if (!useDefaultAttributes) {
- attributes.put("split-position", "20.5%");
- // The unitless number should correspond to 20%
- attributes.put("min-split-position", "20");
- attributes.put("max-split-position", "50px");
- attributes.put("locked", "");
- attributes.put("reversed", "");
- }
- String tagName = horizontal ? "v-horizontal-split-panel"
- : "v-vertical-split-panel";
- Element element = new Element(Tag.valueOf(tagName), "", attributes);
- // Create the children
- if (hasFirstChild) {
- Element child = new Element(Tag.valueOf("v-table"), "");
- element.appendChild(child);
- }
- if (hasSecondChild) {
- Element child = new Element(Tag.valueOf("v-vertical-layout"), "");
- if (!hasFirstChild) {
- child.attr(":second", "");
- }
- element.appendChild(child);
- }
- return element;
- }
-
- /*
- * Checks the reversed property of a split panel.
- */
- private void checkReversed(AbstractSplitPanel sp, boolean expected)
- throws Exception {
- Method getter = AbstractSplitPanel.class
- .getDeclaredMethod("getSplitterState");
- getter.setAccessible(true);
- SplitterState state = (SplitterState) getter.invoke(sp);
- assertEquals("Wrong value for split panel property reversed.",
- expected, state.positionReversed);
- }
-} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/WriteDesignTest.java
deleted file mode 100644
index a75fe911f8..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/abstractsplitpanel/WriteDesignTest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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.abstractsplitpanel;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Element;
-
-import com.vaadin.server.Sizeable.Unit;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.HorizontalSplitPanel;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.VerticalSplitPanel;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Tests synchronizing the properties and child components of split panels to a
- * design.
- *
- * @author Vaadin Ltd
- */
-public class WriteDesignTest extends TestCase {
- private DesignContext ctx;
-
- @Override
- public void setUp() {
- ctx = new DesignContext();
- }
-
- public void testHorizontalWithDefaultValues() {
- // no attributes or child elements should appear
- HorizontalSplitPanel sp = new HorizontalSplitPanel();
- Element e = ctx.createElement(sp);
- assertEquals("Wrong tag name.", "v-horizontal-split-panel",
- e.nodeName());
- assertEquals("The split panel should not have attributes.", 0, e
- .attributes().size());
- assertEquals("The split panel should not have children.", 0, e
- .children().size());
- }
-
- public void testVerticalWithAttributes() {
- // All defined attributes should be output in the tree node. No child
- // components are present in this test.
- VerticalSplitPanel sp = new VerticalSplitPanel();
- sp.setSplitPosition(27f, Unit.PIXELS, true);
- sp.setMinSplitPosition(5.5f, Unit.PERCENTAGE);
- sp.setMaxSplitPosition(95, Unit.PERCENTAGE);
- sp.setLocked(true);
- Element e = ctx.createElement(sp);
- assertEquals("Wrong tag name.", "v-vertical-split-panel", e.nodeName());
- assertEquals("Unexpected number of attributes.", 5, e.attributes()
- .size());
- assertEquals("Wrong split position.", "27px", e.attr("split-position"));
- assertEquals("Wrong minimum split position.", "5.5%",
- e.attr("min-split-position"));
- assertEquals("Wrong maximum split position.", "95%",
- e.attr("max-split-position"));
- assertTrue("Unexpected value for locked: " + e.attr("locked"),
- "true".equals(e.attr("locked")) || "".equals(e.attr("locked")));
- assertTrue(
- "Unexpected value for reversed: " + e.attr("reversed"),
- "true".equals(e.attr("reversed"))
- || "".equals(e.attr("reversed")));
- }
-
- public void testHorizontalWithFirstChild() {
- // The split panel contains only the first child.
- HorizontalSplitPanel sp = new HorizontalSplitPanel();
- sp.setSplitPosition(25f);
- sp.setFirstComponent(new Button("First slot"));
- Element e = ctx.createElement(sp);
- assertEquals("Wrong split position.", "25%", e.attr("split-position"));
- assertEquals("Wrong number of child elements.", 1, e.children().size());
- Element eb = e.children().get(0);
- assertEquals("Wrong tag name of first child element.", "v-button",
- eb.nodeName());
- assertEquals("Wrong text in the button element.", "First slot",
- eb.html());
- }
-
- public void testVerticalWithSecondChild() {
- // The split panel contains only the second child.
- VerticalSplitPanel sp = new VerticalSplitPanel();
- sp.setMinSplitPosition(25f, Unit.PIXELS);
- sp.setSecondComponent(new Label("Second slot"));
- Element e = ctx.createElement(sp);
- assertEquals("Wrong minimum split position.", "25px",
- e.attr("min-split-position"));
- assertEquals("Wrong number of child elements.", 1, e.children().size());
- Element el = e.children().get(0);
- assertEquals("Wrong tag name of child element.", "v-label",
- el.nodeName());
- assertEquals("Wrong text in the label element.", "Second slot",
- el.html());
- assertTrue("Missing attribute :second in the label element.",
- el.hasAttr(":second"));
- }
-
- public void testVerticalWithBothChildren() {
- // The split panel has both child components.
- VerticalSplitPanel sp = new VerticalSplitPanel();
- sp.setFirstComponent(new Button("First slot"));
- sp.setSecondComponent(new Label("Second slot"));
- Element e = ctx.createElement(sp);
- assertEquals("Wrong number of child elements.", 2, e.children().size());
- Element eb = e.children().get(0);
- assertEquals("Wrong tag name of first child element.", "v-button",
- eb.nodeName());
- assertEquals("Wrong text in the button element.", "First slot",
- eb.html());
- Element el = e.children().get(1);
- assertEquals("Wrong tag name of second child element.", "v-label",
- el.nodeName());
- assertEquals("Wrong text in the label element.", "Second slot",
- el.html());
- assertFalse(
- "There should be no :second attribute when a split panel has both children.",
- el.hasAttr(":second"));
- }
-
- public void testReSynchronize() {
- // Test that old children and attributes are removed when an element is
- // synchronized to a new component.
- VerticalSplitPanel sp = new VerticalSplitPanel();
- sp.setMinSplitPosition(5.5f, Unit.PERCENTAGE);
- sp.setMaxSplitPosition(95, Unit.PERCENTAGE);
- sp.setFirstComponent(new Button("First slot"));
- sp.setSecondComponent(new Label("Second slot"));
- Element e = ctx.createElement(sp);
- sp = new VerticalSplitPanel();
- sp.writeDesign(e, ctx);
- assertTrue("There should be no attributes in the node.", e.attributes()
- .size() == 0);
- assertTrue("There should be no child elements.",
- e.children().size() == 0);
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java
new file mode 100644
index 0000000000..a3594b7159
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.abstracttextfield;
+
+import org.junit.Test;
+
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.AbstractTextField;
+import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
+import com.vaadin.ui.TextField;
+
+/**
+ * Tests declarative support for AbstractTextField.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class AbstractTextFieldDeclarativeTest extends
+ DeclarativeTestBase<AbstractTextField> {
+
+ @Test
+ public void testAttributes() {
+ String design = "<v-text-field null-representation=this-is-null "
+ + "null-setting-allowed=true maxlength=5 columns=3 "
+ + "input-prompt=input text-change-event-mode=eager "
+ + "text-change-timeout=100 />";
+ AbstractTextField tf = new TextField();
+ tf.setNullRepresentation("this-is-null");
+ tf.setNullSettingAllowed(true);
+ tf.setMaxLength(5);
+ tf.setColumns(3);
+ tf.setInputPrompt("input");
+ tf.setTextChangeEventMode(TextChangeEventMode.EAGER);
+ tf.setTextChangeTimeout(100);
+ testRead(design, tf);
+ testWrite(design, tf);
+ }
+
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/ReadDesignTest.java
deleted file mode 100644
index 2645ce4255..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/ReadDesignTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.abstracttextfield;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.AbstractTextField;
-import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for reading the attributes of the AbstractTextField from design
- */
-public class ReadDesignTest extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- public void testAttributes() {
- Element design = createDesign();
- AbstractTextField component = getComponent();
- component.readDesign(design, ctx);
- assertEquals("this-is-null", component.getNullRepresentation());
- assertEquals(true, component.isNullSettingAllowed());
- assertEquals(5, component.getMaxLength());
- assertEquals(3, component.getColumns());
- assertEquals("input", component.getInputPrompt());
- assertEquals(TextChangeEventMode.EAGER,
- component.getTextChangeEventMode());
- assertEquals(100, component.getTextChangeTimeout());
- }
-
- private AbstractTextField getComponent() {
- return new TextField();
- }
-
- private Element createDesign() {
- Attributes attributes = new Attributes();
- attributes.put("null-representation", "this-is-null");
- attributes.put("null-setting-allowed", "true");
- attributes.put("maxlength", "5");
- attributes.put("columns", "3");
- attributes.put("input-prompt", "input");
- attributes.put("text-change-event-mode", "eager");
- attributes.put("text-change-timeout", "100");
- Element node = new Element(Tag.valueOf("v-text-field"), "", attributes);
- return node;
- }
-
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/WriteDesignTest.java
deleted file mode 100644
index 840de9e819..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/abstracttextfield/WriteDesignTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.abstracttextfield;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.AbstractTextField;
-import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for writing the attributes of the AbstractTextField to design
- *
- * @author Vaadin Ltd
- */
-public class WriteDesignTest extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- public void testSynchronizetestAttributes() {
- Element design = createDesign();
- AbstractTextField component = getComponent();
- component.setNullRepresentation("this-is-null");
- component.setNullSettingAllowed(true);
- component.setMaxLength(5);
- component.setColumns(3);
- component.setInputPrompt("input");
- component.setTextChangeEventMode(TextChangeEventMode.EAGER);
- component.setTextChangeTimeout(100);
- component.writeDesign(design, ctx);
- assertEquals("this-is-null", design.attr("null-representation"));
- assertEquals("true", design.attr("null-setting-allowed"));
- assertEquals("5", design.attr("maxlength"));
- assertEquals("3", design.attr("columns"));
- assertEquals("input", design.attr("input-prompt"));
- assertEquals("eager", design.attr("text-change-event-mode"));
- assertEquals("100", design.attr("text-change-timeout"));
- }
-
- private AbstractTextField getComponent() {
- return new TextField();
- }
-
- private Element createDesign() {
- Attributes attr = new Attributes();
- return new Element(Tag.valueOf("v-text-field"), "", attr);
- }
-
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java
index 2962620052..02dfa22671 100644
--- a/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java
@@ -15,13 +15,23 @@
*/
package com.vaadin.tests.server.component.button;
+import static org.junit.Assert.assertTrue;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
import org.junit.Test;
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.event.ShortcutAction.ModifierKey;
import com.vaadin.tests.design.DeclarativeTestBase;
import com.vaadin.ui.Button;
+import com.vaadin.ui.NativeButton;
+import com.vaadin.ui.declarative.DesignContext;
/**
- * Tests declarative support for implementations of {@link Button}.
+ * Tests declarative support for implementations of {@link Button} and
+ * {@link NativeButton}.
*
* @since 7.4
* @author Vaadin Ltd
@@ -29,44 +39,90 @@ import com.vaadin.ui.Button;
public class ButtonDeclarativeTest extends DeclarativeTestBase<Button> {
@Test
- public void testPlainTextRead() {
- testRead(getDesignPlainText(), getExpectedPlainText());
+ public void testEmptyPlainText() {
+ String design = "<v-button plain-text=''></v-button>";
+ testButtonAndNativeButton(design, false, "");
}
@Test
- public void testPlainTextWrite() {
- testWrite(getDesignPlainText(), getExpectedPlainText());
+ public void testPlainTextCaption() {
+ String design = "<v-button plain-text=''>Click</v-button>";
+ testButtonAndNativeButton(design, false, "Click");
}
- protected String getDesignPlainText() {
- return "<v-button plain-text=''></v-button>";
+ @Test
+ public void testEmptyHtml() {
+ String design = "<v-button />";
+ testButtonAndNativeButton(design, true, "");
}
- protected Button getExpectedPlainText() {
- Button c = new Button();
- c.setCaption("");
- return c;
- };
+ @Test
+ public void testHtmlCaption() {
+ String design = "<v-button><b>Click</b></v-button>";
+ testButtonAndNativeButton(design, true, "<b>Click</b>");
+ }
@Test
- public void testHtmlRead() {
- testRead(getDesignHtml(), getExpectedHtml());
+ public void testWithCaptionAttribute() {
+ // The caption attribute should be ignored
+ String design = "<v-button caption=Caption>Click</v-button>";
+ String expectedWritten = "<v-button>Click</v-button>";
+ testButtonAndNativeButton(design, true, "Click", expectedWritten);
}
@Test
- public void testHtmlWrite() {
- testWrite(getDesignHtml(), getExpectedHtml());
+ public void testWithOnlyCaptionAttribute() {
+ String design = "<v-button caption=Click/>";
+ String expectedWritten = "<v-button/>";
+ testButtonAndNativeButton(design, true, "", expectedWritten);
}
- protected String getDesignHtml() {
- return "<v-button />";
+ public void testButtonAndNativeButton(String design, boolean html,
+ String caption) {
+ testButtonAndNativeButton(design, html, caption, design);
}
- protected Button getExpectedHtml() {
- Button c = new Button();
- c.setCaption("");
- c.setCaptionAsHtml(true);
- return c;
- };
+ public void testButtonAndNativeButton(String design, boolean html,
+ String caption, String expectedWritten) {
+ // Test Button
+ Button b = new Button();
+ b.setCaptionAsHtml(html);
+ b.setCaption(caption);
+ testRead(expectedWritten, b);
+ testWrite(expectedWritten, b);
+ // Test NativeButton
+ design = design.replace("v-button", "v-native-button");
+ expectedWritten = expectedWritten
+ .replace("v-button", "v-native-button");
+ NativeButton nb = new NativeButton();
+ nb.setCaptionAsHtml(html);
+ nb.setCaption(caption);
+ testRead(expectedWritten, nb);
+ testWrite(expectedWritten, nb);
+ }
-}
+ @Test
+ public void testAttributes() {
+ String design = "<v-button tabindex=3 plain-text='' icon-alt=OK "
+ + "click-shortcut=ctrl-shift-o></v-button>";
+ Button b = new Button("");
+ b.setTabIndex(3);
+ b.setIconAlternateText("OK");
+ b.setClickShortcut(KeyCode.O, ModifierKey.CTRL, ModifierKey.SHIFT);
+ testRead(design, b);
+ testWrite(design, b);
+ }
+
+ @Test
+ public void testWriteUpdatesContentMode() {
+ DesignContext ctx = new DesignContext();
+ Button button = new Button("OK");
+ Element e = new Element(Tag.valueOf("v-button"), "", new Attributes());
+ button.writeDesign(e, ctx);
+ assertTrue("Button is plain text by default", e.hasAttr("plain-text"));
+
+ button.setHtmlContentAllowed(true);
+ button.writeDesign(e, ctx);
+ assertTrue("Button is updated to HTML", !e.hasAttr("plain-text"));
+ }
+} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/button/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/button/ReadDesignTest.java
deleted file mode 100644
index 0e503b54b8..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/button/ReadDesignTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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.button;
-
-import java.lang.reflect.Field;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-import org.junit.Test;
-
-import com.vaadin.event.ShortcutAction.KeyCode;
-import com.vaadin.event.ShortcutAction.ModifierKey;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Button.ClickShortcut;
-import com.vaadin.ui.NativeButton;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- *
- * Test cases for reading the contents of a Button and a NativeButton from a
- * design.
- *
- */
-public class ReadDesignTest extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- @Test
- public void testWithContent() {
- createAndTestButtons("Click", null);
- }
-
- @Test
- public void testWithHtmlCaption() {
- createAndTestButtons("<b>Click me</b>", null);
- }
-
- @Test
- public void testWithContentAndCaption() {
- createAndTestButtons("Click me", "caption");
- }
-
- @Test
- public void testWithCaption() {
- createAndTestButtons(null, "Click me");
- }
-
- @Test
- public void testAttributes() throws IllegalArgumentException,
- SecurityException, IllegalAccessException, NoSuchFieldException {
- Attributes attributes = new Attributes();
- attributes.put("tabindex", "3");
- attributes.put("plain-text", "");
- attributes.put("icon-alt", "OK");
- attributes.put("click-shortcut", "ctrl-shift-o");
- Button button = (Button) ctx
- .readDesign(createButtonWithAttributes(attributes));
- assertEquals(3, button.getTabIndex());
- assertEquals(false, button.isHtmlContentAllowed());
- assertEquals("OK", button.getIconAlternateText());
- Field field = Button.class.getDeclaredField("clickShortcut");
- field.setAccessible(true);
- ClickShortcut value = (ClickShortcut) field.get(button);
- assertEquals(KeyCode.O, value.getKeyCode());
- assertEquals(ModifierKey.CTRL, value.getModifiers()[0]);
- assertEquals(ModifierKey.SHIFT, value.getModifiers()[1]);
- }
-
- /*
- * Test both Button and NativeButton. Caption should always be ignored. If
- * content is null, the created button should have empty content.
- */
- private void createAndTestButtons(String content, String caption) {
- Element e1 = createElement("v-button", content, caption);
- Button b1 = (Button) ctx.readDesign(e1);
- Element e2 = createElement("v-native-button", content, caption);
- NativeButton b2 = (NativeButton) ctx.readDesign(e2);
- if (content != null) {
- assertEquals("The button has the wrong text content.", content,
- b1.getCaption());
- assertEquals("The button has the wrong text content.", content,
- b2.getCaption());
- } else {
- assertTrue("The button has the wrong content.",
- b1.getCaption() == null || "".equals(b1.getCaption()));
- assertTrue("The button has the wrong content.",
- b2.getCaption() == null || "".equals(b2.getCaption()));
- }
- }
-
- private Element createButtonWithAttributes(Attributes attributes) {
- return new Element(Tag.valueOf("v-button"), "", attributes);
- }
-
- private Element createElement(String elementName, String content,
- String caption) {
- Attributes attributes = new Attributes();
- if (caption != null) {
- attributes.put("caption", caption);
- }
- Element node = new Element(Tag.valueOf(elementName), "", attributes);
- if (content != null) {
- node.html(content);
- }
- return node;
- }
-} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/button/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/button/WriteDesignTest.java
deleted file mode 100644
index 6d553da835..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/button/WriteDesignTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.button;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-import org.junit.Test;
-
-import com.vaadin.event.ShortcutAction.KeyCode;
-import com.vaadin.event.ShortcutAction.ModifierKey;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.NativeButton;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Tests generating html tree nodes corresponding to the contents of a Button
- * and a NativeButton.
- */
-public class WriteDesignTest extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- @Test
- public void testWithTextContent() {
- createAndTestButtons("Click me");
- }
-
- @Test
- public void testWithHtmlContent() {
- createAndTestButtons("<b>Click</b>");
- }
-
- @Test
- public void testAttributes() {
- Button button = new Button();
- button.setTabIndex(3);
- button.setIconAlternateText("OK");
- button.setClickShortcut(KeyCode.O, ModifierKey.CTRL, ModifierKey.SHIFT);
- Element e = new Element(Tag.valueOf("v-button"), "", new Attributes());
- button.writeDesign(e, ctx);
- assertEquals("3", e.attr("tabindex"));
- assertTrue("Button is plain text by default", e.hasAttr("plain-text"));
- assertEquals("OK", e.attr("icon-alt"));
- assertEquals("ctrl-shift-o", e.attr("click-shortcut"));
- }
-
- @Test
- public void testUpdateContentMode() {
- Button button = new Button("OK");
- Element e = new Element(Tag.valueOf("v-button"), "", new Attributes());
- button.writeDesign(e, ctx);
- assertTrue("Button is plain text by default", e.hasAttr("plain-text"));
-
- button.setHtmlContentAllowed(true);
- button.writeDesign(e, ctx);
- assertTrue("Button is updated to HTML", !e.hasAttr("plain-text"));
-
- }
-
- private void createAndTestButtons(String content) {
- Button b1 = new Button(content);
- // we need to set this on, since the plain-text attribute will appear
- // otherwise
- b1.setHtmlContentAllowed(true);
- Element e1 = ctx.createElement(b1);
- assertEquals("Wrong tag name for button.", "v-button", e1.tagName());
- assertEquals("Unexpected content in the v-button element.", content,
- e1.html());
- assertTrue("The v-button element should not have attributes.", e1
- .attributes().size() == 0);
- NativeButton b2 = new NativeButton(content);
- b2.setHtmlContentAllowed(true);
- Element e2 = ctx.createElement(b2);
- assertEquals("Wrong tag name for button.", "v-native-button",
- e2.tagName());
- assertEquals("Unexpected content in the v-button element.", content,
- e2.html());
- assertTrue("The v-button element should not have attributes.", e2
- .attributes().size() == 0);
- }
-} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java
index 30a9e411a1..6162e41494 100644
--- a/server/tests/src/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java
@@ -28,29 +28,20 @@ import com.vaadin.ui.CheckBox;
*/
public class CheckboxDeclarativeTest extends DeclarativeTestBase<CheckBox> {
- protected String getDesign() {
- return "<v-check-box checked='true' />";
- }
-
- protected CheckBox getExpectedResult() {
- CheckBox c = new CheckBox();
- c.setValue(true);
- return c;
- };
-
@Test
- public void read() {
- testRead(getDesign(), getExpectedResult());
+ public void testChecked() {
+ String design = "<v-check-box />";
+ CheckBox checkBox = new CheckBox();
+ testRead(design, checkBox);
+ testWrite(design, checkBox);
}
@Test
- public void write() {
- testWrite(getDesign(), getExpectedResult());
+ public void testUnchecked() {
+ String design = "<v-check-box checked='true' />";
+ CheckBox checkBox = new CheckBox();
+ checkBox.setValue(true);
+ testRead(design, checkBox);
+ testWrite(design, checkBox);
}
-
- @Test
- public void testEmpty() {
- testRead("<v-check-box>", new CheckBox());
- }
-
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/checkbox/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/checkbox/ReadDesignTest.java
deleted file mode 100644
index 9456fa4b31..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/checkbox/ReadDesignTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.checkbox;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-import org.junit.Test;
-
-import com.vaadin.ui.CheckBox;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- *
- * Test cases for reading the contents of a Checkbox from a design.
- *
- */
-public class ReadDesignTest extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- @Test
- public void testChecked() {
- Element e = createElement(true);
- CheckBox box = (CheckBox) ctx.readDesign(e);
- assertEquals("The checkbox must be checked", Boolean.TRUE,
- box.getValue());
- }
-
- @Test
- public void testUnchecked() {
- Element e = createElement(false);
- CheckBox box = (CheckBox) ctx.readDesign(e);
- assertEquals("The checkbox must be unchecked", Boolean.FALSE,
- box.getValue());
- }
-
- private Element createElement(boolean checked) {
- Attributes attributes = new Attributes();
- if (checked) {
- attributes.put("checked", "");
- }
- Element node = new Element(Tag.valueOf("v-check-box"), "", attributes);
- return node;
- }
-} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/checkbox/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/checkbox/WriteDesignTest.java
deleted file mode 100644
index 4c41f67ac5..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/checkbox/WriteDesignTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.checkbox;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Element;
-import org.junit.Test;
-
-import com.vaadin.ui.CheckBox;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Tests generating html tree nodes corresponding to the contents of a Checkbox
- */
-public class WriteDesignTest extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- @Test
- public void testChecked() {
- CheckBox box = new CheckBox();
- box.setValue(true);
- Element e = ctx.createElement(box);
- assertTrue("element must have checked attribute", e.hasAttr("checked"));
- assertTrue("the checked attribute must be true", e.attr("checked")
- .equals("true") || e.attr("checked").equals(""));
- }
-
- @Test
- public void testUnchecked() {
- CheckBox box = new CheckBox();
- box.setValue(false);
- Element e = ctx.createElement(box);
- assertFalse("the element must not have checked attribute",
- e.hasAttr("checked"));
- }
-} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/csslayout/CssLayoutDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/csslayout/CssLayoutDeclarativeTest.java
new file mode 100644
index 0000000000..4cb3fb13e5
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/csslayout/CssLayoutDeclarativeTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.csslayout;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+import org.junit.Test;
+
+import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CssLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Tests declarative support for CssLayout.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class CssLayoutDeclarativeTest extends DeclarativeTestBase<CssLayout> {
+
+ @Test
+ public void testNoChildren() {
+ String design = "<v-css-layout />";
+ CssLayout layout = new CssLayout();
+ testRead(design, layout);
+ testWrite(design, layout);
+ design = "<v-css-layout caption=\"A caption\"/>";
+ layout = new CssLayout();
+ layout.setCaption("A caption");
+ testRead(design, layout);
+ testWrite(design, layout);
+ }
+
+ @Test
+ public void testFeatures() {
+ String design = "<v-css-layout caption=test-layout><v-label caption=test-label />"
+ + "<v-button>test-button</v-button></v-css-layout>";
+ CssLayout layout = new CssLayout();
+ layout.setCaption("test-layout");
+ Label l = new Label();
+ l.setContentMode(ContentMode.HTML);
+ l.setCaption("test-label");
+ layout.addComponent(l);
+ Button b = new Button("test-button");
+ b.setCaptionAsHtml(true);
+ layout.addComponent(b);
+ testRead(design, layout);
+ testWrite(design, layout);
+ }
+
+ @Test
+ public void testWriteWithOldContents() {
+ // Test that any old contents of an element are removed when
+ // writing a design.
+ Element design = createDesign();
+ CssLayout layout = new CssLayout();
+ layout.addComponent(new Label("test-label"));
+ layout.getComponent(0).setCaption("test-caption");
+ layout.addComponent(new Label("test-label-2"));
+ layout.writeDesign(design, new DesignContext());
+ assertEquals(2, design.childNodes().size());
+ assertEquals("v-label", ((Element) design.childNode(0)).tagName());
+ assertEquals("test-caption", design.childNode(0).attr("caption"));
+ }
+
+ private Element createDesign() {
+ // create an element with some contents
+ Attributes rootAttributes = new Attributes();
+ rootAttributes.put("caption", "test-layout");
+ Element node = new Element(Tag.valueOf("v-vertical-layout"), "",
+ rootAttributes);
+ Attributes childAttributes = new Attributes();
+ childAttributes.put("caption", "test-label");
+ Element child = new Element(Tag.valueOf("v-label"), "", childAttributes);
+ node.appendChild(child);
+
+ return node;
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/csslayout/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/csslayout/ReadDesignTest.java
deleted file mode 100644
index 5c3517fa56..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/csslayout/ReadDesignTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.csslayout;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.Component;
-import com.vaadin.ui.CssLayout;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for reading CssLayout from design
- *
- * @author Vaadin Ltd
- */
-public class ReadDesignTest extends TestCase {
-
- public void testChildCount() {
- CssLayout root = createLayout();
- assertEquals(2, root.getComponentCount());
- }
-
- public void testAttributes() {
- CssLayout root = createLayout();
- assertEquals("test-layout", root.getCaption());
- assertEquals("test-label", root.getComponent(0).getCaption());
- assertEquals("test-button", root.getComponent(1).getCaption());
- }
-
- private CssLayout createLayout() {
- DesignContext ctx = new DesignContext();
- Element design = createDesign();
- Component child = ctx.readDesign(design);
- return (CssLayout) child;
- }
-
- private Element createDesign() {
-
- Attributes rootAttributes = new Attributes();
- rootAttributes.put("caption", "test-layout");
- Element node = new Element(Tag.valueOf("v-css-layout"), "",
- rootAttributes);
-
- Attributes firstChildAttributes = new Attributes();
- firstChildAttributes.put("caption", "test-label");
- Element firstChild = new Element(Tag.valueOf("v-label"), "",
- firstChildAttributes);
- node.appendChild(firstChild);
-
- Attributes secondChildAttributes = new Attributes();
- Element secondChild = new Element(Tag.valueOf("v-button"), "",
- secondChildAttributes);
- secondChild.html("test-button");
- node.appendChild(secondChild);
- return node;
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/csslayout/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/csslayout/WriteDesignTest.java
deleted file mode 100644
index 0fdb1c8335..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/csslayout/WriteDesignTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.csslayout;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.CssLayout;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for writing CssLayout to design
- *
- * @author Vaadin Ltd
- */
-public class WriteDesignTest extends TestCase {
-
- public void testSynchronizeEmptyLayout() {
- CssLayout layout = new CssLayout();
- layout.setCaption("changed-caption");
- Element design = createDesign();
- layout.writeDesign(design, createDesignContext());
- assertEquals(0, design.childNodes().size());
- assertEquals("changed-caption", design.attr("caption"));
- }
-
- public void testSynchronizeLayoutWithChildren() {
- CssLayout layout = new CssLayout();
- layout.addComponent(new Label("test-label"));
- layout.getComponent(0).setCaption("test-caption");
- layout.addComponent(new Label("test-label-2"));
- Element design = createDesign();
- layout.writeDesign(design, createDesignContext());
- assertEquals(2, design.childNodes().size());
- assertEquals("v-label", ((Element) design.childNode(0)).tagName());
- assertEquals("test-caption", design.childNode(0).attr("caption"));
- }
-
- private Element createDesign() {
- // make sure that the design node has old content that should be removed
- Attributes rootAttributes = new Attributes();
- rootAttributes.put("caption", "test-layout");
- Element node = new Element(Tag.valueOf("v-vertical-layout"), "",
- rootAttributes);
- Attributes firstChildAttributes = new Attributes();
- firstChildAttributes.put("caption", "test-label");
- Element firstChild = new Element(Tag.valueOf("v-label"), "",
- firstChildAttributes);
- node.appendChild(firstChild);
-
- Element secondChild = new Element(Tag.valueOf("v-button"), "",
- new Attributes());
- secondChild.html("test-button");
- node.appendChild(secondChild);
- return node;
- }
-
- private DesignContext createDesignContext() {
- return new DesignContext();
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeAttributeTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeAttributeTest.java
index d27968cb07..8ffe749f6f 100644
--- a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeAttributeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeAttributeTest.java
@@ -54,6 +54,20 @@ public class GridDeclarativeAttributeTest extends DeclarativeTestBase<Grid> {
}
@Test
+ public void testFrozenColumnsAttributes() {
+ String design = "<v-grid frozen-columns='2'><table>" //
+ + "<colgroup><col><col><col></colgroup></table></v-grid>";
+
+ Grid grid = new Grid();
+ grid.addColumn("property-0", String.class);
+ grid.addColumn("property-1", String.class);
+ grid.addColumn("property-2", String.class);
+ grid.setFrozenColumnCount(2);
+
+ testRead(design, grid);
+ }
+
+ @Test
public void testSelectionMode() {
String design = "<v-grid selection-mode='none'>";
assertSame(NoSelectionModel.class, read(design).getSelectionModel()
diff --git a/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java
index 9af08a26f4..a3f27e4397 100644
--- a/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java
@@ -15,11 +15,18 @@
*/
package com.vaadin.tests.server.component.label;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
import org.junit.Test;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.design.DeclarativeTestBase;
import com.vaadin.ui.Label;
+import com.vaadin.ui.declarative.DesignContext;
/**
* Tests declarative support for implementations of {@link Label}.
@@ -30,66 +37,85 @@ import com.vaadin.ui.Label;
public class LabelDeclarativeTest extends DeclarativeTestBase<Label> {
@Test
- public void testDefaultRead() {
- testRead(getDefaultDesign(), getDefaultExpected());
+ public void testEmpty() {
+ String design = "<v-label />";
+ Label l = new Label();
+ l.setContentMode(ContentMode.HTML);
+ testRead(design, l);
+ testWrite(design, l);
}
@Test
- public void testDefaultWrite() {
- testWrite(getDefaultDesign(), getDefaultExpected());
- }
-
- protected String getDefaultDesign() {
- return "<v-label>Hello world!</v-label>";
+ public void testDefault() {
+ String design = "<v-label>Hello world!</v-label>";
+ Label l = createLabel("Hello world!", null, true);
+ testRead(design, l);
+ testWrite(design, l);
}
- protected Label getDefaultExpected() {
- Label tf = new Label();
- tf.setContentMode(ContentMode.HTML);
- tf.setValue("Hello world!");
- return tf;
- };
-
@Test
- public void testRichRead() {
- testRead(getRichDesign(), getRichExpected());
+ public void testRich() {
+ String design = "<v-label>This is <b><u>Rich</u></b> content!</v-label>";
+ Label l = createLabel("This is \n<b><u>Rich</u></b> content!", null,
+ true);
+ testRead(design, l);
+ testWrite(design, l);
}
@Test
- public void testRichWrite() {
- testWrite(getRichDesign(), getRichExpected());
+ public void testPlainText() {
+ String design = "<v-label plain-text>This is only <b>text</b>"
+ + " and will contain visible tags</v-label>";
+ Label l = createLabel(
+ "This is only \n<b>text</b> and will contain visible tags",
+ null, false);
+ testRead(design, l);
+ testWrite(design, l);
}
- protected String getRichDesign() {
- return "<v-label>This is <b><u>Rich</u></b> content!</v-label>";
+ @Test
+ public void testContentAndCaption() {
+ String design = "<v-label caption='This is a label'>This is <b><u>Rich</u></b> "
+ + "content!</v-label>";
+ Label l = createLabel("This is \n<b><u>Rich</u></b> content!",
+ "This is a label", true);
+ testRead(design, l);
+ testWrite(design, l);
}
- protected Label getRichExpected() {
- Label tf = new Label();
- tf.setContentMode(ContentMode.HTML);
- tf.setValue("This is \n<b><u>Rich</u></b> content!");
- return tf;
- };
-
@Test
- public void testPlainTextRead() {
- testRead(getPlainTextDesign(), getPlainTextExpected());
+ public void testCaption() {
+ String design = "<v-label caption='This is a label' />";
+ Label l = createLabel(null, "This is a label", true);
+ testRead(design, l);
+ testWrite(design, l);
}
@Test
- public void testPlainTextWrite() {
- testWrite(getPlainTextDesign(), getPlainTextExpected());
+ public void testWriteContentMode() {
+ // test that the plain-text attribute is overwritten by writeDesign
+ DesignContext ctx = new DesignContext();
+ Label l = new Label("label");
+ l.setContentMode(ContentMode.TEXT);
+ Element e = new Element(Tag.valueOf("v-label"), "", new Attributes());
+ l.writeDesign(e, ctx);
+ assertTrue("Label should be marked as plain text",
+ e.hasAttr("plain-text"));
+ l.setContentMode(ContentMode.HTML);
+ l.writeDesign(e, ctx);
+ assertFalse("Label should not be marked as plain text",
+ e.hasAttr("plain-text"));
}
- protected String getPlainTextDesign() {
- return "<v-label plain-text>This is only <b>text</b> and will contain visible tags</v-label>";
+ private Label createLabel(String content, String caption, boolean html) {
+ Label label = new Label();
+ label.setContentMode(html ? ContentMode.HTML : ContentMode.TEXT);
+ if (content != null) {
+ label.setValue(content);
+ }
+ if (caption != null) {
+ label.setCaption(caption);
+ }
+ return label;
}
-
- protected Label getPlainTextExpected() {
- Label tf = new Label();
- tf.setContentMode(ContentMode.TEXT);
- tf.setValue("This is only \n<b>text</b> and will contain visible tags");
- return tf;
- };
-
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/label/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/label/ReadDesignTest.java
deleted file mode 100644
index 9ccaf43398..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/label/ReadDesignTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.label;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-import org.junit.Test;
-
-import com.vaadin.ui.Label;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- *
- * Test case for reading the contents of a Label from a design.
- *
- */
-public class ReadDesignTest extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- @Test
- public void testWithContent() {
- createAndTestLabel("A label", null);
- }
-
- @Test
- public void testWithHtmlContent() {
- createAndTestLabel("<b>A label</b>", null);
- }
-
- @Test
- public void testWithContentAndCaption() {
- createAndTestLabel("A label", "This is a label");
- }
-
- @Test
- public void testWithCaption() {
- createAndTestLabel(null, "This is a label");
- }
-
- @Test
- public void testWithoutContentAndCaption() {
- createAndTestLabel(null, null);
- }
-
- /*
- * Test creating a Label. A Label can have both caption and content.
- */
- private void createAndTestLabel(String content, String caption) {
- Element e = createElement("v-label", content, caption);
- Label l = (Label) ctx.readDesign(e);
- if (content != null) {
- assertEquals("The label has wrong text content.", content,
- l.getValue());
- } else {
- assertTrue("The label has wrong text content.",
- l.getValue() == null || "".equals(l.getValue()));
- }
- if (caption != null) {
- assertEquals("The label has wrong caption.", caption,
- l.getCaption());
- } else {
- assertTrue("The label has wrong caption.", l.getCaption() == null
- || "".equals(l.getCaption()));
- }
- }
-
- private Element createElement(String elementName, String content,
- String caption) {
- Attributes attributes = new Attributes();
- if (caption != null) {
- attributes.put("caption", caption);
- }
- Element node = new Element(Tag.valueOf(elementName), "", attributes);
- if (content != null) {
- node.html(content);
- }
- return node;
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/label/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/label/WriteDesignTest.java
deleted file mode 100644
index 3d13767d35..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/label/WriteDesignTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.label;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-import org.junit.Test;
-
-import com.vaadin.shared.ui.label.ContentMode;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Tests generating an html tree node corresponding to a Label.
- */
-public class WriteDesignTest extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- @Test
- public void testWithContent() {
- createAndTestLabel("A label", null);
- }
-
- @Test
- public void testWithHtmlContent() {
- createAndTestLabel("<b>A label</b>", null);
- }
-
- @Test
- public void testWithCaption() {
- createAndTestLabel(null, "Label caption");
- }
-
- @Test
- public void testWithContentAndCaption() {
- createAndTestLabel("A label", "Label caption");
- }
-
- @Test
- public void testContentModeText() {
- Label l = new Label("plain text label");
- Element e = new Element(Tag.valueOf("v-label"), "", new Attributes());
- l.writeDesign(e, ctx);
- assertTrue("Label should be marked as plain text",
- e.hasAttr("plain-text"));
- }
-
- @Test
- public void testContentModeHtml() {
- Label l = new Label("html label");
- l.setContentMode(ContentMode.HTML);
-
- Element e = new Element(Tag.valueOf("v-label"), "", new Attributes());
- l.writeDesign(e, ctx);
- assertFalse("Label should not be marked as plain text",
- e.hasAttr("plain-text"));
- }
-
- @Test
- public void testChangeContentMode() {
- Label l = new Label("html label");
- l.setContentMode(ContentMode.HTML);
-
- Element e = new Element(Tag.valueOf("v-label"), "", new Attributes());
- l.writeDesign(e, ctx);
-
- assertFalse("Label should not be marked as plain text",
- e.hasAttr("plain-text"));
- l.setContentMode(ContentMode.TEXT);
- l.writeDesign(e, ctx);
-
- assertTrue("Label should be marked as plain text",
- e.hasAttr("plain-text"));
- }
-
- @Test
- public void testWithoutContentAndCaption() {
- createAndTestLabel(null, null);
- }
-
- private void createAndTestLabel(String content, String caption) {
- Label l = new Label(content);
- if (caption != null) {
- l.setCaption(caption);
- }
- Element e = ctx.createElement(l);
- assertEquals("Wrong tag name for label.", "v-label", e.tagName());
- if (content != null) {
- assertEquals("Unexpected content in the v-label element.", content,
- e.html());
- } else {
- assertTrue("Unexpected content in the v-label element.",
- e.html() == null || "".equals(e.html()));
- }
- if (caption != null) {
- assertEquals("Wrong caption in the v-label element.", caption,
- e.attr("caption"));
- } else {
- assertTrue("Unexpected caption in the v-label element.",
- e.attr("caption") == null || "".equals(e.attr("caption")));
- }
- }
-} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/panel/PanelDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/panel/PanelDeclarativeTest.java
new file mode 100644
index 0000000000..103d427df9
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/panel/PanelDeclarativeTest.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.server.component.panel;
+
+import org.junit.Test;
+
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.declarative.DesignException;
+
+/**
+ * Tests declarative support for Panel.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class PanelDeclarativeTest extends DeclarativeTestBase<Panel> {
+
+ @Test
+ public void testFeatures() {
+ String design = "<v-panel id=panelId caption=\"A panel\" tabindex=2 scroll-left=10 "
+ + "scroll-top=20 width=200px height=150px> "
+ + "<v-vertical-layout width=300px height=400px /> "
+ + "</v-panel>";
+ Panel p = new Panel();
+ p.setId("panelId");
+ p.setCaption("A panel");
+ p.setTabIndex(2);
+ p.setScrollLeft(10);
+ p.setScrollTop(20);
+ p.setWidth("200px");
+ p.setHeight("150px");
+ VerticalLayout vl = new VerticalLayout();
+ vl.setWidth("300px");
+ vl.setHeight("400px");
+ p.setContent(vl);
+ testRead(design, p);
+ testWrite(design, p);
+ }
+
+ @Test(expected = DesignException.class)
+ public void testWithMoreThanOneChild() {
+ // Check that attempting to have two components in a panel causes a
+ // DesignException.
+ String design = "<v-panel> <v-vertical-layout/> <v-horizontal-layout/> </v-panel>";
+ testRead(design, null);
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/panel/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/panel/ReadDesignTest.java
deleted file mode 100644
index 41b19c9778..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/panel/ReadDesignTest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.panel;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.Panel;
-import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.declarative.DesignContext;
-import com.vaadin.ui.declarative.DesignException;
-
-/**
- * Test case for reading the attributes of a Panel from design.
- *
- * @author Vaadin Ltd
- */
-public class ReadDesignTest extends TestCase {
- DesignContext ctx;
-
- @Override
- public void setUp() {
- ctx = new DesignContext();
- }
-
- public void testAttributes() {
- Element design = createDesign();
- Panel panel = new Panel();
- panel.readDesign(design, ctx);
- assertEquals("A panel", panel.getCaption());
- assertEquals(2, panel.getTabIndex());
- assertEquals(10, panel.getScrollLeft());
- assertEquals(20, panel.getScrollTop());
- assertEquals(200f, panel.getWidth());
- assertEquals(150f, panel.getHeight());
- }
-
- public void testChild() {
- Element design = createDesign();
- Panel panel = new Panel();
- panel.readDesign(design, ctx);
- VerticalLayout vLayout = (VerticalLayout) panel.getContent();
- assertEquals(300f, vLayout.getWidth());
- assertEquals(400f, vLayout.getHeight());
- }
-
- public void testWithMoreThanOneChild() {
- Element design = createDesign();
- // Add a new child to the panel element. An exception should be
- // thrown when parsing the design.
- Element newChild = new Element(Tag.valueOf("v-horizontal-layout"), "");
- design.appendChild(newChild);
- Panel panel = new Panel();
- try {
- panel.readDesign(design, ctx);
- fail("Parsing a design containing a Panel with more than one child component should have failed.");
- } catch (DesignException e) {
- // Nothing needs to be done, this is the expected case.
- }
- }
-
- /*
- * Creates an html document that can be parsed into a valid component
- * hierarchy.
- */
- private Element createDesign() {
- // Create a node defining a Panel
- Element panelElement = new Element(Tag.valueOf("v-panel"), "");
- panelElement.attr("caption", "A panel");
- panelElement.attr("tabindex", "2");
- panelElement.attr("scroll-left", "10");
- panelElement.attr("scroll-top", "20");
- panelElement.attr("width", "200px");
- panelElement.attr("height", "150px");
- // Add some content to the panel
- Element layoutElement = new Element(Tag.valueOf("v-vertical-layout"),
- "");
- layoutElement.attr("width", "300px");
- layoutElement.attr("height", "400px");
- panelElement.appendChild(layoutElement);
- return panelElement;
- }
-} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/panel/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/panel/WriteDesignTest.java
deleted file mode 100644
index 8b8c6e5e13..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/panel/WriteDesignTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.panel;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.Panel;
-import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for writing the attributes and the child element of a Panel to a
- * design.
- *
- * @author Vaadin Ltd
- */
-public class WriteDesignTest extends TestCase {
- Element panelElement;
-
- @Override
- public void setUp() {
- // create a component hierarchy
- Panel panel = new Panel("A panel");
- panel.setId("panelId");
- panel.setHeight("250px");
- panel.setScrollTop(50);
- panel.setTabIndex(4);
- VerticalLayout vLayout = new VerticalLayout();
- vLayout.setWidth("500px");
- panel.setContent(vLayout);
- // synchronize to design
- DesignContext ctx = new DesignContext();
- panelElement = new Element(Tag.valueOf("div"), "");
- panel.writeDesign(panelElement, ctx);
- }
-
- public void testAttributes() {
- // should have caption, id, height, scroll top and tab index
- assertEquals(5, panelElement.attributes().size());
- // check the values of the attributes
- assertEquals("A panel", panelElement.attr("caption"));
- assertEquals("panelId", panelElement.attr("id"));
- assertEquals("250px", panelElement.attr("height"));
- assertEquals("50", panelElement.attr("scroll-top"));
- assertEquals("4", panelElement.attr("tabindex"));
- }
-
- public void testChild() {
- // the panel element should have exactly one child, a v-vertical-layout
- assertEquals(1, panelElement.childNodes().size());
- Element vLayoutElement = panelElement.child(0);
- assertEquals("v-vertical-layout", vLayoutElement.nodeName());
- assertEquals("500px", vLayoutElement.attr("width"));
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/tabsheet/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/tabsheet/ReadDesignTest.java
deleted file mode 100644
index 67533c8b11..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/tabsheet/ReadDesignTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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.tabsheet;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.server.ExternalResource;
-import com.vaadin.ui.TabSheet;
-import com.vaadin.ui.TabSheet.Tab;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case from reading TabSheet from design
- *
- * @since
- * @author Vaadin Ltd
- */
-public class ReadDesignTest extends TestCase {
-
- private TabSheet sheet;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- sheet = createTabSheet();
- }
-
- public void testChildCount() {
- assertEquals(1, sheet.getComponentCount());
- }
-
- public void testTabIndex() {
- assertEquals(5, sheet.getTabIndex());
- }
-
- public void testTabAttributes() {
- Tab tab = sheet.getTab(0);
- assertEquals("test-caption", tab.getCaption());
- assertEquals(false, tab.isVisible());
- assertEquals(false, tab.isClosable());
- assertEquals(false, tab.isEnabled());
- assertEquals("http://www.vaadin.com/test.png",
- ((ExternalResource) tab.getIcon()).getURL());
- assertEquals("OK", tab.getIconAlternateText());
- assertEquals("test-desc", tab.getDescription());
- assertEquals("test-style", tab.getStyleName());
- assertEquals("test-id", tab.getId());
- }
-
- public void testSelectedComponent() {
- TabSheet tabSheet = new TabSheet();
- tabSheet.readDesign(createFirstTabSelectedDesign(), new DesignContext());
- assertEquals(tabSheet.getTab(0).getComponent(),
- tabSheet.getSelectedTab());
- }
-
- public void testTabContent() {
- assertTrue("The child for the tabsheet should be textfield", sheet
- .getTab(0).getComponent() instanceof TextField);
- }
-
- private TabSheet createTabSheet() {
- TabSheet tabSheet = new TabSheet();
- DesignContext ctx = new DesignContext();
- Element design = createDesign();
- tabSheet.readDesign(design, ctx);
- return tabSheet;
- }
-
- private Element createDesign() {
- // create root design
- Attributes rootAttributes = new Attributes();
- rootAttributes.put("tabindex", "5");
- Element node = new Element(Tag.valueOf("v-tab-sheet"), "",
- rootAttributes);
- // create tab design
- Attributes tabAttributes = new Attributes();
- tabAttributes.put("caption", "test-caption");
- tabAttributes.put("visible", "false");
- tabAttributes.put("closable", "false");
- tabAttributes.put("enabled", "false");
- tabAttributes.put("icon", "http://www.vaadin.com/test.png");
- tabAttributes.put("icon-alt", "OK");
- tabAttributes.put("description", "test-desc");
- tabAttributes.put("style-name", "test-style");
- tabAttributes.put("id", "test-id");
- Element tab = new Element(Tag.valueOf("tab"), "", tabAttributes);
- // add child component to tab
- tab.appendChild(new Element(Tag.valueOf("v-text-field"), "",
- new Attributes()));
- // add tab to root design
- node.appendChild(tab);
- return node;
- }
-
- private Element createFirstTabSelectedDesign() {
- // create root design
- Attributes rootAttributes = new Attributes();
- Element node = new Element(Tag.valueOf("v-tab-sheet"), "",
- rootAttributes);
- // create tab design
- Attributes tabAttributes = new Attributes();
- tabAttributes.put("selected", "");
- tabAttributes.put("caption", "test-caption");
- Element tab = new Element(Tag.valueOf("tab"), "", tabAttributes);
- // add child component to tab
- tab.appendChild(new Element(Tag.valueOf("v-text-field"), "",
- new Attributes()));
- // add tab to root design
- node.appendChild(tab);
- return node;
-
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/tabsheet/TabSheetDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/tabsheet/TabSheetDeclarativeTest.java
new file mode 100644
index 0000000000..c614e7fa1f
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/tabsheet/TabSheetDeclarativeTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.tabsheet;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+import org.junit.Test;
+
+import com.vaadin.server.ExternalResource;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.TabSheet;
+import com.vaadin.ui.TabSheet.Tab;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Tests declarative support for TabSheet.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class TabSheetDeclarativeTest extends DeclarativeTestBase<TabSheet> {
+
+ @Test
+ public void testFeatures() {
+ String design = "<v-tab-sheet tabindex=5><tab caption=test-caption "
+ + "visible=false closable=true enabled=false icon=http://www.vaadin.com/test.png"
+ + " icon-alt=OK description=test-desc style-name=test-style "
+ + "id=test-id><v-text-field/></tab></v-tab-sheet>";
+ TabSheet ts = new TabSheet();
+ ts.setTabIndex(5);
+ TextField tf = new TextField();
+ Tab tab = ts.addTab(tf);
+ tab.setCaption("test-caption");
+ tab.setVisible(false);
+ tab.setClosable(true);
+ tab.setEnabled(false);
+ tab.setIcon(new ExternalResource("http://www.vaadin.com/test.png"));
+ tab.setIconAlternateText("OK");
+ tab.setDescription("test-desc");
+ tab.setStyleName("test-style");
+ tab.setId("test-id");
+ ts.setSelectedTab(tf);
+ testRead(design, ts);
+ testWrite(design, ts);
+ }
+
+ @Test
+ public void testSelected() {
+ String design = "<v-tab-sheet><tab selected=true><v-text-field/></tab></v-tab-sheet>";
+ TabSheet ts = new TabSheet();
+ TextField tf = new TextField();
+ ts.addTab(tf);
+ ts.setSelectedTab(tf);
+ testRead(design, ts);
+ testWrite(design, ts);
+ }
+
+ @Test
+ public void testWriteRemovesOldContent() {
+ // create old content that should be removed when writing
+ Element design = new Element(Tag.valueOf("v-tab-sheet"), "",
+ new Attributes());
+ design.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes()));
+ design.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes()));
+ design.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes()));
+ // create a new TabSheet with one tab
+ TabSheet ts = new TabSheet();
+ ts.setTabIndex(5);
+ ts.addTab(new TextField());
+ Tab tab = ts.getTab(0);
+ tab.setVisible(false);
+ tab.setClosable(true);
+ tab.setEnabled(false);
+ // write the design and check written contents
+ ts.writeDesign(design, new DesignContext());
+ assertEquals("There should be only one child", 1, design.children()
+ .size());
+ assertEquals("v-text-field", design.child(0).child(0).tagName());
+ assertEquals("5", design.attr("tabindex"));
+ Element tabDesign = design.child(0);
+ assertEquals("false", tabDesign.attr("visible"));
+ }
+} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/tabsheet/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/tabsheet/WriteDesignTest.java
deleted file mode 100644
index ab7ef9977c..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/tabsheet/WriteDesignTest.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.tabsheet;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.server.ExternalResource;
-import com.vaadin.ui.TabSheet;
-import com.vaadin.ui.TabSheet.Tab;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for writing TabSheet to design
- *
- * @since
- * @author Vaadin Ltd
- */
-public class WriteDesignTest extends TestCase {
-
- private TabSheet sheet;
- private Element design;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- sheet = createTabSheet();
- design = createDesign();
- sheet.writeDesign(design, createDesignContext());
- }
-
- public void testOnlyOneTab() {
- assertEquals("There should be only one child", 1, design.children()
- .size());
- }
-
- public void testAttributes() {
- Element tabDesign = design.child(0);
- assertEquals("5", design.attr("tabindex"));
- assertEquals("test-caption", tabDesign.attr("caption"));
- assertEquals("false", tabDesign.attr("visible"));
- assertTrue(tabDesign.hasAttr("closable"));
- assertTrue(tabDesign.attr("closable").equals("true")
- || tabDesign.attr("closable").equals(""));
- assertEquals("false", tabDesign.attr("enabled"));
- assertEquals("http://www.vaadin.com/test.png", tabDesign.attr("icon"));
- assertEquals("OK", tabDesign.attr("icon-alt"));
- assertEquals("test-desc", tabDesign.attr("description"));
- assertEquals("test-style", tabDesign.attr("style-name"));
- assertEquals("test-id", tabDesign.attr("id"));
- }
-
- public void testContent() {
- Element tabDesign = design.child(0);
- Element content = tabDesign.child(0);
- assertEquals("Tab must have only one child", 1, tabDesign.children()
- .size());
- assertEquals("v-text-field", content.tagName());
- }
-
- private Element createDesign() {
- // make sure that the design node has old content that should be removed
- Element node = new Element(Tag.valueOf("v-tab-sheet"), "",
- new Attributes());
- node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes()));
- node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes()));
- node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes()));
- return node;
- }
-
- private DesignContext createDesignContext() {
- return new DesignContext();
- }
-
- private TabSheet createTabSheet() {
- TabSheet sheet = new TabSheet();
- sheet.setTabIndex(5);
- sheet.addTab(new TextField());
- Tab tab = sheet.getTab(0);
- tab.setCaption("test-caption");
- tab.setVisible(false);
- tab.setClosable(true);
- tab.setEnabled(false);
- tab.setIcon(new ExternalResource("http://www.vaadin.com/test.png"));
- tab.setIconAlternateText("OK");
- tab.setDescription("test-desc");
- tab.setStyleName("test-style");
- tab.setId("test-id");
- return sheet;
- }
-
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/textarea/ReadDesignTest.java
deleted file mode 100644
index aad831e91c..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/textarea/ReadDesignTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.textarea;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.AbstractTextField;
-import com.vaadin.ui.TextArea;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for reading the value of the TextField from design
- *
- * @author Vaadin Ltd
- */
-public class ReadDesignTest extends TestCase {
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- public void testValue() {
- Element design = createDesign();
- AbstractTextField component = getComponent();
- component.readDesign(design, ctx);
- assertEquals("test value", component.getValue());
- }
-
- private AbstractTextField getComponent() {
- return new TextArea();
- }
-
- private Element createDesign() {
- Attributes attributes = new Attributes();
- Element node = new Element(Tag.valueOf("v-text-area"), "", attributes);
- node.html("test value");
- return node;
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java
index 56f1355bc5..8b0c26df87 100644
--- a/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java
@@ -29,25 +29,13 @@ import com.vaadin.ui.TextArea;
public class TextAreaDeclarativeTest extends DeclarativeTestBase<TextArea> {
@Test
- public void testRead() {
- testRead(getDesign(), getExpected());
+ public void testTextArea() {
+ String design = "<v-text-area rows=6 wordwrap=false>Hello World!</v-text-area>";
+ TextArea ta = new TextArea();
+ ta.setRows(6);
+ ta.setWordwrap(false);
+ ta.setValue("Hello World!");
+ testRead(design, ta);
+ testWrite(design, ta);
}
-
- @Test
- public void testWrite() {
- testWrite(getDesign(), getExpected());
- }
-
- protected String getDesign() {
- return "<v-text-area rows=6 wordwrap=false>Hello World!</v-text-area>";
- }
-
- protected TextArea getExpected() {
- TextArea tf = new TextArea();
- tf.setRows(6);
- tf.setWordwrap(false);
- tf.setValue("Hello World!");
- return tf;
- };
-
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/textarea/WriteDesignTest.java
deleted file mode 100644
index 63712eba15..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/textarea/WriteDesignTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.textarea;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.AbstractTextField;
-import com.vaadin.ui.TextArea;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for writing the value of the TextField to design
- *
- * @author Vaadin Ltd
- */
-public class WriteDesignTest extends TestCase {
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- public void testSynchronizeValue() {
- Element design = createDesign();
- AbstractTextField component = getComponent();
- component.setValue("test value");
- component.writeDesign(design, ctx);
- assertEquals("test value", design.html());
- assertFalse(design.hasAttr("value"));
- }
-
- private AbstractTextField getComponent() {
- return new TextArea();
- }
-
- private Element createDesign() {
- Attributes attr = new Attributes();
- return new Element(Tag.valueOf("v-text-area"), "", attr);
- }
-
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/textfield/ReadDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/textfield/ReadDesignTest.java
deleted file mode 100644
index d3da7fef8b..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/textfield/ReadDesignTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.textfield;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.AbstractTextField;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for reading the value of the TextField from design
- *
- * @author Vaadin Ltd
- */
-public class ReadDesignTest extends TestCase {
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- public void testValue() {
- Element design = createDesign();
- AbstractTextField component = getComponent();
- component.readDesign(design, ctx);
- assertEquals("test value", component.getValue());
- }
-
- private AbstractTextField getComponent() {
- return new TextField();
- }
-
- private Element createDesign() {
- Attributes attributes = new Attributes();
- attributes.put("value", "test value");
- Element node = new Element(Tag.valueOf("v-text-field"), "", attributes);
- return node;
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java
index 4f1c2f795b..b4e7f9dae3 100644
--- a/server/tests/src/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java
@@ -29,22 +29,19 @@ import com.vaadin.ui.TextField;
public class TextFieldDeclarativeTest extends DeclarativeTestBase<TextField> {
@Test
- public void testPlainTextRead() {
- testRead(getDesign(), getExpected());
+ public void testEmpty() {
+ String design = "<v-text-field/>";
+ TextField tf = new TextField();
+ testRead(design, tf);
+ testWrite(design, tf);
}
@Test
- public void testPlainTextWrite() {
- testWrite(getDesign(), getExpected());
- }
-
- protected String getDesign() {
- return "<v-text-field/>";
- }
-
- protected TextField getExpected() {
+ public void testValue() {
+ String design = "<v-text-field value=\"test value\"/>";
TextField tf = new TextField();
- return tf;
- };
-
+ tf.setValue("test value");
+ testRead(design, tf);
+ testWrite(design, tf);
+ }
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/textfield/WriteDesignTest.java b/server/tests/src/com/vaadin/tests/server/component/textfield/WriteDesignTest.java
deleted file mode 100644
index 061b0ff402..0000000000
--- a/server/tests/src/com/vaadin/tests/server/component/textfield/WriteDesignTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.textfield;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.AbstractTextField;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for writing the value of the TextField to design
- *
- * @author Vaadin Ltd
- */
-public class WriteDesignTest extends TestCase {
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- public void testSynchronizeValue() {
- Element design = createDesign();
- AbstractTextField component = getComponent();
- component.setValue("test value");
- component.writeDesign(design, ctx);
- assertEquals("test value", design.attr("value"));
- }
-
- private AbstractTextField getComponent() {
- return new TextField();
- }
-
- private Element createDesign() {
- Attributes attr = new Attributes();
- return new Element(Tag.valueOf("v-text-field"), "", attr);
- }
-
-}