-
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.
ArC - support interception of static methods with repeatable bindings
- related to #32786
- Loading branch information
Showing
4 changed files
with
115 additions
and
10 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
85 changes: 85 additions & 0 deletions
85
.../java/io/quarkus/arc/test/interceptor/staticmethods/RepeatingBindingStaticMethodTest.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,85 @@ | ||
package io.quarkus.arc.test.interceptor.staticmethods; | ||
|
||
import static java.lang.annotation.ElementType.CONSTRUCTOR; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.lang.annotation.Repeatable; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InterceptorBinding; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class RepeatingBindingStaticMethodTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addClasses(InterceptMe.class, SimpleBean.class, InterceptMeAlpha.class, InterceptMeBravo.class)); | ||
|
||
@Test | ||
public void testInterceptor() { | ||
assertEquals("a/b/PONG/b/a", SimpleBean.ping("pong")); | ||
} | ||
|
||
public static class SimpleBean { | ||
|
||
@InterceptMe("alpha") | ||
@InterceptMe("bravo") | ||
public static String ping(String val) { | ||
return val.toUpperCase(); | ||
} | ||
} | ||
|
||
@Priority(1) | ||
@Interceptor | ||
@InterceptMe("alpha") | ||
static class InterceptMeAlpha { | ||
|
||
@AroundInvoke | ||
Object aroundInvoke(InvocationContext ctx) throws Exception { | ||
return "a/" + ctx.proceed() + "/a"; | ||
} | ||
|
||
} | ||
|
||
@Priority(2) | ||
@Interceptor | ||
@InterceptMe("bravo") | ||
static class InterceptMeBravo { | ||
|
||
@AroundInvoke | ||
Object aroundInvoke(InvocationContext ctx) throws Exception { | ||
return "b/" + ctx.proceed() + "/b"; | ||
} | ||
|
||
} | ||
|
||
@Repeatable(InterceptMe.List.class) | ||
@InterceptorBinding | ||
@Target({ TYPE, METHOD, CONSTRUCTOR }) | ||
@Retention(RUNTIME) | ||
@interface InterceptMe { | ||
|
||
String value(); | ||
|
||
@Target({ TYPE, METHOD, CONSTRUCTOR }) | ||
@Retention(RUNTIME) | ||
@interface List { | ||
InterceptMe[] value(); | ||
} | ||
|
||
} | ||
|
||
} |
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