-
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 #15633 from mkouba/issue-1794
ArC - enable implementing all types of interception with single method
- Loading branch information
Showing
5 changed files
with
105 additions
and
25 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
59 changes: 59 additions & 0 deletions
59
...rc/test/java/io/quarkus/arc/test/interceptors/mixed/BusinessLifecycleInterceptorTest.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,59 @@ | ||
package io.quarkus.arc.test.interceptors.mixed; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.InstanceHandle; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.annotation.Priority; | ||
import javax.enterprise.context.Dependent; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
public class BusinessLifecycleInterceptorTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(MyTransactional.class, SimpleBean.class, | ||
SimpleInterceptor.class); | ||
|
||
public static final AtomicInteger INTERCEPTORS_CALLED = new AtomicInteger(); | ||
|
||
@Test | ||
public void testInterception() { | ||
InstanceHandle<SimpleBean> instance = Arc.container().instance(SimpleBean.class); | ||
SimpleBean simpleBean = instance.get(); | ||
assertEquals(1, INTERCEPTORS_CALLED.get()); | ||
assertEquals(2, simpleBean.ping()); | ||
assertEquals(2, INTERCEPTORS_CALLED.get()); | ||
} | ||
|
||
@Dependent | ||
@MyTransactional | ||
static class SimpleBean { | ||
|
||
int ping() { | ||
return 0; | ||
} | ||
|
||
} | ||
|
||
@Priority(1) | ||
@MyTransactional | ||
@Interceptor | ||
public static class SimpleInterceptor { | ||
|
||
@PostConstruct | ||
@PreDestroy | ||
@AroundInvoke | ||
Object intercept(InvocationContext ctx) throws Exception { | ||
return INTERCEPTORS_CALLED.incrementAndGet(); | ||
} | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...jects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/mixed/MyTransactional.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,16 @@ | ||
package io.quarkus.arc.test.interceptors.mixed; | ||
|
||
import static java.lang.annotation.ElementType.CONSTRUCTOR; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.interceptor.InterceptorBinding; | ||
|
||
@Target({ TYPE, CONSTRUCTOR }) | ||
@Retention(RUNTIME) | ||
@InterceptorBinding | ||
public @interface MyTransactional { | ||
|
||
} |