From 25eeb8bb980e679d9cdab9b469002a0489c8802c Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 15 Oct 2010 18:06:37 +0000 Subject: [PATCH] Refactored test case structure to have similar hierarchy as components Added PopupDateFields2 test case (PopupDateField) Added InlineDateFields test case (InlineDateField) Added ComboBoxes2 test case (ComboBox) svn changeset:15577/svn branch:6.4 --- .../components/AbstractComponentTestCase.java | 92 ++++++++- .../MenuBasedComponentTestCase.java | 193 +++++++----------- .../abstractfield/AbstractFieldTestCase.java | 124 +++++++++++ .../components/combobox/ComboBoxes2.java | 45 ++++ .../datefield/DateFieldTestCase.java | 108 ++++++++++ .../datefield/InlineDateFields2.java | 12 ++ .../datefield/PopupDateFields2.java | 38 ++++ .../select/AbstractSelectTestCase.java | 118 +++++++++++ .../vaadin/tests/components/table/Tables.java | 31 +-- 9 files changed, 618 insertions(+), 143 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/abstractfield/AbstractFieldTestCase.java create mode 100644 tests/src/com/vaadin/tests/components/combobox/ComboBoxes2.java create mode 100644 tests/src/com/vaadin/tests/components/datefield/DateFieldTestCase.java create mode 100644 tests/src/com/vaadin/tests/components/datefield/InlineDateFields2.java create mode 100644 tests/src/com/vaadin/tests/components/datefield/PopupDateFields2.java create mode 100644 tests/src/com/vaadin/tests/components/select/AbstractSelectTestCase.java diff --git a/tests/src/com/vaadin/tests/components/AbstractComponentTestCase.java b/tests/src/com/vaadin/tests/components/AbstractComponentTestCase.java index fdd3a3fce7..aa7da25e7e 100644 --- a/tests/src/com/vaadin/tests/components/AbstractComponentTestCase.java +++ b/tests/src/com/vaadin/tests/components/AbstractComponentTestCase.java @@ -1,8 +1,12 @@ package com.vaadin.tests.components; import java.util.ArrayList; +import java.util.Date; import java.util.List; +import java.util.Locale; +import com.vaadin.terminal.Resource; +import com.vaadin.terminal.ThemeResource; import com.vaadin.terminal.UserError; import com.vaadin.tests.util.Log; import com.vaadin.ui.AbstractComponent; @@ -12,10 +16,27 @@ import com.vaadin.ui.Layout.SpacingHandler; public abstract class AbstractComponentTestCase extends TestBase { + protected static final ThemeResource ICON_16_USER_PNG_CACHEABLE = cacheableThemeResource("../runo/icons/16/user.png"); + protected static final ThemeResource ICON_16_USER_PNG_UNCACHEABLE = uncacheableThemeResource("../runo/icons/16/user.png"); + protected static final ThemeResource ICON_32_ATTENTION_PNG_CACHEABLE = cacheableThemeResource("../runo/icons/32/attention.png"); + protected static final ThemeResource ICON_32_ATTENTION_PNG_UNCACHEABLE = uncacheableThemeResource("../runo/icons/32/attention.png"); + protected static final ThemeResource ICON_64_EMAIL_REPLY_PNG_CACHEABLE = cacheableThemeResource("../runo/icons/64/email-reply.png"); + protected static final ThemeResource ICON_64_EMAIL_REPLY_PNG_UNCACHEABLE = uncacheableThemeResource("../runo/icons/64/email-reply.png"); + private List testComponents = new ArrayList(); abstract protected Class getTestClass(); + protected static ThemeResource uncacheableThemeResource( + String resourceLocation) { + return new ThemeResource(resourceLocation + "?" + new Date().getTime()); + } + + protected static ThemeResource cacheableThemeResource( + String resourceLocation) { + return new ThemeResource(resourceLocation); + } + abstract protected void initializeComponents(); private Log log = null; @@ -75,6 +96,32 @@ public abstract class AbstractComponentTestCase } }; + protected Command errorIndicatorCommand = new Command() { + + public void execute(T c, Boolean enabled, Object data) { + if (enabled) { + c.setComponentError(new UserError(errorMessage)); + } else { + c.setComponentError(null); + + } + } + }; + private String errorMessage = null; + + protected Command errorMessageCommand = new Command() { + + public void execute(T c, String value, Object data) { + errorMessage = value; + if (c.getComponentError() != null) { + errorIndicatorCommand.execute(c, true, null); + } + + } + + }; + + // TODO Move to AbstractFieldTestCase protected Command requiredCommand = new Command() { public void execute(T c, Boolean enabled, Object data) { @@ -86,16 +133,17 @@ public abstract class AbstractComponentTestCase } } }; + protected Command requiredErrorMessageCommand = new Command() { - protected Command errorIndicatorCommand = new Command() { + public void execute(T c, String value, Object data) { + ((Field) c).setRequiredError(value); + } - public void execute(T c, Boolean enabled, Object data) { - if (enabled) { - c.setComponentError(new UserError("It failed!")); - } else { - c.setComponentError(null); + }; - } + protected Command descriptionCommand = new Command() { + public void execute(T c, String value, Object data) { + c.setDescription(value); } }; @@ -106,6 +154,36 @@ public abstract class AbstractComponentTestCase } }; + protected Command visibleCommand = new Command() { + + public void execute(T c, Boolean enabled, Object data) { + c.setVisible(enabled); + } + }; + + protected Command iconCommand = new Command() { + + public void execute(T c, Resource value, Object data) { + c.setIcon(value); + } + + }; + protected Command captionCommand = new Command() { + + public void execute(T c, String value, Object data) { + c.setCaption(value); + } + + }; + + protected Command localeCommand = new Command() { + + public void execute(T c, Locale value, Object data) { + c.setLocale(value); + } + + }; + protected void doCommand(Command command, VALUET value) { doCommand(command, value, null); } diff --git a/tests/src/com/vaadin/tests/components/MenuBasedComponentTestCase.java b/tests/src/com/vaadin/tests/components/MenuBasedComponentTestCase.java index 88129ecedc..873ca2171a 100644 --- a/tests/src/com/vaadin/tests/components/MenuBasedComponentTestCase.java +++ b/tests/src/com/vaadin/tests/components/MenuBasedComponentTestCase.java @@ -3,22 +3,27 @@ package com.vaadin.tests.components; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Set; -import com.vaadin.data.Container; -import com.vaadin.data.Item; -import com.vaadin.data.util.IndexedContainer; import com.vaadin.terminal.Resource; import com.vaadin.terminal.ThemeResource; +import com.vaadin.tests.util.LoremIpsum; import com.vaadin.ui.AbstractComponent; -import com.vaadin.ui.AbstractSelect; -import com.vaadin.ui.Field; import com.vaadin.ui.MenuBar; import com.vaadin.ui.MenuBar.MenuItem; +//TODO swap the inheritance order so AbstractComponentTestCase refers to AbstractComponent and this is the base class. Can only be done when all old tests are converted to use this. public abstract class MenuBasedComponentTestCase extends AbstractComponentTestCase { + protected static final String TEXT_SHORT = "Short"; + protected static final String TEXT_MEDIUM = "This is a semi-long text that might wrap."; + protected static final String TEXT_LONG = "This is a long text. " + + LoremIpsum.get(500); + protected static final String TEXT_VERY_LONG = "This is a very, very long text. " + + LoremIpsum.get(5000); + private static final Resource SELECTED_ICON = new ThemeResource( "../runo/icons/16/ok.png"); @@ -35,8 +40,9 @@ public abstract class MenuBasedComponentTestCase protected static final String CATEGORY_STATE = "State"; protected static final String CATEGORY_SIZE = "Size"; protected static final String CATEGORY_SELECTION = "Selection"; - protected static final String CATEGORY_CONTENT = "Contents"; protected static final String CATEGORY_LISTENERS = "Listeners"; + protected static final String CATEGORY_FEATURES = "Features"; + protected static final String CATEGORY_DECORATIONS = "Decorations"; @Override protected final void setup() { @@ -50,7 +56,7 @@ public abstract class MenuBasedComponentTestCase super.setup(); // Create menu actions and trigger default actions - populateMenu(); + createActions(); // Clear initialization log messages clearLog(); @@ -94,96 +100,67 @@ public abstract class MenuBasedComponentTestCase } } - private void populateMenu() { - createDefaultActions(); - createCustomActions(); - } - - private void createDefaultActions() { + /** + * Create actions for the component. Remember to call super.createActions() + * when overriding. + */ + protected void createActions() { createBooleanAction("Immediate", CATEGORY_STATE, true, immediateCommand); createBooleanAction("Enabled", CATEGORY_STATE, true, enabledCommand); createBooleanAction("Readonly", CATEGORY_STATE, false, readonlyCommand); + createBooleanAction("Visible", CATEGORY_STATE, true, visibleCommand); createBooleanAction("Error indicator", CATEGORY_STATE, false, errorIndicatorCommand); + createErrorMessageSelect(CATEGORY_DECORATIONS); + + createDescriptionSelect(CATEGORY_DECORATIONS); + createCaptionSelect(CATEGORY_DECORATIONS); + createIconSelect(CATEGORY_DECORATIONS); - if (component instanceof Field) { - createBooleanAction("Required", CATEGORY_STATE, false, - requiredCommand); - } createWidthSelect(CATEGORY_SIZE); createHeightSelect(CATEGORY_SIZE); - if (component instanceof AbstractSelect) { - createNullSelectAllowedCheckbox(CATEGORY_SELECTION); - createItemsInContainerSelect(CATEGORY_CONTENT); - createColumnsInContainerSelect(CATEGORY_CONTENT); - } - } - - @SuppressWarnings("unchecked") - protected void createItemsInContainerSelect(String category) { - LinkedHashMap options = new LinkedHashMap(); - options.put("0", 0); - options.put("20", 20); - options.put("100", 100); - options.put("1000", 1000); - options.put("10000", 10000); - options.put("100000", 100000); - - createSelectAction("Items in container", category, options, "20", - (Command) itemsInContainerCommand); - } + // TODO Style name - @SuppressWarnings("unchecked") - protected void createColumnsInContainerSelect(String category) { - LinkedHashMap options = new LinkedHashMap(); - options.put("0", 0); - options.put("5", 5); - options.put("10", 10); - options.put("50", 50); - options.put("100", 100); - options.put("1000", 1000); - - createSelectAction("Columns in container", category, options, "10", - (Command) columnsInContainerCommand); } - private Container createContainer(int properties, int items) { - IndexedContainer c = new IndexedContainer(); - for (int i = 1; i <= properties; i++) { - c.addContainerProperty("Column " + i, String.class, ""); - } - for (int i = 1; i <= items; i++) { - Item item = c.addItem("Item " + i); - for (int j = 1; j <= properties; j++) { - item.getItemProperty("Column " + j).setValue( - "Item " + i + "," + j); - } - } + private void createErrorMessageSelect(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("-", null); + options.put(TEXT_SHORT, TEXT_SHORT); + options.put("Medium", TEXT_MEDIUM); + options.put("Long", TEXT_LONG); + options.put("Very long", TEXT_VERY_LONG); + createSelectAction("Error message", category, options, "-", + errorMessageCommand); - return c; } - @SuppressWarnings("unchecked") - protected void createNullSelectAllowedCheckbox(String category) { - createBooleanAction("Null Selection Allowed", category, false, - (Command) nullSelectionAllowedCommand); + private void createDescriptionSelect(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("-", null); + options.put(TEXT_SHORT, TEXT_SHORT); + options.put("Medium", TEXT_MEDIUM); + options.put("Long", TEXT_LONG); + options.put("Very long", TEXT_VERY_LONG); + createSelectAction("Description / tooltip", category, options, "-", + descriptionCommand); } - @SuppressWarnings("unchecked") - protected void createNullSelectItemId(String category) { - LinkedHashMap options = new LinkedHashMap(); - options.put("- None -", null); - for (Object id : ((AbstractSelect) component).getContainerDataSource() - .getContainerPropertyIds()) { - options.put(id.toString(), id); - } - createSelectAction("Null Selection Item Id", category, options, - "- None -", (Command) nullSelectItemIdCommand); + private void createCaptionSelect(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("-", null); + options.put("Short", TEXT_SHORT); + options.put("Medium", TEXT_MEDIUM); + options.put("Long", TEXT_LONG); + options.put("Very long", TEXT_VERY_LONG); + createSelectAction("Caption", category, options, "Short", + captionCommand); + } - protected void createWidthSelect(String category) { + private void createWidthSelect(String category) { LinkedHashMap options = new LinkedHashMap(); options.put("Undefined", null); options.put("50%", "50%"); @@ -196,7 +173,29 @@ public abstract class MenuBasedComponentTestCase widthCommand, null); } - protected void createHeightSelect(String category) { + private void createIconSelect(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("-", null); + options.put("16x16", ICON_16_USER_PNG_CACHEABLE); + options.put("32x32", ICON_32_ATTENTION_PNG_CACHEABLE); + options.put("64x64", ICON_64_EMAIL_REPLY_PNG_CACHEABLE); + + createSelectAction("Icon", category, options, "-", iconCommand, null); + } + + private void createLocaleSelect(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("-", null); + options.put("fi_FI", new Locale("fi", "FI")); + options.put("en_US", Locale.US); + options.put("zh_CN", Locale.SIMPLIFIED_CHINESE); + options.put("fr_FR", Locale.FRANCE); + + createSelectAction("Locale", category, options, "-", localeCommand, + null); + } + + private void createHeightSelect(String category) { LinkedHashMap options = new LinkedHashMap(); options.put("Undefined", null); options.put("50%", "50%"); @@ -239,11 +238,6 @@ public abstract class MenuBasedComponentTestCase return mainMenu.addItem(category, null); } - /** - * Provide custom actions for the test case by creating them in this method. - */ - protected abstract void createCustomActions(); - private MenuBar.Command menuBooleanCommand( final com.vaadin.tests.components.ComponentTestCase.Command booleanCommand, final Object data) { @@ -349,37 +343,4 @@ public abstract class MenuBasedComponentTestCase } } - /* COMMANDS */ - - protected Command nullSelectionAllowedCommand = new Command() { - - public void execute(AbstractSelect c, Boolean value, Object data) { - (c).setNullSelectionAllowed(value); - } - }; - - protected Command nullSelectItemIdCommand = new Command() { - - public void execute(AbstractSelect c, Object value, Object data) { - c.setNullSelectionItemId(value); - } - }; - - protected Command itemsInContainerCommand = new Command() { - - public void execute(AbstractSelect t, Integer value, Object data) { - t.setContainerDataSource(createContainer(t.getContainerDataSource() - .getContainerPropertyIds().size(), value)); - } - }; - - protected Command columnsInContainerCommand = new Command() { - - public void execute(AbstractSelect t, Integer value, Object data) { - t.setContainerDataSource(createContainer(value, t - .getContainerDataSource().size())); - } - }; - - /* COMMANDS END */ } diff --git a/tests/src/com/vaadin/tests/components/abstractfield/AbstractFieldTestCase.java b/tests/src/com/vaadin/tests/components/abstractfield/AbstractFieldTestCase.java new file mode 100644 index 0000000000..d13e164b6e --- /dev/null +++ b/tests/src/com/vaadin/tests/components/abstractfield/AbstractFieldTestCase.java @@ -0,0 +1,124 @@ +package com.vaadin.tests.components.abstractfield; + +import java.util.LinkedHashMap; + +import com.vaadin.data.Property.ReadOnlyStatusChangeEvent; +import com.vaadin.data.Property.ReadOnlyStatusChangeListener; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.event.FieldEvents.BlurEvent; +import com.vaadin.event.FieldEvents.BlurListener; +import com.vaadin.event.FieldEvents.BlurNotifier; +import com.vaadin.event.FieldEvents.FocusEvent; +import com.vaadin.event.FieldEvents.FocusListener; +import com.vaadin.event.FieldEvents.FocusNotifier; +import com.vaadin.tests.components.MenuBasedComponentTestCase; +import com.vaadin.ui.AbstractField; + +public abstract class AbstractFieldTestCase extends + MenuBasedComponentTestCase implements ValueChangeListener, + ReadOnlyStatusChangeListener, FocusListener, BlurListener { + + @Override + protected void createActions() { + super.createActions(); + createBooleanAction("Required", CATEGORY_STATE, false, requiredCommand); + createRequiredErrorSelect(CATEGORY_DECORATIONS); + + createValueChangeListener(CATEGORY_LISTENERS); + createReadOnlyStatusChangeListener(CATEGORY_LISTENERS); + } + + private void createRequiredErrorSelect(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("-", null); + options.put(TEXT_SHORT, TEXT_SHORT); + options.put("Medium", TEXT_MEDIUM); + options.put("Long", TEXT_LONG); + options.put("Very long", TEXT_VERY_LONG); + createSelectAction("Required error message", category, options, "-", + requiredErrorMessageCommand); + + } + + private void createValueChangeListener(String category) { + + createBooleanAction("Value change listener", category, false, + valueChangeListenerCommand); + } + + private void createReadOnlyStatusChangeListener(String category) { + + createBooleanAction("Read only status change listener", category, + false, readonlyStatusChangeListenerCommand); + } + + protected void createFocusListener(String category) { + createBooleanAction("Focus listener", category, false, + focusListenerCommand); + + } + + protected void createBlurListener(String category) { + createBooleanAction("Blur listener", category, false, + blurListenerCommand); + + } + + protected Command valueChangeListenerCommand = new Command() { + + public void execute(T c, Boolean value, Object data) { + if (value) { + c.addListener((ValueChangeListener) AbstractFieldTestCase.this); + } else { + c.removeListener((ValueChangeListener) AbstractFieldTestCase.this); + } + } + }; + protected Command readonlyStatusChangeListenerCommand = new Command() { + + public void execute(T c, Boolean value, Object data) { + if (value) { + c.addListener((ReadOnlyStatusChangeListener) AbstractFieldTestCase.this); + } else { + c.removeListener((ReadOnlyStatusChangeListener) AbstractFieldTestCase.this); + } + } + }; + protected Command focusListenerCommand = new Command() { + + public void execute(T c, Boolean value, Object data) { + if (value) { + ((FocusNotifier) c).addListener(AbstractFieldTestCase.this); + } else { + ((FocusNotifier) c).removeListener(AbstractFieldTestCase.this); + } + } + }; + protected Command blurListenerCommand = new Command() { + + public void execute(T c, Boolean value, Object data) { + if (value) { + ((BlurNotifier) c).addListener(AbstractFieldTestCase.this); + } else { + ((BlurNotifier) c).removeListener(AbstractFieldTestCase.this); + } + } + }; + + public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) { + log(event.getClass().getSimpleName() + ", new value: " + + event.getProperty().getValue()); + }; + + public void readOnlyStatusChange(ReadOnlyStatusChangeEvent event) { + log(event.getClass().getSimpleName()); + } + + public void focus(FocusEvent event) { + log(event.getClass().getSimpleName()); + } + + public void blur(BlurEvent event) { + log(event.getClass().getSimpleName()); + } +} diff --git a/tests/src/com/vaadin/tests/components/combobox/ComboBoxes2.java b/tests/src/com/vaadin/tests/components/combobox/ComboBoxes2.java new file mode 100644 index 0000000000..45d4728f49 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/combobox/ComboBoxes2.java @@ -0,0 +1,45 @@ +package com.vaadin.tests.components.combobox; + +import java.util.LinkedHashMap; + +import com.vaadin.terminal.Resource; +import com.vaadin.tests.components.select.AbstractSelectTestCase; +import com.vaadin.ui.ComboBox; + +public class ComboBoxes2 extends AbstractSelectTestCase { + + @Override + protected Class getTestClass() { + return ComboBox.class; + } + + @Override + protected void createActions() { + super.createActions(); + createItemIconSelect(CATEGORY_CONTENT); + } + + private void createItemIconSelect(String category) { + + LinkedHashMap options = new LinkedHashMap(); + options.put("-", null); + options.put("16x16", ICON_16_USER_PNG_UNCACHEABLE); + options.put("32x32", ICON_32_ATTENTION_PNG_UNCACHEABLE); + options.put("64x64", ICON_64_EMAIL_REPLY_PNG_UNCACHEABLE); + + createSelectAction("Icon", category, options, "-", + new Command() { + + public void execute(ComboBox c, Resource value, Object data) { + for (Object id : c.getItemIds()) { + if (value == null) { + c.setItemIcon(id, null); + } else { + c.setItemIcon(id, value); + } + } + } + }); + } + +} diff --git a/tests/src/com/vaadin/tests/components/datefield/DateFieldTestCase.java b/tests/src/com/vaadin/tests/components/datefield/DateFieldTestCase.java new file mode 100644 index 0000000000..e99ebbcd08 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/datefield/DateFieldTestCase.java @@ -0,0 +1,108 @@ +package com.vaadin.tests.components.datefield; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.LinkedHashMap; +import java.util.Locale; + +import com.vaadin.tests.components.abstractfield.AbstractFieldTestCase; +import com.vaadin.ui.DateField; + +public abstract class DateFieldTestCase extends + AbstractFieldTestCase { + + @Override + protected void createActions() { + super.createActions(); + createResolutionSelectAction(CATEGORY_FEATURES); + createBooleanAction("Lenient", CATEGORY_FEATURES, false, lenientCommand); + createBooleanAction("Show week numbers", CATEGORY_FEATURES, false, + weekNumberCommand); + createDateFormatSelectAction(CATEGORY_FEATURES); + createFocusListener(CATEGORY_LISTENERS); + createBlurListener(CATEGORY_LISTENERS); + }; + + private void createDateFormatSelectAction(String category) { + LinkedHashMap options = new LinkedHashMap(); + + options.put("-", null); + options.put("d M yyyy", "d M yyyy"); + options.put("d MM yyyy", "d MM yyyy"); + options.put("d MMM yyyy", "d MMM yyyy"); + options.put("d MMMM yyyy", "d MMMM yyyy"); + options.put("dd M yyyy", "dd M yyyy"); + options.put("ddd M yyyy", "ddd M yyyy"); + options.put("d M y", "d M y"); + options.put("d M yy", "d M yy"); + options.put("d M yyy", "d M yyy"); + options.put("d M yyyy", "d M yyyy"); + options.put("d M 'custom text' yyyy", "d M 'custom text' yyyy"); + options.put("'day:'d', month:'M', year: 'yyyy", + "'day:'d', month:'M', year: 'yyyy"); + options.put(getDatePattern(new Locale("fi", "FI"), DateFormat.LONG), + getDatePattern(new Locale("fi", "FI"), DateFormat.LONG)); + options.put(getDatePattern(new Locale("fi", "FI"), DateFormat.MEDIUM), + getDatePattern(new Locale("fi", "FI"), DateFormat.MEDIUM)); + options.put(getDatePattern(new Locale("fi", "FI"), DateFormat.SHORT), + getDatePattern(new Locale("fi", "FI"), DateFormat.SHORT)); + + createSelectAction("Date format", category, options, "-", + dateFormatCommand); + + } + + private String getDatePattern(Locale locale, int dateStyle) { + DateFormat dateFormat = DateFormat.getDateInstance(dateStyle, locale); + + if (dateFormat instanceof SimpleDateFormat) { + String pattern = ((SimpleDateFormat) dateFormat).toPattern(); + return pattern; + } + return null; + + } + + private void createResolutionSelectAction(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("Year", DateField.RESOLUTION_YEAR); + options.put("Month", DateField.RESOLUTION_MONTH); + options.put("Day", DateField.RESOLUTION_DAY); + options.put("Hour", DateField.RESOLUTION_HOUR); + options.put("Min", DateField.RESOLUTION_MIN); + options.put("Sec", DateField.RESOLUTION_SEC); + options.put("Msec", DateField.RESOLUTION_MSEC); + + createSelectAction("Resolution", category, options, "Year", + resolutionCommand); + } + + private Command resolutionCommand = new Command() { + + public void execute(T c, Integer value, Object data) { + c.setResolution(value); + + } + }; + private Command lenientCommand = new Command() { + + public void execute(T c, Boolean value, Object data) { + c.setLenient(false); + + } + }; + private Command weekNumberCommand = new Command() { + + public void execute(T c, Boolean value, Object data) { + c.setShowISOWeekNumbers(true); + + } + }; + private Command dateFormatCommand = new Command() { + + public void execute(T c, String value, Object data) { + c.setDateFormat(value); + } + }; + +} diff --git a/tests/src/com/vaadin/tests/components/datefield/InlineDateFields2.java b/tests/src/com/vaadin/tests/components/datefield/InlineDateFields2.java new file mode 100644 index 0000000000..773531c24a --- /dev/null +++ b/tests/src/com/vaadin/tests/components/datefield/InlineDateFields2.java @@ -0,0 +1,12 @@ +package com.vaadin.tests.components.datefield; + +import com.vaadin.ui.InlineDateField; + +public class InlineDateFields2 extends DateFieldTestCase { + + @Override + protected Class getTestClass() { + return InlineDateField.class; + } + +} diff --git a/tests/src/com/vaadin/tests/components/datefield/PopupDateFields2.java b/tests/src/com/vaadin/tests/components/datefield/PopupDateFields2.java new file mode 100644 index 0000000000..465ccc6a37 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/datefield/PopupDateFields2.java @@ -0,0 +1,38 @@ +package com.vaadin.tests.components.datefield; + +import java.util.LinkedHashMap; + +import com.vaadin.ui.PopupDateField; + +public class PopupDateFields2 extends DateFieldTestCase { + + @Override + protected Class getTestClass() { + return PopupDateField.class; + } + + @Override + protected void createActions() { + super.createActions(); + + createInputPromptSelectAction(CATEGORY_FEATURES); + } + + private void createInputPromptSelectAction(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("", null); + options.put("Please enter date", "Please enter date"); + options.put("åäöÅÄÖ", "åäöÅÄÖ"); + + createSelectAction("Input prompt", category, options, "", + new Command() { + + public void execute(PopupDateField c, String value, + Object data) { + c.setInputPrompt(value); + + } + }); + } + +} diff --git a/tests/src/com/vaadin/tests/components/select/AbstractSelectTestCase.java b/tests/src/com/vaadin/tests/components/select/AbstractSelectTestCase.java new file mode 100644 index 0000000000..cb67ab1a05 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/select/AbstractSelectTestCase.java @@ -0,0 +1,118 @@ +package com.vaadin.tests.components.select; + +import java.util.LinkedHashMap; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.tests.components.MenuBasedComponentTestCase; +import com.vaadin.ui.AbstractSelect; + +public abstract class AbstractSelectTestCase extends + MenuBasedComponentTestCase { + + protected static final String CATEGORY_CONTENT = "Contents"; + + @Override + protected void createActions() { + super.createActions(); + createNullSelectAllowedCheckbox(CATEGORY_SELECTION); + createItemsInContainerSelect(CATEGORY_CONTENT); + createColumnsInContainerSelect(CATEGORY_CONTENT); + + } + + protected void createNullSelectAllowedCheckbox(String category) { + createBooleanAction("Null Selection Allowed", category, false, + nullSelectionAllowedCommand); + + } + + protected void createNullSelectItemId(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("- None -", null); + for (Object id : (getComponent()).getContainerDataSource() + .getContainerPropertyIds()) { + options.put(id.toString(), id); + } + createSelectAction("Null Selection Item Id", category, options, + "- None -", nullSelectItemIdCommand); + } + + protected Container createContainer(int properties, int items) { + IndexedContainer c = new IndexedContainer(); + for (int i = 1; i <= properties; i++) { + c.addContainerProperty("Column " + i, String.class, ""); + } + for (int i = 1; i <= items; i++) { + Item item = c.addItem("Item " + i); + for (int j = 1; j <= properties; j++) { + item.getItemProperty("Column " + j).setValue( + "Item " + i + "," + j); + } + } + + return c; + } + + protected void createItemsInContainerSelect(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("0", 0); + options.put("20", 20); + options.put("100", 100); + options.put("1000", 1000); + options.put("10000", 10000); + options.put("100000", 100000); + + createSelectAction("Items in container", category, options, "20", + itemsInContainerCommand); + } + + protected void createColumnsInContainerSelect(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("0", 0); + options.put("5", 5); + options.put("10", 10); + options.put("50", 50); + options.put("100", 100); + options.put("1000", 1000); + + createSelectAction("Columns in container", category, options, "10", + columnsInContainerCommand); + } + + /* COMMANDS */ + + protected Command nullSelectionAllowedCommand = new Command() { + + public void execute(T c, Boolean value, Object data) { + (c).setNullSelectionAllowed(value); + } + }; + + protected Command nullSelectItemIdCommand = new Command() { + + public void execute(T c, Object value, Object data) { + c.setNullSelectionItemId(value); + } + }; + + protected Command itemsInContainerCommand = new Command() { + + public void execute(T t, Integer value, Object data) { + t.setContainerDataSource(createContainer(t.getContainerDataSource() + .getContainerPropertyIds().size(), value)); + } + }; + + protected Command columnsInContainerCommand = new Command() { + + public void execute(T t, Integer value, Object data) { + t.setContainerDataSource(createContainer(value, t + .getContainerDataSource().size())); + } + }; + + /* COMMANDS END */ + +} diff --git a/tests/src/com/vaadin/tests/components/table/Tables.java b/tests/src/com/vaadin/tests/components/table/Tables.java index a4b8833349..7173244c3f 100644 --- a/tests/src/com/vaadin/tests/components/table/Tables.java +++ b/tests/src/com/vaadin/tests/components/table/Tables.java @@ -7,7 +7,7 @@ import java.util.List; import com.vaadin.event.ItemClickEvent; import com.vaadin.event.ItemClickEvent.ItemClickListener; -import com.vaadin.tests.components.MenuBasedComponentTestCase; +import com.vaadin.tests.components.select.AbstractSelectTestCase; import com.vaadin.ui.AbstractSelect.MultiSelectMode; import com.vaadin.ui.Table; import com.vaadin.ui.Table.ColumnResizeEvent; @@ -17,16 +17,20 @@ import com.vaadin.ui.Table.FooterClickListener; import com.vaadin.ui.Table.HeaderClickEvent; import com.vaadin.ui.Table.HeaderClickListener; -public class Tables extends MenuBasedComponentTestCase implements +public class Tables extends AbstractSelectTestCase
implements ItemClickListener, HeaderClickListener, FooterClickListener, ColumnResizeListener { protected static final String CATEGORY_ROWS = "Rows"; private static final String CATEGORY_HEADER = "Header"; private static final String CATEGORY_FOOTER = "Footer"; - private static final String CATEGORY_FEATURE_TOGGLES = "Features"; private static final String CATEGORY_VISIBLE_COLUMNS = "Visible columns"; + @Override + protected Class
getTestClass() { + return Table.class; + } + /* COMMANDS */ private Command visibleColumnCommand = new Command() { public void execute(Table c, Boolean visible, Object propertyId) { @@ -118,12 +122,9 @@ public class Tables extends MenuBasedComponentTestCase
implements /* COMMANDS END */ @Override - protected Class
getTestClass() { - return Table.class; - } + protected void createActions() { + super.createActions(); - @Override - protected void createCustomActions() { createPageLengthSelect(CATEGORY_SIZE); createSelectionModeSelect(CATEGORY_SELECTION); @@ -141,9 +142,8 @@ public class Tables extends MenuBasedComponentTestCase
implements createFooterVisibilityCheckbox(CATEGORY_FOOTER); createFooterTextSelect(CATEGORY_FOOTER); - createColumnReorderingAllowedCheckbox(CATEGORY_FEATURE_TOGGLES); - createColumnCollapsingAllowedCheckbox(CATEGORY_FEATURE_TOGGLES); - createSortAllowedCheckbox(CATEGORY_FEATURE_TOGGLES); + createColumnReorderingAllowedCheckbox(CATEGORY_FEATURES); + createColumnCollapsingAllowedCheckbox(CATEGORY_FEATURES); createVisibleColumnsMultiToggle(CATEGORY_VISIBLE_COLUMNS); @@ -167,15 +167,6 @@ public class Tables extends MenuBasedComponentTestCase
implements }); } - private void createSortAllowedCheckbox(String category) { - createBooleanAction("Sorting allowed", category, true, - new Command() { - public void execute(Table c, Boolean value, Object data) { - c.setSortDisabled(!value); - } - }); - } - private void createVisibleColumnsMultiToggle(String category) { for (Object id : getComponent().getContainerPropertyIds()) { createBooleanAction(id.toString() + " - visible", category, true, -- 2.39.5