-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-2794 Add an automated test covering a related issue
- Loading branch information
Showing
5 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
tests-arquillian/src/test/java/org/jboss/weld/tests/accessibility/bce/BceInLibTest.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,57 @@ | ||
package org.jboss.weld.tests.accessibility.bce; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; | ||
|
||
import jakarta.inject.Inject; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.BeanDiscoveryMode; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.shrinkwrap.impl.BeansXml; | ||
import org.jboss.weld.test.util.Utils; | ||
import org.jboss.weld.tests.accessibility.bce.lib.MyBeanCreator; | ||
import org.jboss.weld.tests.accessibility.bce.lib.MyBce; | ||
import org.jboss.weld.tests.accessibility.bce.lib.SomeType; | ||
import org.jboss.weld.tests.category.Integration; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Tests a scenario in which an application (WAR) has a library (/lib) which isn't a bean archive but has registered BCE. | ||
* While such BCE creates synth bean, its {@code Instance} should be able to access beans from the application (WAR) | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@Category(Integration.class) | ||
public class BceInLibTest { | ||
|
||
@Deployment | ||
public static WebArchive getDeployment() { | ||
WebArchive war = ShrinkWrap | ||
.create(WebArchive.class, Utils.getDeploymentNameAsHash(BceInLibTest.class, Utils.ARCHIVE_TYPE.WAR)) | ||
.addClasses(MyBean.class) | ||
.addAsWebInfResource(new BeansXml(BeanDiscoveryMode.ANNOTATED), "beans.xml"); | ||
// archive with extension and no beans.xml == not a bean archive | ||
JavaArchive lib = ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MyBce.class, MyBeanCreator.class, SomeType.class) | ||
.addAsServiceProvider(BuildCompatibleExtension.class, MyBce.class); | ||
return war.addAsLibrary(lib); | ||
} | ||
|
||
@Inject | ||
Instance<Object> instance; | ||
|
||
@Test | ||
public void testVisibility() { | ||
// assert dummy bean is available | ||
assertTrue(instance.select(MyBean.class).isResolvable()); | ||
// assert we can select type added through BCE from here | ||
assertTrue(instance.select(SomeType.class).isResolvable()); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
tests-arquillian/src/test/java/org/jboss/weld/tests/accessibility/bce/MyBean.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.tests.accessibility.bce; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class MyBean { | ||
} |
18 changes: 18 additions & 0 deletions
18
tests-arquillian/src/test/java/org/jboss/weld/tests/accessibility/bce/lib/MyBce.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 org.jboss.weld.tests.accessibility.bce.lib; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; | ||
import jakarta.enterprise.inject.build.compatible.spi.Synthesis; | ||
import jakarta.enterprise.inject.build.compatible.spi.SyntheticComponents; | ||
|
||
public class MyBce implements BuildCompatibleExtension { | ||
|
||
|
||
@Synthesis | ||
public void registerSynthBean(SyntheticComponents syntheticComponents) { | ||
syntheticComponents.addBean(SomeType.class) | ||
.type(SomeType.class) | ||
.createWith(MyBeanCreator.class) | ||
.scope(Dependent.class); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests-arquillian/src/test/java/org/jboss/weld/tests/accessibility/bce/lib/MyBeanCreator.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,17 @@ | ||
package org.jboss.weld.tests.accessibility.bce.lib; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.enterprise.inject.build.compatible.spi.Parameters; | ||
import jakarta.enterprise.inject.build.compatible.spi.SyntheticBeanCreator; | ||
import org.jboss.weld.tests.accessibility.bce.MyBean; | ||
|
||
public class MyBeanCreator implements SyntheticBeanCreator<SomeType> { | ||
@Override | ||
public SomeType create(Instance<Object> lookup, Parameters params) { | ||
// assert that Instance provided here (BCE in non bean archive lib) can "see" MyBean | ||
assertTrue(lookup.select(MyBean.class).isResolvable()); | ||
return new SomeType(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
tests-arquillian/src/test/java/org/jboss/weld/tests/accessibility/bce/lib/SomeType.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,4 @@ | ||
package org.jboss.weld.tests.accessibility.bce.lib; | ||
|
||
public class SomeType { | ||
} |