-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test obtaining interceptor bindings along with interception factory
- Loading branch information
Showing
8 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...nterceptors/contract/invocationContext/InterceptorBindingsWithInterceptorFactoryTest.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,49 @@ | ||
package org.jboss.cdi.tck.tests.full.interceptors.contract.invocationContext; | ||
|
||
import static org.jboss.cdi.tck.TestGroups.CDI_FULL; | ||
import static org.jboss.cdi.tck.interceptors.InterceptorsSections.INVOCATIONCONTEXT; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.cdi.tck.AbstractTest; | ||
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.test.audit.annotations.SpecAssertion; | ||
import org.jboss.test.audit.annotations.SpecVersion; | ||
import org.testng.annotations.Test; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Set; | ||
|
||
@SpecVersion(spec = "interceptors", version = "2.2") | ||
@Test(groups = CDI_FULL) | ||
public class InterceptorBindingsWithInterceptorFactoryTest extends AbstractTest { | ||
|
||
@Deployment | ||
public static WebArchive createTestArchive() { | ||
return new WebArchiveBuilder().withTestClassPackage(InterceptorBindingsWithInterceptorFactoryTest.class).build(); | ||
} | ||
|
||
@Test | ||
@SpecAssertion(section = INVOCATIONCONTEXT, id = "n") | ||
public void testInterceptorBindingsAppliedViaInterceptorFactory() { | ||
Product product = getContextualReference(Product.class); | ||
assertEquals(product.ping(), 42); | ||
assertEquals(product.pong(), 42); | ||
|
||
Set<Annotation> interceptor1Bindings = ProductInterceptor1.getAllBindings(); | ||
assertNotNull(interceptor1Bindings); | ||
assertEquals(interceptor1Bindings.size(), 2); | ||
assertTrue(interceptor1Bindings.contains(ProductInterceptorBinding1.Literal.INSTANCE)); | ||
assertTrue(interceptor1Bindings.contains(ProductInterceptorBinding2.Literal.INSTANCE)); | ||
|
||
Set<Annotation> interceptor2Bindings = ProductInterceptor2.getAllBindings(); | ||
assertNotNull(interceptor2Bindings); | ||
assertEquals(interceptor2Bindings.size(), 2); | ||
assertTrue(interceptor2Bindings.contains(ProductInterceptorBinding1.Literal.INSTANCE)); | ||
assertTrue(interceptor2Bindings.contains(ProductInterceptorBinding3.Literal.INSTANCE)); | ||
|
||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...va/org/jboss/cdi/tck/tests/full/interceptors/contract/invocationContext/ProducerBean.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,24 @@ | ||
package org.jboss.cdi.tck.tests.full.interceptors.contract.invocationContext; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.enterprise.inject.spi.InterceptionFactory; | ||
import jakarta.enterprise.inject.spi.configurator.AnnotatedTypeConfigurator; | ||
|
||
@ApplicationScoped | ||
public class ProducerBean { | ||
|
||
@Produces | ||
@ApplicationScoped | ||
public Product createProduct(InterceptionFactory<Product> interceptionFactory) { | ||
AnnotatedTypeConfigurator<Product> configurator = interceptionFactory.configure(); | ||
configurator.add(ProductInterceptorBinding1.Literal.INSTANCE) | ||
.filterMethods(m -> m.getJavaMember().getName().equals("ping")) | ||
.findFirst().get() | ||
.add(ProductInterceptorBinding2.Literal.INSTANCE); | ||
configurator.filterMethods(m -> m.getJavaMember().getName().equals("pong")) | ||
.findFirst().get() | ||
.add(ProductInterceptorBinding3.Literal.INSTANCE); | ||
return interceptionFactory.createInterceptedInstance(new Product()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...in/java/org/jboss/cdi/tck/tests/full/interceptors/contract/invocationContext/Product.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 org.jboss.cdi.tck.tests.full.interceptors.contract.invocationContext; | ||
|
||
public class Product { | ||
|
||
public int ping() { | ||
return 41; | ||
} | ||
|
||
public int pong() { | ||
return 41; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...jboss/cdi/tck/tests/full/interceptors/contract/invocationContext/ProductInterceptor1.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 org.jboss.cdi.tck.tests.full.interceptors.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; | ||
|
||
@Priority(Interceptor.Priority.APPLICATION + 400) | ||
@ProductInterceptorBinding2 | ||
@Interceptor | ||
public class ProductInterceptor1 { | ||
|
||
private static Set<Annotation> allBindings; | ||
|
||
@AroundInvoke | ||
public Object aroundInvoke(InvocationContext invocationContext) throws Exception { | ||
allBindings = invocationContext.getInterceptorBindings(); | ||
return (1 + (Integer)invocationContext.proceed()); | ||
} | ||
|
||
public static Set<Annotation> getAllBindings() { | ||
return allBindings; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...jboss/cdi/tck/tests/full/interceptors/contract/invocationContext/ProductInterceptor2.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 org.jboss.cdi.tck.tests.full.interceptors.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; | ||
|
||
@Priority(Interceptor.Priority.APPLICATION + 400) | ||
@ProductInterceptorBinding3 | ||
@Interceptor | ||
public class ProductInterceptor2 { | ||
|
||
private static Set<Annotation> allBindings; | ||
|
||
@AroundInvoke | ||
public Object aroundInvoke(InvocationContext invocationContext) throws Exception { | ||
allBindings = invocationContext.getInterceptorBindings(); | ||
return (1 + (Integer)invocationContext.proceed()); | ||
} | ||
|
||
public static Set<Annotation> getAllBindings() { | ||
return allBindings; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...di/tck/tests/full/interceptors/contract/invocationContext/ProductInterceptorBinding1.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,25 @@ | ||
package org.jboss.cdi.tck.tests.full.interceptors.contract.invocationContext; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import jakarta.enterprise.util.AnnotationLiteral; | ||
import jakarta.interceptor.InterceptorBinding; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({TYPE, METHOD}) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface ProductInterceptorBinding1 { | ||
|
||
class Literal extends AnnotationLiteral<ProductInterceptorBinding1> implements ProductInterceptorBinding1 { | ||
|
||
public static Literal INSTANCE = new Literal(); | ||
|
||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...di/tck/tests/full/interceptors/contract/invocationContext/ProductInterceptorBinding2.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,25 @@ | ||
package org.jboss.cdi.tck.tests.full.interceptors.contract.invocationContext; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import jakarta.enterprise.util.AnnotationLiteral; | ||
import jakarta.interceptor.InterceptorBinding; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface ProductInterceptorBinding2 { | ||
|
||
class Literal extends AnnotationLiteral<ProductInterceptorBinding2> implements ProductInterceptorBinding2 { | ||
|
||
public static Literal INSTANCE = new Literal(); | ||
|
||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...di/tck/tests/full/interceptors/contract/invocationContext/ProductInterceptorBinding3.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,25 @@ | ||
package org.jboss.cdi.tck.tests.full.interceptors.contract.invocationContext; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import jakarta.enterprise.util.AnnotationLiteral; | ||
import jakarta.interceptor.InterceptorBinding; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface ProductInterceptorBinding3 { | ||
|
||
class Literal extends AnnotationLiteral<ProductInterceptorBinding3> implements ProductInterceptorBinding3 { | ||
|
||
public static Literal INSTANCE = new Literal(); | ||
|
||
} | ||
} |