click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bck...@apache.org
Subject svn commit: r984158 - in /click/trunk/click/framework/test/org/apache/click/control: ButtonTest.java CheckboxTest.java RadioGroupTest.java RadioTest.java SubmitTest.java TextAreaTest.java TextFieldTest.java
Date Tue, 10 Aug 2010 18:40:28 GMT
Author: bckfnn
Date: Tue Aug 10 18:40:28 2010
New Revision: 984158

URL: http://svn.apache.org/viewvc?rev=984158&view=rev
Log:
improve test code coverage.

Added:
    click/trunk/click/framework/test/org/apache/click/control/ButtonTest.java   (with props)
    click/trunk/click/framework/test/org/apache/click/control/RadioGroupTest.java   (with
props)
    click/trunk/click/framework/test/org/apache/click/control/SubmitTest.java   (with props)
Modified:
    click/trunk/click/framework/test/org/apache/click/control/CheckboxTest.java
    click/trunk/click/framework/test/org/apache/click/control/RadioTest.java
    click/trunk/click/framework/test/org/apache/click/control/TextAreaTest.java
    click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java

Added: click/trunk/click/framework/test/org/apache/click/control/ButtonTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/ButtonTest.java?rev=984158&view=auto
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/ButtonTest.java (added)
+++ click/trunk/click/framework/test/org/apache/click/control/ButtonTest.java Tue Aug 10 18:40:28
2010
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.control;
+
+import junit.framework.TestCase;
+
+import org.apache.click.ActionListener;
+import org.apache.click.Control;
+import org.apache.click.MockContext;
+import org.apache.click.servlet.MockRequest;
+
+/**
+ * Test Button behavior.
+ */
+public class ButtonTest extends TestCase {
+    /**
+     * Test Button onProcess behavior.
+     */
+    public void testOnProcess() {
+        MockContext context = MockContext.initContext();
+        MockRequest request = context.getMockRequest();
+        
+        Button button = new Button("button");
+        assertEquals("button", button.getName());
+        
+        assertTrue(button.onProcess());
+        
+        request.setParameter("button", "true");
+        assertTrue(button.onProcess());
+        
+        final boolean check[] = new boolean[1];
+        button.setActionListener(new ActionListener() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public boolean onAction(Control source) {
+                check[0] = true;
+                return false;
+            }
+        });
+
+        // No request param -> no action listener executed
+        request.removeParameter("button");
+        assertTrue(button.onProcess());
+        context.executeActionListeners();
+        assertFalse(check[0]);
+        
+        request.setParameter("button", "true");
+
+        // Not an ajax request -> no action listener executed
+        assertTrue(button.onProcess());
+        context.executeActionListeners();
+        assertFalse(check[0]);
+
+        // ajax request, but no request param -> no action listener executed
+        request.removeParameter("button");
+        request.setParameter("X-Requested-With", "true");
+        assertTrue(button.onProcess());
+        context.executeActionListeners();
+        assertFalse(check[0]);
+
+        // Ajax request & request param -> call the onAction.
+        request.setParameter("button", "true");
+        request.setParameter("X-Requested-With", "true");
+        assertTrue(button.onProcess());
+        context.executeActionListeners();
+        assertTrue(check[0]);
+        
+       
+        button.setDisabled(true);
+        assertTrue(button.onProcess());
+        assertTrue(button.isValid());
+        assertFalse(button.isDisabled());
+
+        request.removeParameter("button");
+        
+        button.setDisabled(true);
+        assertTrue(button.onProcess());
+        assertTrue(button.isValid());
+        assertTrue(button.isDisabled());
+        
+        request.removeParameter("button");
+        assertTrue(button.onProcess());
+        assertTrue(button.isValid());
+    }
+    
+    /**
+     * Coverage test of constructors.
+     */
+    public void testConstructors() {
+        Button button = new Button();
+        assertNull(button.getName());
+        
+        button = new Button("button", "label");
+        assertEquals("label", button.getLabel());
+    }
+        
+    /**
+     * Coverage test of onClick.
+     */
+    public void testOnClick() {
+        MockContext.initContext();
+        
+        Button button = new Button("button");
+        assertNull(button.getOnClick());
+
+        button.setOnClick("javascript:return false;");
+        assertEquals("javascript:return false;", button.getOnClick());
+    }
+    
+    /**
+     * Coverage test of tab-index.
+     */
+    public void testTabIndex() {
+        MockContext.initContext();
+        
+        Button button = new Button("button");
+        button.setTabIndex(5);
+
+        assertTrue(button.toString().contains("tabindex=\"5\""));
+    }
+
+    /**
+     * Coverage test of disabled property.
+     */
+    public void testDisabled() {
+        MockContext.initContext();
+        
+        Button button = new Button("button");
+        button.setDisabled(true);
+        System.out.println(button.toString());
+        assertTrue(button.toString().contains("disabled=\"disabled\""));
+    }
+}

Propchange: click/trunk/click/framework/test/org/apache/click/control/ButtonTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: click/trunk/click/framework/test/org/apache/click/control/CheckboxTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/CheckboxTest.java?rev=984158&r1=984157&r2=984158&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/CheckboxTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/CheckboxTest.java Tue Aug 10
18:40:28 2010
@@ -20,6 +20,7 @@ package org.apache.click.control;
 
 import junit.framework.TestCase;
 import org.apache.click.MockContext;
+import org.apache.click.servlet.MockRequest;
 import org.apache.commons.lang.StringUtils;
 
 /**
@@ -46,4 +47,159 @@ public class CheckboxTest extends TestCa
         // Check that the value <script> is not rendered
         assertTrue(checkbox.toString().indexOf(value) < 0);
     }
+    
+    /**
+     * Test TextField onProcess behavior.
+     */
+    public void testOnProcess() {
+        MockContext context = MockContext.initContext();
+        MockRequest request = context.getMockRequest();
+        
+        Checkbox checkbox = new Checkbox("checkbox");
+        assertEquals("checkbox", checkbox.getName());
+        
+        request.setParameter("checkbox", "");
+        
+        assertTrue(checkbox.onProcess());
+        assertTrue(checkbox.isValid());
+        assertEquals("true", checkbox.getValue());
+        assertEquals(Boolean.TRUE, checkbox.getValueObject());
+        
+        request.setParameter("checkbox", "true");
+        
+        assertTrue(checkbox.onProcess());
+        assertTrue(checkbox.isValid());
+        assertEquals("true", checkbox.getValue());
+        assertEquals(Boolean.TRUE, checkbox.getValueObject());
+        
+        checkbox.setRequired(true);
+        request.removeParameter("checkbox");
+        
+        assertTrue(checkbox.onProcess());
+        assertFalse(checkbox.isValid());
+        assertEquals("false", checkbox.getValue());
+        assertEquals(Boolean.FALSE, checkbox.getValueObject());
+        assertTrue(checkbox.toString().contains("class=\"error\""));
+        
+        request.setParameter("checkbox", "true");
+
+        assertTrue(checkbox.onProcess());
+        assertTrue(checkbox.isValid());
+        assertEquals("true", checkbox.getValue());
+        assertEquals(Boolean.TRUE, checkbox.getValueObject());
+        
+        request.setParameter("checkbox", "true");
+
+        checkbox.setDisabled(true);
+        assertTrue(checkbox.onProcess());
+        assertTrue(checkbox.isValid());
+        assertFalse(checkbox.isDisabled());
+    }
+    
+    /**
+     * Coverage test of constructors.
+     */
+    public void testConstructors() {
+        Checkbox field = new Checkbox("field", true);
+        assertTrue(field.isRequired());
+        
+        field = new Checkbox("field", "label");
+        assertEquals("label", field.getLabel());
+        
+        field = new Checkbox();
+        assertNull(field.getName());
+    }
+    
+    /**
+     * Coverage test of tab-index.
+     */
+    public void testTabIndex() {
+        MockContext.initContext();
+        
+        Checkbox field = new Checkbox("field");
+        field.setTabIndex(5);
+
+        assertTrue(field.toString().contains("tabindex=\"5\""));
+    }
+
+    /**
+     * Coverage test of disabled property.
+     */
+    public void testDisabled() {
+        MockContext.initContext();
+        
+        Checkbox field = new Checkbox("field");
+        field.setDisabled(true);
+        assertTrue(field.toString().contains("disabled=\"disabled\""));
+    }
+
+    /**
+     * Coverage test of readonly property.
+     */
+    public void testReadonly() {
+        MockContext.initContext();
+        
+        Checkbox field = new Checkbox("field");
+        field.setReadonly(true);
+
+        assertTrue(field.toString().contains("disabled=\"disabled\""));
+        
+        field = new Checkbox("field");
+        field.setReadonly(true);
+        field.setChecked(true);
+
+        assertTrue(field.toString().contains("disabled=\"disabled\""));
+        assertTrue(field.toString().contains("<input type=\"hidden\""));
+
+    }
+
+    /**
+     * Coverage test of help property.
+     */
+    public void testHelp() {
+        MockContext.initContext();
+        
+        Checkbox field = new Checkbox("field");
+        field.setHelp("help");
+
+        assertTrue(field.toString().contains("help"));
+    }
+
+    /**
+     * Coverage test of validation javascript.
+     */
+    public void testValidationJS() {
+        MockContext.initContext();
+        
+        Checkbox field = new Checkbox("field");
+        assertNull(field.getValidationJavaScript());
+        
+        field = new Checkbox("field");
+        field.setRequired(true);
+
+        assertTrue(field.getValidationJavaScript().startsWith("function validate_field()"));
+    }
+    
+    public void testValue() {
+        MockContext.initContext();
+        
+        Checkbox field = new Checkbox("field");
+        field.setValue("xxx");
+        assertFalse(field.isChecked());
+        
+        field.setValue("true");
+        assertTrue(field.isChecked());
+        field.setValue("false");
+        assertFalse(field.isChecked());
+        
+        field.setChecked(false);
+        
+        field.setValueObject("xxx");
+        assertFalse(field.isChecked());
+        field.setValueObject(null);
+        assertFalse(field.isChecked());
+
+        field.setValueObject(true);
+        assertTrue(field.isChecked());
+    }
 }

Added: click/trunk/click/framework/test/org/apache/click/control/RadioGroupTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/RadioGroupTest.java?rev=984158&view=auto
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/RadioGroupTest.java (added)
+++ click/trunk/click/framework/test/org/apache/click/control/RadioGroupTest.java Tue Aug
10 18:40:28 2010
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.control;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.click.MockContext;
+
+/**
+ * Test Radio behavior.
+ */
+public class RadioGroupTest extends TestCase {
+
+    /**
+     * Coverage test of constructors.
+     */
+    public void testConstructors() {
+        MockContext.initContext();
+
+        RadioGroup group = new RadioGroup("group");
+        assertEquals("group", group.getName());
+        assertFalse(group.isRequired());
+
+        group = new RadioGroup("group", true);
+        assertEquals("group", group.getName());
+        assertTrue(group.isRequired());
+
+        group = new RadioGroup("group", "label");
+        assertEquals("group", group.getName());
+        assertEquals("label", group.getLabel());
+
+        group = new RadioGroup("group", "label", true);
+        assertEquals("group", group.getName());
+        assertEquals("label", group.getLabel());
+        assertTrue(group.isRequired());
+
+        group = new RadioGroup();
+        assertNull(group.getName());
+        assertEquals("", group.getLabel());
+        assertFalse(group.isRequired());
+    }
+    
+    /**
+     * Coverage test of add(Radio).
+     */
+    public void testAdd() {
+        MockContext.initContext();
+        
+        RadioGroup group = new RadioGroup("group");
+        Radio r1 = new Radio("val1");
+        Radio r2 = new Radio("val2");
+        group.add(r1);
+        group.add(r2);
+        
+        assertSame(group, r1.getParent());
+        assertSame(group, r2.getParent());
+        
+        assertTrue(group.getRadioList().contains(r1));
+        assertTrue(group.getRadioList().contains(r2));
+    }
+
+    /**
+     * Coverage test of addAll(Collection<Radio>).
+     */
+
+    public void testAddAll() {
+        MockContext.initContext();
+        
+        RadioGroup group = new RadioGroup("group");
+        
+        Radio r1 = new Radio("val1");
+        Radio r2 = new Radio("val2");
+
+        group.addAll(Arrays.asList(r1, r2));
+        
+        assertSame(group, r1.getParent());
+        assertSame(group, r2.getParent());
+        
+        assertTrue(group.getRadioList().contains(r1));
+        assertTrue(group.getRadioList().contains(r2));
+    }
+    
+    /**
+     * Coverage test of addAll(Map).
+     */
+    public void testAddAllMap() {
+        MockContext.initContext();
+        
+        RadioGroup group = new RadioGroup("group");
+        
+        Map<Object, Object> map = new LinkedHashMap<Object, Object>();
+        map.put(1, "one");
+        map.put("two", 2);
+        
+        group.addAll(map);
+        
+        assertEquals(group.getRadioList().get(0).getValue(), "1");
+        assertEquals(group.getRadioList().get(0).getLabel(), "one");
+        assertEquals(group.getRadioList().get(1).getValue(), "two");
+        assertEquals(group.getRadioList().get(1).getLabel(), "2");
+    }
+
+    /**
+     * Coverage test of addAll(Colelction<Object>).
+     */
+    public void testAddAllObject() {
+        MockContext.initContext();
+        
+        RadioGroup group = new RadioGroup("group");
+        
+        List<RadioFoo> list = Arrays.asList(new RadioFoo("value1", "label1"), new RadioFoo("value2",
"label2"));
+        
+        group.addAll(list, "val", "lab");
+        
+        assertEquals(group.getRadioList().get(0).getValue(), "value1");
+        assertEquals(group.getRadioList().get(0).getLabel(), "label1");
+        assertEquals(group.getRadioList().get(1).getValue(), "value2");
+        assertEquals(group.getRadioList().get(1).getLabel(), "label2");
+    }
+
+    public static class RadioFoo {
+        String value;
+        String label;
+        
+        RadioFoo(String value, String label) {
+            this.value = value;
+            this.label = label;
+        }
+        
+        public String getVal() {
+            return value;
+        }
+        public String getLab() {
+            return label;
+        }
+    }
+    
+    /**
+     * Coverage test of addAll(Colelction<Object>).
+     */
+    public void testFocusJs() {
+        MockContext.initContext();
+        
+        RadioGroup group = new RadioGroup("group");
+        Radio r1 = new Radio("val1");
+        Radio r2 = new Radio("val2");
+        group.add(r1);
+        group.add(r2);
+
+        System.out.println(group.getFocusJavaScript());
+        
+        group = new RadioGroup("group");
+        System.out.println(group.getFocusJavaScript());
+
+    }
+}

Propchange: click/trunk/click/framework/test/org/apache/click/control/RadioGroupTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: click/trunk/click/framework/test/org/apache/click/control/RadioTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/RadioTest.java?rev=984158&r1=984157&r2=984158&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/RadioTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/RadioTest.java Tue Aug 10 18:40:28
2010
@@ -19,7 +19,11 @@
 package org.apache.click.control;
 
 import junit.framework.TestCase;
+
+import org.apache.click.ActionListener;
+import org.apache.click.Control;
 import org.apache.click.MockContext;
+import org.apache.click.servlet.MockRequest;
 
 /**
  * Test Radio behavior.
@@ -61,4 +65,174 @@ public class RadioTest extends TestCase 
         // Check that the value <script> is not rendered
         assertTrue(radio.toString().indexOf(value) < 0);
     }
+    
+    /**
+     * Radio Submit onProcess behavior.
+     */
+    public void testOnProcess() {
+        MockContext context = MockContext.initContext();
+        MockRequest request = context.getMockRequest();
+        
+        Radio button = new Radio("value", "label", "button");
+        assertEquals("button", button.getName());
+        
+        assertTrue(button.onProcess());
+        
+        request.setParameter("button", "true");
+        assertTrue(button.onProcess());
+        
+        Listener l = new Listener();
+        button.setActionListener(l);
+
+        // No request param -> no action listener executed
+        request.removeParameter("button");
+        assertTrue(button.onProcess());
+        context.executeActionListeners();
+        assertFalse(l.fired);
+
+        // No request param -> no action listener executed
+        request.setParameter("button", "value");
+        assertTrue(button.onProcess());
+        context.executeActionListeners();
+        assertTrue(button.isChecked());
+        assertTrue(l.fired);
+
+        // Disabled button with request param
+        request.setParameter("button", "true");
+        button.setDisabled(true);
+        assertTrue(button.onProcess());
+        assertTrue(button.isValid());
+        assertFalse(button.isDisabled());
+        
+        // Diasabled button without request param
+        request.removeParameter("button");
+        button.setDisabled(true);
+        assertTrue(button.onProcess());
+        assertTrue(button.isValid());
+        assertTrue(button.isDisabled());
+    }
+
+    /**
+     * Coverage test of constructors.
+     */
+    public void testConstructors() {
+        Radio field = new Radio("value", "label", "field");
+        assertEquals("value", field.getValue());
+        assertEquals("label", field.getLabel());
+        assertEquals("field", field.getName());
+        
+        field = new Radio("value", "label");
+        assertEquals("value", field.getValue());
+        assertEquals("label", field.getLabel());
+        
+        field = new Radio();
+        assertEquals("", field.getValue());
+        assertEquals("", field.getLabel());
+        assertNull(field.getName());
+    }
+    
+    /**
+     * Coverage test of getId()
+     */
+    public void testId() {
+        Radio field = new Radio("value", "label", "a/b c<d>e");
+        assertEquals("a_b_c_d_e_value", field.getId());
+    }
+
+    /**
+     * Coverage test of tab-index.
+     */
+    public void testTabIndex() {
+        MockContext.initContext();
+        
+        Radio field = new Radio("value");
+        field.setTabIndex(5);
+
+        assertTrue(field.toString().contains("tabindex=\"5\""));
+    }
+
+    /**
+     * Coverage test of disabled property.
+     */
+    public void testDisabled() {
+        MockContext.initContext();
+        
+        Radio field = new Radio("value");
+        field.setDisabled(true);
+        assertTrue(field.toString().contains("disabled=\"disabled\""));
+    }
+
+    /**
+     * Coverage test of readonly property.
+     */
+    public void testReadonly() {
+        MockContext.initContext();
+        
+        Radio field = new Radio("value");
+        field.setReadonly(true);
+
+        assertTrue(field.toString().contains("disabled=\"disabled\""));
+        
+        field = new Radio("value");
+        field.setReadonly(true);
+        field.setChecked(true);
+
+        assertTrue(field.toString().contains("disabled=\"disabled\""));
+        assertTrue(field.toString().contains("<input type=\"hidden\""));
+
+    }
+
+    /**
+     * Coverage test of help property.
+     */
+    public void testHelp() {
+        MockContext.initContext();
+        
+        Radio field = new Radio("value");
+        field.setHelp("help");
+
+        // Note that help is currently not rendered.
+        assertFalse(field.toString().contains("help"));
+    }
+
+    /**
+     * Coverage test of validation javascript.
+     */
+    public void testValidationJS() {
+        MockContext.initContext();
+        
+        Radio field = new Radio("value");
+        assertNull(field.getValidationJavaScript());
+    }
+    
+    public void testValue() {
+        MockContext.initContext();
+        
+        Radio field = new Radio("value", "label", "field");
+        assertFalse(field.isChecked());
+        
+        field.setValue("value");
+        assertTrue(field.isChecked());
+        field.setValue("xxx");
+        assertFalse(field.isChecked());
+        
+        field.setChecked(false);
+        
+        field.setValueObject("xxx");
+        assertFalse(field.isChecked());
+        field.setValueObject(null);
+        assertFalse(field.isChecked());
+    }
+
+    static class Listener implements ActionListener {
+        private static final long serialVersionUID = 1L;
+        
+        public boolean fired;
+
+        @Override
+        public boolean onAction(Control source) {
+            fired = true;
+            return true;
+        }
+    }
 }

Added: click/trunk/click/framework/test/org/apache/click/control/SubmitTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/SubmitTest.java?rev=984158&view=auto
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/SubmitTest.java (added)
+++ click/trunk/click/framework/test/org/apache/click/control/SubmitTest.java Tue Aug 10 18:40:28
2010
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.control;
+
+import junit.framework.TestCase;
+
+import org.apache.click.ActionListener;
+import org.apache.click.Control;
+import org.apache.click.MockContext;
+import org.apache.click.servlet.MockRequest;
+
+/**
+ * Test Button behavior.
+ */
+public class SubmitTest extends TestCase {
+    /**
+     * Test Submit onProcess behavior.
+     */
+    public void testOnProcess() {
+        MockContext context = MockContext.initContext();
+        MockRequest request = context.getMockRequest();
+        
+        Submit button = new Submit("button");
+        assertEquals("button", button.getName());
+        
+        assertTrue(button.onProcess());
+        
+        request.setParameter("button", "true");
+        assertTrue(button.onProcess());
+        
+        final boolean check[] = new boolean[1];
+        button.setActionListener(new ActionListener() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public boolean onAction(Control source) {
+                check[0] = true;
+                return false;
+            }
+        });
+
+        // No request param -> no action listener executed
+        request.removeParameter("button");
+        assertTrue(button.onProcess());
+        context.executeActionListeners();
+        assertFalse(check[0]);
+
+        // Disabled button with request param
+        request.setParameter("button", "true");
+        button.setDisabled(true);
+        assertTrue(button.onProcess());
+        assertTrue(button.isValid());
+        assertFalse(button.isDisabled());
+
+        // Diasabled button without request param
+        request.removeParameter("button");
+        button.setDisabled(true);
+        assertTrue(button.onProcess());
+        assertTrue(button.isValid());
+        assertTrue(button.isDisabled());
+    }
+    
+    /**
+     * Coverage test of constructors.
+     */
+    public void testConstructors() {
+        Submit button = new Submit();
+        assertNull(button.getName());
+        
+        button = new Submit("button", "label");
+        assertEquals("button", button.getName());
+        assertEquals("label", button.getLabel());
+        
+        Listener l = new Listener();
+        assertEquals("button", button.getName());
+        button = new Submit("button", l, "onAction");
+
+        try {
+            button = new Submit("button", null, "onAction");
+            assertTrue("Should throw exception", false);
+        } catch (IllegalArgumentException e) { }
+
+        try {
+            button = new Submit("button", l, null);
+            assertTrue("Should throw exception", false);
+        } catch (IllegalArgumentException e) { }
+
+        button = new Submit("button", "label", l, "onAction");
+        assertEquals("button", button.getName());
+        assertEquals("label", button.getLabel());
+
+        try {
+            button = new Submit("button", "label", null, "onAction");
+            assertTrue("Should throw exception", false);
+        } catch (IllegalArgumentException e) { }
+
+        try {
+            button = new Submit("button", "label", l, null);
+            assertTrue("Should throw exception", false);
+        } catch (IllegalArgumentException e) { }
+
+    }
+
+    static class Listener {
+        public boolean fired;
+        public boolean onAction() {
+            fired = true;
+            return true;
+        }
+    }
+
+    /**
+     * Coverage test of onClick.
+     */
+    public void testCancelJavaScriptValidation() {
+        MockContext.initContext();
+        
+        Submit button = new Submit("button");
+        assertFalse(button.getCancelJavaScriptValidation());
+
+        button = new Submit("button");
+        button.setCancelJavaScriptValidation(false);
+        assertFalse(button.getCancelJavaScriptValidation());
+        
+        button.setCancelJavaScriptValidation(true);
+        assertTrue(button.getCancelJavaScriptValidation());
+        assertNotNull(button.getAttribute("onclick"));
+    }
+    
+    /**
+     * Coverage test of tab-index.
+     */
+    public void testTabIndex() {
+        MockContext.initContext();
+        
+        Submit button = new Submit("button");
+        button.setTabIndex(5);
+
+        assertTrue(button.toString().contains("tabindex=\"5\""));
+    }
+
+    /**
+     * Coverage test of disabled property.
+     */
+    public void testDisabled() {
+        MockContext.initContext();
+        
+        Submit button = new Submit("button");
+        button.setDisabled(true);
+
+        assertTrue(button.toString().contains("disabled=\"disabled\""));
+    }
+}

Propchange: click/trunk/click/framework/test/org/apache/click/control/SubmitTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: click/trunk/click/framework/test/org/apache/click/control/TextAreaTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/TextAreaTest.java?rev=984158&r1=984157&r2=984158&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/TextAreaTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/TextAreaTest.java Tue Aug 10
18:40:28 2010
@@ -84,7 +84,8 @@ public class TextAreaTest extends TestCa
         assertTrue(textArea.onProcess());
         assertFalse(textArea.isValid());
         assertEquals("ratherlongtextvalue", textArea.getValue());
-        assertEquals("ratherlongtextvalue", textArea.getValueObject());   
+        assertEquals("ratherlongtextvalue", textArea.getValueObject());
+        assertTrue(textArea.toString().contains("class=\"error\""));
     }
 
     /**
@@ -101,4 +102,111 @@ public class TextAreaTest extends TestCa
         // Check that the value <script> is not rendered
         assertTrue(field.toString().indexOf(value) < 0);
     }
+    
+    /**
+     * Coverage test of constructors.
+     */
+    public void testConstructors() {
+        TextArea field = new TextArea();
+        assertNull(field.getName());
+        
+        field = new TextArea("field", true);
+        assertTrue(field.isRequired());
+        
+        field = new TextArea("field", "label");
+        assertEquals("label", field.getLabel());
+        
+        field = new TextArea("field", "label", true);
+        assertEquals("label", field.getLabel());
+        assertTrue(field.isRequired());
+
+        field = new TextArea("field", 25, 4);
+        assertEquals(25, field.getCols());
+        assertEquals(4, field.getRows());
+        
+        field = new TextArea("field", "label", 25, 4);
+        assertEquals("label", field.getLabel());
+        assertEquals(25, field.getCols());
+        assertEquals(4, field.getRows());
+
+        field = new TextArea("field", "label", 25, 4, true);
+        assertEquals("label", field.getLabel());
+        assertEquals(25, field.getCols());
+        assertEquals(4, field.getRows());
+        assertTrue(field.isRequired());
+    }
+    
+    /**
+     * Coverage test of tab-index.
+     */
+    public void testTabIndex() {
+        MockContext.initContext();
+        
+        TextArea field = new TextArea("field");
+        field.setTabIndex(5);
+
+        assertTrue(field.toString().contains("tabindex=\"5\""));
+    }
+
+    /**
+     * Coverage test of disabled property.
+     */
+    public void testDisabled() {
+        MockContext.initContext();
+        
+        TextArea field = new TextArea("field");
+        field.setDisabled(true);
+
+        assertTrue(field.toString().contains("class=\"disabled\""));
+        assertTrue(field.toString().contains("disabled=\"disabled\""));
+    }
+
+    /**
+     * Coverage test of readonly property.
+     */
+    public void testReadonly() {
+        MockContext.initContext();
+        
+        TextArea field = new TextArea("field");
+        field.setReadonly(true);
+
+        assertTrue(field.toString().contains("readonly=\"readonly\""));
+    }
+
+    /**
+     * Coverage test of cols and rows property.
+     */
+    public void testColsRows() {
+        MockContext.initContext();
+        
+        TextArea field = new TextArea("field");
+        field.setCols(25);
+        field.setRows(4);
+        
+        assertTrue(field.toString().contains("cols=\"25\""));
+        assertTrue(field.toString().contains("rows=\"4\""));
+    }
+
+    /**
+     * Coverage test of help property.
+     */
+    public void testHelp() {
+        MockContext.initContext();
+        
+        TextArea field = new TextArea("field");
+        field.setHelp("help");
+
+        assertTrue(field.toString().contains("help"));
+    }
+
+    /**
+     * Coverage test of validation javascript.
+     */
+    public void testValidationJS() {
+        MockContext.initContext();
+        
+        TextArea field = new TextArea("field");
+
+        assertTrue(field.getValidationJavaScript().startsWith("function validate_field()"));
+    }
 }

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=984158&r1=984157&r2=984158&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 Tue Aug 10
18:40:28 2010
@@ -250,4 +250,100 @@ public class TextFieldTest extends TestC
         // Check that field does not trim its request value
         assertEquals(value, field.getValue());
     }
+    
+    /**
+     * Coverage test of constructors.
+     */
+    public void testConstructors() {
+        TextField field = new TextField("field", true);
+        assertTrue(field.isRequired());
+        
+        field = new TextField("field", "label");
+        assertEquals("label", field.getLabel());
+        
+        field = new TextField("field", "label", true);
+        assertEquals("label", field.getLabel());
+        assertTrue(field.isRequired());
+
+        field = new TextField("field", "label", 25);
+        assertEquals("label", field.getLabel());
+        assertEquals(25, field.getSize());
+        
+        field = new TextField("field", "label", 25, true);
+        assertEquals("label", field.getLabel());
+        assertEquals(25, field.getSize());
+        assertTrue(field.isRequired());
+    }
+    
+    /**
+     * Coverage test of tab-index.
+     */
+    public void testTabIndex() {
+        MockContext.initContext();
+        
+        TextField field = new TextField("field");
+        field.setTabIndex(5);
+
+        assertTrue(field.toString().contains("tabindex=\"5\""));
+    }
+
+    /**
+     * Coverage test of disabled property.
+     */
+    public void testDisabled() {
+        MockContext.initContext();
+        
+        TextField field = new TextField("field");
+        field.setDisabled(true);
+
+        assertTrue(field.toString().contains("class=\"disabled\""));
+        assertTrue(field.toString().contains("disabled=\"disabled\""));
+    }
+
+    /**
+     * Coverage test of readonly property.
+     */
+    public void testReadonly() {
+        MockContext.initContext();
+        
+        TextField field = new TextField("field");
+        field.setReadonly(true);
+
+        assertTrue(field.toString().contains("readonly=\"readonly\""));
+    }
+
+    /**
+     * Coverage test of max-length property.
+     */
+    public void testMaxLength() {
+        MockContext.initContext();
+        
+        TextField field = new TextField("field");
+        field.setMaxLength(25);
+
+        assertTrue(field.toString().contains("maxlength=\"25\""));
+    }
+
+    /**
+     * Coverage test of help property.
+     */
+    public void testHelp() {
+        MockContext.initContext();
+        
+        TextField field = new TextField("field");
+        field.setHelp("help");
+
+        assertTrue(field.toString().contains("help"));
+    }
+
+    /**
+     * Coverage test of validation javascript.
+     */
+    public void testValidationJS() {
+        MockContext.initContext();
+        
+        TextField field = new TextField("field");
+
+        assertTrue(field.getValidationJavaScript().startsWith("function validate_field()"));
+    }
 }



Mime
View raw message