-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ArC: treat additional scope annotations correctly, even if there's no…
… corresponding context It makes no sense to register an additional scope annotation without registering a corresponding context, but the CDI TCK uses that and it isn't terribly hard to support. With this commit, ArC treats additional bean defining annotations that are meta-annotated `@Scope` or `@NormalScope` as scope annotations, even if there is no corresponding context. This commit also fixes the type discovery implementations to also discover scope annotations and register them as additional bean defining annotations.
- Loading branch information
Showing
5 changed files
with
110 additions
and
21 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
58 changes: 58 additions & 0 deletions
58
...arc/tests/src/test/java/io/quarkus/arc/test/bean/scope/CustomScopeWithoutContextTest.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,58 @@ | ||
package io.quarkus.arc.test.bean.scope; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.enterprise.context.NormalScope; | ||
import jakarta.enterprise.inject.spi.Bean; | ||
import jakarta.enterprise.inject.spi.BeanManager; | ||
import jakarta.inject.Scope; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class CustomScopeWithoutContextTest { | ||
@RegisterExtension | ||
ArcTestContainer container = new ArcTestContainer(MyScope.class, MyNormalScope.class, MyBean.class, MyNormalBean.class); | ||
|
||
@Test | ||
public void pseudoScope() { | ||
BeanManager bm = Arc.container().beanManager(); | ||
Bean<MyBean> bean = (Bean<MyBean>) bm.resolve(bm.getBeans(MyBean.class)); | ||
assertEquals(MyScope.class, bean.getScope()); | ||
} | ||
|
||
@Test | ||
public void normalScope() { | ||
BeanManager bm = Arc.container().beanManager(); | ||
Bean<MyNormalBean> bean = (Bean<MyNormalBean>) bm.resolve(bm.getBeans(MyNormalBean.class)); | ||
assertEquals(MyNormalScope.class, bean.getScope()); | ||
} | ||
|
||
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Scope | ||
@interface MyScope { | ||
} | ||
|
||
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@NormalScope | ||
@interface MyNormalScope { | ||
} | ||
|
||
@MyScope | ||
static class MyBean { | ||
} | ||
|
||
@MyNormalScope | ||
static class MyNormalBean { | ||
} | ||
} |