mirror of
https://github.com/apache/struts.git
synced 2026-08-07 07:37:20 +00:00
Replaces empty file upload test with simple one
This commit is contained in:
@@ -129,6 +129,12 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.htmlunit</groupId>
|
||||
<artifactId>htmlunit</artifactId>
|
||||
@@ -231,7 +237,7 @@
|
||||
<httpConnector>
|
||||
<port>8090</port>
|
||||
</httpConnector>
|
||||
<scanIntervalSeconds>10</scanIntervalSeconds>
|
||||
<scan>10</scan>
|
||||
<webAppSourceDirectory>${basedir}/src/main/webapp/</webAppSourceDirectory>
|
||||
<webApp>
|
||||
<extraClasspath>
|
||||
|
||||
@@ -19,35 +19,46 @@
|
||||
package it.org.apache.struts2.showcase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import org.htmlunit.WebClient;
|
||||
import org.htmlunit.html.DomElement;
|
||||
import org.htmlunit.html.HtmlFileInput;
|
||||
import org.htmlunit.html.HtmlForm;
|
||||
import org.htmlunit.html.HtmlInput;
|
||||
import org.htmlunit.html.HtmlPage;
|
||||
import org.htmlunit.html.HtmlSubmitInput;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class FileUploadTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyFile() throws Exception {
|
||||
public void testSimpleFileUpload() 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");
|
||||
File tempFile = File.createTempFile("testEmptyFile", ".txt");
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
try (FileWriter writer = new FileWriter(tempFile)) {
|
||||
writer.append("Some strings");
|
||||
}
|
||||
|
||||
uploadInput.setValue(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());
|
||||
|
||||
String content = resultPage.getVisibleText();
|
||||
System.out.println(content);
|
||||
assertThat(content).contains(
|
||||
"ContentType: text/plain",
|
||||
"Original FileName: " + tempFile.getName(),
|
||||
"Caption:some caption"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user