diff options
40 files changed, 778 insertions, 722 deletions
diff --git a/WebContent/VAADIN/themes/valo/components/_combobox.scss b/WebContent/VAADIN/themes/valo/components/_combobox.scss index f84faef603..ace3dbb4bb 100644 --- a/WebContent/VAADIN/themes/valo/components/_combobox.scss +++ b/WebContent/VAADIN/themes/valo/components/_combobox.scss @@ -266,17 +266,21 @@ * @group combobox */ @mixin valo-combobox-button-style ($unit-size: $v-unit-size, $bevel: $v-bevel, $background-color: $v-textfield-background-color, $border-radius: $v-border-radius, $border: $v-textfield-border) { - $border-width: first-number($v-textfield-border) or 0; + $border-width: first-number($border) or 0; @include valo-tappable; position: absolute; - top: $border-width; - right: $border-width; - bottom: $border-width; width: $unit-size; - cursor: pointer; + + @if $border and $border != none { + top: $border-width; + right: $border-width; + bottom: $border-width; + } @if type-of($background-color) == color { - border-left: valo-border($color: $background-color, $border: $v-textfield-border, $strength: 0.5); + @if $border { + border-left: valo-border($color: $background-color, $border: $v-textfield-border, $strength: 0.5); + } color: mix($background-color, valo-font-color($background-color)); .v-ie8 & { diff --git a/WebContent/VAADIN/themes/valo/components/_datefield.scss b/WebContent/VAADIN/themes/valo/components/_datefield.scss index 6d36ade43a..52a4acf821 100644 --- a/WebContent/VAADIN/themes/valo/components/_datefield.scss +++ b/WebContent/VAADIN/themes/valo/components/_datefield.scss @@ -202,26 +202,30 @@ @include valo-tappable; -webkit-appearance: none; background: transparent; - @if $border { - // Only override border if we are actually setting some border - border: none; - } padding: 0; position: absolute; z-index: 10; - top: $border-width; - bottom: $border-width; - left: $border-width; width: $unit-size; line-height: $unit-size - ($border-width*2); text-align: center; - cursor: pointer; font: inherit; outline: none; margin: 0; + @if $border and $border != none { + top: $border-width; + bottom: $border-width; + left: $border-width; + } + + @if $border { + border: none; + } + @if type-of($background-color) == color { - border-right: valo-border($color: $background-color, $border: $v-textfield-border, $strength: 0.5); + @if $border { + border-right: valo-border($color: $background-color, $border: $v-textfield-border, $strength: 0.5); + } color: mix($background-color, valo-font-color($background-color)); &:hover { diff --git a/WebContent/release-notes.html b/WebContent/release-notes.html index d02e0eeb37..a060372580 100644 --- a/WebContent/release-notes.html +++ b/WebContent/release-notes.html @@ -133,6 +133,7 @@ <p>JavascriptFunction.call parameter type has been changed to elemental.json.JsonArray, affecting JavaScript.addFunction, AbstractJavaScriptComponent.addFunction and AbstractJavaScriptExtension.addFunction</p> <p>Raw JSON values passed to AbstractJavaScriptComponent.callFunction and AbstractJavaScriptExtension.callFunction should be changed to use elemental.json types.</p> </li> + <li>The semantics of empty and required for Field classes has been made more consistent. This mainly affects Checkbox which is now considered to be empty when it is not checked.</li> <li>Support for Opera 12 has been dropped. Newer versions based on the Blink rendering engine are still supported.</li> </ul> <h3 id="knownissues">Known issues</h3> diff --git a/client/src/com/vaadin/client/LayoutManager.java b/client/src/com/vaadin/client/LayoutManager.java index bf79009f4c..2f39eaedd4 100644 --- a/client/src/com/vaadin/client/LayoutManager.java +++ b/client/src/com/vaadin/client/LayoutManager.java @@ -443,7 +443,7 @@ public class LayoutManager { try { String key = null; if (Profiler.isEnabled()) { - key = "layoutHorizontally() for " + key = "layoutVertically() for " + Util.getSimpleName(cl); Profiler.enter(key); } diff --git a/client/src/com/vaadin/client/debug/internal/ErrorNotificationHandler.java b/client/src/com/vaadin/client/debug/internal/ErrorNotificationHandler.java index f4fbe12c0d..5d128cbdcc 100644 --- a/client/src/com/vaadin/client/debug/internal/ErrorNotificationHandler.java +++ b/client/src/com/vaadin/client/debug/internal/ErrorNotificationHandler.java @@ -20,6 +20,7 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; +import com.google.gwt.dom.client.Style.TextAlign; import com.google.gwt.logging.client.TextLogFormatter; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConfiguration; @@ -65,10 +66,12 @@ public class ErrorNotificationHandler extends Handler { .getRunningApplications().get(0); owner = connection.getUIConnector().getWidget(); } - VNotification - .createNotification(VNotification.DELAY_FOREVER, owner) - .show("<h1>Uncaught client side exception</h1><br />" - + exceptionText, VNotification.CENTERED, "error"); + VNotification n = VNotification.createNotification( + VNotification.DELAY_FOREVER, owner); + n.getElement().getStyle().setTextAlign(TextAlign.LEFT); + n.show("<h1>Uncaught client side exception</h1><br />" + + exceptionText.replace("\n", "<br/>\n"), + VNotification.CENTERED, "error"); } catch (Exception e2) { // Just swallow this exception } diff --git a/client/src/com/vaadin/client/ui/ShortcutActionHandler.java b/client/src/com/vaadin/client/ui/ShortcutActionHandler.java index 9e9279267d..a9d5f0731a 100644 --- a/client/src/com/vaadin/client/ui/ShortcutActionHandler.java +++ b/client/src/com/vaadin/client/ui/ShortcutActionHandler.java @@ -123,6 +123,9 @@ public class ShortcutActionHandler { final int modifiers = KeyboardListenerCollection .getKeyboardModifiers(event); final char keyCode = (char) DOM.eventGetKeyCode(event); + if (keyCode == 0) { + return; + } final ShortcutKeyCombination kc = new ShortcutKeyCombination(keyCode, modifiers); final Iterator<ShortcutAction> it = actions.iterator(); diff --git a/client/src/com/vaadin/client/ui/VAccordion.java b/client/src/com/vaadin/client/ui/VAccordion.java index ff77a8cb91..422f195af9 100644 --- a/client/src/com/vaadin/client/ui/VAccordion.java +++ b/client/src/com/vaadin/client/ui/VAccordion.java @@ -344,6 +344,7 @@ public class VAccordion extends VTabsheetBase { public void updateCaption(TabState tabState) { // TODO need to call this because the caption does not have an owner + caption.setCaptionAsHtml(isTabCaptionsAsHtml()); caption.updateCaptionWithoutOwner( tabState.caption, !tabState.enabled, diff --git a/client/src/com/vaadin/client/ui/VTabsheet.java b/client/src/com/vaadin/client/ui/VTabsheet.java index 10c9a332e0..2d34897986 100644 --- a/client/src/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/com/vaadin/client/ui/VTabsheet.java @@ -235,6 +235,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware } private void updateFromState(TabState tabState) { + tabCaption.setCaptionAsHtml(getTabsheet().isTabCaptionsAsHtml()); tabCaption.update(tabState); // Apply the styleName set for the tab String newStyleName = tabState.styleName; diff --git a/client/src/com/vaadin/client/ui/VTabsheetBase.java b/client/src/com/vaadin/client/ui/VTabsheetBase.java index d3c9bf9e10..e96aa035ed 100644 --- a/client/src/com/vaadin/client/ui/VTabsheetBase.java +++ b/client/src/com/vaadin/client/ui/VTabsheetBase.java @@ -49,6 +49,8 @@ public abstract class VTabsheetBase extends ComplexPanel implements HasEnabled { /** For internal use only. May be removed or replaced in the future. */ protected AbstractComponentConnector connector; + private boolean tabCaptionsAsHtml = false; + public VTabsheetBase(String classname) { setElement(DOM.createDiv()); setStyleName(classname); @@ -168,4 +170,32 @@ public abstract class VTabsheetBase extends ComplexPanel implements HasEnabled { public boolean isEnabled() { return !disabled; } + + /** + * Sets whether the caption is rendered as HTML. + * <p> + * The default is false, i.e. render tab captions as plain text + * + * @since 7.4 + * @param captionAsHtml + * true if the captions are rendered as HTML, false if rendered + * as plain text + */ + public void setTabCaptionsAsHtml(boolean tabCaptionsAsHtml) { + this.tabCaptionsAsHtml = tabCaptionsAsHtml; + } + + /** + * Checks whether captions are rendered as HTML + * + * The default is false, i.e. render tab captions as plain text + * + * @since 7.4 + * @return true if the captions are rendered as HTML, false if rendered as + * plain text + */ + public boolean isTabCaptionsAsHtml() { + return tabCaptionsAsHtml; + } + } diff --git a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java index 23a72ee1e5..0a92c00cad 100644 --- a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java +++ b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java @@ -155,10 +155,10 @@ public class BeanFieldGroup<T> extends FieldGroup { } @Override - public Field<?> buildAndBind(String caption, Object propertyId) - throws BindException { + public <T extends Field> T buildAndBind(String caption, Object propertyId, + Class<T> fieldType) throws BindException { ensureNestedPropertyAdded(propertyId); - return super.buildAndBind(caption, propertyId); + return super.buildAndBind(caption, propertyId, fieldType); } @Override diff --git a/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java b/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java index 98fed3ad01..8e32585a47 100644 --- a/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java +++ b/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java @@ -91,10 +91,20 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory { private <T extends Field> T createEnumField(Class<?> type, Class<T> fieldType) { + // Determine first if we should (or can) create a select for the enum + Class<AbstractSelect> selectClass = null; if (AbstractSelect.class.isAssignableFrom(fieldType)) { - AbstractSelect s = createCompatibleSelect((Class<? extends AbstractSelect>) fieldType); + selectClass = (Class<AbstractSelect>) fieldType; + } else if (anySelect(fieldType)) { + selectClass = AbstractSelect.class; + } + + if (selectClass != null) { + AbstractSelect s = createCompatibleSelect(selectClass); populateWithEnumData(s, (Class<? extends Enum>) type); return (T) s; + } else if (AbstractTextField.class.isAssignableFrom(fieldType)) { + return (T) createAbstractTextField((Class<? extends AbstractTextField>) fieldType); } return null; @@ -106,8 +116,8 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory { if (InlineDateField.class.isAssignableFrom(fieldType)) { field = new InlineDateField(); - } else if (DateField.class.isAssignableFrom(fieldType) - || fieldType == Field.class) { + } else if (anyField(fieldType) + || DateField.class.isAssignableFrom(fieldType)) { field = new PopupDateField(); } else if (AbstractTextField.class.isAssignableFrom(fieldType)) { field = createAbstractTextField((Class<? extends AbstractTextField>) fieldType); @@ -119,6 +129,10 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory { return (T) field; } + private boolean anyField(Class<?> fieldType) { + return fieldType == Field.class || fieldType == AbstractField.class; + } + protected AbstractSelect createCompatibleSelect( Class<? extends AbstractSelect> fieldType) { AbstractSelect select; @@ -143,6 +157,10 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory { return select; } + private boolean anySelect(Class<? extends Field> fieldType) { + return anyField(fieldType) || fieldType == AbstractSelect.class; + } + protected <T extends Field> T createBooleanField(Class<T> fieldType) { if (fieldType.isAssignableFrom(CheckBox.class)) { CheckBox cb = new CheckBox(null); diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index 591f73dc75..ef5c61a294 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -58,9 +58,8 @@ import com.vaadin.ui.UI; * Views can be explicitly registered or dynamically generated and listening to * view changes is possible. * <p> - * Note that {@link Navigator} is not a component itself but comes with - * {@link SimpleViewDisplay} which is a component that displays the selected - * view as its contents. + * Note that {@link Navigator} is not a component itself but uses a + * {@link ViewDisplay} to update contents based on the state. * * @author Vaadin Ltd * @since 7.0 @@ -627,11 +626,9 @@ public class Navigator implements Serializable { } /** - * Return the ViewDisplay used by the navigator. Unless another display is - * specified, a {@link SimpleViewDisplay} (which is a {@link Component}) is - * used by default. + * Return the {@link ViewDisplay} used by the navigator. * - * @return current ViewDisplay + * @return the ViewDisplay used for displaying views */ public ViewDisplay getDisplay() { return display; diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java index 985d7ef765..bfe195ccf9 100644 --- a/server/src/com/vaadin/server/BootstrapHandler.java +++ b/server/src/com/vaadin/server/BootstrapHandler.java @@ -39,6 +39,7 @@ import org.jsoup.parser.Tag; import com.vaadin.annotations.Viewport; import com.vaadin.annotations.ViewportGeneratorClass; +import com.vaadin.server.communication.AtmospherePushConnection; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.Version; import com.vaadin.shared.communication.PushMode; @@ -505,8 +506,12 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { JsonObject versionInfo = Json.createObject(); versionInfo.put("vaadinVersion", Version.getFullVersion()); - versionInfo.put("atmosphereVersion", - org.atmosphere.util.Version.getRawVersion()); + String atmosphereVersion = AtmospherePushConnection + .getAtmosphereVersion(); + if (atmosphereVersion != null) { + versionInfo.put("atmosphereVersion", atmosphereVersion); + } + appConfig.put("versionInfo", versionInfo); appConfig.put("widgetset", context.getWidgetsetName()); diff --git a/server/src/com/vaadin/server/VaadinServletService.java b/server/src/com/vaadin/server/VaadinServletService.java index 6832da236a..22848c023c 100644 --- a/server/src/com/vaadin/server/VaadinServletService.java +++ b/server/src/com/vaadin/server/VaadinServletService.java @@ -27,8 +27,7 @@ import java.util.logging.Logger; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; -import org.atmosphere.util.Version; - +import com.vaadin.server.communication.AtmospherePushConnection; import com.vaadin.server.communication.PushRequestHandler; import com.vaadin.server.communication.ServletBootstrapHandler; import com.vaadin.server.communication.ServletUIInitHandler; @@ -54,21 +53,20 @@ public class VaadinServletService extends VaadinService { } private static boolean checkAtmosphereSupport() { - try { - String rawVersion = Version.getRawVersion(); - if (!Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION - .equals(rawVersion)) { - getLogger().log( - Level.WARNING, - Constants.INVALID_ATMOSPHERE_VERSION_WARNING, - new Object[] { - Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION, - rawVersion }); - } - return true; - } catch (NoClassDefFoundError e) { + String rawVersion = AtmospherePushConnection.getAtmosphereVersion(); + if (rawVersion == null) { return false; } + + if (!Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION.equals(rawVersion)) { + getLogger().log( + Level.WARNING, + Constants.INVALID_ATMOSPHERE_VERSION_WARNING, + new Object[] { + Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION, + rawVersion }); + } + return true; } @Override diff --git a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java index a274fbbb9b..0819a24ee9 100644 --- a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java +++ b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java @@ -31,6 +31,7 @@ import java.util.logging.Logger; import org.atmosphere.cpr.AtmosphereResource; import org.atmosphere.cpr.AtmosphereResource.TRANSPORT; +import org.atmosphere.util.Version; import com.vaadin.shared.communication.PushConstants; import com.vaadin.ui.UI; @@ -44,6 +45,16 @@ import com.vaadin.ui.UI; */ public class AtmospherePushConnection implements PushConnection { + public static String getAtmosphereVersion() { + try { + String v = Version.getRawVersion(); + assert v != null; + return v; + } catch (NoClassDefFoundError e) { + return null; + } + } + /** * Represents a message that can arrive as multiple fragments. */ diff --git a/server/src/com/vaadin/server/communication/PushRequestHandler.java b/server/src/com/vaadin/server/communication/PushRequestHandler.java index 40eb1b688e..d0367d0bed 100644 --- a/server/src/com/vaadin/server/communication/PushRequestHandler.java +++ b/server/src/com/vaadin/server/communication/PushRequestHandler.java @@ -29,6 +29,7 @@ import org.atmosphere.cpr.AtmosphereInterceptor; import org.atmosphere.cpr.AtmosphereRequest; import org.atmosphere.cpr.AtmosphereResponse; import org.atmosphere.interceptor.HeartbeatInterceptor; +import org.atmosphere.util.VoidAnnotationProcessor; import com.vaadin.server.RequestHandler; import com.vaadin.server.ServiceDestroyEvent; @@ -91,6 +92,8 @@ public class PushRequestHandler implements RequestHandler, atmosphere.addAtmosphereHandler("/*", pushHandler.handler); atmosphere.addInitParameter(ApplicationConfig.BROADCASTER_CACHE, UUIDBroadcasterCache.class.getName()); + atmosphere.addInitParameter(ApplicationConfig.ANNOTATION_PROCESSOR, + VoidAnnotationProcessor.class.getName()); atmosphere.addInitParameter(ApplicationConfig.PROPERTY_SESSION_SUPPORT, "true"); atmosphere.addInitParameter(ApplicationConfig.MESSAGE_DELIMITER, diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index d5e47b2286..423ebcb46a 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -1688,8 +1688,6 @@ public abstract class AbstractSelect extends AbstractField<Object> implements // Clears the item id mapping table itemIdMapper.removeAll(); - adjustSelection(); - // Notify all listeners fireItemSetChange(); } @@ -1728,25 +1726,6 @@ public abstract class AbstractSelect extends AbstractField<Object> implements } /** - * Removes orphaned ids from selection. - * - * @since 7.4 - */ - protected void adjustSelection() { - Object value = getValue(); - if (isMultiSelect() && (value instanceof Collection)) { - Collection<?> collection = (Collection<?>) value; - for (Object id : collection) { - if (!containsId(id)) { - unselect(id); - } - } - } else if (!containsId(value)) { - unselect(value); - } - } - - /** * Implementation of item set change event. */ private static class ItemSetChangeEvent extends EventObject implements diff --git a/server/src/com/vaadin/ui/AbstractSplitPanel.java b/server/src/com/vaadin/ui/AbstractSplitPanel.java index 414681f5dd..af73fca6a8 100644 --- a/server/src/com/vaadin/ui/AbstractSplitPanel.java +++ b/server/src/com/vaadin/ui/AbstractSplitPanel.java @@ -358,7 +358,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * by the first region, but if split position is reversed the measuring is * done by the second region instead. * - * @since 7.4 + * @since 7.3.6 * @return {@code true} if reversed, {@code false} otherwise. * @see #setSplitPosition(float, boolean) */ diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java index 677f29ba13..6beb6ed686 100644 --- a/server/src/com/vaadin/ui/Button.java +++ b/server/src/com/vaadin/ui/Button.java @@ -365,7 +365,7 @@ public class Button extends AbstractComponent implements * No action is taken is the button is disabled. */ public void click() { - if (isConnectorEnabled() && !isReadOnly()) { + if (isEnabled() && !isReadOnly()) { fireClick(); } } diff --git a/server/src/com/vaadin/ui/TabSheet.java b/server/src/com/vaadin/ui/TabSheet.java index 266c93e81f..67dfdd4258 100644 --- a/server/src/com/vaadin/ui/TabSheet.java +++ b/server/src/com/vaadin/ui/TabSheet.java @@ -1621,4 +1621,34 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, } } + /** + * Sets whether HTML is allowed in the tab captions. + * <p> + * If set to true, the captions are rendered in the browser as HTML and the + * developer is responsible for ensuring no harmful HTML is used. If set to + * false, the content is rendered in the browser as plain text. + * <p> + * The default is false, i.e. render tab captions as plain text + * + * @param tabCaptionsAsHtml + * true if the tab captions are rendered as HTML, false if + * rendered as plain text + * @since 7.4 + */ + public void setTabCaptionsAsHtml(boolean tabCaptionsAsHtml) { + getState().tabCaptionsAsHtml = tabCaptionsAsHtml; + } + + /** + * Checks whether HTML is allowed in the tab captions. + * <p> + * The default is false, i.e. render tab captions as plain text + * + * @return true if the tab captions are rendered as HTML, false if rendered + * as plain text + * @since 7.4 + */ + public boolean isTabCaptionsAsHtml() { + return getState(false).tabCaptionsAsHtml; + } } diff --git a/server/src/com/vaadin/ui/declarative/Design.java b/server/src/com/vaadin/ui/declarative/Design.java index 59393a7815..dc96e789bf 100644 --- a/server/src/com/vaadin/ui/declarative/Design.java +++ b/server/src/com/vaadin/ui/declarative/Design.java @@ -184,13 +184,18 @@ public class Design implements Serializable { // taken care of by jsoup. Element root = doc.body(); Elements children = root.children(); - if (children.size() != 1) { + if (children.size() > 1) { throw new DesignException( - "The first level of a component hierarchy should contain exactly one root component, but found " - + children.size()); + "The first level of a component hierarchy should contain at most one root component, but found " + + children.size() + "."); } - Element element = children.first(); + Element element = children.size() == 0 ? null : children.first(); if (componentRoot != null) { + if (element == null) { + throw new DesignException( + "The root element cannot be null when the specified root Component is" + + " not null."); + } // user has specified root instance that may have member fields that // should be bound final FieldBinder binder; @@ -222,7 +227,8 @@ public class Design implements Serializable { designContext.removeComponentCreationListener(creationListener); } else { // createChild creates the entire component hierarchy - componentRoot = designContext.readDesign(element); + componentRoot = element == null ? null : designContext + .readDesign(element); } designContext.setRootComponent(componentRoot); return designContext; @@ -255,8 +261,10 @@ public class Design implements Serializable { // creates the entire component hierarchy rooted at the // given root node. Component root = designContext.getRootComponent(); - Node rootNode = designContext.createElement(root); - body.appendChild(rootNode); + if (root != null) { + Node rootNode = designContext.createElement(root); + body.appendChild(rootNode); + } designContext.writePackageMappings(doc); return doc; } @@ -424,10 +432,11 @@ public class Design implements Serializable { /** * Writes the given component tree in design format to the given output - * stream + * stream. * * @param component - * the root component of the component tree + * the root component of the component tree, null can be used for + * generating an empty design * @param outputStream * the output stream to write the design to. The design is always * written as UTF-8 @@ -446,8 +455,10 @@ public class Design implements Serializable { * and other information not available in the component tree. * * @param designContext - * the DesignContext object specifying the component hierarchy - * and the local id values of the objects + * The DesignContext object specifying the component hierarchy + * and the local id values of the objects. If + * designContext.getRootComponent() is null, an empty design will + * be generated. * @param outputStream * the output stream to write the design to. The design is always * written as UTF-8 diff --git a/server/src/com/vaadin/ui/declarative/DesignContext.java b/server/src/com/vaadin/ui/declarative/DesignContext.java index ade2494638..fd83339b76 100644 --- a/server/src/com/vaadin/ui/declarative/DesignContext.java +++ b/server/src/com/vaadin/ui/declarative/DesignContext.java @@ -415,7 +415,7 @@ public class DesignContext implements Serializable { * * @param componentDesign * The design element containing the description of the component - * to be created + * to be created. * @return the root component of component tree */ public Component readDesign(Element componentDesign) { diff --git a/server/tests/src/com/vaadin/data/DefaultFieldGroupFieldFactoryTest.java b/server/tests/src/com/vaadin/data/DefaultFieldGroupFieldFactoryTest.java index bbf74bfb21..fc258ab138 100644 --- a/server/tests/src/com/vaadin/data/DefaultFieldGroupFieldFactoryTest.java +++ b/server/tests/src/com/vaadin/data/DefaultFieldGroupFieldFactoryTest.java @@ -23,9 +23,12 @@ import org.junit.Before; import org.junit.Test; import com.vaadin.data.fieldgroup.DefaultFieldGroupFieldFactory; +import com.vaadin.ui.AbstractSelect; +import com.vaadin.ui.ComboBox; import com.vaadin.ui.DateField; import com.vaadin.ui.Field; import com.vaadin.ui.InlineDateField; +import com.vaadin.ui.ListSelect; import com.vaadin.ui.PopupDateField; import com.vaadin.ui.TextField; @@ -89,4 +92,29 @@ public class DefaultFieldGroupFieldFactoryTest { Assert.assertEquals(PopupDateField.class, f.getClass()); } + public enum SomeEnum { + FOO, BAR; + } + + @Test + public void testEnumComboBox() { + Field f = fieldFactory.createField(SomeEnum.class, ComboBox.class); + Assert.assertNotNull(f); + Assert.assertEquals(ComboBox.class, f.getClass()); + } + + @Test + public void testEnumAnySelect() { + Field f = fieldFactory + .createField(SomeEnum.class, AbstractSelect.class); + Assert.assertNotNull(f); + Assert.assertEquals(ListSelect.class, f.getClass()); + } + + @Test + public void testEnumAnyField() { + Field f = fieldFactory.createField(SomeEnum.class, Field.class); + Assert.assertNotNull(f); + Assert.assertEquals(ListSelect.class, f.getClass()); + } } diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java index f82ba49c3e..2d66b728a7 100644 --- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java +++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java @@ -29,10 +29,9 @@ import static org.junit.Assert.assertTrue; public class SQLContainerTableQueryTest { private static final int offset = SQLTestsConstants.offset; - private static final String createGarbage = SQLTestsConstants.createGarbage; private JDBCConnectionPool connectionPool; private TableQuery peopleQuery; - private SQLContainer peopleContainer; + private SQLContainer container; @Before public void setUp() throws SQLException { @@ -48,9 +47,19 @@ public class SQLContainerTableQueryTest { DataGenerator.addPeopleToDatabase(connectionPool); - peopleQuery = new TableQuery("people", connectionPool, + peopleQuery = getTableQuery("people"); + container = new SQLContainer(peopleQuery); + } + + private TableQuery getTableQuery(String tableName) { + return new TableQuery(tableName, connectionPool, SQLTestsConstants.sqlGen); - peopleContainer = new SQLContainer(peopleQuery); + } + + private SQLContainer getGarbageContainer() throws SQLException { + DataGenerator.createGarbage(connectionPool); + + return new SQLContainer(getTableQuery("garbage")); } @After @@ -63,19 +72,19 @@ public class SQLContainerTableQueryTest { @Test public void itemWithExistingVersionColumnIsRemoved() throws SQLException { - peopleContainer.setAutoCommit(true); + container.setAutoCommit(true); peopleQuery.setVersionColumn("ID"); - assertTrue(peopleContainer.removeItem(peopleContainer.lastItemId())); + assertTrue(container.removeItem(container.lastItemId())); } @Test(expected = IllegalArgumentException.class) public void itemWithNonExistingVersionColumnCannotBeRemoved() throws SQLException { peopleQuery.setVersionColumn("version"); - peopleContainer.removeItem(peopleContainer.lastItemId()); + container.removeItem(container.lastItemId()); - peopleContainer.commit(); + container.commit(); } @Test @@ -89,74 +98,87 @@ public class SQLContainerTableQueryTest { throws SQLException { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); + assertTrue(container.containsId(new RowId( new Object[]{1 + offset}))); + Assert.assertTrue(container.containsId(new RowId( + new Object[] { 1 + offset }))); + assertTrue(this.container.containsId(new RowId( + new Object[]{1 + offset}))); } @Test public void containsId_withTableQueryAndNonexistingId_returnsFalse() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Assert.assertFalse(container.containsId(new RowId( - new Object[] { 1337 + offset }))); + new Object[]{1337 + offset}))); + } + + @Test + public void getContainerProperty_tableExistingItemIdAndNonexistingPropertyId_returnsNull() + throws SQLException { + Assert.assertNull(container.getContainerProperty(new RowId( + new Object[]{1 + offset}), "asdf")); + } + + @Test + public void getContainerProperty_tableNonexistingItemId_returnsNull() + throws SQLException { + Assert.assertNull(container.getContainerProperty(new RowId( + new Object[]{1337 + offset}), "NAME")); + } + + @Test + public void getType_tableIDPropertyId_returnsInteger() throws SQLException { + if (SQLTestsConstants.db == DB.ORACLE) { + Assert.assertEquals(BigDecimal.class, container.getType("ID")); + } else { + Assert.assertEquals(Integer.class, container.getType("ID")); + } + } + + @Test + public void getType_tableNonexistingPropertyId_returnsNull() + throws SQLException { + Assert.assertNull(container.getType("asdf")); + } + + @Test + public void size_table_returnsFour() throws SQLException { + Assert.assertEquals(4, container.size()); } @Test public void getContainerProperty_tableExistingItemIdAndPropertyId_returnsProperty() throws SQLException { - TableQuery t = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(t); if (SQLTestsConstants.db == DB.ORACLE) { Assert.assertEquals( "Ville", container .getContainerProperty( - new RowId(new Object[] { new BigDecimal( - 0 + offset) }), "NAME").getValue()); + new RowId(new Object[]{new BigDecimal( + 0 + offset)}), "NAME").getValue()); } else { Assert.assertEquals( "Ville", container.getContainerProperty( - new RowId(new Object[] { 0 + offset }), "NAME") + new RowId(new Object[]{0 + offset}), "NAME") .getValue()); } } - @Test - public void getContainerProperty_tableExistingItemIdAndNonexistingPropertyId_returnsNull() - throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); - Assert.assertNull(container.getContainerProperty(new RowId( - new Object[] { 1 + offset }), "asdf")); - } - - @Test - public void getContainerProperty_tableNonexistingItemId_returnsNull() - throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); - Assert.assertNull(container.getContainerProperty(new RowId( - new Object[] { 1337 + offset }), "NAME")); - } @Test public void getContainerPropertyIds_table_returnsIDAndNAME() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Collection<?> propertyIds = container.getContainerPropertyIds(); Assert.assertEquals(3, propertyIds.size()); - Assert.assertArrayEquals(new String[] { "ID", "NAME", "AGE" }, + Assert.assertArrayEquals(new String[]{"ID", "NAME", "AGE"}, propertyIds.toArray()); } @Test public void getItem_tableExistingItemId_returnsItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Item item; if (SQLTestsConstants.db == DB.ORACLE) { item = container.getItem(new RowId(new Object[] { new BigDecimal( @@ -173,8 +195,6 @@ public class SQLContainerTableQueryTest { String OLD_VALUE = "SomeValue"; //$NON-NLS-1$ String NEW_VALUE = "OtherValue"; //$NON-NLS-1$ - SQLContainer container = new SQLContainer(new TableQuery("people", //$NON-NLS-1$ - connectionPool, SQLTestsConstants.sqlGen)); Object itemID = container.addItem(); Item item = container.getItem(itemID); item.getItemProperty("NAME").setValue(OLD_VALUE); //$NON-NLS-1$ @@ -201,9 +221,6 @@ public class SQLContainerTableQueryTest { public void getItem_table5000RowsWithParameter1337_returnsItemWithId1337() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); Item item; if (SQLTestsConstants.db == DB.ORACLE) { @@ -225,8 +242,6 @@ public class SQLContainerTableQueryTest { @Test public void getItemIds_table_returnsItemIdsWithKeys0through3() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Collection<?> itemIds = container.getItemIds(); Assert.assertEquals(4, itemIds.size()); RowId zero = new RowId(new Object[] { 0 + offset }); @@ -248,38 +263,10 @@ public class SQLContainerTableQueryTest { @Test public void getType_tableNAMEPropertyId_returnsString() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Assert.assertEquals(String.class, container.getType("NAME")); } @Test - public void getType_tableIDPropertyId_returnsInteger() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); - if (SQLTestsConstants.db == DB.ORACLE) { - Assert.assertEquals(BigDecimal.class, container.getType("ID")); - } else { - Assert.assertEquals(Integer.class, container.getType("ID")); - } - } - - @Test - public void getType_tableNonexistingPropertyId_returnsNull() - throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); - Assert.assertNull(container.getType("asdf")); - } - - @Test - public void size_table_returnsFour() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); - Assert.assertEquals(4, container.size()); - } - - @Test public void size_tableOneAddedItem_returnsFive() throws SQLException { Connection conn = connectionPool.reserveConnection(); Statement statement = conn.createStatement(); @@ -293,22 +280,18 @@ public class SQLContainerTableQueryTest { conn.commit(); connectionPool.releaseConnection(conn); - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Assert.assertEquals(5, container.size()); } @Test public void indexOfId_tableWithParameterThree_returnsThree() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { Assert.assertEquals(3, container.indexOfId(new RowId( - new Object[] { new BigDecimal(3 + offset) }))); + new Object[]{new BigDecimal(3 + offset)}))); } else { Assert.assertEquals(3, - container.indexOfId(new RowId(new Object[] { 3 + offset }))); + container.indexOfId(new RowId(new Object[]{3 + offset}))); } } @@ -316,18 +299,16 @@ public class SQLContainerTableQueryTest { public void indexOfId_table5000RowsWithParameter1337_returns1337() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); - TableQuery q = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(q); + if (SQLTestsConstants.db == DB.ORACLE) { - container.getItem(new RowId(new Object[] { new BigDecimal( - 1337 + offset) })); + container.getItem(new RowId(new Object[]{new BigDecimal( + 1337 + offset)})); Assert.assertEquals(1337, container.indexOfId(new RowId( - new Object[] { new BigDecimal(1337 + offset) }))); + new Object[]{new BigDecimal(1337 + offset)}))); } else { - container.getItem(new RowId(new Object[] { 1337 + offset })); + container.getItem(new RowId(new Object[]{1337 + offset})); Assert.assertEquals(1337, container.indexOfId(new RowId( - new Object[] { 1337 + offset }))); + new Object[]{1337 + offset}))); } } @@ -335,8 +316,6 @@ public class SQLContainerTableQueryTest { public void getIdByIndex_table5000rowsIndex1337_returnsRowId1337() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object itemId = container.getIdByIndex(1337); if (SQLTestsConstants.db == DB.ORACLE) { Assert.assertEquals( @@ -352,10 +331,8 @@ public class SQLContainerTableQueryTest { public void getIdByIndex_tableWithPaging5000rowsIndex1337_returnsRowId1337() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); - Object itemId = container.getIdByIndex(1337); + + Object itemId = container.getIdByIndex(1337); if (SQLTestsConstants.db == DB.ORACLE) { Assert.assertEquals( new RowId(new Object[] { 1337 + offset }).toString(), @@ -387,29 +364,25 @@ public class SQLContainerTableQueryTest { public void prevItemId_tableCurrentItem1337_returns1336() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object itemId = container.getIdByIndex(1337); if (SQLTestsConstants.db == DB.ORACLE) { Assert.assertEquals( - new RowId(new Object[] { 1336 + offset }).toString(), + new RowId(new Object[]{1336 + offset}).toString(), container.prevItemId(itemId).toString()); } else { - Assert.assertEquals(new RowId(new Object[] { 1336 + offset }), + Assert.assertEquals(new RowId(new Object[]{1336 + offset}), container.prevItemId(itemId)); } } @Test public void firstItemId_table_returnsItemId0() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { Assert.assertEquals( - new RowId(new Object[] { 0 + offset }).toString(), + new RowId(new Object[]{0 + offset}).toString(), container.firstItemId().toString()); } else { - Assert.assertEquals(new RowId(new Object[] { 0 + offset }), + Assert.assertEquals(new RowId(new Object[]{0 + offset}), container.firstItemId()); } } @@ -419,22 +392,18 @@ public class SQLContainerTableQueryTest { throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { Assert.assertEquals( - new RowId(new Object[] { 4999 + offset }).toString(), + new RowId(new Object[]{4999 + offset}).toString(), container.lastItemId().toString()); } else { - Assert.assertEquals(new RowId(new Object[] { 4999 + offset }), + Assert.assertEquals(new RowId(new Object[]{4999 + offset}), container.lastItemId()); } } @Test public void isFirstId_tableActualFirstId_returnsTrue() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { assertTrue(container.isFirstId(new RowId( new Object[]{new BigDecimal(0 + offset)}))); @@ -446,34 +415,28 @@ public class SQLContainerTableQueryTest { @Test public void isFirstId_tableSecondId_returnsFalse() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { Assert.assertFalse(container.isFirstId(new RowId( - new Object[] { new BigDecimal(1 + offset) }))); + new Object[]{new BigDecimal(1 + offset)}))); } else { Assert.assertFalse(container.isFirstId(new RowId( - new Object[] { 1 + offset }))); + new Object[]{1 + offset}))); } } @Test public void isLastId_tableSecondId_returnsFalse() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { Assert.assertFalse(container.isLastId(new RowId( - new Object[] { new BigDecimal(1 + offset) }))); + new Object[]{new BigDecimal(1 + offset)}))); } else { Assert.assertFalse(container.isLastId(new RowId( - new Object[] { 1 + offset }))); + new Object[]{1 + offset}))); } } @Test public void isLastId_tableLastId_returnsTrue() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { assertTrue(container.isLastId(new RowId( new Object[]{new BigDecimal(3 + offset)}))); @@ -486,8 +449,6 @@ public class SQLContainerTableQueryTest { @Test public void isLastId_table5000RowsLastId_returnsTrue() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { assertTrue(container.isLastId(new RowId( new Object[]{new BigDecimal(4999 + offset)}))); @@ -501,8 +462,7 @@ public class SQLContainerTableQueryTest { public void allIdsFound_table5000RowsLastId_shouldSucceed() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); + for (int i = 0; i < 5000; i++) { assertTrue(container.containsId(container.getIdByIndex(i))); } @@ -512,8 +472,7 @@ public class SQLContainerTableQueryTest { public void allIdsFound_table5000RowsLastId_autoCommit_shouldSucceed() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); + container.setAutoCommit(true); for (int i = 0; i < 5000; i++) { assertTrue(container.containsId(container.getIdByIndex(i))); @@ -522,8 +481,6 @@ public class SQLContainerTableQueryTest { @Test public void refresh_table_sizeShouldUpdate() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Assert.assertEquals(4, container.size()); DataGenerator.addFiveThousandPeople(connectionPool); container.refresh(); @@ -537,8 +494,6 @@ public class SQLContainerTableQueryTest { // after adding lots of items unless we call refresh inbetween. This to // make sure that the refresh method actually refreshes stuff and isn't // a NOP. - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Assert.assertEquals(4, container.size()); DataGenerator.addFiveThousandPeople(connectionPool); Assert.assertEquals(4, container.size()); @@ -546,8 +501,6 @@ public class SQLContainerTableQueryTest { @Test public void setAutoCommit_table_shouldSucceed() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.setAutoCommit(true); assertTrue(container.isAutoCommit()); container.setAutoCommit(false); @@ -556,15 +509,11 @@ public class SQLContainerTableQueryTest { @Test public void getPageLength_table_returnsDefault100() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Assert.assertEquals(100, container.getPageLength()); } @Test public void setPageLength_table_shouldSucceed() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.setPageLength(20); Assert.assertEquals(20, container.getPageLength()); container.setPageLength(200); @@ -573,59 +522,43 @@ public class SQLContainerTableQueryTest { @Test(expected = UnsupportedOperationException.class) public void addContainerProperty_normal_isUnsupported() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.addContainerProperty("asdf", String.class, ""); } @Test(expected = UnsupportedOperationException.class) public void removeContainerProperty_normal_isUnsupported() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.removeContainerProperty("asdf"); } @Test(expected = UnsupportedOperationException.class) public void addItemObject_normal_isUnsupported() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.addItem("asdf"); } @Test(expected = UnsupportedOperationException.class) public void addItemAfterObjectObject_normal_isUnsupported() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.addItemAfter("asdf", "foo"); } @Test(expected = UnsupportedOperationException.class) public void addItemAtIntObject_normal_isUnsupported() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.addItemAt(2, "asdf"); } @Test(expected = UnsupportedOperationException.class) public void addItemAtInt_normal_isUnsupported() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.addItemAt(2); } @Test(expected = UnsupportedOperationException.class) public void addItemAfterObject_normal_isUnsupported() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.addItemAfter("asdf"); } @Test public void addItem_tableAddOneNewItem_returnsItemId() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object itemId = container.addItem(); Assert.assertNotNull(itemId); } @@ -633,9 +566,6 @@ public class SQLContainerTableQueryTest { @Test public void addItem_tableAddOneNewItem_autoCommit_returnsFinalItemId() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); container.setAutoCommit(true); Object itemId = container.addItem(); Assert.assertNotNull(itemId); @@ -646,9 +576,6 @@ public class SQLContainerTableQueryTest { @Test public void addItem_tableAddOneNewItem_autoCommit_sizeIsIncreased() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); container.setAutoCommit(true); int originalSize = container.size(); container.addItem(); @@ -658,8 +585,6 @@ public class SQLContainerTableQueryTest { @Test public void addItem_tableAddOneNewItem_shouldChangeSize() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); int size = container.size(); container.addItem(); Assert.assertEquals(size + 1, container.size()); @@ -668,8 +593,6 @@ public class SQLContainerTableQueryTest { @Test public void addItem_tableAddTwoNewItems_shouldChangeSize() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); int size = container.size(); Object id1 = container.addItem(); Object id2 = container.addItem(); @@ -681,8 +604,6 @@ public class SQLContainerTableQueryTest { @Test public void nextItemId_tableNewlyAddedItem_returnsNewlyAdded() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object lastId = container.lastItemId(); Object id = container.addItem(); Assert.assertEquals(id, container.nextItemId(lastId)); @@ -691,8 +612,6 @@ public class SQLContainerTableQueryTest { @Test public void lastItemId_tableNewlyAddedItem_returnsNewlyAdded() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object lastId = container.lastItemId(); Object id = container.addItem(); Assert.assertEquals(id, container.lastItemId()); @@ -701,8 +620,6 @@ public class SQLContainerTableQueryTest { @Test public void indexOfId_tableNewlyAddedItem_returnsFour() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); Assert.assertEquals(4, container.indexOfId(id)); } @@ -710,8 +627,6 @@ public class SQLContainerTableQueryTest { @Test public void getItem_tableNewlyAddedItem_returnsNewlyAdded() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); Assert.assertNotNull(container.getItem(id)); } @@ -719,8 +634,6 @@ public class SQLContainerTableQueryTest { @Test public void getItemIds_tableNewlyAddedItem_containsNewlyAdded() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); assertTrue(container.getItemIds().contains(id)); } @@ -728,8 +641,6 @@ public class SQLContainerTableQueryTest { @Test public void getContainerProperty_tableNewlyAddedItem_returnsPropertyOfNewlyAddedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); Item item = container.getItem(id); item.getItemProperty("NAME").setValue("asdf"); @@ -740,86 +651,80 @@ public class SQLContainerTableQueryTest { @Test public void containsId_tableNewlyAddedItem_returnsTrue() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); + assertTrue(container.containsId(id)); } @Test public void prevItemId_tableTwoNewlyAddedItems_returnsFirstAddedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id1 = container.addItem(); Object id2 = container.addItem(); + Assert.assertEquals(id1, container.prevItemId(id2)); } @Test public void firstItemId_tableEmptyResultSet_returnsFirstAddedItem() throws SQLException { - DataGenerator.createGarbage(connectionPool); - SQLContainer container = new SQLContainer(new TableQuery("garbage", - connectionPool, SQLTestsConstants.sqlGen)); - Object id = container.addItem(); - Assert.assertSame(id, container.firstItemId()); + SQLContainer garbageContainer = getGarbageContainer(); + + Object id = garbageContainer.addItem(); + + Assert.assertSame(id, garbageContainer.firstItemId()); } @Test public void isFirstId_tableEmptyResultSet_returnsFirstAddedItem() throws SQLException { - DataGenerator.createGarbage(connectionPool); - SQLContainer container = new SQLContainer(new TableQuery("garbage", - connectionPool, SQLTestsConstants.sqlGen)); - Object id = container.addItem(); - assertTrue(container.isFirstId(id)); + SQLContainer garbageContainer = getGarbageContainer(); + + Object id = garbageContainer.addItem(); + + assertTrue(garbageContainer.isFirstId(id)); } @Test public void isLastId_tableOneItemAdded_returnsTrueForAddedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); + assertTrue(container.isLastId(id)); } @Test public void isLastId_tableTwoItemsAdded_returnsTrueForLastAddedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.addItem(); + Object id2 = container.addItem(); + assertTrue(container.isLastId(id2)); } @Test public void getIdByIndex_tableOneItemAddedLastIndexInContainer_returnsAddedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); + Assert.assertEquals(id, container.getIdByIndex(container.size() - 1)); } @Test public void removeItem_tableNoAddedItems_removesItemFromContainer() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); - int size = container.size(); + int originalSize = container.size(); Object id = container.firstItemId(); + assertTrue(container.removeItem(id)); + Assert.assertNotSame(id, container.firstItemId()); - Assert.assertEquals(size - 1, container.size()); + Assert.assertEquals(originalSize - 1, container.size()); } @Test public void containsId_tableRemovedItem_returnsFalse() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.firstItemId(); assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); @@ -828,10 +733,9 @@ public class SQLContainerTableQueryTest { @Test public void removeItem_tableOneAddedItem_removesTheAddedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); int size = container.size(); + assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); Assert.assertEquals(size - 1, container.size()); @@ -839,18 +743,16 @@ public class SQLContainerTableQueryTest { @Test public void getItem_tableItemRemoved_returnsNull() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.firstItemId(); + assertTrue(container.removeItem(id)); Assert.assertNull(container.getItem(id)); } @Test public void getItem_tableAddedItemRemoved_returnsNull() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); + Assert.assertNotNull(container.getItem(id)); assertTrue(container.removeItem(id)); Assert.assertNull(container.getItem(id)); @@ -859,9 +761,8 @@ public class SQLContainerTableQueryTest { @Test public void getItemIds_tableItemRemoved_shouldNotContainRemovedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.firstItemId(); + assertTrue(container.getItemIds().contains(id)); assertTrue(container.removeItem(id)); Assert.assertFalse(container.getItemIds().contains(id)); @@ -870,9 +771,8 @@ public class SQLContainerTableQueryTest { @Test public void getItemIds_tableAddedItemRemoved_shouldNotContainRemovedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); + assertTrue(container.getItemIds().contains(id)); assertTrue(container.removeItem(id)); Assert.assertFalse(container.getItemIds().contains(id)); @@ -880,9 +780,8 @@ public class SQLContainerTableQueryTest { @Test public void containsId_tableItemRemoved_returnsFalse() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.firstItemId(); + assertTrue(container.containsId(id)); assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); @@ -891,10 +790,8 @@ public class SQLContainerTableQueryTest { @Test public void containsId_tableAddedItemRemoved_returnsFalse() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); Object id = container.addItem(); + assertTrue(container.containsId(id)); assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); @@ -903,11 +800,10 @@ public class SQLContainerTableQueryTest { @Test public void nextItemId_tableItemRemoved_skipsRemovedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object first = container.getIdByIndex(0); Object second = container.getIdByIndex(1); Object third = container.getIdByIndex(2); + assertTrue(container.removeItem(second)); Assert.assertEquals(third, container.nextItemId(first)); } @@ -915,11 +811,10 @@ public class SQLContainerTableQueryTest { @Test public void nextItemId_tableAddedItemRemoved_skipsRemovedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object first = container.lastItemId(); Object second = container.addItem(); Object third = container.addItem(); + assertTrue(container.removeItem(second)); Assert.assertEquals(third, container.nextItemId(first)); } @@ -927,11 +822,10 @@ public class SQLContainerTableQueryTest { @Test public void prevItemId_tableItemRemoved_skipsRemovedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object first = container.getIdByIndex(0); Object second = container.getIdByIndex(1); Object third = container.getIdByIndex(2); + assertTrue(container.removeItem(second)); Assert.assertEquals(first, container.prevItemId(third)); } @@ -939,11 +833,10 @@ public class SQLContainerTableQueryTest { @Test public void prevItemId_tableAddedItemRemoved_skipsRemovedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object first = container.lastItemId(); Object second = container.addItem(); Object third = container.addItem(); + assertTrue(container.removeItem(second)); Assert.assertEquals(first, container.prevItemId(third)); } @@ -951,9 +844,8 @@ public class SQLContainerTableQueryTest { @Test public void firstItemId_tableFirstItemRemoved_resultChanges() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object first = container.firstItemId(); + assertTrue(container.removeItem(first)); Assert.assertNotSame(first, container.firstItemId()); } @@ -961,22 +853,20 @@ public class SQLContainerTableQueryTest { @Test public void firstItemId_tableNewlyAddedFirstItemRemoved_resultChanges() throws SQLException { - DataGenerator.createGarbage(connectionPool); - SQLContainer container = new SQLContainer(new TableQuery("garbage", - connectionPool, SQLTestsConstants.sqlGen)); - Object first = container.addItem(); - Object second = container.addItem(); - Assert.assertSame(first, container.firstItemId()); - assertTrue(container.removeItem(first)); - Assert.assertSame(second, container.firstItemId()); - } + SQLContainer garbageContainer = getGarbageContainer(); + + Object first = garbageContainer.addItem(); + Object second = garbageContainer.addItem(); + Assert.assertSame(first, garbageContainer.firstItemId()); + assertTrue(garbageContainer.removeItem(first)); + Assert.assertSame(second, garbageContainer.firstItemId()); + } @Test public void lastItemId_tableLastItemRemoved_resultChanges() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object last = container.lastItemId(); + assertTrue(container.removeItem(last)); Assert.assertNotSame(last, container.lastItemId()); } @@ -984,9 +874,8 @@ public class SQLContainerTableQueryTest { @Test public void lastItemId_tableAddedLastItemRemoved_resultChanges() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object last = container.addItem(); + Assert.assertSame(last, container.lastItemId()); assertTrue(container.removeItem(last)); Assert.assertNotSame(last, container.lastItemId()); @@ -995,9 +884,8 @@ public class SQLContainerTableQueryTest { @Test public void isFirstId_tableFirstItemRemoved_returnsFalse() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object first = container.firstItemId(); + assertTrue(container.removeItem(first)); Assert.assertFalse(container.isFirstId(first)); } @@ -1005,22 +893,21 @@ public class SQLContainerTableQueryTest { @Test public void isFirstId_tableAddedFirstItemRemoved_returnsFalse() throws SQLException { - DataGenerator.createGarbage(connectionPool); - SQLContainer container = new SQLContainer(new TableQuery("garbage", - connectionPool, SQLTestsConstants.sqlGen)); - Object first = container.addItem(); - container.addItem(); - Assert.assertSame(first, container.firstItemId()); - assertTrue(container.removeItem(first)); - Assert.assertFalse(container.isFirstId(first)); + SQLContainer garbageContainer = getGarbageContainer(); + + Object first = garbageContainer.addItem(); + garbageContainer.addItem(); + + Assert.assertSame(first, garbageContainer.firstItemId()); + assertTrue(garbageContainer.removeItem(first)); + Assert.assertFalse(garbageContainer.isFirstId(first)); } @Test public void isLastId_tableLastItemRemoved_returnsFalse() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object last = container.lastItemId(); + assertTrue(container.removeItem(last)); Assert.assertFalse(container.isLastId(last)); } @@ -1028,9 +915,8 @@ public class SQLContainerTableQueryTest { @Test public void isLastId_tableAddedLastItemRemoved_returnsFalse() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object last = container.addItem(); + Assert.assertSame(last, container.lastItemId()); assertTrue(container.removeItem(last)); Assert.assertFalse(container.isLastId(last)); @@ -1038,9 +924,8 @@ public class SQLContainerTableQueryTest { @Test public void indexOfId_tableItemRemoved_returnsNegOne() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.getIdByIndex(2); + assertTrue(container.removeItem(id)); Assert.assertEquals(-1, container.indexOfId(id)); } @@ -1048,9 +933,8 @@ public class SQLContainerTableQueryTest { @Test public void indexOfId_tableAddedItemRemoved_returnsNegOne() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); + assertTrue(container.indexOfId(id) != -1); assertTrue(container.removeItem(id)); Assert.assertEquals(-1, container.indexOfId(id)); @@ -1059,9 +943,8 @@ public class SQLContainerTableQueryTest { @Test public void getIdByIndex_tableItemRemoved_resultChanges() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.getIdByIndex(2); + assertTrue(container.removeItem(id)); Assert.assertNotSame(id, container.getIdByIndex(2)); } @@ -1069,19 +952,16 @@ public class SQLContainerTableQueryTest { @Test public void getIdByIndex_tableAddedItemRemoved_resultChanges() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); container.addItem(); int index = container.indexOfId(id); + assertTrue(container.removeItem(id)); Assert.assertNotSame(id, container.getIdByIndex(index)); } @Test public void removeAllItems_table_shouldSucceed() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); assertTrue(container.removeAllItems()); Assert.assertEquals(0, container.size()); } @@ -1089,10 +969,9 @@ public class SQLContainerTableQueryTest { @Test public void removeAllItems_tableAddedItems_shouldSucceed() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.addItem(); container.addItem(); + assertTrue(container.removeAllItems()); Assert.assertEquals(0, container.size()); } @@ -1101,11 +980,11 @@ public class SQLContainerTableQueryTest { @Test(timeout = 1000) public void removeAllItems_manyItems_commit_shouldSucceed() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); final int itemNumber = (SQLContainer.CACHE_RATIO + 1) * SQLContainer.DEFAULT_PAGE_LENGTH + 1; + container.removeAllItems(); + Assert.assertEquals(container.size(), 0); for (int i = 0; i < itemNumber; ++i) { container.addItem(); @@ -1119,11 +998,9 @@ public class SQLContainerTableQueryTest { @Test public void commit_tableAddedItem_shouldBeWrittenToDB() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); Object id = container.addItem(); container.getContainerProperty(id, "NAME").setValue("New Name"); + assertTrue(id instanceof TemporaryRowId); Assert.assertSame(id, container.lastItemId()); container.commit(); @@ -1136,9 +1013,6 @@ public class SQLContainerTableQueryTest { @Test public void commit_tableTwoAddedItems_shouldBeWrittenToDB() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); Object id = container.addItem(); Object id2 = container.addItem(); container.getContainerProperty(id, "NAME").setValue("Herbert"); @@ -1147,6 +1021,7 @@ public class SQLContainerTableQueryTest { Assert.assertSame(id2, container.lastItemId()); container.commit(); Object nextToLast = container.getIdByIndex(container.size() - 2); + Assert.assertFalse(nextToLast instanceof TemporaryRowId); Assert.assertEquals("Herbert", container.getContainerProperty(nextToLast, "NAME").getValue()); @@ -1159,24 +1034,20 @@ public class SQLContainerTableQueryTest { @Test public void commit_tableRemovedItem_shouldBeRemovedFromDB() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); Object last = container.lastItemId(); container.removeItem(last); container.commit(); + Assert.assertFalse(last.equals(container.lastItemId())); } @Test public void commit_tableLastItemUpdated_shouldUpdateRowInDB() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); Object last = container.lastItemId(); container.getContainerProperty(last, "NAME").setValue("Donald"); container.commit(); + Assert.assertEquals("Donald", container.getContainerProperty(container.lastItemId(), "NAME") .getValue()); @@ -1184,13 +1055,11 @@ public class SQLContainerTableQueryTest { @Test public void commit_removeModifiedItem_shouldSucceed() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); int size = container.size(); Object key = container.firstItemId(); Item row = container.getItem(key); row.getItemProperty("NAME").setValue("Pekka"); + assertTrue(container.removeItem(key)); container.commit(); Assert.assertEquals(size - 1, container.size()); @@ -1198,8 +1067,6 @@ public class SQLContainerTableQueryTest { @Test public void rollback_tableItemAdded_discardsAddedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); int size = container.size(); Object id = container.addItem(); container.getContainerProperty(id, "NAME").setValue("foo"); @@ -1213,8 +1080,6 @@ public class SQLContainerTableQueryTest { @Test public void rollback_tableItemRemoved_restoresRemovedItem() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); int size = container.size(); Object last = container.lastItemId(); container.removeItem(last); @@ -1226,8 +1091,6 @@ public class SQLContainerTableQueryTest { @Test public void rollback_tableItemChanged_discardsChanges() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Object last = container.lastItemId(); container.getContainerProperty(last, "NAME").setValue("foo"); container.rollback(); @@ -1238,8 +1101,6 @@ public class SQLContainerTableQueryTest { @Test public void itemChangeNotification_table_isModifiedReturnsTrue() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Assert.assertFalse(container.isModified()); RowItem last = (RowItem) container.getItem(container.lastItemId()); container.itemChangeNotification(last); @@ -1248,8 +1109,6 @@ public class SQLContainerTableQueryTest { @Test public void itemSetChangeListeners_table_shouldFire() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); ItemSetChangeListener listener = EasyMock .createMock(ItemSetChangeListener.class); listener.containerItemSetChange(EasyMock.isA(ItemSetChangeEvent.class)); @@ -1264,8 +1123,6 @@ public class SQLContainerTableQueryTest { @Test public void itemSetChangeListeners_tableItemRemoved_shouldFire() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); ItemSetChangeListener listener = EasyMock .createMock(ItemSetChangeListener.class); listener.containerItemSetChange(EasyMock.isA(ItemSetChangeEvent.class)); @@ -1280,8 +1137,6 @@ public class SQLContainerTableQueryTest { @Test public void removeListener_table_shouldNotFire() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); ItemSetChangeListener listener = EasyMock .createMock(ItemSetChangeListener.class); EasyMock.replay(listener); @@ -1295,8 +1150,6 @@ public class SQLContainerTableQueryTest { @Test public void isModified_tableRemovedItem_returnsTrue() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Assert.assertFalse(container.isModified()); container.removeItem(container.lastItemId()); assertTrue(container.isModified()); @@ -1304,8 +1157,6 @@ public class SQLContainerTableQueryTest { @Test public void isModified_tableAddedItem_returnsTrue() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Assert.assertFalse(container.isModified()); container.addItem(); assertTrue(container.isModified()); @@ -1313,8 +1164,6 @@ public class SQLContainerTableQueryTest { @Test public void isModified_tableChangedItem_returnsTrue() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Assert.assertFalse(container.isModified()); container.getContainerProperty(container.lastItemId(), "NAME") .setValue("foo"); @@ -1324,8 +1173,6 @@ public class SQLContainerTableQueryTest { @Test public void getSortableContainerPropertyIds_table_returnsAllPropertyIds() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); Collection<?> sortableIds = container.getSortableContainerPropertyIds(); assertTrue(sortableIds.contains("ID")); assertTrue(sortableIds.contains("NAME")); @@ -1339,9 +1186,6 @@ public class SQLContainerTableQueryTest { @Test public void addOrderBy_table_shouldReorderResults() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); // Ville, Kalle, Pelle, Börje Assert.assertEquals("Ville", container.getContainerProperty(container.firstItemId(), "NAME") @@ -1362,16 +1206,11 @@ public class SQLContainerTableQueryTest { @Test(expected = IllegalArgumentException.class) public void addOrderBy_tableIllegalColumn_shouldFail() throws SQLException { - SQLContainer container = new SQLContainer(new TableQuery("people", - connectionPool, SQLTestsConstants.sqlGen)); container.addOrderBy(new OrderBy("asdf", true)); } @Test public void sort_table_sortsByName() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); // Ville, Kalle, Pelle, Börje Assert.assertEquals("Ville", container.getContainerProperty(container.firstItemId(), "NAME") @@ -1393,9 +1232,6 @@ public class SQLContainerTableQueryTest { @Test public void addFilter_table_filtersResults() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); // Ville, Kalle, Pelle, Börje Assert.assertEquals(4, container.size()); Assert.assertEquals("Börje", @@ -1412,9 +1248,6 @@ public class SQLContainerTableQueryTest { @Test public void addContainerFilter_filtersResults() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); // Ville, Kalle, Pelle, Börje Assert.assertEquals(4, container.size()); @@ -1430,9 +1263,6 @@ public class SQLContainerTableQueryTest { @Test public void addContainerFilter_ignoreCase_filtersResults() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); // Ville, Kalle, Pelle, Börje Assert.assertEquals(4, container.size()); @@ -1448,9 +1278,6 @@ public class SQLContainerTableQueryTest { @Test public void removeAllContainerFilters_table_noFiltering() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); // Ville, Kalle, Pelle, Börje Assert.assertEquals(4, container.size()); @@ -1472,9 +1299,6 @@ public class SQLContainerTableQueryTest { @Test public void removeContainerFilters_table_noFiltering() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); // Ville, Kalle, Pelle, Börje Assert.assertEquals(4, container.size()); @@ -1497,9 +1321,6 @@ public class SQLContainerTableQueryTest { @Test public void addFilter_tableBufferedItems_alsoFiltersBufferedItems() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); // Ville, Kalle, Pelle, Börje Assert.assertEquals(4, container.size()); Assert.assertEquals("Börje", @@ -1553,9 +1374,6 @@ public class SQLContainerTableQueryTest { @Test public void sort_tableBufferedItems_sortsBufferedItemsLastInOrderAdded() throws SQLException { - TableQuery query = new TableQuery("people", connectionPool, - SQLTestsConstants.sqlGen); - SQLContainer container = new SQLContainer(query); // Ville, Kalle, Pelle, Börje Assert.assertEquals("Ville", container.getContainerProperty(container.firstItemId(), "NAME") diff --git a/server/tests/src/com/vaadin/tests/server/component/TestReadEmptyDesign.java b/server/tests/src/com/vaadin/tests/server/component/TestReadEmptyDesign.java new file mode 100644 index 0000000000..ecd303b678 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/TestReadEmptyDesign.java @@ -0,0 +1,78 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Document; +import org.jsoup.nodes.DocumentType; +import org.jsoup.nodes.Element; + +import com.vaadin.ui.Component; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.Design; +import com.vaadin.ui.declarative.DesignContext; +import com.vaadin.ui.declarative.DesignException; + +/** + * Test cases for checking that reading a design with no elements in the html + * body produces null as the root component. + */ +public class TestReadEmptyDesign extends TestCase { + InputStream is; + + @Override + protected void setUp() throws Exception { + super.setUp(); + String html = createDesign().toString(); + is = new ByteArrayInputStream(html.getBytes()); + } + + public void testReadComponent() { + Component root = Design.read(is); + assertNull("The root component should be null.", root); + } + + public void testReadContext() { + DesignContext ctx = Design.read(is, null); + assertNotNull("The design context should not be null.", ctx); + assertNull("The root component should be null.", ctx.getRootComponent()); + } + + public void testReadContextWithRootParameter() { + try { + Component rootComponent = new VerticalLayout(); + DesignContext ctx = Design.read(is, rootComponent); + fail("Reading a design with no elements should fail when a non-null root Component is specified."); + } catch (DesignException e) { + // This is the expected outcome, nothing to do. + } + } + + private Document createDesign() { + Document doc = new Document(""); + DocumentType docType = new DocumentType("html", "", "", ""); + doc.appendChild(docType); + Element html = doc.createElement("html"); + doc.appendChild(html); + html.appendChild(doc.createElement("head")); + html.appendChild(doc.createElement("body")); + return doc; + } +}
\ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/TestWriteEmptyDesign.java b/server/tests/src/com/vaadin/tests/server/component/TestWriteEmptyDesign.java new file mode 100644 index 0000000000..b50915f1fd --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/TestWriteEmptyDesign.java @@ -0,0 +1,58 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import junit.framework.TestCase; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.vaadin.ui.Component; +import com.vaadin.ui.declarative.Design; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test cases for checking that writing a component hierarchy with null root + * produces an html document that has no elements in the html body. + */ +public class TestWriteEmptyDesign extends TestCase { + + public void testWriteComponent() throws IOException { + OutputStream os = new ByteArrayOutputStream(); + Design.write((Component) null, os); + checkHtml(os.toString()); + } + + public void testWriteContext() throws IOException { + OutputStream os = new ByteArrayOutputStream(); + DesignContext ctx = new DesignContext(); + ctx.setRootComponent(null); + Design.write(ctx, os); + checkHtml(os.toString()); + } + + private void checkHtml(String html) { + Document doc = Jsoup.parse(html); + Element body = doc.body(); + assertEquals("There should be no elements in the html body.", "", + body.html()); + } +}
\ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestAbstractSelectValueUpdate.java b/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestAbstractSelectValueUpdate.java deleted file mode 100644 index e81f6e09b6..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestAbstractSelectValueUpdate.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2000-2014 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.server.component.abstractselect; - -import java.util.Collection; -import java.util.Collections; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.data.util.BeanItemContainer; -import com.vaadin.ui.AbstractSelect; - -public class TestAbstractSelectValueUpdate { - - @Test - public void removeItem_deleteItemFromUnderlyingContainer_selectValueIsUpdated() { - BeanItemContainer<Object> container = new BeanItemContainer<Object>( - Object.class); - Object item1 = new Object(); - Object item2 = new Object(); - container.addBean(item1); - container.addBean(item2); - TestSelect select = new TestSelect(); - select.setContainerDataSource(container); - - select.setValue(item1); - - Assert.assertNotNull("Value is null after selection", select.getValue()); - - container.removeItem(item1); - - Assert.assertNull("Value is not null after removal", select.getValue()); - } - - @Test - public void removeItem_multiselectSectionDeleteItemFromUnderlyingContainer_selectValueIsUpdated() { - BeanItemContainer<Object> container = new BeanItemContainer<Object>( - Object.class); - Object item1 = new Object(); - Object item2 = new Object(); - container.addBean(item1); - container.addBean(item2); - TestSelect select = new TestSelect(); - select.setMultiSelect(true); - select.setContainerDataSource(container); - - select.setValue(Collections.singletonList(item1)); - - checkSelectedItemsCount(select, 1); - - container.removeItem(item1); - - checkSelectedItemsCount(select, 0); - } - - private void checkSelectedItemsCount(TestSelect select, int count) { - Assert.assertNotNull("Selected value is null", select.getValue()); - Assert.assertTrue("Selected value is not a collection", - select.getValue() instanceof Collection); - Assert.assertEquals("Wrong number of selected items", - ((Collection<?>) select.getValue()).size(), count); - } - - private class TestSelect extends AbstractSelect { - - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/button/ButtonClick.java b/server/tests/src/com/vaadin/tests/server/component/button/ButtonClick.java index b41e93900f..3d5fe77f8e 100644 --- a/server/tests/src/com/vaadin/tests/server/component/button/ButtonClick.java +++ b/server/tests/src/com/vaadin/tests/server/component/button/ButtonClick.java @@ -3,9 +3,11 @@ package com.vaadin.tests.server.component.button; import org.junit.Assert; import org.junit.Test; +import com.vaadin.data.util.ObjectProperty; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.UI; /** @@ -15,6 +17,22 @@ public class ButtonClick { private boolean clicked = false; @Test + public void clickDetachedButton() { + Button b = new Button(); + final ObjectProperty<Integer> counter = new ObjectProperty<Integer>(0); + b.addClickListener(new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + counter.setValue(counter.getValue() + 1); + } + }); + + b.click(); + Assert.assertEquals(Integer.valueOf(1), counter.getValue()); + } + + @Test public void testClick() { getButton().click(); Assert.assertTrue("Button doesn't fire clicks", clicked); @@ -36,22 +54,6 @@ public class ButtonClick { Assert.assertFalse("Read only button fires click events", clicked); } - @Test - public void testClickConnectorDisabled() { - Button b = new Button() { - @Override - public boolean isConnectorEnabled() { - return false; - } - }; - UI ui = createUI(); - b.setParent(ui); - addClickListener(b); - b.click(); - Assert.assertFalse("Button with disabled connector fires click events", - clicked); - } - private Button getButton() { Button b = new Button(); UI ui = createUI(); diff --git a/server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java b/server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java index 9c37b91ef5..90c079b35c 100644 --- a/server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java @@ -11,6 +11,7 @@ import com.vaadin.data.fieldgroup.FieldGroup.CommitException; import com.vaadin.data.fieldgroup.PropertyId; import com.vaadin.data.util.BeanItem; import com.vaadin.ui.Field; +import com.vaadin.ui.RichTextArea; import com.vaadin.ui.TextField; public class BeanFieldGroupTest { @@ -136,6 +137,19 @@ public class BeanFieldGroupTest { } @Test + public void buildAndBindNestedRichTextAreaProperty() { + + MyBean bean = new MyBean(); + + BeanFieldGroup<MyBean> bfg = new BeanFieldGroup<MyBean>(MyBean.class); + bfg.setItemDataSource(bean); + + RichTextArea helloField = bfg.buildAndBind("Hello string", + "nestedBean.hello", RichTextArea.class); + assertEquals(bean.nestedBean.hello, helloField.getValue().toString()); + } + + @Test public void setDataSource_nullBean_nullBeanIsSetInDataSource() { BeanFieldGroup<MyBean> group = new BeanFieldGroup<MyBean>(MyBean.class); diff --git a/server/tests/src/com/vaadin/ui/DateFieldTests.java b/server/tests/src/com/vaadin/ui/DateFieldTests.java new file mode 100644 index 0000000000..6a75b4630c --- /dev/null +++ b/server/tests/src/com/vaadin/ui/DateFieldTests.java @@ -0,0 +1,56 @@ +package com.vaadin.ui; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Date; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsNull.nullValue; + +public class DateFieldTests { + + private DateField dateField; + private Date date; + + @Before + public void setup() { + dateField = new DateField(); + date = new Date(); + } + + @Test + public void rangeStartIsSetToNull() { + dateField.setRangeStart(null); + + assertThat(dateField.getRangeStart(), is(nullValue())); + } + + @Test + public void rangeStartIsImmutable() { + long expectedTime = date.getTime(); + + dateField.setRangeStart(date); + date.setTime(expectedTime + 1); + + assertThat(dateField.getRangeStart().getTime(), is(expectedTime)); + } + + @Test + public void rangeEndIsSetToNull() { + dateField.setRangeEnd(null); + + assertThat(dateField.getRangeEnd(), is(nullValue())); + } + + @Test + public void rangeEndIsImmutable() { + long expectedTime = date.getTime(); + + dateField.setRangeEnd(date); + date.setTime(expectedTime + 1); + + assertThat(dateField.getRangeEnd().getTime(), is(expectedTime)); + } +} diff --git a/shared/src/com/vaadin/shared/ui/tabsheet/TabsheetState.java b/shared/src/com/vaadin/shared/ui/tabsheet/TabsheetState.java index 69a3330f64..6059379dc5 100644 --- a/shared/src/com/vaadin/shared/ui/tabsheet/TabsheetState.java +++ b/shared/src/com/vaadin/shared/ui/tabsheet/TabsheetState.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; import com.vaadin.shared.AbstractComponentState; +import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.annotations.NoLayout; public class TabsheetState extends AbstractComponentState { @@ -43,4 +44,7 @@ public class TabsheetState extends AbstractComponentState { /** the key of the currently selected tab */ public String selected; + @DelegateToWidget + public boolean tabCaptionsAsHtml = false; + } diff --git a/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java b/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java index f00a05e810..871111ad8b 100644 --- a/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java +++ b/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java @@ -48,7 +48,6 @@ import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.server.ssl.SslSocketConnector; -import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.webapp.WebAppContext; @@ -257,7 +256,6 @@ public class DevelopmentServerLauncher { webappcontext.stop(); server.stop(); webappcontext.start(); - disableAtmosphereAnnotationScan(webappcontext); server.start(); } }); @@ -278,8 +276,6 @@ public class DevelopmentServerLauncher { // Read web.xml to find all configured servlets webappcontext.start(); - disableAtmosphereAnnotationScan(webappcontext); - try { server.start(); @@ -351,19 +347,6 @@ public class DevelopmentServerLauncher { return "http://localhost:" + port + serverArgs.get("context"); } - private static void disableAtmosphereAnnotationScan( - WebAppContext webappcontext) { - // Reconfigure all servlets to avoid startup delay - for (ServletHolder servletHolder : webappcontext.getServletHandler() - .getServlets()) { - if (servletHolder - .getInitParameter("org.atmosphere.cpr.scanClassPath") == null) { - servletHolder.setInitParameter( - "org.atmosphere.cpr.scanClassPath", "false"); - } - } - } - /** * Assign default value for given key. * diff --git a/uitest/src/com/vaadin/tests/actions/ActionsWithoutKeyCode.java b/uitest/src/com/vaadin/tests/actions/ActionsWithoutKeyCode.java new file mode 100644 index 0000000000..e94a4b1ade --- /dev/null +++ b/uitest/src/com/vaadin/tests/actions/ActionsWithoutKeyCode.java @@ -0,0 +1,39 @@ +package com.vaadin.tests.actions; + +import com.vaadin.event.Action; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.TextField; + +@SuppressWarnings("serial") +public class ActionsWithoutKeyCode extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + TextField tf = new TextField(); + tf.setWidth("100%"); + tf.setInputPrompt("Enter text with å,ä or ä or press windows key while textfield is focused"); + addComponent(tf); + + addActionHandler(new Action.Handler() { + + private Action[] actions; + { + actions = new Action[] { new Action("test1") }; + } + + @Override + public Action[] getActions(Object target, Object sender) { + return actions; + } + + @Override + public void handleAction(Action action, Object sender, Object target) { + log("action " + action.getCaption() + " triggered by " + + sender.getClass().getSimpleName() + " on " + + target.getClass().getSimpleName()); + } + }); + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponents.java b/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponents.java index 4bdec81ccf..64f1a64558 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponents.java +++ b/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponents.java @@ -38,7 +38,7 @@ public class TableClickAndDragOnIconAndComponents extends AbstractTestUI { table.setId("testable-table"); addComponent(table); for (int i = 0; i < 5; i++) { - addItemAfter(i + "foo", null, false); + addItemAfter(i + "foo", null); } table.addGeneratedColumn("Label", new ColumnGenerator() { @@ -118,15 +118,14 @@ public class TableClickAndDragOnIconAndComponents extends AbstractTestUI { IndexedContainer container = (IndexedContainer) table .getContainerDataSource(); - boolean selected = table.getValue().equals(dragged); container.removeItem(dragged); - addItemAfter(dragged, target, selected); + addItemAfter(dragged, target); } }); } @SuppressWarnings("unchecked") - private void addItemAfter(Object itemId, Object afterItemId, boolean select) { + private void addItemAfter(Object itemId, Object afterItemId) { Item item; if (afterItemId != null) { item = table.addItemAfter(afterItemId, itemId); @@ -137,9 +136,6 @@ public class TableClickAndDragOnIconAndComponents extends AbstractTestUI { item.getItemProperty("red").setValue("red " + itemId); item.getItemProperty("icon").setValue( new ThemeResource("../runo/icons/16/ok.png")); - if (select) { - table.select(itemId); - } } @Override diff --git a/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRow.java b/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRow.java deleted file mode 100644 index 349fbc73fe..0000000000 --- a/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRow.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2000-2014 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.table; - -import java.util.Collection; - -import com.vaadin.data.util.BeanItemContainer; -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.MultiSelectMode; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Label; -import com.vaadin.ui.Table; - -/** - * Test UI for delete rows operation in multiselect table. - * - * @author Vaadin Ltd - */ -public class TableDeleteSelectedRow extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - final Table table = new Table(); - table.setSelectable(true); - table.setImmediate(true); - - BeanItemContainer<TableBean> container = createContainer(); - - table.setContainerDataSource(container); - - final Label selectedSize = new Label(); - selectedSize.addStyleName("selected-rows"); - - Button changeMode = new Button("Set multiselect", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - table.setMultiSelect(true); - table.setMultiSelectMode(MultiSelectMode.SIMPLE); - - BeanItemContainer<TableBean> container = createContainer(); - - table.setContainerDataSource(container); - } - }); - changeMode.addStyleName("multiselect"); - - Button delete = new Button("Delete selected", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - if (table.getValue() instanceof Collection) { - Collection<?> rows = (Collection<?>) table.getValue(); - for (Object row : rows) { - table.getContainerDataSource().removeItem(row); - } - rows = (Collection<?>) table.getValue(); - selectedSize.setValue(String.valueOf(rows.size())); - } else { - table.getContainerDataSource().removeItem(table.getValue()); - selectedSize.setValue(table.getValue() == null ? "0" : "1"); - } - } - }); - delete.addStyleName("delete"); - - addComponents(delete, changeMode, selectedSize, table); - } - - @Override - protected String getTestDescription() { - return "Items deleted via container data source should not be available as selected in the table."; - } - - @Override - protected Integer getTicketNumber() { - return 13580; - } - - private BeanItemContainer<TableBean> createContainer() { - BeanItemContainer<TableBean> container = new BeanItemContainer<TableBean>( - TableBean.class); - container.addBean(new TableBean("first")); - container.addBean(new TableBean("second")); - container.addBean(new TableBean("third")); - return container; - } - - public static class TableBean { - - TableBean(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - private String name; - } -} diff --git a/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRowTest.java b/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRowTest.java deleted file mode 100644 index 0e807edf14..0000000000 --- a/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRowTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2000-2014 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.table; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import com.vaadin.tests.tb3.MultiBrowserTest; - -/** - * Test to check selected rows in multiselect table after deletion. - * - * @author Vaadin Ltd - */ -public class TableDeleteSelectedRowTest extends MultiBrowserTest { - - @Test - public void deleteSelectedRows() { - openTestURL(); - - // Select row in the table - findElement(By.className("v-table-row-odd")).click(); - - // Delete selected row - findElement(By.className("delete")).click(); - - WebElement selectedSize = findElement(By.className("selected-rows")); - int size = Integer.parseInt(selectedSize.getText()); - - Assert.assertEquals( - "Non empty collection of selected rows after remove via container", - 0, size); - - // Reset table and set multiselect mode - findElement(By.className("multiselect")).click(); - - // Select row in the table - findElement(By.className("v-table-row-odd")).click(); - - // Delete selected row - findElement(By.className("delete")).click(); - - selectedSize = findElement(By.className("selected-rows")); - size = Integer.parseInt(selectedSize.getText()); - - Assert.assertEquals( - "Non empty collection of selected rows after remove via container", - 0, size); - } -} diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/HtmlInTabCaption.java b/uitest/src/com/vaadin/tests/components/tabsheet/HtmlInTabCaption.java new file mode 100644 index 0000000000..66a27a10b5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/HtmlInTabCaption.java @@ -0,0 +1,72 @@ +/* + * 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.components.tabsheet; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Accordion; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet; + +public class HtmlInTabCaption extends AbstractTestUI { + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. + * VaadinRequest) + */ + @Override + protected void setup(VaadinRequest request) { + getLayout().setSpacing(true); + TabSheet ts = new TabSheet(); + ts.setCaption("TabSheet - no <u>html</u> in tab captions"); + ts.setCaptionAsHtml(true); + ts.addTab(new Label(), "<font color='red'>red</font>"); + ts.addTab(new Label(), "<font color='blue'>blue</font>"); + addComponent(ts); + + ts = new TabSheet(); + ts.setCaption("TabSheet - <b>html</b> in tab captions"); + ts.setCaptionAsHtml(false); + ts.setTabCaptionsAsHtml(true); + ts.addTab(new Label(), "<font color='red'>red</font>"); + ts.addTab(new Label(), "<font color='blue'>blue</font>"); + addComponent(ts); + + Accordion acc = new Accordion(); + acc.setCaption("Accordion - no <u>html</u> in tab captions"); + acc.setCaptionAsHtml(true); + acc.addTab(new Label(), "<font color='red'>red</font>"); + acc.addTab(new Label(), "<font color='blue'>blue</font>"); + addComponent(acc); + + acc = new Accordion(); + acc.setCaption("Accordion - <b>html</b> in tab captions"); + acc.setCaptionAsHtml(false); + acc.setTabCaptionsAsHtml(true); + acc.addTab(new Label(), "<font color='red'>red</font>"); + acc.addTab(new Label(), "<font color='blue'>blue</font>"); + addComponent(acc); + + } + + @Override + protected Integer getTicketNumber() { + return 14609; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/HtmlInTabCaptionTest.java b/uitest/src/com/vaadin/tests/components/tabsheet/HtmlInTabCaptionTest.java new file mode 100644 index 0000000000..41b7037b09 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/HtmlInTabCaptionTest.java @@ -0,0 +1,73 @@ +/* + * 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.components.tabsheet; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.AccordionElement; +import com.vaadin.testbench.elements.TabSheetElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class HtmlInTabCaptionTest extends SingleBrowserTest { + static final String PLAIN_TEXT_RED = "<font color='red'>red</font>"; + static final String HTML_TEXT_RED = "red"; + static final String PLAIN_TEXT_BLUE = "<font color='blue'>blue</font>"; + static final String HTML_TEXT_BLUE = "blue"; + + @Test + public void tabsheetWithoutHtmlCaptions() { + openTestURL(); + TabSheetElement ts = $(TabSheetElement.class).get(0); + Assert.assertEquals(PLAIN_TEXT_RED, getTab(ts, 0).getText()); + Assert.assertEquals(PLAIN_TEXT_BLUE, getTab(ts, 1).getText()); + } + + private WebElement getTab(TabSheetElement tabSheetElement, int i) { + String className = "v-tabsheet-tabitem"; + if (tabSheetElement instanceof AccordionElement) { + className = "v-accordion-item"; + } + return tabSheetElement.findElements(By.className(className)).get(i); + } + + @Test + public void tabsheetWithHtmlCaptions() { + openTestURL(); + TabSheetElement ts = $(TabSheetElement.class).get(1); + Assert.assertEquals(HTML_TEXT_RED, getTab(ts, 0).getText()); + Assert.assertEquals(HTML_TEXT_BLUE, getTab(ts, 1).getText()); + } + + @Test + public void accordionWithoutHtmlCaptions() { + openTestURL(); + AccordionElement acc = $(AccordionElement.class).get(0); + Assert.assertEquals(PLAIN_TEXT_RED, getTab(acc, 0).getText()); + Assert.assertEquals(PLAIN_TEXT_BLUE, getTab(acc, 1).getText()); + + } + + @Test + public void accordionWithHtmlCaptions() { + openTestURL(); + AccordionElement acc = $(AccordionElement.class).get(1); + Assert.assertEquals(HTML_TEXT_RED, getTab(acc, 0).getText()); + Assert.assertEquals(HTML_TEXT_BLUE, getTab(acc, 1).getText()); + } +} diff --git a/uitest/src/com/vaadin/tests/fieldgroup/FormWithNestedProperties.java b/uitest/src/com/vaadin/tests/fieldgroup/FormWithNestedProperties.java index f66d822495..6caa8f3e26 100644 --- a/uitest/src/com/vaadin/tests/fieldgroup/FormWithNestedProperties.java +++ b/uitest/src/com/vaadin/tests/fieldgroup/FormWithNestedProperties.java @@ -31,8 +31,8 @@ public class FormWithNestedProperties extends AbstractBeanFieldGroupTest { super.setup(); setFieldBinder(new BeanFieldGroup<Person>(Person.class)); - country = getFieldBinder().buildAndBind("country", "address.country", - NativeSelect.class); + country = (NativeSelect) getFieldBinder().buildAndBind("country", + "address.country", NativeSelect.class); getFieldBinder().bindMemberFields(this); addComponent(firstName); addComponent(lastName); diff --git a/uitest/tb2/com/vaadin/tests/components/tabsheet/TabSheetBasicOperations.html b/uitest/tb2/com/vaadin/tests/components/tabsheet/TabSheetBasicOperations.html index 357455545e..f0f08efb58 100644 --- a/uitest/tb2/com/vaadin/tests/components/tabsheet/TabSheetBasicOperations.html +++ b/uitest/tb2/com/vaadin/tests/components/tabsheet/TabSheetBasicOperations.html @@ -300,7 +300,7 @@ <tr> <td>assertText</td> <td>vaadin=runcomvaadintestscomponentstabsheetTabSheetTest::PID_SLog/ChildComponentContainer[0]/VLabel[0]</td> - <td>11. Tab 0 selected</td> + <td>11. Tab 2 selected</td> </tr> <!--select tab 1--> <tr> @@ -324,7 +324,6 @@ <td>vaadin=runcomvaadintestscomponentstabsheetTabSheetTest::PID_SLog/ChildComponentContainer[0]/VLabel[0]</td> <td>13. Tab 2 selected</td> </tr> - </tbody></table> </body> </html> |