forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent non-public classes of method params from breaking interceptor…
… handling Fixes: quarkusio#18477
- Loading branch information
Showing
7 changed files
with
125 additions
and
4 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
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
27 changes: 27 additions & 0 deletions
27
.../arc/tests/src/test/java/io/quarkus/arc/test/interceptors/methodargs/ExampleResource.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,27 @@ | ||
package io.quarkus.arc.test.interceptors.methodargs; | ||
|
||
import java.util.List; | ||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
@Simple | ||
public class ExampleResource { | ||
|
||
// Just to try to confuse our bridge method impl. algorithm | ||
public String create(List<String> strings) { | ||
return String.join(",", strings); | ||
} | ||
|
||
String otherCreate(NotPublic notPublic) { | ||
return notPublic.toString(); | ||
} | ||
|
||
static class NotPublic { | ||
|
||
@Override | ||
public String toString() { | ||
return "NotPublic{}"; | ||
} | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...src/test/java/io/quarkus/arc/test/interceptors/methodargs/MethodArgsInterceptionTest.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,34 @@ | ||
package io.quarkus.arc.test.interceptors.methodargs; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ArcContainer; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import io.quarkus.arc.test.interceptors.Counter; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
public class MethodArgsInterceptionTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Simple.class, SimpleInterceptor.class, ExampleResource.class, | ||
Counter.class); | ||
|
||
@Test | ||
public void testInterception() { | ||
ArcContainer container = Arc.container(); | ||
Counter counter = container.instance(Counter.class).get(); | ||
|
||
counter.reset(); | ||
ExampleResource exampleResource = container.instance(ExampleResource.class).get(); | ||
|
||
assertEquals("first,second", exampleResource.create(List.of("first", "second"))); | ||
assertEquals(1, counter.get()); | ||
|
||
assertEquals("NotPublic{}", exampleResource.otherCreate(new ExampleResource.NotPublic())); | ||
assertEquals(1, counter.get()); // the interceptor should not have been called because the method argument is not public | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/methodargs/Simple.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 io.quarkus.arc.test.interceptors.methodargs; | ||
|
||
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.interceptor.InterceptorBinding; | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface Simple { | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...rc/tests/src/test/java/io/quarkus/arc/test/interceptors/methodargs/SimpleInterceptor.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,23 @@ | ||
package io.quarkus.arc.test.interceptors.methodargs; | ||
|
||
import io.quarkus.arc.test.interceptors.Counter; | ||
import javax.annotation.Priority; | ||
import javax.inject.Inject; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
@Simple | ||
@Priority(1) | ||
@Interceptor | ||
public class SimpleInterceptor { | ||
|
||
@Inject | ||
Counter counter; | ||
|
||
@AroundInvoke | ||
Object mySuperCoolAroundInvoke(InvocationContext ctx) throws Exception { | ||
counter.incrementAndGet(); | ||
return ctx.proceed(); | ||
} | ||
} |