-
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.
Merge pull request #33793 from geoand/rr-context-unremovable
Remove the need for @Unremoveable producer with custom @context types
- Loading branch information
Showing
2 changed files
with
114 additions
and
4 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
79 changes: 79 additions & 0 deletions
79
.../src/test/java/io/quarkus/resteasy/reactive/server/test/simple/CustomContextTypeTest.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,79 @@ | ||
package io.quarkus.resteasy.reactive.server.test.simple; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.inject.Singleton; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class CustomContextTypeTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(TestResource.class, CustomType.class, CustomTypeProducer.class); | ||
} | ||
}); | ||
|
||
@Test | ||
public void firstTest() { | ||
RestAssured.given().headers("foo", "bar") | ||
.get("/test") | ||
.then().statusCode(200).body(is("bar")); | ||
} | ||
|
||
@Test | ||
public void secondTest() { | ||
RestAssured.given().headers("foo", "baz") | ||
.get("/test") | ||
.then().statusCode(200).body(is("baz")); | ||
} | ||
|
||
@Path("/test") | ||
public static class TestResource { | ||
|
||
@GET | ||
public String get(@Context CustomType customType) { | ||
return customType.getValue(); | ||
} | ||
} | ||
|
||
public static class CustomType { | ||
private final String value; | ||
|
||
public CustomType(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} | ||
|
||
@Singleton | ||
public static class CustomTypeProducer { | ||
|
||
@Produces | ||
@RequestScoped | ||
public CustomType customType(HttpHeaders headers) { | ||
return new CustomType(headers.getHeaderString("foo")); | ||
} | ||
} | ||
} |