import com.vaadin.shared.communication.SharedState;
import com.vaadin.ui.UI;
import com.vaadin.util.ReflectTools;
+
import elemental.json.JsonObject;
/**
* .
*
* @return a JSON object with the encoded connector state
- * if the state can not be encoded
*/
- public JsonObject encodeState() ;
+ public JsonObject encodeState();
/**
* Handle a request directed to this connector. This can be used by
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
- * .Node, com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractComponent#readDesign(org.jsoup.nodes .Node,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
+ public void readDesign(Element design, DesignContext designContext) {
// process default attributes
- super.synchronizeFromDesign(design, designContext);
+ super.readDesign(design, designContext);
// remove current children
removeAllComponents();
// handle children
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Node,
+ * @see com.vaadin.ui.AbstractComponent#writeDesign(org.jsoup.nodes.Node,
* com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
- super.synchronizeToDesign(design, designContext);
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
// handle children
Element designElement = design;
for (Component child : this) {
Element childNode = designContext.createNode(child);
designElement.appendChild(childNode);
- child.synchronizeToDesign(childNode, designContext);
+ child.writeDesign(childNode, designContext);
// handle position
ComponentPosition position = getPosition(child);
writePositionAttribute(childNode, ATTR_TOP, position.getTopUnits()
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.Component#synchronizeFromDesign(org.jsoup.nodes.Element,
+ * @see com.vaadin.ui.Component#readDesign(org.jsoup.nodes.Element,
* com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
+ public void readDesign(Element design, DesignContext designContext) {
Attributes attr = design.attributes();
AbstractComponent def = designContext.getDefaultInstance(this
.getClass());
/**
* Returns a collection of attributes that should not be handled by the
* basic implementation of the {@link synhronizeFromDesign} and
- * {@link synchronizeToDesign} methods. Typically these are handled in a
- * custom way in the overridden versions of the above methods
+ * {@link writeDesign} methods. Typically these are handled in a custom way
+ * in the overridden versions of the above methods
*
* @return the collection of attributes that are not handled by the basic
* implementation
/*
* (non-Javadoc)
*
- * @see com.vaadin.ui.Component#synchronizeToDesign(org.jsoup.nodes.Element,
+ * @see com.vaadin.ui.Component#writeDesign(org.jsoup.nodes.Element,
* com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
+ public void writeDesign(Element design, DesignContext designContext) {
// clear element contents
DesignAttributeHandler.clearElement(design);
AbstractComponent def = designContext.getDefaultInstance(this
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractComponent#readDesign(org.jsoup.nodes .Element,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
- super.synchronizeFromDesign(design, designContext);
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
AbstractField def = designContext.getDefaultInstance(this.getClass());
Attributes attr = design.attributes();
boolean readOnly = DesignAttributeHandler.readAttribute("readonly",
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element
+ * @see com.vaadin.ui.AbstractComponent#writeDesign(org.jsoup.nodes.Element
* , com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
- super.synchronizeToDesign(design, designContext);
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
AbstractField def = designContext.getDefaultInstance(this.getClass());
Attributes attr = design.attributes();
// handle readonly
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractComponent#readDesign(org.jsoup.nodes .Element,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
+ public void readDesign(Element design, DesignContext designContext) {
// process default attributes
- super.synchronizeFromDesign(design, designContext);
+ super.readDesign(design, designContext);
// remove current children
removeAllComponents();
// handle margin
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element
+ * @see com.vaadin.ui.AbstractComponent#writeDesign(org.jsoup.nodes.Element
* , com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
+ public void writeDesign(Element design, DesignContext designContext) {
// synchronize default attributes
- super.synchronizeToDesign(design, designContext);
+ super.writeDesign(design, designContext);
// handle margin
AbstractOrderedLayout def = designContext.getDefaultInstance(this
.getClass());
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractComponent#readDesign(org.jsoup.nodes .Element,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
+ public void readDesign(Element design, DesignContext designContext) {
// process default attributes
- super.synchronizeFromDesign(design, designContext);
+ super.readDesign(design, designContext);
// handle child element, checking that the design specifies at most one
// child
int childCount = design.children().size();
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element
+ * @see com.vaadin.ui.AbstractComponent#writeDesign(org.jsoup.nodes.Element
* , com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
+ public void writeDesign(Element design, DesignContext designContext) {
// synchronize default attributes (also clears children and attributes)
- super.synchronizeToDesign(design, designContext);
+ super.writeDesign(design, designContext);
// handle child component
Component child = getContent();
if (child != null) {
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractComponent#readDesign(org.jsoup.nodes .Element,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
+ public void readDesign(Element design, DesignContext designContext) {
// handle default attributes
- super.synchronizeFromDesign(design, designContext);
+ super.readDesign(design, designContext);
// handle custom attributes, use default values if no explicit value
// set
AbstractSplitPanel def = designContext.getDefaultInstance(this
}
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
+ public void writeDesign(Element design, DesignContext designContext) {
// handle default attributes (also clears children and attributes)
- super.synchronizeToDesign(design, designContext);
+ super.writeDesign(design, designContext);
// handle custom attributes (write only if a value is not the
// default value)
AbstractSplitPanel def = designContext.getDefaultInstance(this
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractField#synchronizeFromDesign(org.jsoup.nodes.Element
- * , com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element ,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
- super.synchronizeFromDesign(design, designContext);
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
AbstractTextField def = designContext.getDefaultInstance(this
.getClass());
Attributes attr = design.attributes();
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractField#synchronizeToDesign(org.jsoup.nodes.Element,
+ * @see com.vaadin.ui.AbstractField#writeDesign(org.jsoup.nodes.Element,
* com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
- super.synchronizeToDesign(design, designContext);
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
AbstractTextField def = designContext.getDefaultInstance(this
.getClass());
Attributes attr = design.attributes();
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractComponent#readDesign(org.jsoup.nodes .Element,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
- super.synchronizeFromDesign(design, designContext);
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
Button def = designContext.getDefaultInstance(this.getClass());
Attributes attr = design.attributes();
String content = design.html();
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element
+ * @see com.vaadin.ui.AbstractComponent#writeDesign(org.jsoup.nodes.Element
* , com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
- super.synchronizeToDesign(design, designContext);
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
Attributes attr = design.attributes();
Button def = designContext.getDefaultInstance(this.getClass());
String content = getCaption();
* @param designContext
* The DesignContext instance used for parsing the design
*/
- public void synchronizeFromDesign(Element design,
- DesignContext designContext);
+ public void readDesign(Element design, DesignContext designContext);
/**
* Update the given design based on the component state. The component is
* The design as HTML to update with the current state
* @param designContext
*/
- public void synchronizeToDesign(Element design, DesignContext designContext);
+ public void writeDesign(Element design, DesignContext designContext);
/* Component event framework */
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractComponent#readDesign(org.jsoup.nodes .Element,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
+ public void readDesign(Element design, DesignContext designContext) {
// process default attributes
- super.synchronizeFromDesign(design, designContext);
+ super.readDesign(design, designContext);
// remove current children
removeAllComponents();
// handle children
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element
+ * @see com.vaadin.ui.AbstractComponent#writeDesign(org.jsoup.nodes.Element
* , com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
+ public void writeDesign(Element design, DesignContext designContext) {
// synchronize default attributes
- super.synchronizeToDesign(design, designContext);
+ super.writeDesign(design, designContext);
// handle children
Element designElement = design;
for (Component child : this) {
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractComponent#readDesign(org.jsoup.nodes .Element,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
- super.synchronizeFromDesign(design, designContext);
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
String innerHtml = design.html();
if (innerHtml != null && !"".equals(innerHtml)) {
setValue(innerHtml);
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element
+ * @see com.vaadin.ui.AbstractComponent#writeDesign(org.jsoup.nodes.Element
* , com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
- super.synchronizeToDesign(design, designContext);
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
String content = getValue();
if (content != null) {
design.html(getValue());
}
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
- super.synchronizeFromDesign(design, designContext);
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
// handle tabindex
Panel def = designContext.getDefaultInstance(this.getClass());
int tabIndex = DesignAttributeHandler.readAttribute("tabindex",
}
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
- super.synchronizeToDesign(design, designContext);
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
// handle tabindex
Panel def = designContext.getDefaultInstance(this.getClass());
DesignAttributeHandler.writeAttribute("tabindex", design.attributes(),
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractField#synchronizeFromDesign(org.jsoup.nodes.Element
- * , com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element ,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
- super.synchronizeFromDesign(design, designContext);
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
AbstractTextField def = designContext.getDefaultInstance(this
.getClass());
Attributes attr = design.attributes();
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractTextField#synchronizeToDesign(org.jsoup.nodes.Element
+ * @see com.vaadin.ui.AbstractTextField#writeDesign(org.jsoup.nodes.Element
* , com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
- super.synchronizeToDesign(design, designContext);
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
AbstractTextField def = designContext.getDefaultInstance(this
.getClass());
Attributes attr = design.attributes();
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractComponent#readDesign(org.jsoup.nodes .Element,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
- super.synchronizeFromDesign(design, designContext);
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
Attributes attr = design.attributes();
TabSheet def = designContext.getDefaultInstance(this.getClass());
// handle tab index
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element
+ * @see com.vaadin.ui.AbstractComponent#writeDesign(org.jsoup.nodes.Element
* , com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
- super.synchronizeToDesign(design, designContext);
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
TabSheet def = designContext.getDefaultInstance(this.getClass());
Attributes attr = design.attributes();
// handle tab index
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractField#synchronizeFromDesign(org.jsoup.nodes.Element
- * , com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element ,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
- super.synchronizeFromDesign(design, designContext);
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
setValue(design.html());
}
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractTextField#synchronizeToDesign(org.jsoup.nodes.Element
+ * @see com.vaadin.ui.AbstractTextField#writeDesign(org.jsoup.nodes.Element
* , com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
- super.synchronizeToDesign(design, designContext);
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
design.html(getValue());
}
}
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractField#synchronizeFromDesign(org.jsoup.nodes.Element
- * , com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element ,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeFromDesign(Element design,
- DesignContext designContext) {
- super.synchronizeFromDesign(design, designContext);
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
AbstractTextField def = designContext.getDefaultInstance(this
.getClass());
Attributes attr = design.attributes();
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractTextField#synchronizeToDesign(org.jsoup.nodes.Element
+ * @see com.vaadin.ui.AbstractTextField#writeDesign(org.jsoup.nodes.Element
* , com.vaadin.ui.declarative.DesignContext)
*/
@Override
- public void synchronizeToDesign(Element design, DesignContext designContext) {
- super.synchronizeToDesign(design, designContext);
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
AbstractTextField def = designContext.getDefaultInstance(this
.getClass());
Attributes attr = design.attributes();
/**
* Creates an html tree node corresponding to the given element. Also
- * initializes its attributes by calling synchronizeToDesign. As a result of
- * the synchronizeToDesign() call, this method creates the entire subtree
- * rooted at the returned Node.
+ * initializes its attributes by calling writeDesign. As a result of the
+ * writeDesign() call, this method creates the entire subtree rooted at the
+ * returned Node.
*
* @param childComponent
* The component with state that is synchronized in to the node
String className = classNameToElementName(componentClass
.getSimpleName());
Element newElement = doc.createElement(prefix + className);
- childComponent.synchronizeToDesign(newElement, this);
+ childComponent.writeDesign(newElement, this);
// Handle the local id. Global id and caption should have been taken
- // care of by synchronizeToDesign.
+ // care of by writeDesign.
String localId = componentToLocalId.get(childComponent);
if (localId != null) {
newElement.attr(LOCAL_ID_ATTRIBUTE, localId);
/**
* Creates a Component corresponding to the given html node. Also calls
- * synchronizeFromDesign() for the created node, in effect creating the
- * entire component hierarchy rooted at the returned component.
+ * readDesign() for the created node, in effect creating the entire
+ * component hierarchy rooted at the returned component.
*
* @param componentDesign
* The html tree node containing the description of the component
}
/**
- * Calls synchronizeFromDesign() for the given component and passes the
- * given component design as a parameter. This creates the entire component
- * hierarchy rooted at the given component. Also registers the componentid,
- * localId and caption of the given component and all its children to the
- * context
+ * Calls readDesign() for the given component and passes the given component
+ * design as a parameter. This creates the entire component hierarchy rooted
+ * at the given component. Also registers the componentid, localId and
+ * caption of the given component and all its children to the context
*
*
* @param component
*/
public void synchronizeAndRegister(Component component,
Element componentDesign) {
- component.synchronizeFromDesign(componentDesign, this);
+ component.readDesign(componentDesign, this);
// Get the ids and the caption of the component and store them in the
// maps of this design context.
org.jsoup.nodes.Attributes attributes = componentDesign.attributes();
--- /dev/null
+/*
+ * 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.absolutelayout;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+
+import com.vaadin.server.Sizeable;
+import com.vaadin.ui.AbsoluteLayout;
+import com.vaadin.ui.AbsoluteLayout.ComponentPosition;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Test case for reading AbsoluteLayout from design
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class TestReadDesign extends TestCase {
+
+ private AbsoluteLayout root;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ root = createLayout();
+ }
+
+ public void testAttributes() {
+ assertEquals("test-layout", root.getCaption());
+ Iterator<Component> children = root.iterator();
+ assertEquals("test-label", children.next().getCaption());
+ assertEquals("test-button", children.next().getCaption());
+ }
+
+ public void testTopLeftPosition() {
+ ComponentPosition position = root.getPosition(root.iterator().next());
+ assertEquals(Sizeable.Unit.PIXELS, position.getTopUnits());
+ assertEquals(100.0f, position.getTopValue());
+ assertEquals(Sizeable.Unit.PERCENTAGE, position.getLeftUnits());
+ assertEquals(50.0f, position.getLeftValue());
+ }
+
+ public void testBottomRightPosition() {
+ Iterator<Component> children = root.iterator();
+ children.next();
+ ComponentPosition position = root.getPosition(children.next());
+ assertEquals(Sizeable.Unit.PIXELS, position.getBottomUnits());
+ assertEquals(100.0f, position.getBottomValue());
+ assertEquals(Sizeable.Unit.PERCENTAGE, position.getRightUnits());
+ assertEquals(50.0f, position.getRightValue());
+ }
+
+ public void testZIndex() {
+ ComponentPosition position = root.getPosition(root.iterator().next());
+ assertEquals(2, position.getZIndex());
+ }
+
+ private AbsoluteLayout createLayout() {
+ DesignContext ctx = new DesignContext();
+ Element design = createDesign();
+ Component child = ctx.createChild(design);
+ return (AbsoluteLayout) child;
+ }
+
+ private Element createDesign() {
+
+ Attributes rootAttributes = new Attributes();
+ rootAttributes.put("caption", "test-layout");
+ Element node = new Element(Tag.valueOf("v-absolute-layout"), "",
+ rootAttributes);
+
+ Attributes firstChildAttributes = new Attributes();
+ firstChildAttributes.put("caption", "test-label");
+ firstChildAttributes.put(":top", "100px");
+ firstChildAttributes.put(":left", "50%");
+ firstChildAttributes.put(":z-index", "2");
+ Element firstChild = new Element(Tag.valueOf("v-label"), "",
+ firstChildAttributes);
+ node.appendChild(firstChild);
+
+ Attributes secondChildAttributes = new Attributes();
+ secondChildAttributes.put(":bottom", "100px");
+ secondChildAttributes.put(":right", "50%");
+ Element secondChild = new Element(Tag.valueOf("v-button"), "",
+ secondChildAttributes);
+ secondChild.html("test-button");
+ node.appendChild(secondChild);
+ return node;
+ }
+}
+++ /dev/null
-/*
- * 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.absolutelayout;
-
-import java.util.Iterator;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.server.Sizeable;
-import com.vaadin.ui.AbsoluteLayout;
-import com.vaadin.ui.AbsoluteLayout.ComponentPosition;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for reading AbsoluteLayout from design
- *
- * @since
- * @author Vaadin Ltd
- */
-public class TestSynchronizeFromDesign extends TestCase {
-
- private AbsoluteLayout root;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- root = createLayout();
- }
-
- public void testAttributes() {
- assertEquals("test-layout", root.getCaption());
- Iterator<Component> children = root.iterator();
- assertEquals("test-label", children.next().getCaption());
- assertEquals("test-button", children.next().getCaption());
- }
-
- public void testTopLeftPosition() {
- ComponentPosition position = root.getPosition(root.iterator().next());
- assertEquals(Sizeable.Unit.PIXELS, position.getTopUnits());
- assertEquals(100.0f, position.getTopValue());
- assertEquals(Sizeable.Unit.PERCENTAGE, position.getLeftUnits());
- assertEquals(50.0f, position.getLeftValue());
- }
-
- public void testBottomRightPosition() {
- Iterator<Component> children = root.iterator();
- children.next();
- ComponentPosition position = root.getPosition(children.next());
- assertEquals(Sizeable.Unit.PIXELS, position.getBottomUnits());
- assertEquals(100.0f, position.getBottomValue());
- assertEquals(Sizeable.Unit.PERCENTAGE, position.getRightUnits());
- assertEquals(50.0f, position.getRightValue());
- }
-
- public void testZIndex() {
- ComponentPosition position = root.getPosition(root.iterator().next());
- assertEquals(2, position.getZIndex());
- }
-
- private AbsoluteLayout createLayout() {
- DesignContext ctx = new DesignContext();
- Element design = createDesign();
- Component child = ctx.createChild(design);
- return (AbsoluteLayout) child;
- }
-
- private Element createDesign() {
-
- Attributes rootAttributes = new Attributes();
- rootAttributes.put("caption", "test-layout");
- Element node = new Element(Tag.valueOf("v-absolute-layout"), "",
- rootAttributes);
-
- Attributes firstChildAttributes = new Attributes();
- firstChildAttributes.put("caption", "test-label");
- firstChildAttributes.put(":top", "100px");
- firstChildAttributes.put(":left", "50%");
- firstChildAttributes.put(":z-index", "2");
- Element firstChild = new Element(Tag.valueOf("v-label"), "",
- firstChildAttributes);
- node.appendChild(firstChild);
-
- Attributes secondChildAttributes = new Attributes();
- secondChildAttributes.put(":bottom", "100px");
- secondChildAttributes.put(":right", "50%");
- Element secondChild = new Element(Tag.valueOf("v-button"), "",
- secondChildAttributes);
- secondChild.html("test-button");
- node.appendChild(secondChild);
- return node;
- }
-}
+++ /dev/null
-/*
- * 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.absolutelayout;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.ui.AbsoluteLayout;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for writing AbsoluteLayout to design
- *
- * @since
- * @author Vaadin Ltd
- */
-public class TestSynchronizeToDesign extends TestCase {
-
- public void testSynchronizeEmptyLayout() {
- AbsoluteLayout layout = createTestLayout();
- layout.removeAllComponents();
- Element design = createDesign();
- layout.synchronizeToDesign(design, createDesignContext());
- assertEquals(0, design.childNodes().size());
- assertEquals("changed-caption", design.attr("caption"));
- }
-
- public void testSynchronizeLayoutWithChildren() {
- AbsoluteLayout layout = createTestLayout();
- Element design = createDesign();
- layout.synchronizeToDesign(design, createDesignContext());
- assertEquals(2, design.childNodes().size());
- assertEquals("v-label", ((Element) design.childNode(0)).tagName());
- assertEquals("v-label", ((Element) design.childNode(1)).tagName());
- }
-
- public void testSynchronizePosition() {
- AbsoluteLayout layout = createTestLayout();
- Element design = createDesign();
- layout.synchronizeToDesign(design, createDesignContext());
- Attributes attributes = design.childNode(0).attributes();
- assertEquals("50px", attributes.get(":top"));
- assertEquals("50%", attributes.get(":left"));
- assertEquals("2", attributes.get(":z-index"));
- attributes = design.childNode(1).attributes();
- assertEquals("50px", attributes.get(":bottom"));
- assertEquals("50%", attributes.get(":right"));
- }
-
- private AbsoluteLayout createTestLayout() {
- AbsoluteLayout layout = new AbsoluteLayout();
- layout.setCaption("changed-caption");
- layout.addComponent(new Label("test-label"),
- "top:50px;left:50%;z-index:2");
- layout.addComponent(new Label("test-label-2"),
- "bottom:50px;right:50%;z-index:3");
- 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-absolute-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();
- }
-}
--- /dev/null
+/*
+ * 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.absolutelayout;
+
+import junit.framework.TestCase;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+
+import com.vaadin.ui.AbsoluteLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Test case for writing AbsoluteLayout to design
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class TestWriteDesign extends TestCase {
+
+ public void testSynchronizeEmptyLayout() {
+ AbsoluteLayout layout = createTestLayout();
+ layout.removeAllComponents();
+ Element design = createDesign();
+ layout.writeDesign(design, createDesignContext());
+ assertEquals(0, design.childNodes().size());
+ assertEquals("changed-caption", design.attr("caption"));
+ }
+
+ public void testSynchronizeLayoutWithChildren() {
+ AbsoluteLayout layout = createTestLayout();
+ Element design = createDesign();
+ layout.writeDesign(design, createDesignContext());
+ assertEquals(2, design.childNodes().size());
+ assertEquals("v-label", ((Element) design.childNode(0)).tagName());
+ assertEquals("v-label", ((Element) design.childNode(1)).tagName());
+ }
+
+ public void testSynchronizePosition() {
+ AbsoluteLayout layout = createTestLayout();
+ Element design = createDesign();
+ layout.writeDesign(design, createDesignContext());
+ Attributes attributes = design.childNode(0).attributes();
+ assertEquals("50px", attributes.get(":top"));
+ assertEquals("50%", attributes.get(":left"));
+ assertEquals("2", attributes.get(":z-index"));
+ attributes = design.childNode(1).attributes();
+ assertEquals("50px", attributes.get(":bottom"));
+ assertEquals("50%", attributes.get(":right"));
+ }
+
+ private AbsoluteLayout createTestLayout() {
+ AbsoluteLayout layout = new AbsoluteLayout();
+ layout.setCaption("changed-caption");
+ layout.addComponent(new Label("test-label"),
+ "top:50px;left:50%;z-index:2");
+ layout.addComponent(new Label("test-label-2"),
+ "bottom:50px;right:50%;z-index:3");
+ 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-absolute-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();
+ }
+}
--- /dev/null
+/*
+ * 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.abstractcomponent;
+
+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 com.vaadin.server.ExternalResource;
+import com.vaadin.server.FileResource;
+import com.vaadin.server.Responsive;
+import com.vaadin.server.ThemeResource;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Test case for reading the attributes of the AbstractComponent from design
+ *
+ * @author Vaadin Ltd
+ */
+public class TestReadDesign extends TestCase {
+
+ private DesignContext ctx;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ ctx = new DesignContext();
+ }
+
+ public void testSynchronizeId() {
+ Element design = createDesign("id", "testId");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals("testId", component.getId());
+ }
+
+ public void testSynchronizePrimaryStyleName() {
+ Element design = createDesign("primary-style-name", "test-style");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals("test-style", component.getPrimaryStyleName());
+ }
+
+ public void testSynchronizeCaption() {
+ Element design = createDesign("caption", "test-caption");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals("test-caption", component.getCaption());
+ }
+
+ public void testSynchronizeLocale() {
+ Element design = createDesign("locale", "fi_FI");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals("fi", component.getLocale().getLanguage());
+ assertEquals("FI", component.getLocale().getCountry());
+ }
+
+ public void testSynchronizeExternalIcon() {
+ Element design = createDesign("icon", "http://example.com/example.gif");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertTrue("Incorrect resource type returned", component.getIcon()
+ .getClass().isAssignableFrom(ExternalResource.class));
+ assertEquals("http://example.com/example.gif",
+ ((ExternalResource) component.getIcon()).getURL());
+ }
+
+ public void testSynchronizeThemeIcon() {
+ Element design = createDesign("icon", "theme://example.gif");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertTrue("Incorrect resource type returned", component.getIcon()
+ .getClass().isAssignableFrom(ThemeResource.class));
+ }
+
+ public void testSynchronizeFileResource() {
+ Element design = createDesign("icon", "img/example.gif");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertTrue("Incorrect resource type returned", component.getIcon()
+ .getClass().isAssignableFrom(FileResource.class));
+ }
+
+ public void testSynchronizeImmediate() {
+ Element design = createDesign("immediate", "true");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals(true, component.isImmediate());
+ assertEquals(Boolean.TRUE, getExplicitImmediate(component));
+ // Synchronize with a design having no immediate attribute -
+ // explicitImmediate should then be null.
+ design = createDesign("description", "test-description");
+ component.readDesign(design, ctx);
+ assertEquals(null, getExplicitImmediate(component));
+ // Synchronize with a design having immediate = false
+ design = createDesign("immediate", "false");
+ component.readDesign(design, ctx);
+ assertEquals(false, component.isImmediate());
+ assertEquals(Boolean.FALSE, getExplicitImmediate(component));
+ // Synchronize with a design having immediate = "" - should correspond
+ // to
+ // true.
+ design = createDesign("immediate", "");
+ component.readDesign(design, ctx);
+ assertEquals(true, component.isImmediate());
+ assertEquals(Boolean.TRUE, getExplicitImmediate(component));
+ }
+
+ public void testSynchronizeDescription() {
+ Element design = createDesign("description", "test-description");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals("test-description", component.getDescription());
+ }
+
+ public void testSynchronizeComponentError() {
+ Element design = createDesign("error", "<div>test-error</div>");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals("<div>test-error</div>", component.getComponentError()
+ .getFormattedHtmlMessage());
+ }
+
+ public void testSynchronizeSizeFull() {
+ Element design = createDesign("size-full", "");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals(100, component.getWidth(), 0.1f);
+ assertEquals(100, component.getHeight(), 0.1f);
+ }
+
+ public void testSynchronizeSizeAuto() {
+ Element design = createDesign("size-auto", "");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals(-1, component.getWidth(), 0.1f);
+ assertEquals(-1, component.getHeight(), 0.1f);
+ }
+
+ public void testSynchronizeHeightFull() {
+ Element design = createDesign("height-full", "");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals(100, component.getHeight(), 0.1f);
+ }
+
+ public void testSynchronizeHeightAuto() {
+ Element design = createDesign("height-auto", "");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals(-1, component.getHeight(), 0.1f);
+ }
+
+ public void testSynchronizeWidthFull() {
+ Element design = createDesign("width-full", "");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals(100, component.getWidth(), 0.1f);
+ }
+
+ public void testSynchronizeWidthAuto() {
+ Element design = createDesign("width-auto", "");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals(-1, component.getWidth(), 0.1f);
+ }
+
+ public void testSynchronizeWidth() {
+ Element design = createDesign("width", "12px");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals(12, component.getWidth(), 0.1f);
+ assertEquals(com.vaadin.server.Sizeable.Unit.PIXELS,
+ component.getWidthUnits());
+ }
+
+ public void testSynchronizeHeight() {
+ Element design = createDesign("height", "12px");
+ AbstractComponent component = getComponent();
+ component.readDesign(design, ctx);
+ assertEquals(12, component.getHeight(), 0.1f);
+ assertEquals(com.vaadin.server.Sizeable.Unit.PIXELS,
+ component.getHeightUnits());
+ }
+
+ public void testSynchronizeNotResponsive() {
+ AbstractComponent component = getComponent();
+ Responsive.makeResponsive(component);
+ Element design = createDesign("responsive", "false");
+ component.readDesign(design, ctx);
+ assertEquals("Component should not have extensions", 0, component
+ .getExtensions().size());
+ }
+
+ public void testSynchronizeResponsive() {
+ AbstractComponent component = getComponent();
+ Element design = createDesign("responsive", "");
+ component.readDesign(design, ctx);
+ assertEquals("Component should have one extension", 1, component
+ .getExtensions().size());
+ assertTrue("Extension should be responsive", component.getExtensions()
+ .iterator().next() instanceof Responsive);
+ }
+
+ public void testSynchronizeAlreadyResponsive() {
+ AbstractComponent component = getComponent();
+ Responsive.makeResponsive(component);
+ Element design = createDesign("responsive", "");
+ component.readDesign(design, ctx);
+ assertEquals("Component should have only one extension", 1, component
+ .getExtensions().size());
+ }
+
+ private AbstractComponent getComponent() {
+ return new Label();
+ }
+
+ private Element createDesign(String key, String value) {
+ Attributes attributes = new Attributes();
+ attributes.put(key, value);
+ Element node = new Element(Tag.valueOf("v-label"), "", attributes);
+ return node;
+ }
+
+ private Boolean getExplicitImmediate(AbstractComponent component) {
+ try {
+ Field immediate = AbstractComponent.class
+ .getDeclaredField("explicitImmediateValue");
+ immediate.setAccessible(true);
+ return (Boolean) immediate.get(component);
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Getting the field explicitImmediateValue failed.");
+ }
+ }
+}
+++ /dev/null
-/*
- * 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.abstractcomponent;
-
-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 com.vaadin.server.ExternalResource;
-import com.vaadin.server.FileResource;
-import com.vaadin.server.Responsive;
-import com.vaadin.server.ThemeResource;
-import com.vaadin.ui.AbstractComponent;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for reading the attributes of the AbstractComponent from design
- *
- * @author Vaadin Ltd
- */
-public class TestSynchronizeFromDesign extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- public void testSynchronizeId() {
- Element design = createDesign("id", "testId");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals("testId", component.getId());
- }
-
- public void testSynchronizePrimaryStyleName() {
- Element design = createDesign("primary-style-name", "test-style");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals("test-style", component.getPrimaryStyleName());
- }
-
- public void testSynchronizeCaption() {
- Element design = createDesign("caption", "test-caption");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals("test-caption", component.getCaption());
- }
-
- public void testSynchronizeLocale() {
- Element design = createDesign("locale", "fi_FI");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals("fi", component.getLocale().getLanguage());
- assertEquals("FI", component.getLocale().getCountry());
- }
-
- public void testSynchronizeExternalIcon() {
- Element design = createDesign("icon", "http://example.com/example.gif");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertTrue("Incorrect resource type returned", component.getIcon()
- .getClass().isAssignableFrom(ExternalResource.class));
- assertEquals("http://example.com/example.gif",
- ((ExternalResource) component.getIcon()).getURL());
- }
-
- public void testSynchronizeThemeIcon() {
- Element design = createDesign("icon", "theme://example.gif");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertTrue("Incorrect resource type returned", component.getIcon()
- .getClass().isAssignableFrom(ThemeResource.class));
- }
-
- public void testSynchronizeFileResource() {
- Element design = createDesign("icon", "img/example.gif");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertTrue("Incorrect resource type returned", component.getIcon()
- .getClass().isAssignableFrom(FileResource.class));
- }
-
- public void testSynchronizeImmediate() {
- Element design = createDesign("immediate", "true");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals(true, component.isImmediate());
- assertEquals(Boolean.TRUE, getExplicitImmediate(component));
- // Synchronize with a design having no immediate attribute -
- // explicitImmediate should then be null.
- design = createDesign("description", "test-description");
- component.synchronizeFromDesign(design, ctx);
- assertEquals(null, getExplicitImmediate(component));
- // Synchronize with a design having immediate = false
- design = createDesign("immediate", "false");
- component.synchronizeFromDesign(design, ctx);
- assertEquals(false, component.isImmediate());
- assertEquals(Boolean.FALSE, getExplicitImmediate(component));
- // Synchronize with a design having immediate = "" - should correspond
- // to
- // true.
- design = createDesign("immediate", "");
- component.synchronizeFromDesign(design, ctx);
- assertEquals(true, component.isImmediate());
- assertEquals(Boolean.TRUE, getExplicitImmediate(component));
- }
-
- public void testSynchronizeDescription() {
- Element design = createDesign("description", "test-description");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals("test-description", component.getDescription());
- }
-
- public void testSynchronizeComponentError() {
- Element design = createDesign("error", "<div>test-error</div>");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals("<div>test-error</div>", component.getComponentError()
- .getFormattedHtmlMessage());
- }
-
- public void testSynchronizeSizeFull() {
- Element design = createDesign("size-full", "");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals(100, component.getWidth(), 0.1f);
- assertEquals(100, component.getHeight(), 0.1f);
- }
-
- public void testSynchronizeSizeAuto() {
- Element design = createDesign("size-auto", "");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals(-1, component.getWidth(), 0.1f);
- assertEquals(-1, component.getHeight(), 0.1f);
- }
-
- public void testSynchronizeHeightFull() {
- Element design = createDesign("height-full", "");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals(100, component.getHeight(), 0.1f);
- }
-
- public void testSynchronizeHeightAuto() {
- Element design = createDesign("height-auto", "");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals(-1, component.getHeight(), 0.1f);
- }
-
- public void testSynchronizeWidthFull() {
- Element design = createDesign("width-full", "");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals(100, component.getWidth(), 0.1f);
- }
-
- public void testSynchronizeWidthAuto() {
- Element design = createDesign("width-auto", "");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals(-1, component.getWidth(), 0.1f);
- }
-
- public void testSynchronizeWidth() {
- Element design = createDesign("width", "12px");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals(12, component.getWidth(), 0.1f);
- assertEquals(com.vaadin.server.Sizeable.Unit.PIXELS,
- component.getWidthUnits());
- }
-
- public void testSynchronizeHeight() {
- Element design = createDesign("height", "12px");
- AbstractComponent component = getComponent();
- component.synchronizeFromDesign(design, ctx);
- assertEquals(12, component.getHeight(), 0.1f);
- assertEquals(com.vaadin.server.Sizeable.Unit.PIXELS,
- component.getHeightUnits());
- }
-
- public void testSynchronizeNotResponsive() {
- AbstractComponent component = getComponent();
- Responsive.makeResponsive(component);
- Element design = createDesign("responsive", "false");
- component.synchronizeFromDesign(design, ctx);
- assertEquals("Component should not have extensions", 0, component
- .getExtensions().size());
- }
-
- public void testSynchronizeResponsive() {
- AbstractComponent component = getComponent();
- Element design = createDesign("responsive", "");
- component.synchronizeFromDesign(design, ctx);
- assertEquals("Component should have one extension", 1, component
- .getExtensions().size());
- assertTrue("Extension should be responsive", component.getExtensions()
- .iterator().next() instanceof Responsive);
- }
-
- public void testSynchronizeAlreadyResponsive() {
- AbstractComponent component = getComponent();
- Responsive.makeResponsive(component);
- Element design = createDesign("responsive", "");
- component.synchronizeFromDesign(design, ctx);
- assertEquals("Component should have only one extension", 1, component
- .getExtensions().size());
- }
-
- private AbstractComponent getComponent() {
- return new Label();
- }
-
- private Element createDesign(String key, String value) {
- Attributes attributes = new Attributes();
- attributes.put(key, value);
- Element node = new Element(Tag.valueOf("v-label"), "", attributes);
- return node;
- }
-
- private Boolean getExplicitImmediate(AbstractComponent component) {
- try {
- Field immediate = AbstractComponent.class
- .getDeclaredField("explicitImmediateValue");
- immediate.setAccessible(true);
- return (Boolean) immediate.get(component);
- } catch (Exception e) {
- throw new RuntimeException(
- "Getting the field explicitImmediateValue failed.");
- }
- }
-}
+++ /dev/null
-/*
- * 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.abstractcomponent;
-
-import java.io.File;
-import java.util.Locale;
-
-import junit.framework.TestCase;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-import com.vaadin.server.AbstractErrorMessage.ContentMode;
-import com.vaadin.server.ErrorMessage.ErrorLevel;
-import com.vaadin.server.ExternalResource;
-import com.vaadin.server.FileResource;
-import com.vaadin.server.Responsive;
-import com.vaadin.server.ThemeResource;
-import com.vaadin.server.UserError;
-import com.vaadin.ui.AbstractComponent;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.HorizontalSplitPanel;
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Test case for writing the attributes of the AbstractComponent to design
- *
- * @author Vaadin Ltd
- */
-public class TestSynchronizeToDesign extends TestCase {
-
- private DesignContext ctx;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ctx = new DesignContext();
- }
-
- public void testSynchronizeId() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setId("testId");
- component.synchronizeToDesign(design, ctx);
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertEquals("testId", design.attr("id"));
- }
-
- public void testSynchronizePrimaryStyleName() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setPrimaryStyleName("test-style");
- component.synchronizeToDesign(design, ctx);
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertEquals("test-style", design.attr("primary-style-name"));
- }
-
- public void testSynchronizeCaption() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setCaption("test-caption");
- component.synchronizeToDesign(design, ctx);
- // We only changed the caption, which is not
- // an attribute.
- assertEquals(0, design.attributes().size());
- assertEquals("test-caption", design.html());
- }
-
- public void testSynchronizeLocale() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setLocale(new Locale("fi", "FI"));
- component.synchronizeToDesign(design, ctx);
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertEquals("fi_FI", design.attr("locale"));
- }
-
- public void testSynchronizeExternalIcon() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component
- .setIcon(new ExternalResource("http://example.com/example.gif"));
- component.synchronizeToDesign(design, ctx);
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertEquals("http://example.com/example.gif", design.attr("icon"));
- }
-
- public void testSynchronizeThemeIcon() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setIcon(new ThemeResource("example.gif"));
- component.synchronizeToDesign(design, ctx);
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertEquals("theme://example.gif", design.attr("icon"));
- }
-
- public void testSynchronizeFileResource() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setIcon(new FileResource(new File("img/example.gif")));
- component.synchronizeToDesign(design, ctx);
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertEquals("img/example.gif", design.attr("icon"));
- }
-
- public void testSynchronizeImmediate() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- // no immediate attribute should be written before setting immediate to
- // some value
- component.synchronizeToDesign(design, ctx);
- assertFalse(design.hasAttr("immediate"));
- component.setImmediate(true);
- component.synchronizeToDesign(design, ctx);
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertEquals("true", design.attr("immediate"));
- }
-
- public void testSynchronizeDescription() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setDescription("test-description");
- component.synchronizeToDesign(design, ctx);
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertEquals("test-description", design.attr("description"));
- }
-
- public void testSynchronizeComponentError() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setComponentError(new UserError("<div>test-error</div>",
- ContentMode.HTML, ErrorLevel.ERROR));
- component.synchronizeToDesign(design, ctx);
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertEquals("<div>test-error</div>", design.attr("error"));
- }
-
- public void testSynchronizeSizeFull() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setSizeFull();
- component.synchronizeToDesign(design, ctx);
- // there should be only size full
- assertEquals(1, design.attributes().size());
- assertEquals("true", design.attr("size-full"));
- }
-
- public void testSynchronizeSizeAuto() {
- Element design = createDesign();
- AbstractComponent component = getPanel();
- component.setSizeUndefined();
- component.synchronizeToDesign(design, ctx);
- // there should be only size auto
- assertEquals(1, design.attributes().size());
- assertEquals("true", design.attr("size-auto"));
- }
-
- public void testSynchronizeHeightFull() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setHeight("100%");
- component.setWidth("20px");
- component.synchronizeToDesign(design, ctx);
- assertEquals("true", design.attr("height-full"));
- }
-
- public void testSynchronizeHeightAuto() {
- Element design = createDesign();
- // we need to have default height of 100% -> use split panel
- AbstractComponent component = getPanel();
- component.setHeight(null);
- component.setWidth("20px");
- component.synchronizeToDesign(design, ctx);
- assertEquals("true", design.attr("height-auto"));
- }
-
- public void testSynchronizeWidthFull() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setHeight("20px");
- component.setWidth("100%");
- component.synchronizeToDesign(design, ctx);
- assertEquals("true", design.attr("width-full"));
- }
-
- public void testSynchronizeWidthAuto() {
- Element design = createDesign();
- // need to get label, otherwise the default would be auto
- AbstractComponent component = getPanel();
- component.setHeight("20px");
- component.setWidth(null);
- component.synchronizeToDesign(design, ctx);
- assertEquals("true", design.attr("width-auto"));
- }
-
- public void testSynchronizeWidth() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setHeight("20px");
- component.setWidth("70%");
- component.synchronizeToDesign(design, ctx);
- assertEquals("70%", design.attr("width"));
- }
-
- public void testSynchronizeHeight() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- component.setHeight("20px");
- component.setWidth("70%");
- component.synchronizeToDesign(design, ctx);
- assertEquals("20px", design.attr("height"));
- }
-
- public void testSynchronizeResponsive() {
- Element design = createDesign();
- AbstractComponent component = getComponent();
- Responsive.makeResponsive(component);
- component.synchronizeToDesign(design, ctx);
- assertTrue("Design attributes should have key 'responsive'", design
- .attributes().hasKey("responsive"));
- assertFalse("Responsive attribute should not be 'false'",
- design.attr("responsive").equalsIgnoreCase("false"));
- }
-
- private AbstractComponent getComponent() {
- Button button = new Button();
- button.setHtmlContentAllowed(true);
- return button;
- }
-
- private AbstractComponent getPanel() {
- return new HorizontalSplitPanel();
- }
-
- private Element createDesign() {
- Attributes attr = new Attributes();
- attr.put("should_be_removed", "foo");
- Element node = new Element(Tag.valueOf("v-button"), "", attr);
- Element child = new Element(Tag.valueOf("to-be-removed"), "foo", attr);
- node.appendChild(child);
- return node;
- }
-}
--- /dev/null
+/*
+ * 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.abstractcomponent;
+
+import java.io.File;
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+
+import com.vaadin.server.AbstractErrorMessage.ContentMode;
+import com.vaadin.server.ErrorMessage.ErrorLevel;
+import com.vaadin.server.ExternalResource;
+import com.vaadin.server.FileResource;
+import com.vaadin.server.Responsive;
+import com.vaadin.server.ThemeResource;
+import com.vaadin.server.UserError;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalSplitPanel;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Test case for writing the attributes of the AbstractComponent to design
+ *
+ * @author Vaadin Ltd
+ */
+public class TestWriteDesign extends TestCase {
+
+ private DesignContext ctx;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ ctx = new DesignContext();
+ }
+
+ public void testSynchronizeId() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setId("testId");
+ component.writeDesign(design, ctx);
+ // we only changed one of the attributes, others are at default values
+ assertEquals(1, design.attributes().size());
+ assertEquals("testId", design.attr("id"));
+ }
+
+ public void testSynchronizePrimaryStyleName() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setPrimaryStyleName("test-style");
+ component.writeDesign(design, ctx);
+ // we only changed one of the attributes, others are at default values
+ assertEquals(1, design.attributes().size());
+ assertEquals("test-style", design.attr("primary-style-name"));
+ }
+
+ public void testSynchronizeCaption() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setCaption("test-caption");
+ component.writeDesign(design, ctx);
+ // We only changed the caption, which is not
+ // an attribute.
+ assertEquals(0, design.attributes().size());
+ assertEquals("test-caption", design.html());
+ }
+
+ public void testSynchronizeLocale() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setLocale(new Locale("fi", "FI"));
+ component.writeDesign(design, ctx);
+ // we only changed one of the attributes, others are at default values
+ assertEquals(1, design.attributes().size());
+ assertEquals("fi_FI", design.attr("locale"));
+ }
+
+ public void testSynchronizeExternalIcon() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component
+ .setIcon(new ExternalResource("http://example.com/example.gif"));
+ component.writeDesign(design, ctx);
+ // we only changed one of the attributes, others are at default values
+ assertEquals(1, design.attributes().size());
+ assertEquals("http://example.com/example.gif", design.attr("icon"));
+ }
+
+ public void testSynchronizeThemeIcon() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setIcon(new ThemeResource("example.gif"));
+ component.writeDesign(design, ctx);
+ // we only changed one of the attributes, others are at default values
+ assertEquals(1, design.attributes().size());
+ assertEquals("theme://example.gif", design.attr("icon"));
+ }
+
+ public void testSynchronizeFileResource() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setIcon(new FileResource(new File("img/example.gif")));
+ component.writeDesign(design, ctx);
+ // we only changed one of the attributes, others are at default values
+ assertEquals(1, design.attributes().size());
+ assertEquals("img/example.gif", design.attr("icon"));
+ }
+
+ public void testSynchronizeImmediate() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ // no immediate attribute should be written before setting immediate to
+ // some value
+ component.writeDesign(design, ctx);
+ assertFalse(design.hasAttr("immediate"));
+ component.setImmediate(true);
+ component.writeDesign(design, ctx);
+ // we only changed one of the attributes, others are at default values
+ assertEquals(1, design.attributes().size());
+ assertEquals("true", design.attr("immediate"));
+ }
+
+ public void testSynchronizeDescription() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setDescription("test-description");
+ component.writeDesign(design, ctx);
+ // we only changed one of the attributes, others are at default values
+ assertEquals(1, design.attributes().size());
+ assertEquals("test-description", design.attr("description"));
+ }
+
+ public void testSynchronizeComponentError() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setComponentError(new UserError("<div>test-error</div>",
+ ContentMode.HTML, ErrorLevel.ERROR));
+ component.writeDesign(design, ctx);
+ // we only changed one of the attributes, others are at default values
+ assertEquals(1, design.attributes().size());
+ assertEquals("<div>test-error</div>", design.attr("error"));
+ }
+
+ public void testSynchronizeSizeFull() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setSizeFull();
+ component.writeDesign(design, ctx);
+ // there should be only size full
+ assertEquals(1, design.attributes().size());
+ assertEquals("true", design.attr("size-full"));
+ }
+
+ public void testSynchronizeSizeAuto() {
+ Element design = createDesign();
+ AbstractComponent component = getPanel();
+ component.setSizeUndefined();
+ component.writeDesign(design, ctx);
+ // there should be only size auto
+ assertEquals(1, design.attributes().size());
+ assertEquals("true", design.attr("size-auto"));
+ }
+
+ public void testSynchronizeHeightFull() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setHeight("100%");
+ component.setWidth("20px");
+ component.writeDesign(design, ctx);
+ assertEquals("true", design.attr("height-full"));
+ }
+
+ public void testSynchronizeHeightAuto() {
+ Element design = createDesign();
+ // we need to have default height of 100% -> use split panel
+ AbstractComponent component = getPanel();
+ component.setHeight(null);
+ component.setWidth("20px");
+ component.writeDesign(design, ctx);
+ assertEquals("true", design.attr("height-auto"));
+ }
+
+ public void testSynchronizeWidthFull() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setHeight("20px");
+ component.setWidth("100%");
+ component.writeDesign(design, ctx);
+ assertEquals("true", design.attr("width-full"));
+ }
+
+ public void testSynchronizeWidthAuto() {
+ Element design = createDesign();
+ // need to get label, otherwise the default would be auto
+ AbstractComponent component = getPanel();
+ component.setHeight("20px");
+ component.setWidth(null);
+ component.writeDesign(design, ctx);
+ assertEquals("true", design.attr("width-auto"));
+ }
+
+ public void testSynchronizeWidth() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setHeight("20px");
+ component.setWidth("70%");
+ component.writeDesign(design, ctx);
+ assertEquals("70%", design.attr("width"));
+ }
+
+ public void testSynchronizeHeight() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ component.setHeight("20px");
+ component.setWidth("70%");
+ component.writeDesign(design, ctx);
+ assertEquals("20px", design.attr("height"));
+ }
+
+ public void testSynchronizeResponsive() {
+ Element design = createDesign();
+ AbstractComponent component = getComponent();
+ Responsive.makeResponsive(component);
+ component.writeDesign(design, ctx);
+ assertTrue("Design attributes should have key 'responsive'", design
+ .attributes().hasKey("responsive"));
+ assertFalse("Responsive attribute should not be 'false'",
+ design.attr("responsive").equalsIgnoreCase("false"));
+ }
+
+ private AbstractComponent getComponent() {
+ Button button = new Button();
+ button.setHtmlContentAllowed(true);
+ return button;
+ }
+
+ private AbstractComponent getPanel() {
+ return new HorizontalSplitPanel();
+ }
+
+ private Element createDesign() {
+ Attributes attr = new Attributes();
+ attr.put("should_be_removed", "foo");
+ Element node = new Element(Tag.valueOf("v-button"), "", attr);
+ Element child = new Element(Tag.valueOf("to-be-removed"), "foo", attr);
+ node.appendChild(child);
+ return node;
+ }
+}
--- /dev/null
+/*
+ * 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 TestReadDesign 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;
+ }
+}
+++ /dev/null
-/*
- * 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 TestSynchronizeFromDesign 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.synchronizeFromDesign(design, ctx);
- assertEquals(true, component.isReadOnly());
- design = createDesign("readonly", "false");
- component.synchronizeFromDesign(design, ctx);
- assertEquals(false, component.isReadOnly());
- }
-
- public void testSynchronizeTabIndex() {
- Element design = createDesign("tabindex", "2");
- AbstractField component = getComponent();
- component.synchronizeFromDesign(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;
- }
-}
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign 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.synchronizeToDesign(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.synchronizeToDesign(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);
- }
-}
--- /dev/null
+/*
+ * 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 TestWriteDesign 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);
+ }
+}
--- /dev/null
+/*
+ * 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 TestReadDesign 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.createChild(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;
+ }
+}
+++ /dev/null
-/*
- * 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 TestSynchronizeFromDesign 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.createChild(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;
- }
-}
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign extends TestCase {
-
- public void testSynchronizeMargin() {
- VerticalLayout layout = new VerticalLayout();
- layout.setMargin(true);
- Element design = createDesign();
- layout.synchronizeToDesign(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.synchronizeToDesign(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.synchronizeToDesign(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.synchronizeToDesign(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.synchronizeToDesign(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.synchronizeToDesign(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.synchronizeToDesign(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.synchronizeToDesign(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.synchronizeToDesign(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();
- }
-}
--- /dev/null
+/*
+ * 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 TestWriteDesign 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();
+ }
+}
--- /dev/null
+/*
+ * 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 TestReadDesign 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);
+ // check that the properties get the default values if the design
+ // does not have attributes corresponding to those properties
+ design = createDesign(true, true, true, true);
+ sp.readDesign(design, ctx);
+ HorizontalSplitPanel def = new HorizontalSplitPanel();
+ assertEquals(def.getSplitPosition(), sp.getSplitPosition());
+ assertEquals(def.getSplitPositionUnit(), sp.getSplitPositionUnit());
+ assertEquals(def.getMinSplitPosition(), sp.getMinSplitPosition());
+ assertEquals(def.getMinSplitPositionUnit(),
+ sp.getMinSplitPositionUnit());
+ assertEquals(def.getMaxSplitPosition(), sp.getMaxSplitPosition());
+ assertEquals(def.getMaxSplitPositionUnit(),
+ sp.getMaxSplitPositionUnit());
+ assertEquals(def.isLocked(), sp.isLocked());
+ checkReversed(sp, false);
+ }
+
+ 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
+++ /dev/null
-/*
- * 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 TestSynchronizeFromDesign 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.synchronizeFromDesign(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);
- // check that the properties get the default values if the design
- // does not have attributes corresponding to those properties
- design = createDesign(true, true, true, true);
- sp.synchronizeFromDesign(design, ctx);
- HorizontalSplitPanel def = new HorizontalSplitPanel();
- assertEquals(def.getSplitPosition(), sp.getSplitPosition());
- assertEquals(def.getSplitPositionUnit(), sp.getSplitPositionUnit());
- assertEquals(def.getMinSplitPosition(), sp.getMinSplitPosition());
- assertEquals(def.getMinSplitPositionUnit(),
- sp.getMinSplitPositionUnit());
- assertEquals(def.getMaxSplitPosition(), sp.getMaxSplitPosition());
- assertEquals(def.getMaxSplitPositionUnit(),
- sp.getMaxSplitPositionUnit());
- assertEquals(def.isLocked(), sp.isLocked());
- checkReversed(sp, false);
- }
-
- public void testWithNoChildren() {
- Element design = createDesign(true, false, false, false);
- HorizontalSplitPanel sp = new HorizontalSplitPanel();
- sp.synchronizeFromDesign(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.synchronizeFromDesign(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.synchronizeFromDesign(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.synchronizeFromDesign(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
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign 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.createNode(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.createNode(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.createNode(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.createNode(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.createNode(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.createNode(sp);
- sp = new VerticalSplitPanel();
- sp.synchronizeToDesign(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);
- }
-}
--- /dev/null
+/*
+ * 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 TestWriteDesign 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.createNode(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.createNode(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.createNode(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.createNode(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.createNode(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.createNode(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);
+ }
+}
--- /dev/null
+/*
+ * 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 TestReadDesign 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;
+ }
+
+}
+++ /dev/null
-/*
- * 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 TestSynchronizeFromDesign 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.synchronizeFromDesign(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;
- }
-
-}
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign 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.synchronizeToDesign(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);
- }
-
-}
--- /dev/null
+/*
+ * 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 TestWriteDesign 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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 TestReadDesign 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
+ .createChild(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.createChild(e1);
+ Element e2 = createElement("v-native-button", content, caption);
+ NativeButton b2 = (NativeButton) ctx.createChild(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
+++ /dev/null
-/*
- * 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 TestSynchronizeFromDesign 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
- .createChild(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.createChild(e1);
- Element e2 = createElement("v-native-button", content, caption);
- NativeButton b2 = (NativeButton) ctx.createChild(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
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign 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.synchronizeToDesign(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.synchronizeToDesign(e, ctx);
- assertTrue("Button is plain text by default", e.hasAttr("plain-text"));
-
- button.setHtmlContentAllowed(true);
- button.synchronizeToDesign(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.createNode(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.createNode(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
--- /dev/null
+/*
+ * 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 TestWriteDesign 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.createNode(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.createNode(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
--- /dev/null
+/*
+ * 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 TestReadDesign 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.createChild(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;
+ }
+}
+++ /dev/null
-/*
- * 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 TestSynchronizeFromDesign 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.createChild(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;
- }
-}
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign extends TestCase {
-
- public void testSynchronizeEmptyLayout() {
- CssLayout layout = new CssLayout();
- layout.setCaption("changed-caption");
- Element design = createDesign();
- layout.synchronizeToDesign(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.synchronizeToDesign(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();
- }
-}
--- /dev/null
+/*
+ * 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 TestWriteDesign 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();
+ }
+}
--- /dev/null
+/*
+ * 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 TestReadDesign 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.createChild(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;
+ }
+}
+++ /dev/null
-/*
- * 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 TestSynchronizeFromDesign 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.createChild(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;
- }
-}
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign 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.synchronizeToDesign(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.synchronizeToDesign(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.synchronizeToDesign(e, ctx);
-
- assertFalse("Label should not be marked as plain text",
- e.hasAttr("plain-text"));
- l.setContentMode(ContentMode.TEXT);
- l.synchronizeToDesign(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.createNode(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
--- /dev/null
+/*
+ * 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 TestWriteDesign 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.createNode(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
--- /dev/null
+/*
+ * 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 TestReadDesign 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
+++ /dev/null
-/*
- * 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 TestSynchronizeFromDesign extends TestCase {
- DesignContext ctx;
-
- @Override
- public void setUp() {
- ctx = new DesignContext();
- }
-
- public void testAttributes() {
- Element design = createDesign();
- Panel panel = new Panel();
- panel.synchronizeFromDesign(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.synchronizeFromDesign(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.synchronizeFromDesign(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
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign 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.synchronizeToDesign(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"));
- }
-}
--- /dev/null
+/*
+ * 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 TestWriteDesign 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"));
+ }
+}
--- /dev/null
+/*
+ * 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.Label;
+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 TestReadDesign 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();
+ // add some tabs that should be cleared on sync
+ tabSheet.addComponent(new Label("tab1"));
+ tabSheet.addComponent(new Label("tab2"));
+ 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;
+
+ }
+}
+++ /dev/null
-/*
- * 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.Label;
-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 TestSynchronizeFromDesign 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.synchronizeFromDesign(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();
- // add some tabs that should be cleared on sync
- tabSheet.addComponent(new Label("tab1"));
- tabSheet.addComponent(new Label("tab2"));
- DesignContext ctx = new DesignContext();
- Element design = createDesign();
- tabSheet.synchronizeFromDesign(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;
-
- }
-}
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign extends TestCase {
-
- private TabSheet sheet;
- private Element design;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- sheet = createTabSheet();
- design = createDesign();
- sheet.synchronizeToDesign(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;
- }
-
-}
--- /dev/null
+/*
+ * 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 TestWriteDesign 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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 TestReadDesign 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;
+ }
+}
+++ /dev/null
-/*
- * 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 TestSynchronizeFromDesign 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.synchronizeFromDesign(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;
- }
-}
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign 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.synchronizeToDesign(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);
- }
-
-}
--- /dev/null
+/*
+ * 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 TestWriteDesign 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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 TestReadDesign 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;
+ }
+}
+++ /dev/null
-/*
- * 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 TestSynchronizeFromDesign 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.synchronizeFromDesign(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;
- }
-}
+++ /dev/null
-/*
- * 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 TestSynchronizeToDesign 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.synchronizeToDesign(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);
- }
-
-}
--- /dev/null
+/*
+ * 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 TestWriteDesign 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);
+ }
+
+}