forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
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 quarkusio#33761 from geoand/quarkusio#33738
Properly implement ClientRequestContext#setEntity
- Loading branch information
Showing
3 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...rc/test/java/io/quarkus/rest/client/reactive/provider/EntitySettingRequestFilterTest.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,74 @@ | ||
package io.quarkus.rest.client.reactive.provider; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
|
||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientRequestFilter; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
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 EntitySettingRequestFilterTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(Resource.class, Client.class, EntityRequestFilter.class)); | ||
|
||
@TestHTTPResource | ||
URI baseUri; | ||
|
||
@Test | ||
void testNullEntity() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri).register(new EntityRequestFilter(null)) | ||
.build(Client.class); | ||
assertThat(client.call("ignored")).isEqualTo("null"); | ||
} | ||
|
||
@Test | ||
void testNonNullEntity() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri).register(new EntityRequestFilter("foo")) | ||
.build(Client.class); | ||
assertThat(client.call("ignored")).isEqualTo("foo"); | ||
} | ||
|
||
@Path("/") | ||
public static class Resource { | ||
@POST | ||
public String returnHeaders(String body) { | ||
if ((body == null) || body.isEmpty()) { | ||
return "null"; | ||
} | ||
return body; | ||
} | ||
} | ||
|
||
public interface Client { | ||
|
||
@Path("/") | ||
@POST | ||
String call(String body); | ||
} | ||
|
||
public static class EntityRequestFilter implements ClientRequestFilter { | ||
|
||
private final String entity; | ||
|
||
public EntityRequestFilter(String entity) { | ||
this.entity = entity; | ||
} | ||
|
||
@Override | ||
public void filter(ClientRequestContext context) throws IOException { | ||
context.setEntity(entity); | ||
} | ||
} | ||
} |
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