click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r991828 - in /click/trunk/click: extras/test/org/apache/click/extras/control/NumberFieldTest.java framework/test/org/apache/click/util/RequestTypeConverterTest.java
Date Thu, 02 Sep 2010 07:30:07 GMT
Author: sabob
Date: Thu Sep  2 07:30:07 2010
New Revision: 991828

URL: http://svn.apache.org/viewvc?rev=991828&view=rev
Log:
CLK-694. Added BigDecimal and BigInteger conversion tests

Modified:
    click/trunk/click/extras/test/org/apache/click/extras/control/NumberFieldTest.java
    click/trunk/click/framework/test/org/apache/click/util/RequestTypeConverterTest.java

Modified: click/trunk/click/extras/test/org/apache/click/extras/control/NumberFieldTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/test/org/apache/click/extras/control/NumberFieldTest.java?rev=991828&r1=991827&r2=991828&view=diff
==============================================================================
--- click/trunk/click/extras/test/org/apache/click/extras/control/NumberFieldTest.java (original)
+++ click/trunk/click/extras/test/org/apache/click/extras/control/NumberFieldTest.java Thu
Sep  2 07:30:07 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.click.extras.control;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.text.NumberFormat;
 import java.util.Locale;
 import java.util.Map;
@@ -25,6 +27,7 @@ import java.util.Map;
 import org.apache.click.MockContext;
 
 import junit.framework.TestCase;
+import org.apache.click.control.Form;
 import org.apache.click.servlet.MockRequest;
 
 public class NumberFieldTest extends TestCase{
@@ -193,5 +196,76 @@ public class NumberFieldTest extends Tes
         assertFalse(engF.isValid());
         assertEquals("some text", engF.getValue());    
     }
-    
+
+
+    /**
+     * Test that the fix for number->BigDecimal conversion work.
+     *
+     * CLK-694.
+     */
+    public void testFormCopyBigDecimal() {
+        MockContext.initContext(Locale.US);
+
+        Form form = new Form("form");
+
+        NumberField bigDecimalField = new NumberField("bigDecimalField");
+        NumberField bigIntegerField = new NumberField("bigIntegerField");
+
+        // Specify a very large value
+        String bigValue = "999999999999999999";
+        bigDecimalField.setValue(bigValue);
+        form.add(bigDecimalField);
+        bigIntegerField.setValue(bigValue);
+        form.add(bigIntegerField);
+
+        MyObj obj = new MyObj();
+        form.copyTo(obj);
+
+        assertEquals(bigValue, obj.bigDecimalField.toString());
+        assertEquals(bigValue, obj.bigIntegerField.toString());
+    }
+
+    /**
+     * Test that Field->BigInteger conversion works.
+     */
+    public void testFormCopyBigInteger() {
+        MockContext.initContext(Locale.US);
+
+        Form form = new Form("form");
+
+        NumberField bigDecimalField = new NumberField("bigDecimalField");
+        NumberField bigIntegerField = new NumberField("bigIntegerField");
+
+        // Specify a very large value
+        String bigValue = "999999999999999999";
+        bigDecimalField.setValue(bigValue);
+        form.add(bigDecimalField);
+        bigIntegerField.setValue(bigValue);
+        form.add(bigIntegerField);
+
+        MyObj obj = new MyObj();
+        form.copyTo(obj);
+
+        assertEquals(bigValue, obj.bigDecimalField.toString());
+        assertEquals(bigValue, obj.bigIntegerField.toString());
+    }
+
+    /**
+     * POJO for testing of copying values between Fields and domain objects.
+     */
+    public static class MyObj {
+
+        public BigDecimal bigDecimalField;
+
+        public BigInteger bigIntegerField;
+
+        public void setBigDecimalField(BigDecimal value) {
+            this.bigDecimalField = value;
+        }
+
+        public void setBigIntegerField(BigInteger value) {
+            this.bigIntegerField = value;
+        }
+    }
+
 }

Modified: click/trunk/click/framework/test/org/apache/click/util/RequestTypeConverterTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/util/RequestTypeConverterTest.java?rev=991828&r1=991827&r2=991828&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/util/RequestTypeConverterTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/util/RequestTypeConverterTest.java Thu
Sep  2 07:30:07 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.click.util;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.Locale;
 import junit.framework.TestCase;
 
@@ -31,7 +33,9 @@ public class RequestTypeConverterTest ex
      */
     public void test() {
         RequestTypeConverter rtc = new RequestTypeConverter();
-        
+        assertEquals("true", rtc.convertValue("true", Boolean.class).toString());
+        assertEquals("false", rtc.convertValue("false", Boolean.class).toString());
+
         assertNull(rtc.convertValue(null, java.util.Date.class));
         assertNull(rtc.convertValue(null, java.sql.Date.class));
         assertNull(rtc.convertValue(null, java.sql.Time.class));
@@ -97,4 +101,28 @@ public class RequestTypeConverterTest ex
 //        assertEquals(date10, date11);
         assertEquals(date11, date12);
     }
+
+    /**
+     * Check that very large BigDecimal numbers are converted correctly.
+     * CLK-694.
+     */
+    public void testLargeBigDecimalConvertion() {
+        RequestTypeConverter rtc = new RequestTypeConverter();
+
+        String requestParam = "9999999999999999999999999999999999999999999999999.99";
+        BigDecimal bd = (BigDecimal) rtc.convertValue(requestParam, BigDecimal.class);
+
+        assertEquals(requestParam, bd.toString());
+    }
+
+    /**
+     * Check that very large BigInteger numbers are converted correctly.
+     */
+    public void testLargeBigIntegerConvertion() {
+        RequestTypeConverter rtc = new RequestTypeConverter();
+
+        String requestParam = "99999999999999999999999999999999999999999999999";
+        BigInteger bi = (BigInteger) rtc.convertValue(requestParam, BigInteger.class);
+        assertEquals(requestParam, bi.toString());
+    }
 }



Mime
View raw message