-
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.
feat: Implement skipping of not Rest parameters indexing processing u…
…sing new build item [The implementation brings a new build item that extension can produce in order to allow Rest resource methods with parameters that are not related to Rest]
- Loading branch information
Showing
6 changed files
with
147 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
60 changes: 60 additions & 0 deletions
60
.../quarkus/resteasy/reactive/server/test/resource/basic/AllowNotResteasyParametersTest.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,60 @@ | ||
package io.quarkus.resteasy.reactive.server.test.resource.basic; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.builder.BuildChainBuilder; | ||
import io.quarkus.builder.BuildContext; | ||
import io.quarkus.builder.BuildStep; | ||
import io.quarkus.resteasy.reactive.server.spi.AllowNotRestParametersBuildItem; | ||
import io.quarkus.resteasy.reactive.server.test.resource.basic.resource.MixedParameterResource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* @tpSubChapter Resources | ||
* @tpChapter Integration tests | ||
* @tpTestCaseDetails Test resources with not all method parameters related to RESTEasy. | ||
*/ | ||
@DisplayName("Allow Not RESTEasy Method Parameters") | ||
public class AllowNotResteasyParametersTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest quarkusUnitTest = new QuarkusUnitTest() | ||
.addBuildChainCustomizer(new Consumer<BuildChainBuilder>() { | ||
@Override | ||
public void accept(BuildChainBuilder buildChainBuilder) { | ||
buildChainBuilder.addBuildStep(new BuildStep() { | ||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(new AllowNotRestParametersBuildItem()); | ||
} | ||
}).produces(AllowNotRestParametersBuildItem.class).build(); | ||
} | ||
}) | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(MixedParameterResource.class)); | ||
|
||
@Test | ||
@DisplayName("Test Resource Method with one param not related to RESTEasy") | ||
public void shouldOkEvenNotResteasyParameterPresence() { | ||
given() | ||
.body("value") | ||
.post("/" + MixedParameterResource.class.getSimpleName() + "/mixed?foo=bar") | ||
.then().statusCode(200).body(is("bar.value")); | ||
} | ||
|
||
@Test | ||
@DisplayName("Test Resource Method with only one param not related to RESTEasy") | ||
public void shouldOkEvenNotResteasySingleParameterPresence() { | ||
given() | ||
.body("value") | ||
.get("/" + MixedParameterResource.class.getSimpleName() + "/single") | ||
.then().statusCode(200); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...quarkus/resteasy/reactive/server/test/resource/basic/resource/MixedParameterResource.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.resource.basic.resource; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.QueryParam; | ||
|
||
@Path("/MixedParameterResource") | ||
public class MixedParameterResource { | ||
|
||
@POST | ||
@Path("/mixed") | ||
public String mixedParam(@OtherAnnotation MyOtherObject otherObject, @QueryParam("foo") String query, String body) { | ||
return query.concat(".").concat(body); | ||
} | ||
|
||
@GET | ||
@Path("/single") | ||
public String singleParam(@OtherAnnotation MyOtherObject otherObject) { | ||
return "ok"; | ||
} | ||
|
||
public static class MyOtherObject { | ||
String param; | ||
|
||
public String getParam() { | ||
return param; | ||
} | ||
|
||
public void setParam(String param) { | ||
this.param = param; | ||
} | ||
} | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.FIELD, ElementType.PARAMETER }) | ||
public @interface OtherAnnotation { | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...rc/main/java/io/quarkus/resteasy/reactive/server/spi/AllowNotRestParametersBuildItem.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,11 @@ | ||
package io.quarkus.resteasy.reactive.server.spi; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* A build item which extensions can generate when they want to allow RESTEasy Reactive methods | ||
* with parameters that are annotated with not REST annotations. This allows RESTEasy Reactive to let mixed parameters coexist | ||
* within resource methods signature | ||
*/ | ||
public final class AllowNotRestParametersBuildItem extends SimpleBuildItem { | ||
} |
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