-
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 - Validate whether interceptors declare producer methods
- Loading branch information
Showing
4 changed files
with
238 additions
and
0 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
73 changes: 73 additions & 0 deletions
73
...rc/test/java/io/quarkus/arc/test/producer/disposer/illegal/DisposerInInterceptorTest.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,73 @@ | ||
package io.quarkus.arc.test.producer.disposer.illegal; | ||
|
||
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.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.Disposes; | ||
import jakarta.enterprise.inject.spi.DefinitionException; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InterceptorBinding; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class DisposerInInterceptorTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder() | ||
.beanClasses(BadInterceptor.class, FooBean.class, MyBinding.class).shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testFailure() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@Interceptor | ||
@MyBinding | ||
@Priority(1) | ||
static class BadInterceptor { | ||
|
||
@AroundInvoke | ||
public Object aroundInvoke(InvocationContext ic) throws Exception { | ||
return ic.proceed(); | ||
} | ||
|
||
// declaring a disposer inside an interceptor should raise DefinitionException | ||
void dispose(@Disposes String ignored) { | ||
} | ||
|
||
} | ||
|
||
@Dependent | ||
@MyBinding | ||
static class FooBean { | ||
|
||
public String ping() { | ||
return FooBean.class.getSimpleName(); | ||
} | ||
|
||
} | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
@interface MyBinding { | ||
|
||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...ts/src/test/java/io/quarkus/arc/test/producer/illegal/ProducerFieldInInterceptorTest.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,73 @@ | ||
package io.quarkus.arc.test.producer.illegal; | ||
|
||
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.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.enterprise.inject.spi.DefinitionException; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InterceptorBinding; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class ProducerFieldInInterceptorTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder() | ||
.beanClasses(BadInterceptor.class, FooBean.class, MyBinding.class).shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testFailure() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@Interceptor | ||
@MyBinding | ||
@Priority(1) | ||
static class BadInterceptor { | ||
|
||
@AroundInvoke | ||
public Object aroundInvoke(InvocationContext ic) throws Exception { | ||
return ic.proceed(); | ||
} | ||
|
||
// declaring a producer inside an interceptor should raise DefinitionException | ||
@Produces | ||
String val = "42"; | ||
} | ||
|
||
@Dependent | ||
@MyBinding | ||
static class FooBean { | ||
|
||
public String ping() { | ||
return ProducerMethodInInterceptorTest.FooBean.class.getSimpleName(); | ||
} | ||
|
||
} | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
@interface MyBinding { | ||
|
||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...s/src/test/java/io/quarkus/arc/test/producer/illegal/ProducerMethodInInterceptorTest.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,76 @@ | ||
package io.quarkus.arc.test.producer.illegal; | ||
|
||
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.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.enterprise.inject.spi.DefinitionException; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InterceptorBinding; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class ProducerMethodInInterceptorTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder() | ||
.beanClasses(BadInterceptor.class, FooBean.class, MyBinding.class).shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testFailure() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@Interceptor | ||
@MyBinding | ||
@Priority(1) | ||
static class BadInterceptor { | ||
|
||
@AroundInvoke | ||
public Object aroundInvoke(InvocationContext ic) throws Exception { | ||
return ic.proceed(); | ||
} | ||
|
||
// declaring a producer inside an interceptor should raise DefinitionException | ||
@Produces | ||
String generateString() { | ||
return "42"; | ||
} | ||
|
||
} | ||
|
||
@Dependent | ||
@MyBinding | ||
static class FooBean { | ||
|
||
public String ping() { | ||
return FooBean.class.getSimpleName(); | ||
} | ||
|
||
} | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
@interface MyBinding { | ||
|
||
} | ||
} |