-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce annotation for changing bean discovery mode in synthetic ar…
…chive
- Loading branch information
Showing
6 changed files
with
80 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
26 changes: 26 additions & 0 deletions
26
junit5/src/main/java/org/jboss/weld/junit5/auto/SetBeanDiscoveryMode.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,26 @@ | ||
package org.jboss.weld.junit5.auto; | ||
|
||
import org.jboss.weld.bootstrap.spi.BeanDiscoveryMode; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Sets discovery mode for Weld SE synthetic bean archive. Valid options are {@link BeanDiscoveryMode#ALL} and | ||
* {@link BeanDiscoveryMode#ANNOTATED}. | ||
* <p> | ||
* Starting with Weld 5 (CDI 4), the default value is {@code ANNOTATED}. Applications can leverage this annotation to | ||
* enforce same behavior as older Weld versions where synthetic archives used discovery mode {@code ALL}. | ||
* <p> | ||
* This annotation is equal to invocation of {@link org.jboss.weld.environment.se.Weld#setBeanDiscoveryMode(BeanDiscoveryMode)}. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Inherited | ||
public @interface SetBeanDiscoveryMode { | ||
|
||
BeanDiscoveryMode value(); | ||
} |
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
31 changes: 31 additions & 0 deletions
31
junit5/src/test/java/org/jboss/weld/junit5/auto/SetDiscoveryModeAllTest.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,31 @@ | ||
package org.jboss.weld.junit5.auto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.inject.Inject; | ||
import org.jboss.weld.bootstrap.spi.BeanDiscoveryMode; | ||
import org.jboss.weld.junit5.auto.discovery.WithBeanDefiningAnnotation; | ||
import org.jboss.weld.junit5.auto.discovery.WithoutBeanDefiningAnnotation; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@EnableAutoWeld | ||
@AddPackages(value = WithBeanDefiningAnnotation.class, recursively = false) | ||
@SetBeanDiscoveryMode(BeanDiscoveryMode.ALL) | ||
public class SetDiscoveryModeAllTest { | ||
|
||
@Inject | ||
private WithBeanDefiningAnnotation standardBean; | ||
|
||
@Inject | ||
Instance<Object> instance; | ||
|
||
@Test | ||
void testDiscoveryModeWasChanged() { | ||
// bean with bean defining annotation is normally resolvable | ||
assertNotNull(standardBean); | ||
// bean without bean defining annotation is discovered as well because we set discovery to ALL | ||
assertTrue(instance.select(WithoutBeanDefiningAnnotation.class).isResolvable()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
junit5/src/test/java/org/jboss/weld/junit5/auto/discovery/WithBeanDefiningAnnotation.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,7 @@ | ||
package org.jboss.weld.junit5.auto.discovery; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class WithBeanDefiningAnnotation { | ||
} |
5 changes: 5 additions & 0 deletions
5
junit5/src/test/java/org/jboss/weld/junit5/auto/discovery/WithoutBeanDefiningAnnotation.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,5 @@ | ||
package org.jboss.weld.junit5.auto.discovery; | ||
|
||
// intentionally doesn't have any bean defining annotation | ||
public class WithoutBeanDefiningAnnotation { | ||
} |