click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r1026278 - in /click/trunk/click/framework/test/org/apache/click/control: FieldSetTest.java TextFieldTest.java
Date Fri, 22 Oct 2010 10:26:50 GMT
Author: sabob
Date: Fri Oct 22 10:26:49 2010
New Revision: 1026278

URL: http://svn.apache.org/viewvc?rev=1026278&view=rev
Log:
added tests for state management. CLK-715

Modified:
    click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java
    click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java

Modified: click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java?rev=1026278&r1=1026277&r2=1026278&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java Fri Oct 22
10:26:49 2010
@@ -18,9 +18,12 @@
  */
 package org.apache.click.control;
 
+import java.util.HashMap;
+import java.util.Map;
 import junit.framework.TestCase;
 import org.apache.click.Control;
 import org.apache.click.MockContext;
+import org.apache.click.Page;
 import org.apache.commons.lang.StringUtils;
 
 /**
@@ -507,6 +510,78 @@ public class FieldSetTest extends TestCa
     }
 
     /**
+     * Test that FieldSet.getState contains the state of all the Fields in the
+     * FieldSet.
+     * CLK-715
+     */
+    public void testGetState() {
+        // Setup FieldSet and Fields
+        FieldSet fs = new FieldSet("fieldSet");
+        Field nameField  = new TextField("name");
+        Field ageField = new TextField("age");
+        nameField.setValue("Steve");
+        ageField.setValue("10");
+        fs.add(nameField);
+        fs.add(ageField);
+
+        FieldSet childFs = new FieldSet("address");
+        Field streetField  = new TextField("street");
+        streetField.setValue("short");
+        childFs.add(streetField);
+        fs.add(childFs);
+
+        Object state = fs.getState();
+        Map fsStateMap = (Map) state;
+
+        // Check that only the fields defined above are returned
+        assertEquals(3, fsStateMap.size());
+
+        assertEquals(fsStateMap.get(nameField.getName()), nameField.getValue());
+        assertEquals(fsStateMap.get(ageField.getName()), ageField.getValue());
+        assertNotNull(fsStateMap.get(childFs.getName()));
+
+        // Retrieve FieldSet state
+        Object childFsState = fsStateMap.get(childFs.getName());
+        Map childFsStateMap = (Map) childFsState;
+        assertEquals(childFsStateMap.get(streetField.getName()), streetField.getValue());
+    }
+
+    /**
+     * Test that FieldSet.setState correctly set the state of the Fields in the
+     * FieldSet.
+     *
+     * CLK-715
+     */
+    public void testSetState() {
+        // Setup FieldSet and Fields
+        FieldSet fs = new FieldSet("fieldSet");
+        Field nameField  = new TextField("name");
+        Field ageField = new TextField("age");
+        fs.add(nameField);
+        fs.add(ageField);
+
+        FieldSet childFs = new FieldSet("address");
+        Field streetField  = new TextField("street");
+        childFs.add(streetField);
+        fs.add(childFs);
+
+        // Setup state
+        Map fsStateMap = new HashMap();
+        fsStateMap.put("name", "Steve");
+        fsStateMap.put("age", "10");
+        Map childFsStateMap = new HashMap();
+        childFsStateMap.put("street", "short");
+        fsStateMap.put("address", childFsStateMap);
+
+        fs.setState(fsStateMap);
+
+        // Check that field values were restored
+        assertEquals("Steve", nameField.getValue());
+        assertEquals("10", ageField.getValue());
+        assertEquals("short", streetField.getValue());
+    }
+
+    /**
      * A custom Div container.
      */
     static class Div extends AbstractContainer {

Modified: click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java?rev=1026278&r1=1026277&r2=1026278&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java Fri Oct 22
10:26:49 2010
@@ -346,4 +346,36 @@ public class TextFieldTest extends TestC
 
         assertTrue(field.getValidationJavaScript().startsWith("function validate_field()"));
     }
+
+    /**
+     * Test that TextField.getState contains the field value.
+     * CLK-715
+     */
+    public void testGetState() {
+        // Setup Field
+        Field field  = new TextField("name");
+        field.setValue("Steve");
+
+        Object state = field.getState();
+
+        assertEquals(state, field.getValue());
+    }
+
+    /**
+     * Test that Field.setState set the field value.
+     *
+     * CLK-715
+     */
+    public void testSetState() {
+        // Setup Field
+        Field field  = new TextField("name");
+
+        // Setup state
+        String state = "Steve";
+
+        field.setState(state);
+
+        // Check that field value was restored
+        assertEquals("Steve", field.getValue());
+    }
 }



Mime
View raw message