Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for @RestForm Map<String, String> handling in REST Client #2183

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.util.List;
import java.util.Map;
import java.util.Set;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
Expand All @@ -13,6 +15,7 @@

import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.jboss.resteasy.reactive.RestForm;
import org.jboss.resteasy.reactive.RestQuery;

import io.quarkus.ts.http.restclient.reactive.json.Book;
Expand Down Expand Up @@ -110,4 +113,10 @@ Uni<List<Book>> getByRestQueryMap(@RestQuery Map<String, Integer> primitiveParam
@Path("/suffix_priority")
@Produces("application/text+json")
Uni<String> getPriorities(@QueryParam("content") String text);

@POST
@Path("/search")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
Set<Book> postFilter(@RestForm Map<String, String> filter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
Expand Down Expand Up @@ -163,6 +166,14 @@ public Uni<String> programmaticRestClient()
.map(Book::getTitle);
}

@POST
@Path("/search")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Set<Book> searchBooks(@FormParam("author") String author) {
return Set.of(new Book("The Wind-Up Bird Chronicle", author));
}

private KeyStore trustStore() throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
KeyStore ks = KeyStore.getInstance("JKS");
try (var is = getClass().getResourceAsStream("META-INF/keystore.jks")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.util.List;
import java.util.Map;
import java.util.Set;

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
Expand Down Expand Up @@ -116,4 +118,10 @@ public Uni<String> getSuffixed(@QueryParam("content") String text,
throw new IllegalStateException("Unexpected value: " + type);
}
}

@POST
@Path("/search")
public Set<Book> postFilter() {
return bookInterface.postFilter(Map.of("author", "Haruki Murakami"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.UUID;

import jakarta.ws.rs.core.MediaType;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -60,6 +63,23 @@ public void shouldGetBookFromRestClientJson() {
assertEquals("Title in Json: 123", response.jsonPath().getString("title"));
}

@Tag("https://github.com/quarkusio/quarkus/issues/43784")
@Test
jcarranzan marked this conversation as resolved.
Show resolved Hide resolved
public void shouldPostBook() {
Response response = app.given()
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.when()
.post("/client/book/search");
assertEquals(HttpStatus.SC_OK, response.statusCode());
List<Book> books = response.jsonPath().getList(".", Book.class);
assertEquals(1, books.size());

Book book = books.iterator().next();

assertEquals("The Wind-Up Bird Chronicle", book.getTitle());
assertEquals("Haruki Murakami", book.getAuthor());
}

@Tag("QUARKUS-1568")
@Test
public void supportPathParamFromBeanParam() {
Expand Down