-
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 #34003 from mkouba/issue-34001
ArC: fix InvocationContext#setParameters()
- Loading branch information
Showing
6 changed files
with
103 additions
and
11 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
24 changes: 24 additions & 0 deletions
24
.../test/java/io/quarkus/arc/test/interceptors/parameters/setter/FirstSetterInterceptor.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,24 @@ | ||
package io.quarkus.arc.test.interceptors.parameters.setter; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
@Setter | ||
@Priority(1) | ||
@Interceptor | ||
public class FirstSetterInterceptor { | ||
|
||
@AroundInvoke | ||
Object fooAroundInvoke(InvocationContext ctx) throws Exception { | ||
assertEquals("bar", ctx.getParameters()[0]); | ||
ctx.setParameters(new String[] { "first" }); | ||
Object ret = ctx.proceed(); | ||
// getParameters() should return the value set by the interceptor with higher priority | ||
assertEquals("second", ctx.getParameters()[0]); | ||
return ret; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...test/java/io/quarkus/arc/test/interceptors/parameters/setter/SecondSetterInterceptor.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,22 @@ | ||
package io.quarkus.arc.test.interceptors.parameters.setter; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
@Setter | ||
@Priority(2) | ||
@Interceptor | ||
public class SecondSetterInterceptor { | ||
|
||
@AroundInvoke | ||
Object fooAroundInvoke(InvocationContext ctx) throws Exception { | ||
assertEquals("first", ctx.getParameters()[0]); | ||
ctx.setParameters(new String[] { "second" }); | ||
assertEquals("second", ctx.getParameters()[0]); | ||
return ctx.proceed(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/setter/SetParamsTest.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,21 @@ | ||
package io.quarkus.arc.test.interceptors.parameters.setter; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class SetParamsTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(TheBean.class, Setter.class, FirstSetterInterceptor.class, | ||
SecondSetterInterceptor.class); | ||
|
||
@Test | ||
public void testSetParameters() { | ||
assertEquals("second", Arc.container().instance(TheBean.class).get().foo("bar")); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ts/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/setter/Setter.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,19 @@ | ||
package io.quarkus.arc.test.interceptors.parameters.setter; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.interceptor.InterceptorBinding; | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface Setter { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...s/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/setter/TheBean.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,13 @@ | ||
package io.quarkus.arc.test.interceptors.parameters.setter; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
public class TheBean { | ||
|
||
@Setter | ||
String foo(String val) { | ||
return val; | ||
} | ||
|
||
} |