-
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
7 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...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,41 @@ | ||
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); | ||
Set<Annotation> allBindings = ProductInterceptor.getAllBindings(); | ||
assertNotNull(allBindings); | ||
assertEquals(allBindings.size(), 3); | ||
assertTrue(allBindings.contains(ProductInterceptorBinding1.Literal.INSTANCE)); | ||
assertTrue(allBindings.contains(ProductInterceptorBinding2.Literal.INSTANCE)); | ||
assertTrue(allBindings.contains(ProductInterceptorBinding3.Literal.INSTANCE)); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...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,19 @@ | ||
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; | ||
|
||
@ApplicationScoped | ||
public class ProducerBean { | ||
|
||
@Produces | ||
@ApplicationScoped | ||
public Product createProduct(InterceptionFactory<Product> interceptionFactory) { | ||
interceptionFactory.configure().add(ProductInterceptorBinding1.Literal.INSTANCE).filterMethods(m -> m.getJavaMember().getName().equals("ping")) | ||
.findFirst().get() | ||
.add(ProductInterceptorBinding2.Literal.INSTANCE) | ||
.add(ProductInterceptorBinding3.Literal.INSTANCE); | ||
return interceptionFactory.createInterceptedInstance(new Product()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...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,8 @@ | ||
package org.jboss.cdi.tck.tests.full.interceptors.contract.invocationContext; | ||
|
||
public class Product { | ||
|
||
public int ping() { | ||
return 41; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../jboss/cdi/tck/tests/full/interceptors/contract/invocationContext/ProductInterceptor.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,30 @@ | ||
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) | ||
@ProductInterceptorBinding1 | ||
@ProductInterceptorBinding2 | ||
@ProductInterceptorBinding3 | ||
@Interceptor | ||
public class ProductInterceptor { | ||
|
||
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(); | ||
|
||
} | ||
} |