diff options
9 files changed, 618 insertions, 143 deletions
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<T extends AbstractComponent> 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<T> testComponents = new ArrayList<T>(); abstract protected Class<T> 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<T extends AbstractComponent> } }; + protected Command<T, Boolean> errorIndicatorCommand = new Command<T, Boolean>() { + + 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<T, String> errorMessageCommand = new Command<T, String>() { + + 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<T, Boolean> requiredCommand = new Command<T, Boolean>() { public void execute(T c, Boolean enabled, Object data) { @@ -86,16 +133,17 @@ public abstract class AbstractComponentTestCase<T extends AbstractComponent> } } }; + protected Command<T, String> requiredErrorMessageCommand = new Command<T, String>() { - protected Command<T, Boolean> errorIndicatorCommand = new Command<T, Boolean>() { + 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<T, String> descriptionCommand = new Command<T, String>() { + public void execute(T c, String value, Object data) { + c.setDescription(value); } }; @@ -106,6 +154,36 @@ public abstract class AbstractComponentTestCase<T extends AbstractComponent> } }; + protected Command<T, Boolean> visibleCommand = new Command<T, Boolean>() { + + public void execute(T c, Boolean enabled, Object data) { + c.setVisible(enabled); + } + }; + + protected Command<T, Resource> iconCommand = new Command<T, Resource>() { + + public void execute(T c, Resource value, Object data) { + c.setIcon(value); + } + + }; + protected Command<T, String> captionCommand = new Command<T, String>() { + + public void execute(T c, String value, Object data) { + c.setCaption(value); + } + + }; + + protected Command<T, Locale> localeCommand = new Command<T, Locale>() { + + public void execute(T c, Locale value, Object data) { + c.setLocale(value); + } + + }; + protected <VALUET> void doCommand(Command<T, VALUET> 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<T extends AbstractComponent>
extends AbstractComponentTestCase<T> {
+ 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<T extends AbstractComponent> 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<T extends AbstractComponent> super.setup();
// Create menu actions and trigger default actions
- populateMenu();
+ createActions();
// Clear initialization log messages
clearLog();
@@ -94,96 +100,67 @@ public abstract class MenuBasedComponentTestCase<T extends AbstractComponent> }
}
- 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<String, Integer> options = new LinkedHashMap<String, Integer>();
- 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<String, Integer> options = new LinkedHashMap<String, Integer>();
- 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<String, String> options = new LinkedHashMap<String, String>();
+ 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<String, String> options = new LinkedHashMap<String, String>();
+ 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<String, Object> options = new LinkedHashMap<String, Object>();
- 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<String, String> options = new LinkedHashMap<String, String>();
+ 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<String, String> options = new LinkedHashMap<String, String>();
options.put("Undefined", null);
options.put("50%", "50%");
@@ -196,7 +173,29 @@ public abstract class MenuBasedComponentTestCase<T extends AbstractComponent> widthCommand, null);
}
- protected void createHeightSelect(String category) {
+ private void createIconSelect(String category) {
+ LinkedHashMap<String, Resource> options = new LinkedHashMap<String, Resource>();
+ 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<String, Locale> options = new LinkedHashMap<String, Locale>();
+ 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<String, String> options = new LinkedHashMap<String, String>();
options.put("Undefined", null);
options.put("50%", "50%");
@@ -239,11 +238,6 @@ public abstract class MenuBasedComponentTestCase<T extends AbstractComponent> 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<T, Boolean> booleanCommand,
final Object data) {
@@ -349,37 +343,4 @@ public abstract class MenuBasedComponentTestCase<T extends AbstractComponent> }
}
- /* COMMANDS */
-
- protected Command<AbstractSelect, Boolean> nullSelectionAllowedCommand = new Command<AbstractSelect, Boolean>() {
-
- public void execute(AbstractSelect c, Boolean value, Object data) {
- (c).setNullSelectionAllowed(value);
- }
- };
-
- protected Command<AbstractSelect, Object> nullSelectItemIdCommand = new Command<AbstractSelect, Object>() {
-
- public void execute(AbstractSelect c, Object value, Object data) {
- c.setNullSelectionItemId(value);
- }
- };
-
- protected Command<AbstractSelect, Integer> itemsInContainerCommand = new Command<AbstractSelect, Integer>() {
-
- public void execute(AbstractSelect t, Integer value, Object data) {
- t.setContainerDataSource(createContainer(t.getContainerDataSource()
- .getContainerPropertyIds().size(), value));
- }
- };
-
- protected Command<AbstractSelect, Integer> columnsInContainerCommand = new Command<AbstractSelect, Integer>() {
-
- 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<T extends AbstractField> extends
+ MenuBasedComponentTestCase<T> 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<String, String> options = new LinkedHashMap<String, String>();
+ 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<T, Boolean> valueChangeListenerCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ if (value) {
+ c.addListener((ValueChangeListener) AbstractFieldTestCase.this);
+ } else {
+ c.removeListener((ValueChangeListener) AbstractFieldTestCase.this);
+ }
+ }
+ };
+ protected Command<T, Boolean> readonlyStatusChangeListenerCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ if (value) {
+ c.addListener((ReadOnlyStatusChangeListener) AbstractFieldTestCase.this);
+ } else {
+ c.removeListener((ReadOnlyStatusChangeListener) AbstractFieldTestCase.this);
+ }
+ }
+ };
+ protected Command<T, Boolean> focusListenerCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ if (value) {
+ ((FocusNotifier) c).addListener(AbstractFieldTestCase.this);
+ } else {
+ ((FocusNotifier) c).removeListener(AbstractFieldTestCase.this);
+ }
+ }
+ };
+ protected Command<T, Boolean> blurListenerCommand = new Command<T, Boolean>() {
+
+ 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<ComboBox> { + + @Override + protected Class<ComboBox> getTestClass() { + return ComboBox.class; + } + + @Override + protected void createActions() { + super.createActions(); + createItemIconSelect(CATEGORY_CONTENT); + } + + private void createItemIconSelect(String category) { + + LinkedHashMap<String, Resource> options = new LinkedHashMap<String, Resource>(); + 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<ComboBox, Resource>() { + + 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<T extends DateField> extends
+ AbstractFieldTestCase<T> {
+
+ @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<String, String> options = new LinkedHashMap<String, String>();
+
+ 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<String, Integer> options = new LinkedHashMap<String, Integer>();
+ 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<T, Integer> resolutionCommand = new Command<T, Integer>() {
+
+ public void execute(T c, Integer value, Object data) {
+ c.setResolution(value);
+
+ }
+ };
+ private Command<T, Boolean> lenientCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ c.setLenient(false);
+
+ }
+ };
+ private Command<T, Boolean> weekNumberCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ c.setShowISOWeekNumbers(true);
+
+ }
+ };
+ private Command<T, String> dateFormatCommand = new Command<T, String>() {
+
+ 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<InlineDateField> {
+
+ @Override
+ protected Class<InlineDateField> 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<PopupDateField> {
+
+ @Override
+ protected Class<PopupDateField> getTestClass() {
+ return PopupDateField.class;
+ }
+
+ @Override
+ protected void createActions() {
+ super.createActions();
+
+ createInputPromptSelectAction(CATEGORY_FEATURES);
+ }
+
+ private void createInputPromptSelectAction(String category) {
+ LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
+ options.put("<none>", null);
+ options.put("Please enter date", "Please enter date");
+ options.put("åäöÅÄÖ", "åäöÅÄÖ");
+
+ createSelectAction("Input prompt", category, options, "<none>",
+ new Command<PopupDateField, String>() {
+
+ 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<T extends AbstractSelect> extends
+ MenuBasedComponentTestCase<T> {
+
+ 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<String, Object> options = new LinkedHashMap<String, Object>();
+ 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<String, Integer> options = new LinkedHashMap<String, Integer>();
+ 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<String, Integer> options = new LinkedHashMap<String, Integer>();
+ 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<T, Boolean> nullSelectionAllowedCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ (c).setNullSelectionAllowed(value);
+ }
+ };
+
+ protected Command<T, Object> nullSelectItemIdCommand = new Command<T, Object>() {
+
+ public void execute(T c, Object value, Object data) {
+ c.setNullSelectionItemId(value);
+ }
+ };
+
+ protected Command<T, Integer> itemsInContainerCommand = new Command<T, Integer>() {
+
+ public void execute(T t, Integer value, Object data) {
+ t.setContainerDataSource(createContainer(t.getContainerDataSource()
+ .getContainerPropertyIds().size(), value));
+ }
+ };
+
+ protected Command<T, Integer> columnsInContainerCommand = new Command<T, Integer>() {
+
+ 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<Table> implements
+public class Tables extends AbstractSelectTestCase<Table> 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<Table> getTestClass() {
+ return Table.class;
+ }
+
/* COMMANDS */
private Command<Table, Boolean> visibleColumnCommand = new Command<Table, Boolean>() {
public void execute(Table c, Boolean visible, Object propertyId) {
@@ -118,12 +122,9 @@ public class Tables extends MenuBasedComponentTestCase<Table> implements /* COMMANDS END */
@Override
- protected Class<Table> 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<Table> 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<Table> implements });
}
- private void createSortAllowedCheckbox(String category) {
- createBooleanAction("Sorting allowed", category, true,
- new Command<Table, Boolean>() {
- 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,
|