forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
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 producer methods and synthetic beans
- Loading branch information
Showing
46 changed files
with
3,612 additions
and
55 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
74 changes: 74 additions & 0 deletions
74
.../java/io/quarkus/arc/test/interceptor/producer/ProducerWithFinalInterceptedClassTest.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,74 @@ | ||
package io.quarkus.arc.test.interceptor.producer; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.Produces; | ||
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.arc.Arc; | ||
import io.quarkus.arc.InterceptionProxy; | ||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ProducerWithFinalInterceptedClassTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar | ||
.addClasses(MyBinding.class, MyInterceptor.class, MyNonbean.class, MyProducer.class)); | ||
|
||
@Test | ||
public void test() { | ||
MyNonbean nonbean = Arc.container().instance(MyNonbean.class).get(); | ||
assertEquals("intercepted: hello1", nonbean.hello1()); | ||
assertEquals("hello2", nonbean.hello2()); | ||
} | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR }) | ||
@InterceptorBinding | ||
@interface MyBinding { | ||
} | ||
|
||
@MyBinding | ||
@Priority(1) | ||
@Interceptor | ||
static class MyInterceptor { | ||
@AroundInvoke | ||
Object intercept(InvocationContext ctx) throws Exception { | ||
return "intercepted: " + ctx.proceed(); | ||
} | ||
} | ||
|
||
static final class MyNonbean { | ||
@MyBinding | ||
String hello1() { | ||
return "hello1"; | ||
} | ||
|
||
String hello2() { | ||
return "hello2"; | ||
} | ||
} | ||
|
||
@Dependent | ||
static class MyProducer { | ||
@Produces | ||
@Unremovable | ||
MyNonbean produce(InterceptionProxy<MyNonbean> proxy) { | ||
return proxy.create(new MyNonbean()); | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...java/io/quarkus/arc/test/interceptor/producer/ProducerWithFinalInterceptedMethodTest.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,74 @@ | ||
package io.quarkus.arc.test.interceptor.producer; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.Produces; | ||
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.arc.Arc; | ||
import io.quarkus.arc.InterceptionProxy; | ||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ProducerWithFinalInterceptedMethodTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar | ||
.addClasses(MyBinding.class, MyInterceptor.class, MyNonbean.class, MyProducer.class)); | ||
|
||
@Test | ||
public void test() { | ||
MyNonbean nonbean = Arc.container().instance(MyNonbean.class).get(); | ||
assertEquals("intercepted: hello1", nonbean.hello1()); | ||
assertEquals("hello2", nonbean.hello2()); | ||
} | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR }) | ||
@InterceptorBinding | ||
@interface MyBinding { | ||
} | ||
|
||
@MyBinding | ||
@Priority(1) | ||
@Interceptor | ||
static class MyInterceptor { | ||
@AroundInvoke | ||
Object intercept(InvocationContext ctx) throws Exception { | ||
return "intercepted: " + ctx.proceed(); | ||
} | ||
} | ||
|
||
static class MyNonbean { | ||
@MyBinding | ||
final String hello1() { | ||
return "hello1"; | ||
} | ||
|
||
final String hello2() { | ||
return "hello2"; | ||
} | ||
} | ||
|
||
@Dependent | ||
static class MyProducer { | ||
@Produces | ||
@Unremovable | ||
MyNonbean produce(InterceptionProxy<MyNonbean> proxy) { | ||
return proxy.create(new MyNonbean()); | ||
} | ||
} | ||
} |
Oops, something went wrong.