From 89da5eba0db08012973e6455e026eb43c1cca673 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Fri, 7 Jan 2011 10:22:38 +0000 Subject: [PATCH] #5927 : cleaned and automated test case svn changeset:16812/svn branch:6.5 --- .../components/datefield/CommitInvalid.html | 251 ++++++++++++++++++ .../components/datefield/CommitInvalid.java | 144 ++++++---- 2 files changed, 346 insertions(+), 49 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/datefield/CommitInvalid.html diff --git a/tests/src/com/vaadin/tests/components/datefield/CommitInvalid.html b/tests/src/com/vaadin/tests/components/datefield/CommitInvalid.html new file mode 100644 index 0000000000..9c498f1df2 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/datefield/CommitInvalid.html @@ -0,0 +1,251 @@ + + + + + + +CommitInvalid + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CommitInvalid
open/run/com.vaadin.tests.components.datefield.CommitInvalid?restartApplication
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_12. Date. Field: 2009-04-01 Property: 2009-04-01
enterCharactervaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field2.4.2009
mouseClickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_IF27,12
enterCharactervaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_IF42f
clickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_commit/domChild[0]/domChild[0]
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_24. Commit failed : Not an integer
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/domChild[0]/domChild[3]/domChild[0]Not an integer
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_15. Date. Field: 2009-04-02 Property: 2009-04-01
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_06. Integer: Field: 42f Property: 42
dragvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_IF
dropvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/VFormLayout[0]/domChild[0]/domChild[1]/domChild[1]/domChild[0]68,7
mouseClickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_IF-15,-2
enterCharactervaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_IF22
dragvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field
dropvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/VFormLayout[0]/domChild[0]/domChild[1]/domChild[0]/domChild[1]7,18
mouseClickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field-5,2
enterCharactervaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#fieldasdfgh
clickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_commit
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_27. Commit failed : Date format not recognized
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_18. Date. Field: null Property: 2009-04-01
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_09. Integer: Field: 22 Property: 42
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/domChild[0]/domChild[3]/domChild[0]Date format not recognized
dragvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field
dropvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/VFormLayout[0]/domChild[0]/domChild[1]/domChild[0]/domChild[0]47,18
mouseClickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field-36,2
typevaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field
clickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_commit
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_210. Commit succeeded
verifyTextPresent11. Date. Field: null Property: null
verifyTextPresent12. Integer: Field: 22 Property: 22
mouseClickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field44,7
mouseClickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field44,7
enterCharactervaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#fieldddd
clickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_validate
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_213. Validation failed:Date format not recognized
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_114. Date. Field: null Property: null
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/domChild[0]/domChild[3]/domChild[0]Date format not recognized
dragvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field
dropvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/VFormLayout[0]/domChild[0]/domChild[1]/domChild[0]/domChild[1]3,19
mouseClickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field-9,3
enterCharactervaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field7.1.2011
clickvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_commit
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_216. Commit succeeded
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_117. Date. Field: 2011-01-07 Property: 2011-01-07
assertTextvaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_018. Integer: Field: 22 Property: 22
+ + diff --git a/tests/src/com/vaadin/tests/components/datefield/CommitInvalid.java b/tests/src/com/vaadin/tests/components/datefield/CommitInvalid.java index 9745f28e23..84b8302790 100644 --- a/tests/src/com/vaadin/tests/components/datefield/CommitInvalid.java +++ b/tests/src/com/vaadin/tests/components/datefield/CommitInvalid.java @@ -1,23 +1,27 @@ package com.vaadin.tests.components.datefield; +import java.text.SimpleDateFormat; import java.util.Date; -import com.vaadin.data.Property; +import com.vaadin.data.Validator.InvalidValueException; import com.vaadin.data.util.ObjectProperty; import com.vaadin.data.validator.IntegerValidator; import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.util.Log; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.DateField; import com.vaadin.ui.Form; -import com.vaadin.ui.Label; import com.vaadin.ui.TextField; public class CommitInvalid extends TestBase { @Override protected String getDescription() { - return "DateField with error is committed regardless of the invalidity."; + return "DateField with parsing error is committed regardless " + + "of the invalidity. Parsing error should be handled" + + " as a builtin validator, similar to isRequired()" + + " in AbstractField."; } @Override @@ -25,67 +29,109 @@ public class CommitInvalid extends TestBase { return 5927; } + ObjectProperty dateProperty; + private DateField dateField; + private ObjectProperty integerProperty; + private TextField integerField; + private Log log; + @Override protected void setup() { + /* + * Create and configure form. + */ final Form form = new Form(); - addComponent(form); - - @SuppressWarnings("deprecation") - ObjectProperty property = new ObjectProperty(new Date( - 2009 - 1900, 4 - 1, 1)); - - final DateField df = new DateField("Year", property) { - @Override - protected Date handleUnparsableDateString(String dateString) - throws ConversionException { - throw new Property.ConversionException( - "Date format not recognized"); - } - }; - df.setResolution(DateField.RESOLUTION_DAY); - // df.setReadThrough(false); - // df.setWriteThrough(false); - // df.setImmediate(true); - form.addField("date", df); - form.setValidationVisible(true); - - final ObjectProperty integer = new ObjectProperty("42"); - final TextField another = new TextField("Another Field", integer); - another.addValidator(new IntegerValidator("Not an integer")); - // another.setReadThrough(false); - // another.setWriteThrough(false); - form.addField("text", another); - - // form.setReadThrough(false); - form.setWriteThrough(false); - + form.setWriteThrough(false); // set write buffering on + form.setImmediate(true); // make form (and especially its fields + // immediate) + + /* + * Create and configure Date Field, the actual component to be tested. + */ + dateProperty = new ObjectProperty(new Date(2009 - 1900, 4 - 1, 1)); + + dateField = new DateField("Year", dateProperty); + dateField.setResolution(DateField.RESOLUTION_DAY); + dateField.setDebugId("_DF"); + form.addField("date", dateField); + + /* + * Create a TextField with integer property (and integer validator, + * preventing invalid typed values to be pushded to property) as a + * reference component. + */ + integerProperty = new ObjectProperty(42); + integerField = new TextField("Another Field", integerProperty); + integerField.addValidator(new IntegerValidator("Not an integer")); + integerField.setDebugId("_IF"); + form.addField("text", integerField); + + /* + * Action buttons. + */ Button validate = new Button("Validate"); + validate.setDebugId("_validate"); + validate.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + try { + form.validate(); + log.log("Form is valid"); + } catch (InvalidValueException e) { + log.log("Validation failed:" + e.getLocalizedMessage()); + } finally { + printState(); + } + } + }); form.getFooter().addComponent(validate); Button commit = new Button("Commit"); - form.getFooter().addComponent(commit); - - validate.addListener(new Button.ClickListener() { + commit.setDebugId("_commit"); + commit.addListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { - form.validate(); + try { + form.commit(); + log.log("Commit succeeded"); + } catch (InvalidValueException e) { + log.log("Commit failed : " + e.getLocalizedMessage()); + } finally { + printState(); + } } }); - commit.addListener(new Button.ClickListener() { + form.getFooter().addComponent(commit); + Button printState = new Button("printState"); + printState.addListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { - form.commit(); - System.out.println("Field value: " - + ((String) another.getValue()) + ", property value: " - + ((String) integer.getValue())); + printState(); } + }); + form.getFooter().addComponent(printState); + + log = new Log(7); + log.log("Test app started"); + printState(); - Label value = new Label("Date Value"); - addComponent(value); - value.setPropertyDataSource(property); + addComponent(form); + addComponent(log); + + } + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + + private String f(Date date) { + if (date == null) { + return "null"; + } + return dateFormat.format(date); + } - Label value2 = new Label("Text Value"); - addComponent(value2); - value2.setPropertyDataSource(integer); + private void printState() { + log.log("Date. Field: " + f((Date) dateField.getValue()) + + " Property: " + f(dateProperty.getValue())); + log.log("Integer: Field: " + integerField.getValue() + " Property: " + + integerProperty.getValue()); } } -- 2.39.5