From fb57afe8158a46b4e93ad3967d06d479cb427eb7 Mon Sep 17 00:00:00 2001 From: Eric Deandrea Date: Thu, 9 May 2024 13:11:09 -0400 Subject: [PATCH] Update wiremock grpc (#907) Signed-off-by: Eric Deandrea --- rest-fights/pom.xml | 2 +- .../superheroes/fight/InjectGrpcWireMock.java | 18 ---------------- .../LocationsWiremockGrpcServerResource.java | 14 +------------ .../fight/client/LocationClientTests.java | 21 ++++++++----------- .../fight/rest/FightResourceIT.java | 9 +++----- 5 files changed, 14 insertions(+), 50 deletions(-) diff --git a/rest-fights/pom.xml b/rest-fights/pom.xml index 31011f47d..ac31aa5b9 100644 --- a/rest-fights/pom.xml +++ b/rest-fights/pom.xml @@ -24,7 +24,7 @@ 3.10.0 3.2.5 3.5.4 - 0.5.0 + 0.6.0 diff --git a/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/InjectGrpcWireMock.java b/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/InjectGrpcWireMock.java index 4ab029bf5..2a611ab3f 100644 --- a/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/InjectGrpcWireMock.java +++ b/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/InjectGrpcWireMock.java @@ -11,8 +11,6 @@ * Annotation that can be used to inject one of the following into a test annotated with either {@link io.quarkus.test.junit.QuarkusTest @QuarkusTest} or {@link io.quarkus.test.junit.QuarkusIntegrationTest @QuarkusIntegrationTest}: *

*

    - *
  • {@link com.github.tomakehurst.wiremock.WireMockServer WireMockServer}
  • - *
  • {@link com.github.tomakehurst.wiremock.client.WireMock WireMock}
  • *
  • {@link org.wiremock.grpc.dsl.WireMockGrpcService WireMockGrpcService}
  • *
*

@@ -20,22 +18,6 @@ *
  *     {@code
  * @InjectWireMock
- * WireMockServer wireMockServer;
- *     }
- *   
- *

- *

- *

- *     {@code
- * @InjectWireMock
- * WireMock wireMock;
- *     }
- *   
- *

- *

- *

- *     {@code
- * @InjectWireMock
  * WireMockGrpcService wireMockGrpcServer;
  *     }
  *   
diff --git a/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/LocationsWiremockGrpcServerResource.java b/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/LocationsWiremockGrpcServerResource.java index d6f554810..13e81781f 100644 --- a/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/LocationsWiremockGrpcServerResource.java +++ b/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/LocationsWiremockGrpcServerResource.java @@ -49,22 +49,10 @@ public void stop() { @Override public void inject(TestInjector testInjector) { - var wireMock = new WireMock(getPort()); - - testInjector.injectIntoFields( - wireMock, - new AnnotatedAndMatchesType(InjectGrpcWireMock.class, WireMock.class) - ); - testInjector.injectIntoFields( - new WireMockGrpcService(wireMock, LocationsGrpc.SERVICE_NAME), + new WireMockGrpcService(new WireMock(getPort()), LocationsGrpc.SERVICE_NAME), new AnnotatedAndMatchesType(InjectGrpcWireMock.class, WireMockGrpcService.class) ); - - testInjector.injectIntoFields( - this.wireMockServer, - new AnnotatedAndMatchesType(InjectGrpcWireMock.class, WireMockServer.class) - ); } private int getPort() { diff --git a/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/client/LocationClientTests.java b/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/client/LocationClientTests.java index 66ba36163..85333f0d8 100644 --- a/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/client/LocationClientTests.java +++ b/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/client/LocationClientTests.java @@ -26,7 +26,6 @@ import io.quarkus.sample.superheroes.location.grpc.LocationType; import io.quarkus.sample.superheroes.location.grpc.RandomLocationRequest; -import com.github.tomakehurst.wiremock.WireMockServer; import io.grpc.StatusRuntimeException; import io.smallrye.faulttolerance.api.CircuitBreakerMaintenance; import io.smallrye.faulttolerance.api.CircuitBreakerState; @@ -34,7 +33,7 @@ @QuarkusTest @QuarkusTestResource(value = LocationsWiremockGrpcServerResource.class, restrictToAnnotatedClass = true) -public class LocationClientTests { +class LocationClientTests { private static final String DEFAULT_HELLO_RESPONSE = "Hello locations!"; private static final String DEFAULT_LOCATION_NAME = "Gotham City"; private static final String DEFAULT_LOCATION_DESCRIPTION = "Dark city where Batman lives."; @@ -46,6 +45,7 @@ public class LocationClientTests { .setPicture(DEFAULT_LOCATION_PICTURE) .setType(DEFAULT_LOCATION_TYPE) .build(); + private static final FightLocation DEFAULT_FIGHT_LOCATION = new FightLocation(DEFAULT_LOCATION_NAME, DEFAULT_LOCATION_DESCRIPTION, DEFAULT_LOCATION_PICTURE); @Inject @@ -54,25 +54,22 @@ public class LocationClientTests { @InjectGrpcWireMock WireMockGrpcService wireMockGrpc; - @InjectGrpcWireMock - WireMockServer wireMockServer; - @Inject CircuitBreakerMaintenance circuitBreakerMaintenance; @BeforeEach - public void beforeEach() { - this.wireMockServer.resetAll(); + void beforeEach() { + this.wireMockGrpc.resetAll(); } @AfterEach - public void afterEach() { + void afterEach() { // Reset all circuit breaker counts after each test this.circuitBreakerMaintenance.resetAll(); } @Test - public void helloLocations() { + void helloLocations() { this.wireMockGrpc.stubFor( method("Hello") .willReturn(message(HelloReply.newBuilder().setMessage(DEFAULT_HELLO_RESPONSE))) @@ -89,7 +86,7 @@ public void helloLocations() { } @Test - public void findsRandom() { + void findsRandom() { this.wireMockGrpc.stubFor( method("GetRandomLocation") .willReturn(message(DEFAULT_LOCATION)) @@ -113,7 +110,7 @@ public void findsRandom() { } @Test - public void findRandomRecoversFromNotFound() { + void findRandomRecoversFromNotFound() { this.wireMockGrpc.stubFor( method("GetRandomLocation") .willReturn(Status.NOT_FOUND, "A location was not found") @@ -132,7 +129,7 @@ public void findRandomRecoversFromNotFound() { } @Test - public void findRandomDoesntRecoverFromError() { + void findRandomDoesntRecoverFromError() { this.wireMockGrpc.stubFor( method("GetRandomLocation") .willReturn(Status.UNAVAILABLE, "Service isn't there") diff --git a/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/rest/FightResourceIT.java b/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/rest/FightResourceIT.java index 56c550b35..f43726cb9 100644 --- a/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/rest/FightResourceIT.java +++ b/rest-fights/src/test/java/io/quarkus/sample/superheroes/fight/rest/FightResourceIT.java @@ -206,9 +206,6 @@ class FightResourceIT { @InjectWireMock WireMockServer wireMockServer; - @InjectGrpcWireMock - WireMockServer wireMockGrpcServer; - @InjectGrpcWireMock WireMockGrpcService wireMockGrpc; @@ -237,7 +234,7 @@ static void afterAll() { void beforeEach() { // Reset WireMock this.wireMockServer.resetAll(); - this.wireMockGrpcServer.resetAll(); + this.wireMockGrpc.resetAll(); // Configure Avro Serde for Fight companion.setCommonClientConfig(Map.of(AvroKafkaSerdeConfig.AVRO_DATUM_PROVIDER, ReflectAvroDatumProvider.class.getName())); @@ -1526,7 +1523,7 @@ private void resetLocationCircuitBreakerToClosedState() { } // Reset all the mocks on the GrpcMock - this.wireMockGrpcServer.resetAll(); + this.wireMockGrpc.resetAll(); // Stub successful requests this.wireMockGrpc.stubFor( @@ -1553,7 +1550,7 @@ private void resetLocationCircuitBreakerToClosedState() { this.wireMockGrpc.verify(9, "GetRandomLocation") .withRequestMessage(equalToMessage(RandomLocationRequest.newBuilder())); - this.wireMockGrpcServer.resetAll(); + this.wireMockGrpc.resetAll(); } private void resetNarrationCircuitBreakersToClosedState() {