You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2009/06/18 23:54:32 UTC

svn commit: r786306 - in /incubator/click/trunk/click/extras/test: org/apache/click/extras/gae/ org/apache/click/extras/pages/ web/ web/WEB-INF/

Author: sabob
Date: Thu Jun 18 21:54:32 2009
New Revision: 786306

URL: http://svn.apache.org/viewvc?rev=786306&view=rev
Log:
added MemoryFileItem tests. CLK-560

Added:
    incubator/click/trunk/click/extras/test/org/apache/click/extras/gae/
    incubator/click/trunk/click/extras/test/org/apache/click/extras/gae/MemoryFileItemTest.java
    incubator/click/trunk/click/extras/test/org/apache/click/extras/pages/
    incubator/click/trunk/click/extras/test/org/apache/click/extras/pages/MemoryFileItemUploadPage.java
    incubator/click/trunk/click/extras/test/web/memory-file-item-upload.htm
    incubator/click/trunk/click/extras/test/web/upload1.txt
    incubator/click/trunk/click/extras/test/web/upload2.txt
Modified:
    incubator/click/trunk/click/extras/test/web/WEB-INF/click.xml

Added: incubator/click/trunk/click/extras/test/org/apache/click/extras/gae/MemoryFileItemTest.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/test/org/apache/click/extras/gae/MemoryFileItemTest.java?rev=786306&view=auto
==============================================================================
--- incubator/click/trunk/click/extras/test/org/apache/click/extras/gae/MemoryFileItemTest.java (added)
+++ incubator/click/trunk/click/extras/test/org/apache/click/extras/gae/MemoryFileItemTest.java Thu Jun 18 21:54:32 2009
@@ -0,0 +1,79 @@
+/*
+ * 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.extras.gae;
+
+import java.io.File;
+import junit.framework.TestCase;
+import org.apache.click.MockContainer;
+import org.apache.click.control.FileField;
+import org.apache.click.control.Form;
+import org.apache.click.extras.pages.MemoryFileItemUploadPage;
+import org.apache.click.servlet.MockRequest;
+
+/**
+ * Provides tests for the Google App Engine MemoryFileItem.
+ *
+ * @author Bob Schellink
+ */
+public class MemoryFileItemTest extends TestCase {
+
+    /**
+     * Test Google App Engine (GAE) MemoryFileItem support.
+     */
+    public void testMemoryFileItem() {
+        MockContainer container = new MockContainer("web");
+        container.start();
+
+        String firstname = "Steve";
+        String lastname = "Jones";
+
+        // Lookup path to files
+        String file1Path = container.getServletContext().getRealPath("upload1.txt");
+        String file2Path = container.getServletContext().getRealPath("upload2.txt");
+
+        File upload1 = new File(file1Path);
+        File upload2 = new File(file2Path);
+        MockRequest request = container.getRequest();
+
+        // Add couple of files to be uploaded
+        request.addFile("upload1", upload1, "utf-8");
+        request.addFile("upload2", upload2, "utf-8");
+
+        // Set firstname and lastname request parameters
+        request.setParameter("firstname", firstname);
+        request.setParameter("lastname", lastname);
+
+        // Set FORM_NAME parameter to ensure Form is submitted
+        request.setParameter(Form.FORM_NAME, "form");
+
+        MemoryFileItemUploadPage page = (MemoryFileItemUploadPage) container.testPage(MemoryFileItemUploadPage.class);
+
+        // Check that field parameters were processed
+        assertEquals(firstname, page.getForm().getFieldValue("firstname"));
+        assertEquals(lastname, page.getForm().getFieldValue("lastname"));
+
+        // Check that file field parameters were processed
+        FileField fileField1 = (FileField) page.getForm().getField("upload1");
+        FileField fileField2 = (FileField) page.getForm().getField("upload2");
+        assertEquals("upload1 success", fileField1.getFileItem().getString());
+        assertEquals("upload2 success", fileField2.getFileItem().getString());
+
+        container.stop();
+    }
+}

Added: incubator/click/trunk/click/extras/test/org/apache/click/extras/pages/MemoryFileItemUploadPage.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/test/org/apache/click/extras/pages/MemoryFileItemUploadPage.java?rev=786306&view=auto
==============================================================================
--- incubator/click/trunk/click/extras/test/org/apache/click/extras/pages/MemoryFileItemUploadPage.java (added)
+++ incubator/click/trunk/click/extras/test/org/apache/click/extras/pages/MemoryFileItemUploadPage.java Thu Jun 18 21:54:32 2009
@@ -0,0 +1,48 @@
+/*
+ * 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.extras.pages;
+
+import org.apache.click.Page;
+import org.apache.click.control.FileField;
+import org.apache.click.control.Form;
+import org.apache.click.control.TextField;
+
+/**
+ * A Google App Engine (GAE) file upload test page.
+ *
+ * @author Bob Schellink
+ */
+public class MemoryFileItemUploadPage extends Page {
+
+    private Form form = new Form("form");
+
+    public void onInit() {
+        addControl(form);
+        form.add(new TextField("firstname"));
+        form.add(new TextField("lastname"));
+        FileField upload1 = new FileField("upload1");
+        form.add(upload1);
+        FileField upload2 = new FileField("upload2");
+        form.add(upload2);
+    }
+
+    public Form getForm() {
+        return form;
+    }
+}

Modified: incubator/click/trunk/click/extras/test/web/WEB-INF/click.xml
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/test/web/WEB-INF/click.xml?rev=786306&r1=786305&r2=786306&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/test/web/WEB-INF/click.xml (original)
+++ incubator/click/trunk/click/extras/test/web/WEB-INF/click.xml Thu Jun 18 21:54:32 2009
@@ -20,4 +20,15 @@
 <click-app charset="UTF-8">
     <pages package="org.apache.click.extras.pages"/>
     <mode value="trace"/>
+
+    <file-upload-service classname="org.apache.click.extras.gae.MemoryFileUploadService">
+      <!-- Set the total request maximum size to 10mb (10 x 1024 x 1024 = 10485760).
+           The default request upload size is unlimited. -->
+      <property name="sizeMax" value="10485760"/>
+
+      <!-- Set the maximum individual file size to 2mb (2 x 1024 x 1024 = 2097152).
+           The default file upload size is unlimited. -->
+      <property name="fileSizeMax" value="2097152"/> 
+    </file-upload-service> 
+
 </click-app>
\ No newline at end of file

Added: incubator/click/trunk/click/extras/test/web/memory-file-item-upload.htm
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/test/web/memory-file-item-upload.htm?rev=786306&view=auto
==============================================================================
--- incubator/click/trunk/click/extras/test/web/memory-file-item-upload.htm (added)
+++ incubator/click/trunk/click/extras/test/web/memory-file-item-upload.htm Thu Jun 18 21:54:32 2009
@@ -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

Added: incubator/click/trunk/click/extras/test/web/upload1.txt
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/test/web/upload1.txt?rev=786306&view=auto
==============================================================================
--- incubator/click/trunk/click/extras/test/web/upload1.txt (added)
+++ incubator/click/trunk/click/extras/test/web/upload1.txt Thu Jun 18 21:54:32 2009
@@ -0,0 +1 @@
+upload1 success
\ No newline at end of file

Added: incubator/click/trunk/click/extras/test/web/upload2.txt
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/test/web/upload2.txt?rev=786306&view=auto
==============================================================================
--- incubator/click/trunk/click/extras/test/web/upload2.txt (added)
+++ incubator/click/trunk/click/extras/test/web/upload2.txt Thu Jun 18 21:54:32 2009
@@ -0,0 +1 @@
+upload2 success
\ No newline at end of file