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

Test Reactive Rest Client support of dynamic number of query parameters #719

Merged
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
@@ -1,16 +1,22 @@
package io.quarkus.ts.http.restclient.reactive;

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

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

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

import io.quarkus.ts.http.restclient.reactive.json.Book;
import io.quarkus.ts.http.restclient.reactive.json.BookIdWrapper;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

Expand Down Expand Up @@ -74,4 +80,10 @@ interface CurrencyClient {
@Path("/%E3%82%AF%E3%82%A4%E3%83%83%E3%82%AF%E6%A4%9C%E7%B4%A2/%25%20%23%20%5B%20%5D%20+%20=%20&%20@%20:%20!%20*%20(%20)%20'%20$%20,%20%3F/-%20_%20.%20~")
Multi<String> getByEncodedSearchTerm(@QueryParam("searchTerm") String searchTerm);

@GET
@Path("/rest-query")
@Produces(MediaType.APPLICATION_JSON)
Uni<List<Book>> getByRestQueryMap(@RestQuery Map<String, Integer> primitiveParams,
@RestQuery Map<String, BookIdWrapper> classParams, @RestQuery MultivaluedMap<String, Integer> multivaluedMap);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.ts.http.restclient.reactive;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.ws.rs.Consumes;
Expand All @@ -9,7 +11,11 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.jboss.resteasy.reactive.RestQuery;

import io.quarkus.ts.http.restclient.reactive.json.Book;
import io.quarkus.ts.http.restclient.reactive.json.BookIdWrapper;
import io.quarkus.ts.http.restclient.reactive.json.BookRepository;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

Expand All @@ -27,6 +33,21 @@ public Uni<Book> getByQueryMap(@QueryParam("param") Map<String, String> params)
params.get("author")));
}

@GET
@Path("/rest-query")
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<Book>> getRestQuery(@RestQuery Integer firstPlainId, @RestQuery Integer secondPlainId,
@RestQuery BookIdWrapper firstObjectId, @RestQuery BookIdWrapper secondObjectId,
@RestQuery List<Integer> additionalIds) {
var books = new ArrayList<Book>();
books.add(BookRepository.getById(firstPlainId));
books.add(BookRepository.getById(secondPlainId));
books.add(BookRepository.getById(firstObjectId.getId()));
books.add(BookRepository.getById(secondObjectId.getId()));
additionalIds.stream().map(BookRepository::getById).forEach(books::add);
return Uni.createFrom().item(books);
}

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package io.quarkus.ts.http.restclient.reactive;

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

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;

import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.quarkus.ts.http.restclient.reactive.json.Book;
import io.quarkus.ts.http.restclient.reactive.json.BookIdWrapper;
import io.quarkus.ts.http.restclient.reactive.json.IdBeanParam;
import io.quarkus.ts.http.restclient.reactive.json.JsonRestInterface;
import io.smallrye.mutiny.Multi;
Expand Down Expand Up @@ -77,4 +82,16 @@ public Multi<String> getDecodedPath(@QueryParam("searchTerm") String searchTerm)
public Multi<String> getEncodedPath(@QueryParam("searchTerm") String searchTerm) {
return bookInterface.getByEncodedSearchTerm(searchTerm);
}

@GET
@Path("/rest-query")
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<Book>> getRestQuery() {
var primitiveParamsMap = Map.of("firstPlainId", 1, "secondPlainId", 2);
var classParamsMap = Map.of("firstObjectId", new BookIdWrapper(3),
"secondObjectId", new BookIdWrapper(4));
var multivaluedMap = new MultivaluedHashMap<String, Integer>();
multivaluedMap.put("additionalIds", List.of(5, 6));
return bookInterface.getByRestQueryMap(primitiveParamsMap, classParamsMap, multivaluedMap);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.ts.http.restclient.reactive.json;

public class BookIdWrapper {

private final int id;

public BookIdWrapper(int id) {
this.id = id;
}

public BookIdWrapper(String id) {
michalvavrik marked this conversation as resolved.
Show resolved Hide resolved
this.id = Integer.parseInt(id);
}

public int getId() {
return id;
}

@Override
public String toString() {
return Integer.toString(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.ts.http.restclient.reactive.json;

import java.util.Map;

public class BookRepository {

private static final Map<Integer, Book> REPO = Map.of(
1, new Book("Title 1", "Author 1"),
2, new Book("Title 2", "Author 2"),
3, new Book("Title 3", "Author 3"),
4, new Book("Title 4", "Author 4"),
5, new Book("Title 5", "Author 5"),
6, new Book("Title 6", "Author 6"));

public static Book getById(Integer id) {
return REPO.get(id);
}

public static int count() {
return REPO.size();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.scenarios.annotations.DisabledOnQuarkusVersion;
import io.quarkus.test.services.QuarkusApplication;
import io.quarkus.ts.http.restclient.reactive.json.Book;
import io.quarkus.ts.http.restclient.reactive.json.BookRepository;
import io.restassured.response.Response;

@QuarkusScenario
Expand Down Expand Up @@ -56,6 +58,21 @@ public void mapInQueryParam() {
assertEquals("Tsuramoto", response.jsonPath().getString("author"));
}

@Tag("QUARKUS-2148")
@Test
public void restQueryParam() {
Response response = app.given().when().get("/client/book/rest-query");
assertEquals(HttpStatus.SC_OK, response.statusCode());
var books = response.jsonPath().getList(".", Book.class);
assertEquals(BookRepository.count(), books.size());
for (int i = 0; i < books.size(); i++) {
var expectedBook = BookRepository.getById(i + 1);
var actualBook = books.get(i);
assertEquals(expectedBook.getTitle(), actualBook.getTitle());
assertEquals(expectedBook.getAuthor(), actualBook.getAuthor());
}
}

@Test
public void resourceDirectly() {
Response response = app.given()
Expand Down