-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide Arc configuration allowing to fail when interceptors used on …
…private methods Follow up of: #21260
- Loading branch information
Showing
7 changed files
with
173 additions
and
2 deletions.
There are no files selected for viewing
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
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
68 changes: 68 additions & 0 deletions
68
...nt/src/test/java/io/quarkus/arc/test/interceptor/FailingPrivateInterceptedMethodTest.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,68 @@ | ||
package io.quarkus.arc.test.interceptor; | ||
|
||
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.annotation.Priority; | ||
import javax.enterprise.inject.spi.DeploymentException; | ||
import javax.inject.Singleton; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InterceptorBinding; | ||
import javax.interceptor.InvocationContext; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class FailingPrivateInterceptedMethodTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(SimpleBean.class, SimpleInterceptor.class, Simple.class) | ||
.addAsResource(new StringAsset("quarkus.arc.fail-on-intercepted-private-method=true"), | ||
"application.properties")) | ||
.setExpectedException(DeploymentException.class); | ||
|
||
@Test | ||
public void testDeploymentFailed() { | ||
// This method should not be invoked | ||
} | ||
|
||
@Singleton | ||
static class SimpleBean { | ||
|
||
@Simple | ||
private String foo() { | ||
return "foo"; | ||
} | ||
|
||
} | ||
|
||
@Simple | ||
@Priority(1) | ||
@Interceptor | ||
public static class SimpleInterceptor { | ||
|
||
@AroundInvoke | ||
public Object mySuperCoolAroundInvoke(InvocationContext ctx) throws Exception { | ||
return "private" + ctx.proceed(); | ||
} | ||
} | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface Simple { | ||
|
||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...nt/src/test/java/io/quarkus/arc/test/interceptor/IgnoredPrivateInterceptedMethodTest.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,68 @@ | ||
package io.quarkus.arc.test.interceptor; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.annotation.Priority; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InterceptorBinding; | ||
import javax.interceptor.InvocationContext; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class IgnoredPrivateInterceptedMethodTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(SimpleBean.class, SimpleInterceptor.class, Simple.class)); | ||
|
||
@Inject | ||
SimpleBean simpleBean; | ||
|
||
@Test | ||
public void testBeanInvocation() { | ||
assertEquals("foo", simpleBean.foo()); | ||
} | ||
|
||
@Singleton | ||
static class SimpleBean { | ||
|
||
@Simple | ||
private String foo() { | ||
return "foo"; | ||
} | ||
|
||
} | ||
|
||
@Simple | ||
@Priority(1) | ||
@Interceptor | ||
public static class SimpleInterceptor { | ||
|
||
@AroundInvoke | ||
public Object mySuperCoolAroundInvoke(InvocationContext ctx) throws Exception { | ||
return "private" + ctx.proceed(); | ||
} | ||
} | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface Simple { | ||
|
||
} | ||
} |
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
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
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