Author: wesw
Date: Thu Jun  4 15:46:32 2009
New Revision: 781782

URL: http://svn.apache.org/viewvc?rev=781782&view=rev
Log:
making sure trackings of multiple files are separate and working

Modified:
    
struts/sandbox/trunk/struts2-fileupload-plugin/src/test/java/org/apache/struts2/fileupload/BasicProgressListenerTest.java

Modified: 
struts/sandbox/trunk/struts2-fileupload-plugin/src/test/java/org/apache/struts2/fileupload/BasicProgressListenerTest.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-fileupload-plugin/src/test/java/org/apache/struts2/fileupload/BasicProgressListenerTest.java?rev=781782&r1=781781&r2=781782&view=diff
==============================================================================
--- 
struts/sandbox/trunk/struts2-fileupload-plugin/src/test/java/org/apache/struts2/fileupload/BasicProgressListenerTest.java
 (original)
+++ 
struts/sandbox/trunk/struts2-fileupload-plugin/src/test/java/org/apache/struts2/fileupload/BasicProgressListenerTest.java
 Thu Jun  4 15:46:32 2009
@@ -35,6 +35,7 @@
 import javax.servlet.http.HttpServletResponse;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.List;
 
 /**
  * Unit test for BasicProgressListener
@@ -54,6 +55,13 @@
      */
     @Before
     public void setUp() {
+        // the basic progress listener keys off of the session id
+        // and the file item id. To find the session id, it will
+        // try to get a session from the servletActionContext
+        // so, we setup a mock context to let it work. I'm not sure
+        // if all of the following is necessary, but it appears to
+        // work and ids are properly generating as of $Date$
+
         Map extraContext = new HashMap();
 
         servletContext = new MockServletContext();
@@ -83,7 +91,7 @@
         UploadStatusTracker tracker2 = new UploadStatusHolder();
 
         String key = request.getSession().getId();
-        System.err.println("key - " + key);
+        // System.err.println("key - " + key);
 
         UploadStatus status = tracker2.getUploadStatus(key , 1);
 
@@ -107,7 +115,31 @@
         UploadStatusTracker tracker2 = new UploadStatusHolder();
 
         String key = request.getSession().getId();
-        System.err.println("key - " + key);
+        // System.err.println("key - " + key);
+
+        UploadStatus status = tracker2.getUploadStatus(key, 1 );
+
+        assertTrue(status.getBytesRead() == 10L);
+        assertTrue(status.getContentLength() == 10L);
+        assertTrue(status.getItemId() == 1);
+
+    }
+
+    /**
+     * 
+     */
+    @Test
+    public void testMultipleFileUploadProgress() {
+        BasicProgressListener listener = new BasicProgressListener();
+        UploadStatusTracker tracker = new UploadStatusHolder();
+        listener.setTracker(tracker);
+        listener.setUpdateFrequency("10");
+        listener.update(10L, 10L, 1);
+        listener.update(100L, 100L, 2);
+
+        UploadStatusTracker tracker2 = new UploadStatusHolder();
+        String key = request.getSession().getId();
+        // System.err.println("key - " + key);
 
         UploadStatus status = tracker2.getUploadStatus(key, 1 );
 
@@ -115,5 +147,14 @@
         assertTrue(status.getContentLength() == 10L);
         assertTrue(status.getItemId() == 1);
 
+        UploadStatus status2 = tracker2.getUploadStatus(key, 2 );
+
+        assertTrue(status2.getBytesRead() == 100L);
+        assertTrue(status2.getContentLength() == 100L);
+        assertTrue(status2.getItemId() == 2);
+
+        List<UploadStatus> bothStatuses = 
tracker2.getAllStatusesInSession(key);
+        assertTrue(bothStatuses.size() == 2) ;
+
     }
 }
\ No newline at end of file


Reply via email to