-
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 the ability to inject ContainerRequestContext via CDI
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
.../io/quarkus/resteasy/reactive/server/test/resource/basic/ContainerRequestContextTest.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,65 @@ | ||
package io.quarkus.resteasy.reactive.server.test.resource.basic; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import java.io.IOException; | ||
import java.util.function.Supplier; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.container.ContainerRequestFilter; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
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 ContainerRequestContextTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClass(HelloResource.class); | ||
} | ||
}); | ||
|
||
@Test | ||
public void helloWorldTest() { | ||
RestAssured.get("/hello") | ||
.then() | ||
.body(equalTo("hello foo")); | ||
} | ||
|
||
@Path("/hello") | ||
public static class HelloResource { | ||
|
||
private final ContainerRequestContext containerRequestContext; | ||
|
||
public HelloResource(ContainerRequestContext containerRequestContext) { | ||
this.containerRequestContext = containerRequestContext; | ||
} | ||
|
||
@GET | ||
public String hello() { | ||
return "hello " + containerRequestContext.getProperty("name"); | ||
} | ||
|
||
} | ||
|
||
@Provider | ||
public static class TestFilter implements ContainerRequestFilter { | ||
|
||
@Override | ||
public void filter(ContainerRequestContext context) throws IOException { | ||
context.setProperty("name", "foo"); | ||
} | ||
} | ||
} |
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