Skip to content

Commit

Permalink
Update workshop to use the latest REST Client developments
Browse files Browse the repository at this point in the history
Closes: #292
  • Loading branch information
geoand committed Sep 6, 2023
1 parent 801b525 commit 8fc66f3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ import jakarta.ws.rs.core.MediaType;
@Path("/api/villains")
@Produces(MediaType.APPLICATION_JSON)
@RegisterRestClient
@RegisterRestClient(configKey = "villain")
public interface VillainProxy {
@GET
Expand Down Expand Up @@ -222,21 +222,14 @@ The name of the property needs to follow a certain convention which is best disp

[source,properties]
----
io.quarkus.workshop.superheroes.fight.client.HeroProxy/mp-rest/url=http://localhost:8083
io.quarkus.workshop.superheroes.fight.client.HeroProxy/mp-rest/scope=jakarta.inject.Singleton
io.quarkus.workshop.superheroes.fight.client.VillainProxy/mp-rest/url=http://localhost:8084
io.quarkus.workshop.superheroes.fight.client.VillainProxy/mp-rest/scope=jakarta.inject.Singleton
quarkus.rest-client.hero.url=http://localhost:8083
quarkus.rest-client.villain.url=http://localhost:8084
----
--

Having this configuration means that all requests performed using `HeroProxy` will use http://localhost:8083 as the base URL.
Using this configuration, calling the `findRandomHero` method of `HeroProxy` would result in an HTTP GET request being made to http://localhost:8083/api/heroes/random.

Having this configuration means that the default scope of `HeroProxy` will be `@Singleton`.
Supported scope values are `@Singleton`, `@Dependent`, `@ApplicationScoped` and `@RequestScoped`.
The default scope is `@Dependent`.
The default scope can also be defined on the interface.

Now, go back in the UI and refresh, you should see some pictures!

== Updating the Test with Mock Support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To avoid port conflicts between the real services and the Pact stubs, let's use
Open the fight service's `application.properties` and add the following

----
%test.io.quarkus.workshop.superheroes.fight.client.HeroProxy/mp-rest/url=http://localhost:8093
%test.quarkus.rest-client.hero.url=http://localhost:8083=http://localhost:8093
----

The `%test` scopes the updated property to only apply in the test mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Path("/api/heroes")
@Produces(MediaType.APPLICATION_JSON)
@RegisterRestClient
@RegisterRestClient(configKey = "hero")
public interface HeroProxy {

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Path("/api/villains")
@Produces(MediaType.APPLICATION_JSON)
@RegisterRestClient
@RegisterRestClient(configKey = "villain")
public interface VillainProxy {

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ quarkus.http.cors=true
## drop and create the database at startup (use `update` to only update the schema)
quarkus.hibernate-orm.database.generation=drop-and-create
## Rest clients
io.quarkus.workshop.superheroes.fight.client.HeroProxy/mp-rest/url=http://localhost:8083
%test.io.quarkus.workshop.superheroes.fight.client.HeroProxy/mp-rest/url=http://localhost:8093
io.quarkus.workshop.superheroes.fight.client.HeroProxy/mp-rest/scope=jakarta.inject.Singleton
io.quarkus.workshop.superheroes.fight.client.VillainProxy/mp-rest/url=http://localhost:8084
io.quarkus.workshop.superheroes.fight.client.VillainProxy/mp-rest/scope=jakarta.inject.Singleton
quarkus.rest-client.hero.url=http://localhost:8083
%test.quarkus.rest-client.hero.url=http://localhost:8093
quarkus.rest-client.villain.url=http://localhost:8084
# tag::adocNarrate[]
io.quarkus.workshop.superheroes.fight.client.NarrationProxy/mp-rest/url=http://localhost:8086
io.quarkus.workshop.superheroes.fight.client.NarrationProxy/mp-rest/scope=jakarta.inject.Singleton
quarkus.rest-client.narration.url=http://localhost:8086
# end::adocNarrate[]
process.milliseconds=0
## Kafka configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package io.quarkus.workshop.superheroes.fight;

import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectMock;
import io.quarkus.workshop.superheroes.fight.client.DefaultTestHero;
import io.quarkus.workshop.superheroes.fight.client.DefaultTestVillain;
import io.quarkus.workshop.superheroes.fight.client.Hero;
import io.quarkus.workshop.superheroes.fight.client.HeroProxy;
import io.quarkus.workshop.superheroes.fight.client.Villain;
import io.quarkus.workshop.superheroes.fight.client.*;
import io.restassured.common.mapper.TypeRef;
import org.eclipse.microprofile.rest.client.inject.RestClient;
Expand Down Expand Up @@ -40,7 +45,7 @@ public class FightResourceTest {
private static final int NB_FIGHTS = 3;
private static String fightId;

@InjectMock(convertScopes = true)
@InjectMock
@RestClient
HeroProxy heroProxy;

Expand Down

0 comments on commit 8fc66f3

Please sign in to comment.