Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interceptor resolution process for multiple bindings, add automated test #7933

Merged
merged 1 commit into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public List<InterceptorInfo> resolve(InterceptionType interceptionType, Set<Anno
if (!interceptor.intercepts(interceptionType)) {
continue;
}
boolean matches = false;
boolean matches = true;
for (AnnotationInstance interceptorBinding : interceptor.getBindings()) {
if (hasInterceptorBinding(bindings, interceptorBinding)) {
matches = true;
if (!hasInterceptorBinding(bindings, interceptorBinding)) {
matches = false;
break;
}
}
Expand Down
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 {
}
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 {
}
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);
}
}
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";
}
}
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();
}
}
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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

@Interceptor
@Priority(2)
@CounterBinding
@AnotherAnnotation // this is a transitive binding which brings in CounterBinding + SomeBinding as well

@SomeAnnotation // this is transitive binding, it also brings in @CounterBinding
public class TransitiveCounterInterceptor {

public static Integer timesInvoked = 0;
Expand Down