Skip to content

Commit

Permalink
Add test coverage for containerResponseFilter issue (#1616)
Browse files Browse the repository at this point in the history
* Add test coverage for containerResponseFilter issue

Issue quarkusio/quarkus#31024
  • Loading branch information
mocenas authored Jan 19, 2024
1 parent 7de5225 commit 09243b3
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ This module will setup a very minimal configuration (only `quarkus-resteasy`) an
Reactive equivalent of the http/rest-client module.
Exclusions: XML test. Reason: https://quarkus.io/blog/resteasy-reactive/#what-jax-rs-features-are-missing

### `http/rest-client-reactive-vanilla`
Verifies Rest Client usage, while no request are going only internally on the server.
This module requires to not have any resteasy dependency, for an issue to be reproducible.

### `http/hibernate-validator`
Verifies HTTP endpoints validation using `quarkus-hibernate-validator` works correctly in Resteasy Classic and Resteasy Reactive.
This module will setup a simple endpoint and will validate the right message format is set when there are validation errors.
Expand Down
19 changes: 19 additions & 0 deletions http/rest-client-reactive-vanilla/pom.xml
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.quarkus.ts.http.restclient.vanilla;

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 initRestApi() {
RestClientBuilder builder = RestClientBuilder.newBuilder()//
.baseUri(URI.create("localhost"));

// API needs to be created for issue to manifest
UselessRestApi api = builder.build(UselessRestApi.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.ts.http.restclient.vanilla;

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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.ts.http.restclient.vanilla;

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;

/**
* Used for {@link RestCallerService}
* Does nothing we just need quarkus to have a possibility to use a ContainerResponseFilter
*/
@Provider
@PreMatching
@ApplicationScoped
public class VersionHeaderFilter implements ContainerResponseFilter {
public VersionHeaderFilter() {
}

public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
// do nothing. implements this method just because ContainerResponseFilter requires it
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.ts.http.restclient.vanilla;

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 for 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/31024 might not be fixed.");
}
}
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@
<module>http/reactive-routes</module>
<module>http/rest-client</module>
<module>http/rest-client-reactive</module>
<module>http/rest-client-reactive-vanilla</module>
<module>http/servlet-undertow</module>
<module>http/vertx-web-client</module>
<module>http/vertx-web-validation</module>
Expand Down

0 comments on commit 09243b3

Please sign in to comment.