Author: wesw Date: Wed Jun 3 21:25:56 2009 New Revision: 781582 URL: http://svn.apache.org/viewvc?rev=781582&view=rev Log: first import, still need to create a struts-plugin.xml file that maps the beans.
Added: struts/sandbox/trunk/src/test/java/org/apache/struts2/fileupload/BasicProgressListenerTest.java Added: struts/sandbox/trunk/src/test/java/org/apache/struts2/fileupload/BasicProgressListenerTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/src/test/java/org/apache/struts2/fileupload/BasicProgressListenerTest.java?rev=781582&view=auto ============================================================================== --- struts/sandbox/trunk/src/test/java/org/apache/struts2/fileupload/BasicProgressListenerTest.java (added) +++ struts/sandbox/trunk/src/test/java/org/apache/struts2/fileupload/BasicProgressListenerTest.java Wed Jun 3 21:25:56 2009 @@ -0,0 +1,117 @@ +/* + * $Id$ + * + * 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.struts2.fileupload; + +import org.junit.Test; +import org.junit.Before; +import static org.junit.Assert.assertTrue; +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.StrutsStatics; +import org.springframework.mock.web.MockServletContext; +import org.springframework.mock.web.MockHttpSession; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import com.opensymphony.xwork2.ActionContext; + +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Map; +import java.util.HashMap; + +/** + * Unit test for BasicProgressListener + * + * @author Wes W + */ +public class BasicProgressListenerTest implements StrutsStatics { + + ActionContext actionContext; + // ServletActionContext servletActionContext; + private MockServletContext servletContext; + private HttpServletRequest request; + private HttpServletResponse response; + + /** + * + */ + @Before + public void setUp() { + Map extraContext = new HashMap(); + + servletContext = new MockServletContext(); + + request = new MockHttpServletRequest(); + response = new MockHttpServletResponse(); + + extraContext.put(HTTP_REQUEST, request); + extraContext.put(HTTP_RESPONSE, response); + extraContext.put(SERVLET_CONTEXT, servletContext); + + actionContext = new ActionContext(extraContext); + ServletActionContext.setContext(actionContext); + } + + /** + * + */ + @Test + public void testUpdate() { + BasicProgressListener listener = new BasicProgressListener(); + listener.setUpdateFrequency("1"); + listener.update(10L,10L,1); + + UploadStatusHolder holder = new UploadStatusHolder(); + + String key = request.getSession().getId(); + System.err.println("key - " + key); + + UploadStatus status = holder.getUploadStatus(key ); + + assertTrue(status.getBytesRead() == 10L); + assertTrue(status.getContentLength() == 10L); + assertTrue(status.getItem() == 1); + } + + /** + * + */ + @Test + public void testDontUpdate() { + BasicProgressListener listener = new BasicProgressListener(); + // listener.setUpdateFrequency("1000"); // let default of 2048 take over + listener.update(10L,10L,1); + listener.update(100L,100L,1); + + UploadStatusHolder holder = new UploadStatusHolder(); + + String key = request.getSession().getId(); + System.err.println("key - " + key); + + UploadStatus status = holder.getUploadStatus(key ); + + assertTrue(status.getBytesRead() == 10L); + assertTrue(status.getContentLength() == 10L); + assertTrue(status.getItem() == 1); + + } +} \ No newline at end of file