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.
Merge pull request quarkusio#19776 from manovotn/interceptionComplexTest
Arc - pre-destroy and post construct shouldn't be considered as candidates for around invoke interception
- Loading branch information
Showing
5 changed files
with
157 additions
and
0 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
53 changes: 53 additions & 0 deletions
53
.../java/io/quarkus/arc/test/interceptors/complex/MultipleInterceptionTypesTogetherTest.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,53 @@ | ||
package io.quarkus.arc.test.interceptors.complex; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.InstanceHandle; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
public class MultipleInterceptionTypesTogetherTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(MyBinding.class, SomeBean.class, MyInterceptor.class); | ||
|
||
@Test | ||
public void testInterceptionIsInvokedWhenAppropriate() { | ||
SomeBean.reset(); | ||
MyInterceptor.reset(); | ||
// assert initial state | ||
Assertions.assertEquals(false, SomeBean.postConstructInvoked.get()); | ||
Assertions.assertEquals(false, SomeBean.preDestroyInvoked.get()); | ||
Assertions.assertEquals(false, MyInterceptor.aroundConstructInvoked.get()); | ||
Assertions.assertEquals(false, MyInterceptor.postConstructInvoked.get()); | ||
Assertions.assertEquals(false, MyInterceptor.preDestroyInvoked.get()); | ||
Assertions.assertEquals(false, MyInterceptor.aroundInvokeInvoked.get()); | ||
// create bean instance, no method was invoked so far | ||
InstanceHandle<SomeBean> instance = Arc.container().instance(SomeBean.class); | ||
SomeBean bean = instance.get(); | ||
// assert lifecycle callback were invoked but no around invoke was triggered | ||
Assertions.assertEquals(true, SomeBean.postConstructInvoked.get()); | ||
Assertions.assertEquals(false, SomeBean.preDestroyInvoked.get()); | ||
Assertions.assertEquals(true, MyInterceptor.aroundConstructInvoked.get()); | ||
Assertions.assertEquals(true, MyInterceptor.postConstructInvoked.get()); | ||
Assertions.assertEquals(false, MyInterceptor.preDestroyInvoked.get()); | ||
Assertions.assertEquals(false, MyInterceptor.aroundInvokeInvoked.get()); | ||
// invoke bean method and assert around invoke was triggered | ||
bean.ping(); | ||
Assertions.assertEquals(true, SomeBean.postConstructInvoked.get()); | ||
Assertions.assertEquals(false, SomeBean.preDestroyInvoked.get()); | ||
Assertions.assertEquals(true, MyInterceptor.aroundConstructInvoked.get()); | ||
Assertions.assertEquals(true, MyInterceptor.postConstructInvoked.get()); | ||
Assertions.assertEquals(false, MyInterceptor.preDestroyInvoked.get()); | ||
Assertions.assertEquals(true, MyInterceptor.aroundInvokeInvoked.get()); | ||
// trigger bean destruction and assert lifecycle interceptors were triggered | ||
instance.destroy(); | ||
Assertions.assertEquals(true, SomeBean.postConstructInvoked.get()); | ||
Assertions.assertEquals(true, SomeBean.preDestroyInvoked.get()); | ||
Assertions.assertEquals(true, MyInterceptor.aroundConstructInvoked.get()); | ||
Assertions.assertEquals(true, MyInterceptor.postConstructInvoked.get()); | ||
Assertions.assertEquals(true, MyInterceptor.preDestroyInvoked.get()); | ||
Assertions.assertEquals(true, MyInterceptor.aroundInvokeInvoked.get()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/complex/MyBinding.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,17 @@ | ||
package io.quarkus.arc.test.interceptors.complex; | ||
|
||
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 javax.interceptor.InterceptorBinding; | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface MyBinding { | ||
} |
50 changes: 50 additions & 0 deletions
50
...jects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/complex/MyInterceptor.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,50 @@ | ||
package io.quarkus.arc.test.interceptors.complex; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.annotation.Priority; | ||
import javax.interceptor.AroundConstruct; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
@Interceptor | ||
@Priority(1) | ||
@MyBinding | ||
public class MyInterceptor { | ||
|
||
public static AtomicBoolean preDestroyInvoked = new AtomicBoolean(false); | ||
public static AtomicBoolean postConstructInvoked = new AtomicBoolean(false); | ||
public static AtomicBoolean aroundConstructInvoked = new AtomicBoolean(false); | ||
public static AtomicBoolean aroundInvokeInvoked = new AtomicBoolean(false); | ||
|
||
@PreDestroy | ||
public void preDestroy(InvocationContext ic) { | ||
preDestroyInvoked.set(true); | ||
} | ||
|
||
@PostConstruct | ||
public void postConstruct(InvocationContext ic) { | ||
postConstructInvoked.set(true); | ||
} | ||
|
||
@AroundConstruct | ||
public void aroundConstruct(InvocationContext ic) throws Exception { | ||
aroundConstructInvoked.set(true); | ||
ic.proceed(); | ||
} | ||
|
||
@AroundInvoke | ||
public Object aroundInvoke(InvocationContext ic) throws Exception { | ||
aroundInvokeInvoked.set(true); | ||
return ic.proceed(); | ||
} | ||
|
||
public static void reset() { | ||
preDestroyInvoked.set(false); | ||
postConstructInvoked.set(false); | ||
aroundConstructInvoked.set(false); | ||
aroundInvokeInvoked.set(false); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...t-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/complex/SomeBean.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,33 @@ | ||
package io.quarkus.arc.test.interceptors.complex; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
@MyBinding | ||
public class SomeBean { | ||
|
||
public static AtomicBoolean preDestroyInvoked = new AtomicBoolean(false); | ||
public static AtomicBoolean postConstructInvoked = new AtomicBoolean(false); | ||
|
||
@PreDestroy | ||
public void preDestroy() { | ||
preDestroyInvoked.set(true); | ||
} | ||
|
||
@PostConstruct | ||
public void postConstruct() { | ||
postConstructInvoked.set(true); | ||
} | ||
|
||
public void ping() { | ||
|
||
} | ||
|
||
public static void reset() { | ||
preDestroyInvoked.set(false); | ||
postConstructInvoked.set(false); | ||
} | ||
} |