Skip to content

Commit

Permalink
Coverage for subresources
Browse files Browse the repository at this point in the history
  • Loading branch information
fedinskiy committed May 2, 2022
1 parent abe1332 commit 6c77867
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.quarkus.ts.http.restclient.reactive;

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 org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

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

@RegisterRestClient
@Path("/books")
@RegisterClientHeaders
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public interface BookClient {

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
Uni<Book> getBook(@QueryParam("title") String title, @QueryParam("author") String author);

@Path("/author")
AuthorClient getAuthor();

@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
interface AuthorClient {
@GET
@Path("/name")
Uni<String> getName(@QueryParam("author") String author);

@Path("profession")
ProfessionClient getProfession();
}

@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
interface ProfessionClient {
@GET
@Path("/name")
Uni<String> getName();

@Path("/wage")
WageClient getWage();
}

interface WageClient {
@GET
@Path("/amount")
String getAmount();

@Path("/currency")
CurrencyClient getCurrency();
}

interface CurrencyClient {
@GET
@Path("/name")
String getName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
Expand All @@ -22,4 +23,31 @@ public Uni<Book> getByQueryMap(@QueryParam("param") Map<String, String> params)
.item(new Book(params.get("id"),
params.get("author")));
}

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Uni<Book> getBook(@QueryParam("title") String title, @QueryParam("author") String author) {
return Uni.createFrom().item(new Book(title, author));
}

@GET
@Path("/author/name")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public Uni<String> getAuthorName(@QueryParam("author") String author) {
return Uni.createFrom().item(author);
}

@GET
@Path("/author/profession/title")
public Uni<String> getProfession() {
return Uni.createFrom().item("writer");
}

@GET
@Path("/author/profession/wage/currency/name")
public Uni<String> getCurrency() {
return Uni.createFrom().item("USD");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 org.eclipse.microprofile.rest.client.inject.RestClient;
Expand All @@ -21,6 +22,10 @@ public class ReactiveClientBookResource {
@RestClient
JsonRestInterface restInterface;

@Inject
@RestClient
BookClient bookInterface;

@GET
@Path("/{id}/json")
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -34,4 +39,29 @@ public Uni<Book> getAsJson(@PathParam("id") String id) {
public Uni<Book> getAsJsonByBeanParam(@PathParam("id") String id) {
return restInterface.getWithBeanParam(new IdBeanParam(id));
}

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Uni<Book> getResource(@QueryParam("title") String title, @QueryParam("author") String author) {
return bookInterface.getBook(title, author);
}

@GET
@Path("/author")
public Uni<String> getSubResource(@QueryParam("author") String author) {
return bookInterface.getAuthor().getName(author);
}

@GET
@Path("/profession")
public Uni<String> getSubSubResource() {
return bookInterface.getAuthor().getProfession().getName();
}

@GET
@Path("/currency")
public String getLastResource() {
return bookInterface.getAuthor().getProfession().getWage().getCurrency().getName();
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
io.quarkus.ts.http.restclient.reactive.json.JsonRestInterface/mp-rest/url=http://localhost:${quarkus.http.port}
io.quarkus.ts.http.restclient.reactive.BookClient/mp-rest/url=http://localhost:${quarkus.http.port}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# new schema introduced in https://github.com/quarkusio/quarkus/pull/17220 . See classic.properties for old-style settings
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.json.JsonRestInterface".url=http://localhost:${quarkus.http.port}
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.files.FileClient".url=http://localhost:${quarkus.http.port}
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.BookClient".url=http://localhost:${quarkus.http.port}
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.BookClient.AuthorClient".url=http://localhost:${quarkus.http.port}
quarkus.rest-client.logging.scope=request-response
quarkus.log.category."org.jboss.resteasy.reactive.client.logging".level=DEBUG
quarkus.http.limits.max-body-size=3G
quarkus.rest-client.read-timeout = 60000
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
Expand Down Expand Up @@ -48,4 +49,62 @@ public void mapInQueryParam() {
assertEquals("Hagakure", response.jsonPath().getString("title"));
assertEquals("Tsuramoto", response.jsonPath().getString("author"));
}

@Test
public void resourceDirectly() {
Response response = app.given()
.when()
.get("/books/?title=Catch-22&author=Heller");
assertEquals(HttpStatus.SC_OK, response.statusCode());
assertEquals("Catch-22", response.jsonPath().getString("title"));
assertEquals("Heller", response.jsonPath().getString("author"));
}

@Test
public void resourceClient() {
Response response = app.given()
.when()
.get("/client/book/?title=Catch-22&author=Heller");
assertEquals(HttpStatus.SC_OK, response.statusCode());
assertEquals("Catch-22", response.jsonPath().getString("title"));
assertEquals("Heller", response.jsonPath().getString("author"));
}

@Test
public void subResourceDirectly() {
Response response = app.given()
.when()
.get("/books/author/name?author=Cimrman");
assertEquals(HttpStatus.SC_OK, response.statusCode());
assertEquals("Cimrman", response.getBody().asString());
}

@Test
public void deepestLevelDirectly() {
Response response = app.given()
.when()
.get("/books/author/profession/wage/currency/name");
assertEquals(HttpStatus.SC_OK, response.statusCode());
assertEquals("USD", response.getBody().asString());
}

@Test
@Disabled("https://github.com/quarkusio/quarkus/issues/25028")
public void subResource() {
Response response = app.given().get("/client/book/author/?author=Heller");
assertEquals(HttpStatus.SC_OK, response.statusCode());
assertEquals("Heller", response.getBody().asString());

Response sub = app.given().get("/client/book/profession");
assertEquals(HttpStatus.SC_OK, sub.statusCode());
assertEquals("writer", sub.getBody().asString());
}

@Test
@Disabled("https://github.com/quarkusio/quarkus/issues/25028")
public void deepLevel() {
Response response = app.given().get("/client/book/currency");
assertEquals(HttpStatus.SC_OK, response.statusCode());
assertEquals("Heller", response.getBody().asString());
}
}

0 comments on commit 6c77867

Please sign in to comment.