-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for case where RestClient uses @url and observability features
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
...ent/src/test/java/io/quarkus/micrometer/deployment/binder/RestClientUriParameterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package io.quarkus.micrometer.deployment.binder; | ||
Check failure on line 1 in extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/RestClientUriParameterTest.java quarkus-bot / Build summary for 0ced4f18479c025a59ee8d0250d6d95d1fafed81JVM Tests - JDK 17 Windows
Raw output
|
||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.micrometer.core.instrument.Metrics; | ||
import io.micrometer.core.instrument.Timer; | ||
import io.micrometer.core.instrument.search.Search; | ||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
import io.quarkus.rest.client.reactive.Url; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class RestClientUriParameterTest { | ||
|
||
final static SimpleMeterRegistry registry = new SimpleMeterRegistry(); | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot( | ||
jar -> jar.addClasses(Resource.class, Client.class)) | ||
.overrideConfigKey("quarkus.rest-client.\"client\".url", "http://does-not-exist.io"); | ||
|
||
@RestClient | ||
Client client; | ||
|
||
@ConfigProperty(name = "quarkus.http.test-port") | ||
Integer testPort; | ||
|
||
@BeforeAll | ||
static void setRegistry() { | ||
Metrics.addRegistry(registry); | ||
} | ||
|
||
@AfterAll() | ||
static void removeRegistry() { | ||
Metrics.removeRegistry(registry); | ||
} | ||
|
||
@Test | ||
public void testOverride() { | ||
String result = client.getById("http://localhost:" + testPort, "bar"); | ||
assertEquals("bar", result); | ||
|
||
Timer clientTimer = registry.find("http.client.requests").timer(); | ||
assertNotNull(clientTimer); | ||
assertEquals("/example/{id}", clientTimer.getId().getTag("uri")); | ||
} | ||
|
||
private Search getMeter(String name) { | ||
return registry.find(name); | ||
} | ||
|
||
@Path("/example") | ||
@RegisterRestClient(baseUri = "http://dummy") | ||
public interface Client { | ||
|
||
@GET | ||
@Path("/{id}") | ||
String getById(@Url String baseUri, @PathParam("id") String id); | ||
} | ||
|
||
@Path("/example") | ||
public static class Resource { | ||
|
||
@RestClient | ||
Client client; | ||
|
||
@GET | ||
@Path("/{id}") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String example() { | ||
return "bar"; | ||
} | ||
|
||
@GET | ||
@Path("/call") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String call() { | ||
return client.getById("http://localhost:8080", "1"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters