-
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 binding added by extension visible
Test that an interceptor binding added to a method via an annotation is used to bind the interceptor and visible via InterceptionContext.getInterceptorBinding Signed-off-by: Andrew Rouse <[email protected]>
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...ild/compatible/extensions/changeInterceptorBinding/ChangeInterceptorBindingExtension.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 org.jboss.cdi.tck.tests.build.compatible.extensions.changeInterceptorBinding; | ||
|
||
import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; | ||
import jakarta.enterprise.inject.build.compatible.spi.ClassConfig; | ||
import jakarta.enterprise.inject.build.compatible.spi.Enhancement; | ||
|
||
public class ChangeInterceptorBindingExtension implements BuildCompatibleExtension { | ||
|
||
@Enhancement(types = MyService.class) | ||
public void enhancement(ClassConfig config) { | ||
config.methods() | ||
.stream() | ||
.filter(it -> "hello".equals(it.info().name())) | ||
.forEach(m -> m.addAnnotation(new MyBinding.Literal("foo"))); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...ts/build/compatible/extensions/changeInterceptorBinding/ChangeInterceptorBindingTest.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,36 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInterceptorBinding; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.cdi.tck.AbstractTest; | ||
import org.jboss.cdi.tck.cdi.Sections; | ||
import org.jboss.cdi.tck.interceptors.InterceptorsSections; | ||
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; | ||
|
||
/** | ||
* Test interceptor bindings applied to methods via extension are used to bind the correct interceptor and returned from InvocationContext.getInterceptorBindings() | ||
*/ | ||
@SpecVersion(spec = "cdi", version = "4.1") | ||
public class ChangeInterceptorBindingTest extends AbstractTest { | ||
|
||
@Deployment | ||
public static WebArchive createTestArchive() { | ||
return new WebArchiveBuilder() | ||
.withTestClassPackage(ChangeInterceptorBindingTest.class) | ||
.withBuildCompatibleExtension(ChangeInterceptorBindingExtension.class) | ||
.build(); | ||
} | ||
|
||
@Test | ||
@SpecAssertion(section = Sections.ENHANCEMENT_PHASE, id = "b") | ||
@SpecAssertion(section = InterceptorsSections.INVOCATIONCONTEXT, id="o") | ||
public void test() { | ||
assertEquals(getContextualReference(MyService.class).hello(), "Intercepted(foo): Hello!"); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...g/jboss/cdi/tck/tests/build/compatible/extensions/changeInterceptorBinding/MyBinding.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,36 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInterceptorBinding; | ||
|
||
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.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.enterprise.util.AnnotationLiteral; | ||
import jakarta.enterprise.util.Nonbinding; | ||
import jakarta.interceptor.InterceptorBinding; | ||
|
||
@InterceptorBinding | ||
@Inherited | ||
@Retention(RUNTIME) | ||
@Target({ TYPE, METHOD }) | ||
public @interface MyBinding { | ||
|
||
@Nonbinding | ||
public String value(); | ||
|
||
public class Literal extends AnnotationLiteral<MyBinding> implements MyBinding { | ||
private String value; | ||
|
||
public Literal(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String value() { | ||
return value; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...oss/cdi/tck/tests/build/compatible/extensions/changeInterceptorBinding/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,18 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInterceptorBinding; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
@Interceptor | ||
@MyBinding("") | ||
@Priority(1000) | ||
public class MyInterceptor { | ||
|
||
@AroundInvoke | ||
public Object aroundInvoke(InvocationContext ctx) throws Exception { | ||
MyBinding binding = ctx.getInterceptorBinding(MyBinding.class); | ||
return "Intercepted(" + binding.value() + "): " + ctx.proceed(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...g/jboss/cdi/tck/tests/build/compatible/extensions/changeInterceptorBinding/MyService.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,11 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInterceptorBinding; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class MyService { | ||
|
||
public String hello() { | ||
return "Hello!"; | ||
} | ||
} |