commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joc...@apache.org
Subject svn commit: r956490 [2/2] - in /commons/sandbox/commons-fileupload2: ./ .settings/ src/changes/ src/java/org/apache/commons/fileupload2/ src/java/org/apache/commons/fileupload2/disk/ src/java/org/apache/commons/fileupload2/impl/ src/java/org/apache/com...
Date Mon, 21 Jun 2010 08:29:23 GMT
Modified: commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/ProgressListenerTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/ProgressListenerTest.java?rev=956490&r1=956489&r2=956490&view=diff
==============================================================================
--- commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/ProgressListenerTest.java
(original)
+++ commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/ProgressListenerTest.java
Mon Jun 21 08:29:22 2010
@@ -33,15 +33,19 @@ import org.junit.Test;
  */
 public class ProgressListenerTest extends FileUploadTestCase {
 	private static class EventListenerImpl implements EventListener {
-		private final long expectedContentLength;
+		private long expectedContentLength;
+
+		protected void setExpectedContentLength(long expectedContentLength) {
+			this.expectedContentLength = expectedContentLength;
+		}
+
 		private final int expectedItems;
 		private boolean startRequestSeen, endRequestSeen;
 		private int startItemsSeen, endItemsSeen;
 		private FileItem previousFileItem;
 		private long bytesRead;
 
-		EventListenerImpl(long pExpectedContentLength, int pExpectedItems) {
-			expectedContentLength = pExpectedContentLength;
+		EventListenerImpl(int pExpectedItems) {
 			expectedItems = pExpectedItems;
 		}
 		
@@ -111,13 +115,14 @@ public class ProgressListenerTest extend
 	 */
 	@Test public void testProgressListener() throws Exception {
 		final int NUM_ITEMS = 512;
+		final int ITEM_SIZE = 16384;
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         for (int i = 0;  i < NUM_ITEMS;  i++) {
             String header = "-----1234\r\n"
                 + "Content-Disposition: form-data; name=\"field" + (i+1) + "\"\r\n"
                 + "\r\n";
             baos.write(header.getBytes("US-ASCII"));
-            for (int j = 0;  j < 16384+i;  j++) {
+			for (int j = 0;  j < ITEM_SIZE+i;  j++) {
                 baos.write((byte) j);
             }
             baos.write("\r\n".getBytes("US-ASCII"));
@@ -126,26 +131,27 @@ public class ProgressListenerTest extend
         byte[] contents = baos.toByteArray();
 
         MockHttpServletRequest request = new MockHttpServletRequest(contents, "multipart/form-data;
boundary=---1234");
-        runTest(NUM_ITEMS, contents.length, request);
+        runTest(NUM_ITEMS, ITEM_SIZE, ITEM_SIZE, request);
         request = new MockHttpServletRequest(contents, "multipart/form-data; boundary=---1234"){
 			@Override
 			public int getContentLength() {
 				return -1;
 			}        	
         };
-        runTest(NUM_ITEMS, contents.length, request);
+        runTest(NUM_ITEMS, ITEM_SIZE, ITEM_SIZE, request);
 	}
 
-	private void runTest(final int NUM_ITEMS, long pContentLength, MockHttpServletRequest request)
throws FileUploadException, IOException {
-		EventListenerImpl listener = new EventListenerImpl(pContentLength, NUM_ITEMS);
+	private void runTest(final int NUM_ITEMS, long pItemSize, long pContentLength, MockHttpServletRequest
request) throws FileUploadException, IOException {
+		EventListenerImpl listener = new EventListenerImpl(NUM_ITEMS);
 		final FileUpload upload = new FileUpload();
 		upload.setEventListener(listener);
 		final FileItemIterator<FileItem> iter = upload.parse(new HttpServletUploadRequest(request));
         for (int i = 0;  i < NUM_ITEMS;  i++) {
+        	listener.setExpectedContentLength(pContentLength+i);
         	assertTrue(iter.hasNext());
         	final FileItem item = iter.next();
         	InputStream istream = item.getInputStream();
-        	for (int j = 0;  j < 16384+i;  j++) {
+        	for (int j = 0;  j < pItemSize+i;  j++) {
         	    /**
                  * This used to be
                  *     assertEquals((byte) j, (byte) istream.read());

Modified: commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/SizesTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/SizesTest.java?rev=956490&r1=956489&r2=956490&view=diff
==============================================================================
--- commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/SizesTest.java
(original)
+++ commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/SizesTest.java
Mon Jun 21 08:29:22 2010
@@ -18,6 +18,7 @@ package org.apache.commons.fileupload2;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.util.Iterator;
 import java.util.List;
 
@@ -95,34 +96,22 @@ public class SizesTest extends FileUploa
 			"-----1234--\r\n";
 
 		{
-			final FileUpload upload = new FileUpload();
-			upload.setFileSizeMax(-1);
-	        final HttpServletRequest req = new MockHttpServletRequest(request.getBytes("US-ASCII"),
CONTENT_TYPE);
-	        final DiskFileItemStore store = new DiskFileItemStore();
-	        final List<StoredFileItem> fileItems = FileUploadUtils.asList(store.parse(upload,
new HttpServletUploadRequest(req)));
-	        assertEquals(1, fileItems.size());
+			final List<StoredFileItem> fileItems = run(request, -1);
 	        final StoredFileItem item = fileItems.get(0);
+			assertEquals(1, fileItems.size());
 	        assertEquals("This is the content of the file\n", Streams.asString(item.getInputStream(),
"US-ASCII"));
 		}
 
 		{
-			final FileUpload upload = new FileUpload();
-			upload.setFileSizeMax(40);
-			final HttpServletRequest req = new MockHttpServletRequest(request.getBytes("US-ASCII"),
CONTENT_TYPE);
-	        final DiskFileItemStore store = new DiskFileItemStore();
-	        final List<StoredFileItem> fileItems = FileUploadUtils.asList(store.parse(upload,
new HttpServletUploadRequest(req)));
+			final List<StoredFileItem> fileItems = run(request, 40);
 			assertEquals(1, fileItems.size());
 			final StoredFileItem item = fileItems.get(0);
 			assertEquals("This is the content of the file\n", Streams.asString(item.getInputStream(),
"US-ASCII"));
 		}
 
 		{
-			final FileUpload upload = new FileUpload();
-			upload.setFileSizeMax(30);
-			final HttpServletRequest req = new MockHttpServletRequest(request.getBytes("US-ASCII"),
CONTENT_TYPE);
-	        final DiskFileItemStore store = new DiskFileItemStore();
 	        try {
-	        	FileUploadUtils.asList(store.parse(upload, new HttpServletUploadRequest(req)));
+	        	run(request, 30);
 	        	fail("Expected exception.");
 	        } catch (IOException e) {
 	        	Assert.assertTrue(e.getClass().getName(), e instanceof FileSizeMaxException);
@@ -133,4 +122,16 @@ public class SizesTest extends FileUploa
 	        }
 		}
     }
+
+	private List<StoredFileItem> run(final String pRequest, int pMaxFileSize)
+			throws UnsupportedEncodingException, FileUploadException,
+			IOException {
+		final FileUpload upload = new FileUpload();
+		upload.setFileSizeMax(pMaxFileSize);
+		final HttpServletRequest req = new MockHttpServletRequest(pRequest.getBytes("US-ASCII"),
CONTENT_TYPE);
+		final DiskFileItemStore store = new DiskFileItemStore();
+		final List<StoredFileItem> fileItems = FileUploadUtils.asList(store.parse(upload,
new HttpServletUploadRequest(req)));
+		assertEquals(1, fileItems.size());
+		return fileItems;
+	}
 }

Modified: commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/StreamingTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/StreamingTest.java?rev=956490&r1=956489&r2=956490&view=diff
==============================================================================
--- commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/StreamingTest.java
(original)
+++ commons/sandbox/commons-fileupload2/src/test/org/apache/commons/fileupload2/StreamingTest.java
Mon Jun 21 08:29:22 2010
@@ -33,8 +33,8 @@ import junit.framework.Assert;
 
 import org.apache.commons.fileupload2.servlet.HttpServletUploadRequest;
 import org.apache.commons.fileupload2.util.FileUploadUtils;
-import org.apache.james.mime4j.parser.Event;
-import org.apache.james.mime4j.parser.MimeParseEventException;
+import org.apache.james.mime4j.stream.Event;
+import org.apache.james.mime4j.stream.MimeParseEventException;
 import org.junit.Test;
 
 



Mime
View raw message