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

Add tests for InvocationContext.getInterceptorBindings() #479

Merged
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
@@ -0,0 +1,22 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.interceptor.InterceptorBinding;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD, CONSTRUCTOR })
@Retention(RUNTIME)
public @interface AroundConstructBinding1 {
class Literal extends AnnotationLiteral<AroundConstructBinding1> implements AroundConstructBinding1 {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.interceptor.InterceptorBinding;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD, CONSTRUCTOR })
@Retention(RUNTIME)
public @interface AroundConstructBinding2 {
class Literal extends AnnotationLiteral<AroundConstructBinding2> implements AroundConstructBinding2 {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.annotation.Priority;
import jakarta.interceptor.AroundConstruct;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;

import java.lang.annotation.Annotation;
import java.util.Set;

@Interceptor
@AroundConstructBinding1
@Priority(100)
public class AroundConstructInterceptor1 {
private static Set<Annotation> allBindings;

@AroundConstruct
public Object intercept(InvocationContext ctx) throws Exception {
allBindings = ctx.getInterceptorBindings();
return ctx.proceed();
}

public static Set<Annotation> getAllBindings() {
return allBindings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.annotation.Priority;
import jakarta.interceptor.AroundConstruct;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;

import java.lang.annotation.Annotation;
import java.util.Set;

@Interceptor
@AroundConstructBinding2
@Priority(200)
public class AroundConstructInterceptor2 {
private static Set<Annotation> allBindings;

@AroundConstruct
public Object intercept(InvocationContext ctx) throws Exception {
allBindings = ctx.getInterceptorBindings();
return ctx.proceed();
}

public static Set<Annotation> getAllBindings() {
return allBindings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.interceptor.InterceptorBinding;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
public @interface Binding11 {
class Literal extends AnnotationLiteral<Binding11> implements Binding11 {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.interceptor.InterceptorBinding;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
public @interface Binding12 {
class Literal extends AnnotationLiteral<Binding12> implements Binding12 {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.interceptor.InterceptorBinding;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
public @interface Binding13 {
String value();

class Literal extends AnnotationLiteral<Binding13> implements Binding13 {
private final String value;

public Literal(String value) {
this.value = value;
}

@Override
public String value() {
return value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.enterprise.util.Nonbinding;
import jakarta.interceptor.InterceptorBinding;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
public @interface Binding14 {
@Nonbinding
String value();

class Literal extends AnnotationLiteral<Binding14> implements Binding14 {
private final String value;

public Literal(String value) {
this.value = value;
}

@Override
public String value() {
return value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;

@Interceptor
@Binding11
@Priority(1100)
public class Interceptor11 {
@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
return ctx.proceed();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;

import java.lang.annotation.Annotation;
import java.util.Set;

@Interceptor
@Binding12
@Priority(1200)
public class Interceptor12 {
private static Set<Annotation> allBindings;

private static Set<Binding12> binding12s; // must be non-empty
private static Binding12 binding12; // must be non-null

private static Set<Binding5> binding5s; // must be empty
private static Binding6 binding6; // must be null

@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
allBindings = ctx.getInterceptorBindings();
binding12s = ctx.getInterceptorBindings(Binding12.class);
binding12 = ctx.getInterceptorBinding(Binding12.class);
binding5s = ctx.getInterceptorBindings(Binding5.class);
binding6 = ctx.getInterceptorBinding(Binding6.class);
return ctx.proceed();
}

public static Set<Annotation> getAllBindings() {
return allBindings;
}

public static Set<Binding12> getBinding12s() {
return binding12s;
}

public static Binding12 getBinding12() {
return binding12;
}

public static Set<Binding5> getBinding5s() {
return binding5s;
}

public static Binding6 getBinding6() {
return binding6;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;

@Interceptor
@Binding13("ok")
@Priority(1300)
public class Interceptor13 {
@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
return ctx.proceed();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;

@Interceptor
@Binding14("")
@Priority(1400)
public class Interceptor14 {
@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
return ctx.proceed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.jboss.cdi.tck.interceptors.InterceptorsSections.INVOCATIONCONTEXT;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;

Expand All @@ -31,13 +32,15 @@
import org.jboss.test.audit.annotations.SpecVersion;
import org.testng.annotations.Test;

import java.util.Set;

/**
* Tests for the InvocationContext implementation
*
* @author Jozef Hartinger
*
*/
@SpecVersion(spec = "interceptors", version = "1.2")
@SpecVersion(spec = "interceptors", version = "2.2")
public class InvocationContextTest extends AbstractTest {

@Deployment
Expand Down Expand Up @@ -122,4 +125,24 @@ public void testBusinessMethodNotCalledWithoutProceedInvocation() {
assertEquals(getContextualReference(SimpleBean.class).echo("foo"), "foo");
assertFalse(SimpleBean.isEchoCalled());
}

@Test
@SpecAssertion(section = INVOCATIONCONTEXT, id = "n")
@SpecAssertion(section = INVOCATIONCONTEXT, id = "o")
public void testGetInterceptorBindings() {
assertTrue(getContextualReference(SimpleBean.class).bindings());
assertEquals(AroundConstructInterceptor1.getAllBindings(), Set.of(new SimplePCBinding.Literal(),
new PseudoBinding.Literal(), new AroundConstructBinding1.Literal(),
new AroundConstructBinding2.Literal()));
assertEquals(AroundConstructInterceptor1.getAllBindings(), AroundConstructInterceptor2.getAllBindings());
assertEquals(PostConstructInterceptor.getAllBindings(), Set.of(new SimplePCBinding.Literal(),
new PseudoBinding.Literal(), new AroundConstructBinding1.Literal()));
assertEquals(Interceptor12.getAllBindings(), Set.of(new SimplePCBinding.Literal(), new PseudoBinding.Literal(),
new AroundConstructBinding1.Literal(), new Binding11.Literal(), new Binding12.Literal(),
new Binding13.Literal("ko"), new Binding14.Literal("foobar")));
assertEquals(Interceptor12.getBinding12s(), Set.of(new Binding12.Literal()));
assertEquals(Interceptor12.getBinding12(), new Binding12.Literal());
assertEquals(Interceptor12.getBinding5s(), Set.of());
assertNull(Interceptor12.getBinding6());
}
}
Loading
Loading