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#7933 from manovotn/multipleBindings
Fix interceptor resolution process for multiple bindings, add automated test
- Loading branch information
Showing
8 changed files
with
112 additions
and
6 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
17 changes: 17 additions & 0 deletions
17
...rc/tests/src/test/java/io/quarkus/arc/test/interceptors/bindings/multiple/BarBinding.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.bindings.multiple; | ||
|
||
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; | ||
|
||
@InterceptorBinding | ||
@Documented | ||
@Retention(RUNTIME) | ||
@Target({ METHOD, TYPE }) | ||
public @interface BarBinding { | ||
} |
17 changes: 17 additions & 0 deletions
17
...rc/tests/src/test/java/io/quarkus/arc/test/interceptors/bindings/multiple/FooBinding.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.bindings.multiple; | ||
|
||
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; | ||
|
||
@InterceptorBinding | ||
@Documented | ||
@Retention(RUNTIME) | ||
@Target({ METHOD, TYPE }) | ||
public @interface FooBinding { | ||
} |
28 changes: 28 additions & 0 deletions
28
...rc/test/java/io/quarkus/arc/test/interceptors/bindings/multiple/MultipleBindingsTest.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,28 @@ | ||
package io.quarkus.arc.test.interceptors.bindings.multiple; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
/** | ||
* Tests behavior the case where there is more then one binding specified on an interceptor. | ||
*/ | ||
public class MultipleBindingsTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(BarBinding.class, FooBinding.class, | ||
MyBean.class, MyInterceptor.class, MyOtherBean.class); | ||
|
||
@Test | ||
public void testInterception() { | ||
assertEquals(0, MyInterceptor.TIMES_INVOKED); | ||
// bean only has one binding, the interceptor should not get triggered | ||
Arc.container().instance(MyBean.class).get().foo(); | ||
assertEquals(0, MyInterceptor.TIMES_INVOKED); | ||
// bean has both bindings that the interceptor has | ||
Arc.container().instance(MyOtherBean.class).get().foo(); | ||
assertEquals(1, MyInterceptor.TIMES_INVOKED); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ts/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/bindings/multiple/MyBean.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,12 @@ | ||
package io.quarkus.arc.test.interceptors.bindings.multiple; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
@BarBinding | ||
public class MyBean { | ||
|
||
public String foo() { | ||
return "foo"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...tests/src/test/java/io/quarkus/arc/test/interceptors/bindings/multiple/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,21 @@ | ||
package io.quarkus.arc.test.interceptors.bindings.multiple; | ||
|
||
import javax.annotation.Priority; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
@Interceptor | ||
@Priority(1) | ||
@BarBinding | ||
@FooBinding | ||
public class MyInterceptor { | ||
|
||
public static int TIMES_INVOKED = 0; | ||
|
||
@AroundInvoke | ||
public Object doAround(InvocationContext context) throws Exception { | ||
TIMES_INVOKED++; | ||
return context.proceed(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...c/tests/src/test/java/io/quarkus/arc/test/interceptors/bindings/multiple/MyOtherBean.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.bindings.multiple; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
@FooBinding | ||
@BarBinding | ||
public class MyOtherBean { | ||
|
||
public String foo() { | ||
return "anotherFoo"; | ||
} | ||
} |
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