-
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.
Wrong type for EncoderMode used in rest-client (#37261)
Add test
- Loading branch information
1 parent
307c35e
commit d6d1606
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
...ent/src/test/java/io/quarkus/rest/client/reactive/multipart/MultipartEncoderModeTest.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,89 @@ | ||
package io.quarkus.rest.client.reactive.multipart; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
|
||
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.jboss.resteasy.reactive.ResponseStatus; | ||
import org.jboss.resteasy.reactive.RestForm; | ||
import org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties; | ||
import org.jboss.resteasy.reactive.client.impl.multipart.PausableHttpPostRequestEncoder; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.FormParam; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientRequestFilter; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
public class MultipartEncoderModeTest { | ||
@TestHTTPResource | ||
URI baseUri; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar.addClasses(Resource.class, Client.class)) | ||
.withConfigurationResource("multipart-encoder-mode-test.properties"); | ||
|
||
@Inject | ||
@RestClient | ||
Client client; | ||
|
||
@Test | ||
void shouldPassUsingCustomMultipartPostEncoderMode(@TempDir File tempDir) throws IOException { | ||
File file = File.createTempFile("MultipartTest", ".txt", tempDir); | ||
assertThat(client.upload(file)).isEqualTo("OK"); | ||
} | ||
|
||
static class MultipartEncoderModeCheck implements ClientRequestFilter { | ||
@Override | ||
public void filter(ClientRequestContext requestContext) throws IOException { | ||
Object mode = requestContext.getConfiguration().getProperty(QuarkusRestClientProperties.MULTIPART_ENCODER_MODE); | ||
if (mode == null) { | ||
requestContext.abortWith(Response.serverError().entity("encoderMode is null").build()); | ||
return; | ||
} | ||
if (mode.getClass() != PausableHttpPostRequestEncoder.EncoderMode.class) { | ||
requestContext.abortWith(Response.serverError().entity("encoderMode illegal type").build()); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
@Path("resource") | ||
static public class Resource { | ||
@Path("upload") | ||
@POST | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@ResponseStatus(200) | ||
public String upload(@RestForm File file) { | ||
return "OK"; | ||
} | ||
} | ||
|
||
@Path("resource") | ||
@RegisterRestClient(configKey = "client") | ||
@RegisterProvider(MultipartEncoderModeCheck.class) | ||
static public interface Client { | ||
@Path("upload") | ||
@POST | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
String upload(@FormParam("file") File file); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...rest-client-reactive/deployment/src/test/resources/multipart-encoder-mode-test.properties
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,2 @@ | ||
quarkus.rest-client.multipart-post-encoder-mode=HTML5 | ||
quarkus.rest-client.client.url=http://localhost:${quarkus.http.test-port} |