-
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-2773 Prevent producer field inheritance when extension manipulat…
…es the annotated type.
- Loading branch information
Showing
5 changed files
with
94 additions
and
2 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
13 changes: 13 additions & 0 deletions
13
tests-arquillian/src/test/java/org/jboss/weld/tests/producer/field/FieldProducerBean.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,13 @@ | ||
package org.jboss.weld.tests.producer.field; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.Produces; | ||
|
||
@Dependent | ||
public class FieldProducerBean { | ||
|
||
@Produces | ||
@ApplicationScoped | ||
FieldProducerExtensionTest.Foo p = new FieldProducerExtensionTest.Foo(); | ||
} |
7 changes: 7 additions & 0 deletions
7
...quillian/src/test/java/org/jboss/weld/tests/producer/field/FieldProducerBeanSubclass.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.producer.field; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
public class FieldProducerBeanSubclass extends FieldProducerBean { | ||
} |
57 changes: 57 additions & 0 deletions
57
...uillian/src/test/java/org/jboss/weld/tests/producer/field/FieldProducerExtensionTest.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.producer.field; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
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.BeanArchive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.weld.test.util.Utils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Field producer should not be inherited into bean subclass. In this scenario, a CDI extension modifies the type | ||
* which leads to a registration of a new annotated type that we need to correctly parse. | ||
* | ||
* See https://issues.redhat.com/browse/WELD-2773 | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class FieldProducerExtensionTest { | ||
|
||
@Deployment | ||
public static Archive<?> deploy() { | ||
return ShrinkWrap.create(BeanArchive.class, Utils.getDeploymentNameAsHash(FieldProducerExtensionTest.class)) | ||
.addPackage(FieldProducerExtensionTest.class.getPackage()) | ||
.addAsServiceProvider(Extension.class, MyExtension.class); | ||
} | ||
|
||
@Inject | ||
Instance<Object> instance; | ||
|
||
@Inject | ||
Foo foo; | ||
|
||
@Test | ||
public void test() { | ||
// assert extension works | ||
Assert.assertEquals(2, MyExtension.extensionTriggered); | ||
// assert producer works | ||
Assert.assertNotNull(foo); | ||
|
||
// assert both beans are there | ||
List<? extends Instance.Handle<FieldProducerBean>> collect = instance.select(FieldProducerBean.class).handlesStream() | ||
.collect(Collectors.toList()); | ||
Assert.assertEquals(2, collect.size()); | ||
} | ||
|
||
public static class Foo { | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tests-arquillian/src/test/java/org/jboss/weld/tests/producer/field/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,15 @@ | ||
package org.jboss.weld.tests.producer.field; | ||
|
||
import jakarta.enterprise.event.Observes; | ||
import jakarta.enterprise.inject.spi.Extension; | ||
import jakarta.enterprise.inject.spi.ProcessAnnotatedType; | ||
|
||
public class MyExtension implements Extension { | ||
|
||
public static int extensionTriggered = 0; | ||
|
||
public void observe(@Observes ProcessAnnotatedType<? extends FieldProducerBean> pat) { | ||
extensionTriggered++; | ||
pat.configureAnnotatedType(); | ||
} | ||
} |