-
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.
Merge pull request #19827 from michalszynkiewicz/multipart-file-name
Set actual file name in Rest Client Reactive multipart support
- Loading branch information
Showing
3 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
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
80 changes: 80 additions & 0 deletions
80
...ctive/deployment/src/test/java/io/quarkus/rest/client/reactive/MultipartFilenameTest.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,80 @@ | ||
package io.quarkus.rest.client.reactive; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.FormParam; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.jboss.resteasy.reactive.MultipartForm; | ||
import org.jboss.resteasy.reactive.PartType; | ||
import org.jboss.resteasy.reactive.multipart.FileUpload; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
|
||
public class MultipartFilenameTest { | ||
|
||
@TestHTTPResource | ||
URI baseUri; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Resource.class, FormData.class, Client.class, ClientForm.class)) | ||
.withConfigurationResource("dependent-test-application.properties"); | ||
|
||
@Test | ||
void shouldPassOriginalFileName() throws IOException { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class); | ||
|
||
File file = File.createTempFile("MultipartTest", ".txt"); | ||
file.deleteOnExit(); | ||
|
||
ClientForm form = new ClientForm(); | ||
form.file = file; | ||
assertThat(client.postMultipart(form)).isEqualTo(file.getName()); | ||
} | ||
|
||
@Path("/multipart") | ||
@ApplicationScoped | ||
public static class Resource { | ||
@POST | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
public String upload(@MultipartForm FormData form) { | ||
return form.myFile.fileName(); | ||
} | ||
} | ||
|
||
public static class FormData { | ||
@FormParam("myFile") | ||
public FileUpload myFile; | ||
|
||
} | ||
|
||
@Path("/multipart") | ||
public interface Client { | ||
@POST | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
String postMultipart(@MultipartForm ClientForm clientForm); | ||
|
||
} | ||
|
||
public static class ClientForm { | ||
@FormParam("myFile") | ||
@PartType(MediaType.APPLICATION_OCTET_STREAM) | ||
public File file; | ||
} | ||
} |