You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2023/12/16 15:49:15 UTC
(struts) 11/11: Replaces empty file upload test with simple one
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch fix/after-rebase
in repository https://gitbox.apache.org/repos/asf/struts.git
commit 576c0646958de04891c0eca6db562478d57de337
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Dec 16 16:48:51 2023 +0100
Replaces empty file upload test with simple one
---
apps/showcase/pom.xml | 8 ++++++-
.../apache/struts2/showcase/FileUploadTest.java | 25 ++++++++++++++++------
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/apps/showcase/pom.xml b/apps/showcase/pom.xml
index 2745be15e..d715790cd 100644
--- a/apps/showcase/pom.xml
+++ b/apps/showcase/pom.xml
@@ -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>
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FileUploadTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FileUploadTest.java
index b5246ae2d..fdbc1c311 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FileUploadTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FileUploadTest.java
@@ -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"
+ );
}
}