-
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.
ArC: add tests for business method interceptors on target classes and…
… fix some issues Co-authored-by: Martin Kouba <[email protected]>
- Loading branch information
Showing
13 changed files
with
604 additions
and
44 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
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
64 changes: 64 additions & 0 deletions
64
...terceptors/targetclass/AroundInvokeOnTargetClassAndManySuperclassesWithOverridesTest.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,64 @@ | ||
package io.quarkus.arc.test.interceptors.targetclass; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import jakarta.inject.Singleton; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ArcContainer; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class AroundInvokeOnTargetClassAndManySuperclassesWithOverridesTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(MyBean.class); | ||
|
||
@Test | ||
public void test() { | ||
ArcContainer arc = Arc.container(); | ||
MyBean bean = arc.instance(MyBean.class).get(); | ||
assertEquals("super-intercepted: intercepted: foobar", bean.doSomething(42)); | ||
} | ||
|
||
static class Alpha { | ||
@AroundInvoke | ||
Object intercept(InvocationContext ctx) throws Exception { | ||
return "this should not be called as the method is overridden in MyBean"; | ||
} | ||
} | ||
|
||
static class Bravo extends Alpha { | ||
@AroundInvoke | ||
Object specialIntercept(InvocationContext ctx) throws Exception { | ||
return "this should not be called as the method is overridden in Charlie"; | ||
} | ||
} | ||
|
||
static class Charlie extends Bravo { | ||
@AroundInvoke | ||
Object superIntercept(InvocationContext ctx) throws Exception { | ||
return "super-intercepted: " + ctx.proceed(); | ||
} | ||
|
||
@Override | ||
Object specialIntercept(InvocationContext ctx) { | ||
return "this is not an interceptor method"; | ||
} | ||
} | ||
|
||
@Singleton | ||
static class MyBean extends Charlie { | ||
String doSomething(int param) { | ||
return "foobar"; | ||
} | ||
|
||
@AroundInvoke | ||
Object intercept(InvocationContext ctx) throws Exception { | ||
return "intercepted: " + ctx.proceed(); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...arkus/arc/test/interceptors/targetclass/AroundInvokeOnTargetClassAndSuperclassesTest.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,45 @@ | ||
package io.quarkus.arc.test.interceptors.targetclass; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import jakarta.inject.Singleton; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ArcContainer; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class AroundInvokeOnTargetClassAndSuperclassesTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(MyBean.class); | ||
|
||
@Test | ||
public void test() { | ||
ArcContainer arc = Arc.container(); | ||
MyBean bean = arc.instance(MyBean.class).get(); | ||
assertEquals("super-intercepted: intercepted: foobar", bean.doSomething()); | ||
} | ||
|
||
static class MyBeanSuperclass { | ||
@AroundInvoke | ||
Object superIntercept(InvocationContext ctx) throws Exception { | ||
return "super-intercepted: " + ctx.proceed(); | ||
} | ||
} | ||
|
||
@Singleton | ||
static class MyBean extends MyBeanSuperclass { | ||
String doSomething() { | ||
return "foobar"; | ||
} | ||
|
||
@AroundInvoke | ||
Object intercept(InvocationContext ctx) throws Exception { | ||
return "intercepted: " + ctx.proceed(); | ||
} | ||
} | ||
} |
Oops, something went wrong.