]> source.dussan.org Git - vaadin-framework.git/commitdiff
#5927 : cleaned and automated test case
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 7 Jan 2011 10:22:38 +0000 (10:22 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 7 Jan 2011 10:22:38 +0000 (10:22 +0000)
svn changeset:16812/svn branch:6.5

tests/src/com/vaadin/tests/components/datefield/CommitInvalid.html [new file with mode: 0644]
tests/src/com/vaadin/tests/components/datefield/CommitInvalid.java

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 (file)
index 0000000..9c498f1
--- /dev/null
@@ -0,0 +1,251 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>CommitInvalid</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">CommitInvalid</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.datefield.CommitInvalid?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_1</td>
+       <td>2. Date. Field: 2009-04-01 Property: 2009-04-01</td>
+</tr>
+<!--change date, make integer invalid, commit-->
+<tr>
+       <td>enterCharacter</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td>2.4.2009</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_IF</td>
+       <td>27,12</td>
+</tr>
+<tr>
+       <td>enterCharacter</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_IF</td>
+       <td>42f</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_commit/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_2</td>
+       <td>4. Commit failed : Not an integer</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/domChild[0]/domChild[3]/domChild[0]</td>
+       <td>Not an integer</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_1</td>
+       <td>5. Date. Field: 2009-04-02 Property: 2009-04-01</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_0</td>
+       <td>6. Integer: Field: 42f Property: 42</td>
+</tr>
+<!--set sane value for integer, invalid for date, commit-->
+<tr>
+       <td>drag</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_IF</td>
+       <td></td>
+</tr>
+<tr>
+       <td>drop</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/VFormLayout[0]/domChild[0]/domChild[1]/domChild[1]/domChild[0]</td>
+       <td>68,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_IF</td>
+       <td>-15,-2</td>
+</tr>
+<tr>
+       <td>enterCharacter</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_IF</td>
+       <td>22</td>
+</tr>
+<tr>
+       <td>drag</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td></td>
+</tr>
+<tr>
+       <td>drop</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/VFormLayout[0]/domChild[0]/domChild[1]/domChild[0]/domChild[1]</td>
+       <td>7,18</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td>-5,2</td>
+</tr>
+<tr>
+       <td>enterCharacter</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td>asdfgh</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_commit</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_2</td>
+       <td>7. Commit failed : Date format not recognized</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_1</td>
+       <td>8. Date. Field: null Property: 2009-04-01</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_0</td>
+       <td>9. Integer: Field: 22 Property: 42</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/domChild[0]/domChild[3]/domChild[0]</td>
+       <td>Date format not recognized</td>
+</tr>
+<!--null date field, commit-->
+<tr>
+       <td>drag</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td></td>
+</tr>
+<tr>
+       <td>drop</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/VFormLayout[0]/domChild[0]/domChild[1]/domChild[0]/domChild[0]</td>
+       <td>47,18</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td>-36,2</td>
+</tr>
+<tr>
+       <td>type</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_commit</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_2</td>
+       <td>10. Commit succeeded</td>
+</tr>
+<tr>
+       <td>verifyTextPresent</td>
+       <td>11. Date. Field: null Property: null</td>
+       <td></td>
+</tr>
+<tr>
+       <td>verifyTextPresent</td>
+       <td>12. Integer: Field: 22 Property: 22</td>
+       <td></td>
+</tr>
+<!--bad date, validate, correct date, commit-->
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td>44,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td>44,7</td>
+</tr>
+<tr>
+       <td>enterCharacter</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td>ddd</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_validate</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_2</td>
+       <td>13. Validation failed:Date format not recognized</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_1</td>
+       <td>14. Date. Field: null Property: null</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/domChild[0]/domChild[3]/domChild[0]</td>
+       <td>Date format not recognized</td>
+</tr>
+<tr>
+       <td>drag</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td></td>
+</tr>
+<tr>
+       <td>drop</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VForm[0]/VFormLayout[0]/domChild[0]/domChild[1]/domChild[0]/domChild[1]</td>
+       <td>3,19</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td>-9,3</td>
+</tr>
+<tr>
+       <td>enterCharacter</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_DF#field</td>
+       <td>7.1.2011</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_S_commit</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_2</td>
+       <td>16. Commit succeeded</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_1</td>
+       <td>17. Date. Field: 2011-01-07 Property: 2011-01-07</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldCommitInvalid::PID_SLog_row_0</td>
+       <td>18. Integer: Field: 22 Property: 22</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
index 9745f28e23a0e66c81d3825767b81a4dbeabe70a..84b83027902f4d24dc0523b8c59e6a926335a1f2 100644 (file)
@@ -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<Date> dateProperty;
+    private DateField dateField;
+    private ObjectProperty<Integer> 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<Date>(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<Integer>(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());
     }
 }