forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly handle REST field injection
This is done by converting the Resource class to @RequestScoped when possible and failing the build when it's not
- Loading branch information
Showing
14 changed files
with
514 additions
and
3 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
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
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
44 changes: 44 additions & 0 deletions
44
.../java/io/quarkus/resteasy/reactive/server/test/injection/FormFieldSingletonScopeTest.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,44 @@ | ||
package io.quarkus.resteasy.reactive.server.test.injection; | ||
|
||
import jakarta.enterprise.inject.spi.DeploymentException; | ||
import jakarta.inject.Singleton; | ||
import jakarta.ws.rs.FormParam; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class FormFieldSingletonScopeTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar.addClasses(Resource.class)) | ||
.assertException(t -> { | ||
org.junit.jupiter.api.Assertions.assertEquals(DeploymentException.class, t.getClass()); | ||
}); | ||
|
||
@Test | ||
public void test() { | ||
Assertions.fail("should never have run"); | ||
} | ||
|
||
@Path("/test") | ||
@Singleton | ||
public static class Resource { | ||
|
||
@FormParam("foo") | ||
String foo; | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
return "foo: " + foo; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...us/resteasy/reactive/server/test/injection/HeaderFieldInSuperClassDependentScopeTest.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,50 @@ | ||
package io.quarkus.resteasy.reactive.server.test.injection; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.spi.DeploymentException; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.HeaderParam; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.jboss.resteasy.reactive.RestHeader; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class HeaderFieldInSuperClassDependentScopeTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar.addClasses(AbstractResource.class, Resource.class)) | ||
.assertException(t -> { | ||
org.junit.jupiter.api.Assertions.assertEquals(DeploymentException.class, t.getClass()); | ||
}); | ||
|
||
@Test | ||
public void test() { | ||
Assertions.fail("should never have run"); | ||
} | ||
|
||
@Path("/test") | ||
@Dependent | ||
public static class Resource extends AbstractResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
return "foo: " + foo + ", bar: " + bar; | ||
} | ||
} | ||
|
||
public static class AbstractResource { | ||
@HeaderParam("foo") | ||
String foo; | ||
|
||
@RestHeader | ||
String bar; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...o/quarkus/resteasy/reactive/server/test/injection/HeaderFieldInSuperClassNoScopeTest.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,66 @@ | ||
package io.quarkus.resteasy.reactive.server.test.injection; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.RestAssured.when; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.HeaderParam; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.jboss.resteasy.reactive.RestHeader; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class HeaderFieldInSuperClassNoScopeTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar.addClasses(AbstractResource.class, AbstractAbstractResource.class, Resource.class)); | ||
|
||
@Test | ||
public void test() { | ||
given() | ||
.header("foo", "f") | ||
.header("bar", "b") | ||
.when() | ||
.get("/test") | ||
.then() | ||
.statusCode(200) | ||
.body(is("foo: f, bar: b")); | ||
|
||
when() | ||
.get("/test") | ||
.then() | ||
.statusCode(200) | ||
.body(is("foo: null, bar: null")); | ||
} | ||
|
||
@Path("/test") | ||
@RequestScoped | ||
public static class Resource extends AbstractAbstractResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
return "foo: " + foo + ", bar: " + bar; | ||
} | ||
} | ||
|
||
public static class AbstractResource { | ||
@HeaderParam("foo") | ||
String foo; | ||
|
||
@RestHeader | ||
String bar; | ||
} | ||
|
||
public static class AbstractAbstractResource extends AbstractResource { | ||
|
||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...rkus/resteasy/reactive/server/test/injection/HeaderFieldInSuperClassRequestScopeTest.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,62 @@ | ||
package io.quarkus.resteasy.reactive.server.test.injection; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.RestAssured.when; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.HeaderParam; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.jboss.resteasy.reactive.RestHeader; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class HeaderFieldInSuperClassRequestScopeTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar.addClasses(AbstractResource.class, Resource.class)); | ||
|
||
@Test | ||
public void test() { | ||
given() | ||
.header("foo", "f") | ||
.header("bar", "b") | ||
.when() | ||
.get("/test") | ||
.then() | ||
.statusCode(200) | ||
.body(is("foo: f, bar: b")); | ||
|
||
when() | ||
.get("/test") | ||
.then() | ||
.statusCode(200) | ||
.body(is("foo: null, bar: null")); | ||
} | ||
|
||
@Path("/test") | ||
@RequestScoped | ||
public static class Resource extends AbstractResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
return "foo: " + foo + ", bar: " + bar; | ||
} | ||
} | ||
|
||
public static class AbstractResource { | ||
@HeaderParam("foo") | ||
String foo; | ||
|
||
@RestHeader | ||
String bar; | ||
} | ||
} |
Oops, something went wrong.