click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From take...@apache.org
Subject svn commit: r1309299 - in /click/trunk/click: framework/src/org/apache/click/control/ framework/test/org/apache/click/util/ mock/src/org/apache/click/fileupload/
Date Wed, 04 Apr 2012 09:31:51 GMT
Author: takezoe
Date: Wed Apr  4 09:31:51 2012
New Revision: 1309299

URL: http://svn.apache.org/viewvc?rev=1309299&view=rev
Log:
[CLK-782]FileField#getValueObject() is fixed to return FileItem.

Added:
    click/trunk/click/mock/src/org/apache/click/fileupload/
    click/trunk/click/mock/src/org/apache/click/fileupload/MockFileItem.java   (with props)
Modified:
    click/trunk/click/framework/src/org/apache/click/control/FileField.java
    click/trunk/click/framework/test/org/apache/click/util/ClickUtilsTest.java
    click/trunk/click/framework/test/org/apache/click/util/SampleObject.java

Modified: click/trunk/click/framework/src/org/apache/click/control/FileField.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/FileField.java?rev=1309299&r1=1309298&r2=1309299&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/FileField.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/FileField.java Wed Apr  4 09:31:51
2012
@@ -220,6 +220,18 @@ public class FileField extends Field {
     }
 
     /**
+     * Return the <tt>org.apache.commons.fileupload.FileItem</tt>, or null.
+     *
+     * @see Field#getValueObject()
+     *
+     * @return the object representation of the Field value
+     */
+    @Override
+    public Object getValueObject() {
+        return this.fileItem;
+    }
+
+    /**
      * Return the FileField JavaScript client side validation function.
      *
      * @return the field JavaScript client side validation function

Modified: click/trunk/click/framework/test/org/apache/click/util/ClickUtilsTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/util/ClickUtilsTest.java?rev=1309299&r1=1309298&r2=1309299&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/util/ClickUtilsTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/util/ClickUtilsTest.java Wed Apr  4
09:31:51 2012
@@ -26,16 +26,20 @@ import java.util.Locale;
 import java.util.Map;
 
 import junit.framework.TestCase;
+
 import org.apache.click.Context;
 import org.apache.click.MockContext;
 import org.apache.click.Page;
 import org.apache.click.control.Checkbox;
 import org.apache.click.control.Field;
 import org.apache.click.control.FieldSet;
+import org.apache.click.control.FileField;
 import org.apache.click.control.Form;
 import org.apache.click.control.HiddenField;
 import org.apache.click.control.TextField;
+import org.apache.click.fileupload.MockFileItem;
 import org.apache.click.servlet.MockRequest;
+import org.apache.commons.fileupload.FileItem;
 
 /**
  * Tests for ClickUtils.
@@ -52,7 +56,8 @@ public class ClickUtilsTest extends Test
     private static final boolean BOOLEAN = true;
     private static final double DOUBLE = -87.23;
     private static final String TELEPHONE = "9877262";
-    
+    private static final FileItem FILEITEM = new MockFileItem();
+
     static {
         Calendar calendar = new GregorianCalendar(2000, 01, 02);
         DATE_OF_BIRTH = calendar.getTime();
@@ -73,7 +78,7 @@ public class ClickUtilsTest extends Test
 
     	// set up the form
         Form form = new Form("sample");
-        
+
         TextField idField = new TextField("id");
         form.add(idField);
 
@@ -85,22 +90,25 @@ public class ClickUtilsTest extends Test
 
         TextField dateField = new TextField("dateOfBirth");
         fieldset.add(dateField);
-        
+
         TextField intField = new TextField("int");
         form.add(intField);
 
         TextField doubleField = new TextField("double");
         form.add(doubleField);
-               
+
         Checkbox checkBox = new Checkbox("boolean");
-        form.add(checkBox);  
-        
+        form.add(checkBox);
+
         TextField telephoneField = new TextField("telephone");
         form.add(telephoneField);
-        
+
         HiddenField hidden = new HiddenField("hidden", String.class);
         form.add(hidden);
-        
+
+        FileField fileField = new FileField("file");
+        form.add(fileField);
+
         // Populate fields
         idField.setValueObject(ID);
         nameField.setValue(NAME);
@@ -109,6 +117,7 @@ public class ClickUtilsTest extends Test
         doubleField.setValue(String.valueOf(DOUBLE));
         checkBox.setChecked(BOOLEAN);
         telephoneField.setValue(TELEPHONE);
+        fileField.setValueObject(FILEITEM);
 
         // copy form to object
         SampleObject sampleObject = new SampleObject();
@@ -117,22 +126,23 @@ public class ClickUtilsTest extends Test
         // has the object been configured correctly?
         assertEquals(new Integer(idField.getValue()), sampleObject.getId());
         assertEquals(nameField.getValue(), sampleObject.getName());
-        
+
         //NOTE the dateField was NOT copied to the sampleObject's Date property.
-        //Use org.apache.click.extras.control.DateField in the extras project, to 
+        //Use org.apache.click.extras.control.DateField in the extras project, to
         //copy a Date property.
         assertEquals(null, sampleObject.getDateOfBirth());
         assertEquals(telephoneField.getValueObject().toString(), sampleObject.getTelephone());
-        assertTrue(sampleObject.getInt() == new Integer(intField.getValue()).intValue());
-        assertTrue(sampleObject.getDouble() == new Double(doubleField.getValue()).doubleValue());
-        assertTrue(sampleObject.isBoolean() == checkBox.isChecked());
-        
+        assertEquals(new Integer(intField.getValue()).intValue(), sampleObject.getInt());
+        assertEquals(new Double(doubleField.getValue()).doubleValue(), sampleObject.getDouble());
+        assertEquals(checkBox.isChecked(), sampleObject.isBoolean());
+        assertSame(fileField.getFileItem(), sampleObject.getFile());
+
         // Test object path copying
-        
+
         User user = new User();
         user.setAddress(new Address());
         user.getAddress().setState(new State());
-        
+
         form = new Form();
         TextField codeField = new TextField("address.state.code");
         codeField.setValue("NSW");
@@ -147,7 +157,7 @@ public class ClickUtilsTest extends Test
     public void testCopyObjectToForm() {
         // set up the form
         Form form = new Form("sample");
-        
+
         TextField idField = new TextField("id");
         form.add(idField);
 
@@ -156,22 +166,25 @@ public class ClickUtilsTest extends Test
 
         TextField nameField = new TextField("name");
         fieldset.add(nameField);
-        
+
         TextField dateField = new TextField("dateOfBirth");
-        fieldset.add(dateField); 
-        
+        fieldset.add(dateField);
+
         TextField intField = new TextField("int");
         form.add(intField);
-                
+
         TextField doubleField = new TextField("double");
         form.add(doubleField);
-               
+
         Checkbox checkBox = new Checkbox("boolean");
         form.add(checkBox);
-        
+
         HiddenField hidden = new HiddenField("hidden", String.class);
         form.add(hidden);
-        
+
+        FileField fileField = new FileField("file");
+        form.add(fileField);
+
         // Populate object
         SampleObject sampleObject = new SampleObject();
         sampleObject.setId(ID);
@@ -180,6 +193,7 @@ public class ClickUtilsTest extends Test
         sampleObject.setInt(INT);
         sampleObject.setDouble(DOUBLE);
         sampleObject.setBoolean(BOOLEAN);
+        sampleObject.setFile(FILEITEM);
 
         // copy object to form
         ClickUtils.copyObjectToForm(sampleObject, form, true);
@@ -188,9 +202,10 @@ public class ClickUtilsTest extends Test
         assertEquals(sampleObject.getId(), new Integer(idField.getValue()));
         assertEquals(sampleObject.getName(), nameField.getValue());
         assertEquals(sampleObject.getDateOfBirth().toString(), dateField.getValue());
-        assertTrue(sampleObject.getInt() == new Integer(intField.getValue()).intValue());
-        assertTrue(sampleObject.getDouble() == new Double(doubleField.getValue()).doubleValue());
-        assertTrue(sampleObject.isBoolean() == checkBox.isChecked());
+        assertEquals(new Integer(intField.getValue()).intValue(), sampleObject.getInt());
+        assertEquals(new Double(doubleField.getValue()).doubleValue(), sampleObject.getDouble());
+        assertEquals(checkBox.isChecked(), sampleObject.isBoolean());
+        assertNull(fileField.getValueObject());
 
         // Test object path copying
 
@@ -198,13 +213,13 @@ public class ClickUtilsTest extends Test
         user.setAddress(new Address());
         user.getAddress().setState(new State());
         user.getAddress().getState().setCode("NSW");
-        
+
         form = new Form();
         TextField codeField = new TextField("address.state.code");
         form.add(codeField);
         form.copyFrom(user, true);
         assertEquals("NSW", codeField.getValueObject());
-        
+
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("name", "malcolm");
         form = new Form();
@@ -226,7 +241,7 @@ public class ClickUtilsTest extends Test
         Integer age = new Integer(61);
         String stateCode = "NSW";
         String street = "12 Short street";
-        
+
         // Setup the map
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("id", id);
@@ -270,7 +285,7 @@ public class ClickUtilsTest extends Test
      * CLK-239.
      */
     public void testCopyFormToMap() {
-        
+
         Integer id = new Integer(9876);
         String name = "Rocky Balboa";
         Integer age = new Integer(61);
@@ -290,16 +305,16 @@ public class ClickUtilsTest extends Test
         TextField idField = new TextField("id");
         idField.setValue(id.toString());
         form.add(idField);
-        
+
         // Create fieldset
         FieldSet fieldset = new FieldSet("fieldset");
         form.add(fieldset);
         TextField nameField = new TextField("name");
         nameField.setValue(name);
         fieldset.add(nameField);
-        
+
         TextField ageField = new TextField("age");
-        ageField.setValue(age.toString());        
+        ageField.setValue(age.toString());
         form.add(ageField);
         TextField streetField = new TextField("address.street");
         streetField.setValue(street);
@@ -329,9 +344,9 @@ public class ClickUtilsTest extends Test
         final String code = "NSW";
         final boolean active = false;
         final Boolean registered = Boolean.TRUE;
-        
+
         Form form = new Form();
-        
+
         TextField idField = new TextField("address.id");
         form.add(idField);
         TextField lineOneField = new TextField("address.lineOne");
@@ -346,15 +361,15 @@ public class ClickUtilsTest extends Test
         TextField codeField = new TextField("address.state.code");
         codeField.setValue(code);
         form.add(codeField);
-        
-        User user = new User();        
+
+        User user = new User();
         form.copyTo(user, true);
-        
+
         assertNull(user.getAddress().getId());
-        assertEquals(lineOne, user.getAddress().getLineOne());        
-        assertEquals(active, user.getAddress().isActive()); 
+        assertEquals(lineOne, user.getAddress().getLineOne());
+        assertEquals(active, user.getAddress().isActive());
         assertEquals(registered, user.getAddress().isRegistered());
-        assertEquals(code, user.getAddress().getState().getCode());        
+        assertEquals(code, user.getAddress().getState().getCode());
     }
 
     /**
@@ -365,39 +380,39 @@ public class ClickUtilsTest extends Test
         assertEquals("Customer Number", ClickUtils.toLabel("customerNumber"));
         assertEquals("Card PIN", ClickUtils.toLabel("cardPIN"));
     }
-    
+
     /**
      * Sanity checks for ClickUtils.toMD5Hash.
      */
     public void testToMD5Hash() {
-        assertEquals("5f4dcc3b5aa765d61d8327deb882cf99", 
+        assertEquals("5f4dcc3b5aa765d61d8327deb882cf99",
                      ClickUtils.toMD5Hash("password"));
     }
-    
+
     /**
      * Sanity checks for ClickUtils.getParentMessages.
      */
     public void testGetParentMessages() {
         TextField textField = new TextField("test");
-        
+
         Map<String, String> map = ClickUtils.getParentMessages(textField);
         assertNotNull(map);
         assertTrue(map.isEmpty());
         assertTrue(map == Collections.EMPTY_MAP);
-        
+
         Page page = new Page();
         page.addControl(textField);
-        
+
         Map<String, String> map2 = ClickUtils.getParentMessages(textField);
         assertNotNull(map2);
         assertEquals(1, map2.size());
         assertFalse(map2 == Collections.EMPTY_MAP);
-        
+
         Page page2 = new Page();
-        
+
         Form form = new Form("form");
         page2.addControl(form);
-        
+
         TextField textField2 = new TextField("test");
         form.add(textField2);
 
@@ -499,7 +514,7 @@ public class ClickUtilsTest extends Test
         String value4 = ClickUtils.escapeHtml(value3);
         assertEquals(value3, value4);
         assertTrue(value3 == value4);
-        
+
         assertEquals("&quot;", ClickUtils.escapeHtml("\""));
         assertEquals("&amp;", ClickUtils.escapeHtml("&"));
         assertEquals("&lt;", ClickUtils.escapeHtml("<"));
@@ -533,23 +548,23 @@ public class ClickUtilsTest extends Test
         	assertTrue(false);
         }
     }
-    
+
     /**
      * Sanity checks for encoding and decoding a password in a cookie.
      */
     public void testCookiePassword() {
         String username = "username";
         String password = "password";
-        
+
         String cookie = ClickUtils.encodePasswordCookie(username, password, 12);
-        
+
         String[] result = ClickUtils.decodePasswordCookie(cookie, 12);
-        
+
         assertEquals(username, result[0]);
         assertEquals(password, result[1]);
-        
+
         result = ClickUtils.decodePasswordCookie(cookie, 21);
-        
+
         assertFalse(username.equals(result[0]));
         assertFalse(password.equals(result[1]));
     }

Modified: click/trunk/click/framework/test/org/apache/click/util/SampleObject.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/util/SampleObject.java?rev=1309299&r1=1309298&r2=1309299&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/util/SampleObject.java (original)
+++ click/trunk/click/framework/test/org/apache/click/util/SampleObject.java Wed Apr  4 09:31:51
2012
@@ -18,6 +18,8 @@
  */
 package org.apache.click.util;
 
+import org.apache.commons.fileupload.FileItem;
+
 public class SampleObject {
     private Integer id;
     private String name;
@@ -27,6 +29,7 @@ public class SampleObject {
     private double _double;
     private String telephone;
     private boolean active;
+    private FileItem file;
 
     public Integer getId() {
         return id;
@@ -51,35 +54,35 @@ public class SampleObject {
     public void setDateOfBirth(java.util.Date dateOfBirth) {
         this.dateOfBirth = dateOfBirth;
     }
-    
+
     public boolean isBoolean() {
         return _boolean;
     }
-    
+
     public void setBoolean(boolean b) {
         _boolean = b;
     }
-    
+
     public double getDouble() {
         return _double;
     }
-    
+
     public void setDouble(double d) {
         _double = d;
     }
-    
+
     public int getInt() {
         return _int;
     }
-    
+
     public void setInt(int i) {
         _int = i;
     }
-    
+
     public String getTelephone() {
         return telephone;
     }
-    
+
     public void setTelephone(String telephone) {
         this.telephone = telephone;
     }
@@ -92,4 +95,12 @@ public class SampleObject {
         this.active = active;
     }
 
+    public void setFile(FileItem file){
+    	this.file = file;
+    }
+
+    public FileItem getFile(){
+    	return this.file;
+    }
+
 }

Added: click/trunk/click/mock/src/org/apache/click/fileupload/MockFileItem.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/src/org/apache/click/fileupload/MockFileItem.java?rev=1309299&view=auto
==============================================================================
--- click/trunk/click/mock/src/org/apache/click/fileupload/MockFileItem.java (added)
+++ click/trunk/click/mock/src/org/apache/click/fileupload/MockFileItem.java Wed Apr  4 09:31:51
2012
@@ -0,0 +1,86 @@
+package org.apache.click.fileupload;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.commons.fileupload.FileItem;
+
+public class MockFileItem implements FileItem {
+
+	private static final long serialVersionUID = 1L;
+
+	@Override
+	public void delete() {
+	}
+
+	@Override
+	public byte[] get() {
+		return null;
+	}
+
+	@Override
+	public String getContentType() {
+		return null;
+	}
+
+	@Override
+	public String getFieldName() {
+		return null;
+	}
+
+	@Override
+	public InputStream getInputStream() throws IOException {
+		return null;
+	}
+
+	@Override
+	public String getName() {
+		return null;
+	}
+
+	@Override
+	public OutputStream getOutputStream() throws IOException {
+		return null;
+	}
+
+	@Override
+	public long getSize() {
+		return 0;
+	}
+
+	@Override
+	public String getString() {
+		return null;
+	}
+
+	@Override
+	public String getString(String arg0) throws UnsupportedEncodingException {
+		return null;
+	}
+
+	@Override
+	public boolean isFormField() {
+		return false;
+	}
+
+	@Override
+	public boolean isInMemory() {
+		return false;
+	}
+
+	@Override
+	public void setFieldName(String arg0) {
+	}
+
+	@Override
+	public void setFormField(boolean arg0) {
+	}
+
+	@Override
+	public void write(File arg0) throws Exception {
+	}
+
+}

Propchange: click/trunk/click/mock/src/org/apache/click/fileupload/MockFileItem.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message