click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r1034418 - in /click/trunk/click/framework/test: org/apache/click/control/FileFieldTest.java org/apache/click/pages/FileFieldPage.java web/file-field.htm
Date Fri, 12 Nov 2010 15:21:45 GMT
Author: sabob
Date: Fri Nov 12 15:21:45 2010
New Revision: 1034418

URL: http://svn.apache.org/viewvc?rev=1034418&view=rev
Log:
added FileField upload test

Added:
    click/trunk/click/framework/test/org/apache/click/pages/FileFieldPage.java
    click/trunk/click/framework/test/web/file-field.htm
Modified:
    click/trunk/click/framework/test/org/apache/click/control/FileFieldTest.java

Modified: click/trunk/click/framework/test/org/apache/click/control/FileFieldTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/FileFieldTest.java?rev=1034418&r1=1034417&r2=1034418&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/FileFieldTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/FileFieldTest.java Fri Nov 12
15:21:45 2010
@@ -18,8 +18,13 @@
  */
 package org.apache.click.control;
 
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
 import junit.framework.TestCase;
+import org.apache.click.MockContainer;
 import org.apache.click.MockContext;
+import org.apache.click.pages.FileFieldPage;
 
 /**
  * Test FileField behavior.
@@ -44,4 +49,44 @@ public class FileFieldTest extends TestC
         // Check that the value <script> is not rendered
         assertTrue(field.toString().indexOf(value) < 0);
     }
+
+    /**
+     * Check that FileField onProcess works properly for multipart requests.
+     */
+    public void testOnProcess() {
+        try {
+            MockContainer container = new MockContainer("web");
+
+        container.start();
+
+          // Prepare a file for upload
+        String fileName = "test.htm";
+        String filePath = "/web/" + fileName;
+            URL resource = FieldTest.class.getResource(filePath);
+            URI uri = new URI(resource.toString());
+            File file = new File(uri);
+
+            // Prepare container parameters
+            String fieldName = "fileField";
+            container.setParameter(fieldName, file, "text/html");
+            container.setParameter("form_name", "form");
+
+            FileFieldPage page = container.testPage(FileFieldPage.class);
+
+        FileField field = page.getFileField();
+
+        // Perform tests
+        assertNotNull(field.getFileItem());
+        field.getFileItem().getName();
+        assertEquals(fieldName, field.getFileItem().getFieldName());
+        assertEquals(fileName, field.getFileItem().getName());
+        assertEquals(file.length(), field.getFileItem().getSize());
+
+        container.stop();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
 }

Added: click/trunk/click/framework/test/org/apache/click/pages/FileFieldPage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/pages/FileFieldPage.java?rev=1034418&view=auto
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/pages/FileFieldPage.java (added)
+++ click/trunk/click/framework/test/org/apache/click/pages/FileFieldPage.java Fri Nov 12
15:21:45 2010
@@ -0,0 +1,43 @@
+/*
+ * 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.pages;
+
+import org.apache.click.Page;
+import org.apache.click.control.FileField;
+import org.apache.click.control.Form;
+
+/**
+ * Page that renders a Form with a FileField.
+ */
+public class FileFieldPage extends Page {
+    private static final long serialVersionUID = 1L;
+
+    private FileField fileField = new FileField("fileField");
+
+    @Override
+    public void onInit() {
+        Form form = new Form("form");
+        form.add(fileField);
+        addControl(form);
+    }
+
+    public FileField getFileField() {
+        return fileField;
+    }
+}

Added: click/trunk/click/framework/test/web/file-field.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/web/file-field.htm?rev=1034418&view=auto
==============================================================================
--- click/trunk/click/framework/test/web/file-field.htm (added)
+++ click/trunk/click/framework/test/web/file-field.htm Fri Nov 12 15:21:45 2010
@@ -0,0 +1,20 @@
+<!--
+   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.
+-->
+
+$form
\ No newline at end of file



Mime
View raw message