-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-2798 Correct injection into injected @resource fields; add autom…
…ated test
- Loading branch information
Showing
12 changed files
with
169 additions
and
10 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
14 changes: 14 additions & 0 deletions
14
...-arquillian/src/test/java/org/jboss/weld/tests/injectionPoint/resource/extension/Foo.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,14 @@ | ||
package org.jboss.weld.tests.injectionPoint.resource.extension; | ||
|
||
import jakarta.annotation.Resource; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class Foo { | ||
@Resource(name = "org.jboss.weld.tests.reproducer.Foo/world") | ||
private String value; | ||
|
||
public String value() { | ||
return "hello " + value; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
.../src/test/java/org/jboss/weld/tests/injectionPoint/resource/extension/FooSpecialized.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,9 @@ | ||
package org.jboss.weld.tests.injectionPoint.resource.extension; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Specializes; | ||
|
||
@ApplicationScoped | ||
@Specializes | ||
public class FooSpecialized extends Foo { | ||
} |
8 changes: 8 additions & 0 deletions
8
.../java/org/jboss/weld/tests/injectionPoint/resource/extension/FooSpecializedNoBeanDef.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,8 @@ | ||
package org.jboss.weld.tests.injectionPoint.resource.extension; | ||
|
||
import jakarta.enterprise.inject.Specializes; | ||
|
||
// no bean defining annotation - this bean is not picked up via discovery but is instead registered via extension | ||
@Specializes | ||
public class FooSpecializedNoBeanDef extends Foo { | ||
} |
14 changes: 14 additions & 0 deletions
14
...ian/src/test/java/org/jboss/weld/tests/injectionPoint/resource/extension/MyExtension.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,14 @@ | ||
package org.jboss.weld.tests.injectionPoint.resource.extension; | ||
|
||
import jakarta.enterprise.event.Observes; | ||
import jakarta.enterprise.inject.spi.AfterTypeDiscovery; | ||
import jakarta.enterprise.inject.spi.BeanManager; | ||
import jakarta.enterprise.inject.spi.Extension; | ||
|
||
public class MyExtension implements Extension { | ||
|
||
void afterTypeDiscovery(@Observes AfterTypeDiscovery event, BeanManager bm) { | ||
event.addAnnotatedType(bm.createAnnotatedType(FooSpecializedNoBeanDef.class), | ||
FooSpecializedNoBeanDef.class.getName() + "_synth"); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...a/org/jboss/weld/tests/injectionPoint/resource/extension/SpecializationDiscoveryTest.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,46 @@ | ||
package org.jboss.weld.tests.injectionPoint.resource.extension; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.weld.test.util.Utils; | ||
import org.jboss.weld.tests.category.Integration; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Test inheritance of {@code @Resource} field when adding a specialized bean through discovery versus through extension | ||
* See https://issues.redhat.com/browse/WELD-2798 | ||
*/ | ||
@Category(Integration.class) | ||
@RunWith(Arquillian.class) | ||
public class SpecializationDiscoveryTest { | ||
|
||
@Deployment | ||
public static Archive<?> deploy() { | ||
return ShrinkWrap | ||
.create(WebArchive.class, | ||
Utils.getDeploymentNameAsHash(SpecializationDiscoveryTest.class, Utils.ARCHIVE_TYPE.WAR)) | ||
.addClasses(Foo.class, FooSpecialized.class, SpecializationDiscoveryTest.class) | ||
.addAsWebInfResource(SpecializationDiscoveryTest.class.getPackage(), "web.xml", "web.xml"); | ||
} | ||
|
||
@Inject | ||
Foo foo; | ||
|
||
@Test | ||
public void test() { | ||
// foo is an instance of the specialized bean | ||
Assert.assertTrue(foo instanceof FooSpecialized); | ||
// resource has been injected | ||
assertEquals("hello world", foo.value()); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...a/org/jboss/weld/tests/injectionPoint/resource/extension/SpecializationExtensionTest.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,53 @@ | ||
package org.jboss.weld.tests.injectionPoint.resource.extension; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import jakarta.enterprise.inject.spi.Extension; | ||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.weld.test.util.Utils; | ||
import org.jboss.weld.tests.category.Integration; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Test inheritance of {@code @Resource} field when adding a specialized bean through discovery versus through extension | ||
* See https://issues.redhat.com/browse/WELD-2798 | ||
*/ | ||
@Category(Integration.class) | ||
@RunWith(Arquillian.class) | ||
public class SpecializationExtensionTest { | ||
|
||
@Deployment | ||
public static Archive<?> deploy() { | ||
return ShrinkWrap | ||
.create(WebArchive.class, | ||
Utils.getDeploymentNameAsHash(SpecializationExtensionTest.class, Utils.ARCHIVE_TYPE.WAR)) | ||
.addClasses(Foo.class, FooSpecializedNoBeanDef.class, MyExtension.class, | ||
SpecializationExtensionTest.class) | ||
.addAsServiceProvider(Extension.class, MyExtension.class) | ||
.addAsWebInfResource(SpecializationExtensionTest.class.getPackage(), "web.xml", "web.xml") | ||
// archive has an extension, it also needs beans.xml to be considered bean archive | ||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); | ||
|
||
} | ||
|
||
@Inject | ||
Foo foo; | ||
|
||
@Test | ||
public void test() { | ||
// foo is an instance of the specialized bean | ||
assertTrue(foo instanceof FooSpecializedNoBeanDef); | ||
// resource has been injected | ||
assertEquals("hello world", foo.value()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...uillian/src/test/resources/org/jboss/weld/tests/injectionPoint/resource/extension/web.xml
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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app version="3.0" | ||
xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> | ||
|
||
<display-name>Resource Injection Tests</display-name> | ||
|
||
<env-entry> | ||
<env-entry-name>org.jboss.weld.tests.reproducer.Foo/world</env-entry-name> | ||
<env-entry-type>java.lang.String</env-entry-type> | ||
<env-entry-value>world</env-entry-value> | ||
</env-entry> | ||
|
||
</web-app> |
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