forked from quarkus-qe/quarkus-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for containerResponseFilter issue
Issue quarkusio/quarkus#31024
- Loading branch information
Showing
5 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus.ts.qe</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
<artifactId>http-rest-client-reactive-vanilla</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Quarkus QE TS: HTTP: Rest Client Reactive Vanilla</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-reactive-jackson</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
30 changes: 30 additions & 0 deletions
30
...ctive-vanilla/src/main/java/io/quarkus/ts/http/restclient/reactive/RestCallerService.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,30 @@ | ||
package io.quarkus.ts.http.restclient.reactive; | ||
|
||
import java.net.URI; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
|
||
import io.quarkus.runtime.Startup; | ||
|
||
/** | ||
* This class is used to reproduce issue https://github.com/quarkusio/quarkus/issues/31024 | ||
* Also requires {@link UselessRestApi} and {@link VersionHeaderFilter} for this | ||
*/ | ||
@Startup | ||
public class RestCallerService { | ||
|
||
@PostConstruct | ||
void init() { | ||
callRest(); | ||
} | ||
|
||
void callRest() { | ||
RestClientBuilder builder = RestClientBuilder.newBuilder()// | ||
.baseUri(URI.create("localhost")); | ||
|
||
// API needs to be created for issue to manifest | ||
UselessRestApi api = builder.build(UselessRestApi.class); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...reactive-vanilla/src/main/java/io/quarkus/ts/http/restclient/reactive/UselessRestApi.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,23 @@ | ||
package io.quarkus.ts.http.restclient.reactive; | ||
|
||
import java.io.Closeable; | ||
import java.util.List; | ||
|
||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
/** | ||
* Useless API, used just for passing type controls in {@link RestCallerService} | ||
*/ | ||
@Path("/useless") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public interface UselessRestApi extends Closeable { | ||
|
||
@GET | ||
@Path("all") | ||
List<String> getAll(); | ||
} |
30 changes: 30 additions & 0 deletions
30
...ive-vanilla/src/main/java/io/quarkus/ts/http/restclient/reactive/VersionHeaderFilter.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,30 @@ | ||
package io.quarkus.ts.http.restclient.reactive; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.ws.rs.container.ContainerRequestContext; | ||
import jakarta.ws.rs.container.ContainerResponseContext; | ||
import jakarta.ws.rs.container.ContainerResponseFilter; | ||
import jakarta.ws.rs.container.PreMatching; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
/** | ||
* Used for {@link RestCallerService} | ||
*/ | ||
@Provider | ||
@PreMatching | ||
@ApplicationScoped | ||
public class VersionHeaderFilter implements ContainerResponseFilter { | ||
@ConfigProperty(name = "quarkus.application.version") | ||
String applicationVersion; | ||
|
||
public VersionHeaderFilter() { | ||
} | ||
|
||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { | ||
responseContext.getHeaders().add("Build-Version", applicationVersion); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...lla/src/test/java/io/quarkus/ts/http/restclient/reactive/VanillaReactiveRestClientIT.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,34 @@ | ||
package io.quarkus.ts.http.restclient.reactive; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
|
||
@QuarkusScenario | ||
public class VanillaReactiveRestClientIT { | ||
private static final String CONTAINER_FILTER_ERROR_TEXT = "CDI: programmatic lookup problem detected"; | ||
|
||
@QuarkusApplication | ||
static RestService app = new RestService(); | ||
|
||
@Test | ||
@Tag("https://github.com/quarkusio/quarkus/issues/31024") | ||
public void restClientContainerFilterTest() { | ||
List<String> logs = app.getLogs(); | ||
|
||
// app produces error log (not stack trace) after startup in its log if issue in not fixed, | ||
// search fox this error text | ||
for (String log : logs) { | ||
if (log.contains(CONTAINER_FILTER_ERROR_TEXT)) { | ||
fail("Detected failure-indicating text in app's log. Issue https://github.com/quarkusio/quarkus/issues/31024is not fixed."); | ||
} | ||
} | ||
} | ||
} |