mirror of
https://github.com/apache/struts.git
synced 2026-08-05 22:56:59 +00:00
WW-5088: Integration test for empty file upload.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package it.org.apache.struts2.showcase;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.html.DomElement;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlFileInput;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlForm;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlInput;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FileUploadTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyFile() throws Exception {
|
||||
try (final WebClient webClient = new WebClient()) {
|
||||
final HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/fileupload/doUpload.action");
|
||||
final HtmlForm form = page.getFormByName("doUpload");
|
||||
HtmlInput captionInput = form.getInputByName("caption");
|
||||
HtmlFileInput uploadInput = form.getInputByName("upload");
|
||||
captionInput.type("some caption");
|
||||
File tempFile = File.createTempFile("testEmptyFile", ".tmp");
|
||||
tempFile.deleteOnExit();
|
||||
uploadInput.setValueAttribute(tempFile.getAbsolutePath());
|
||||
final HtmlSubmitInput button = form.getInputByValue("Submit");
|
||||
final HtmlPage resultPage = button.click();
|
||||
DomElement errorMessage = resultPage.getFirstByXPath("//span[@class='errorMessage']");
|
||||
Assert.assertNotNull(errorMessage);
|
||||
Assert.assertEquals("File cannot be empty", errorMessage.getVisibleText());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -157,7 +157,7 @@ public class JakartaMultiPartRequest extends AbstractMultiPartRequest {
|
||||
protected DiskFileItemFactory createDiskFileItemFactory(String saveDir) {
|
||||
DiskFileItemFactory fac = new DiskFileItemFactory();
|
||||
// Make sure that the data is written to file, even if the file is empty.
|
||||
fac.setSizeThreshold(0);
|
||||
fac.setSizeThreshold(-1);
|
||||
if (saveDir != null) {
|
||||
fac.setRepository(new File(saveDir));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user