-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix NullPointerException when using multipart with optional value
- Loading branch information
1 parent
72cc2d6
commit c015eb7
Showing
3 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...t/java/io/quarkus/resteasy/reactive/server/test/multipart/MultipartOptionalInputTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.quarkus.resteasy.reactive.server.test.multipart; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.function.Supplier; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.resteasy.reactive.server.test.multipart.other.OtherPackageFormDataBase; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class MultipartOptionalInputTest extends AbstractMultipartTest { | ||
|
||
private static final Path uploadDir = Paths.get("file-uploads"); | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<JavaArchive>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(FormDataBase.class, OtherPackageFormDataBase.class, FormData.class, Status.class, | ||
OtherFormData.class, FormDataSameFileName.class, | ||
OtherFormDataBase.class, | ||
MultipartResource.class, OtherMultipartResource.class) | ||
.addAsResource(new StringAsset( | ||
// keep the files around so we can assert the outcome | ||
"quarkus.http.body.delete-uploaded-files-on-end=false\nquarkus.http.body.uploads-directory=" | ||
+ uploadDir.toString() + "\n"), | ||
"application.properties"); | ||
} | ||
|
||
}); | ||
|
||
private final File HTML_FILE = new File("./src/test/resources/test.html"); | ||
|
||
@BeforeEach | ||
public void assertEmptyUploads() { | ||
Assertions.assertTrue(isDirectoryEmpty(uploadDir)); | ||
} | ||
|
||
@AfterEach | ||
public void clearDirectory() { | ||
clearDirectory(uploadDir); | ||
} | ||
|
||
@Test | ||
public void testUploadWithSomeFilesMissing() { | ||
RestAssured.given() | ||
.multiPart("name", "Alice") | ||
.multiPart("active", "true") | ||
.multiPart("num", "25") | ||
.multiPart("status", "WORKING") | ||
.multiPart("htmlFile", HTML_FILE, "text/html") | ||
.accept("text/plain") | ||
.when() | ||
.post("/multipart/optional") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("Alice - true - 50 - WORKING - true - false - false")); | ||
|
||
// ensure that the 1 uploaded file was created on disk | ||
File[] uploadedFiles = uploadDir.toFile().listFiles(); | ||
Assertions.assertNotNull(uploadedFiles); | ||
Assertions.assertEquals(1, uploadedFiles.length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters