diff --git a/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java b/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java index ee180376d2f..6abd7ed4268 100644 --- a/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java +++ b/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java @@ -24,6 +24,7 @@ import java.lang.reflect.Type; import java.util.Set; +import jakarta.annotation.Priority; import jakarta.enterprise.context.Dependent; import jakarta.enterprise.context.spi.CreationalContext; import jakarta.enterprise.inject.spi.AnnotatedMember; @@ -59,6 +60,7 @@ public abstract class AbstractProducerBean extends Abstr // Passivation flags private boolean passivationCapableBean; private boolean passivationCapableDependency; + protected Integer explicitPriority; /** * Constructor @@ -217,4 +219,15 @@ public AbstractClassBean getDeclaringBean() { @Override public abstract EnhancedAnnotatedMember getEnhancedAnnotated(); + + @Override + public Integer getPriority() { + return explicitPriority; + } + + // requires initialized getAnnotated() hence subclasses need to invoke this manually + protected void processExplicitPriority() { + Priority annotation = getAnnotated() == null ? null : getAnnotated().getAnnotation(Priority.class); + this.explicitPriority = annotation == null ? null : annotation.value(); + } } diff --git a/impl/src/main/java/org/jboss/weld/bean/ProducerField.java b/impl/src/main/java/org/jboss/weld/bean/ProducerField.java index 2cb7a7a4508..a3d51db5a74 100644 --- a/impl/src/main/java/org/jboss/weld/bean/ProducerField.java +++ b/impl/src/main/java/org/jboss/weld/bean/ProducerField.java @@ -96,6 +96,7 @@ public Bean getBean() { return ProducerField.this; } }); + processExplicitPriority(); } @Override diff --git a/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java b/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java index 0f3103a8812..47c1366ab0b 100644 --- a/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java +++ b/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java @@ -97,6 +97,7 @@ public Bean getBean() { return ProducerMethod.this; } }); + processExplicitPriority(); } @Override diff --git a/impl/src/main/java/org/jboss/weld/bean/WeldBean.java b/impl/src/main/java/org/jboss/weld/bean/WeldBean.java index 3291deb1afb..fbaadbf3943 100644 --- a/impl/src/main/java/org/jboss/weld/bean/WeldBean.java +++ b/impl/src/main/java/org/jboss/weld/bean/WeldBean.java @@ -35,9 +35,11 @@ public interface WeldBean extends Bean { BeanIdentifier getIdentifier(); /** - * Used for custom beans registered via WeldBeanConfigurator. + * Used for custom beans registered via WeldBeanConfigurator and for {@link ProducerField} and {@link ProducerMethod} + * if they explicitly declare the {@link jakarta.annotation.Priority} annotation. + * All other implementations will return {@code null} by default. * - * @return bean priority or null if not set or overriden + * @return bean priority or null if not set or overridden */ default Integer getPriority() { return null; diff --git a/impl/src/main/java/org/jboss/weld/resolution/AbstractTypeSafeBeanResolver.java b/impl/src/main/java/org/jboss/weld/resolution/AbstractTypeSafeBeanResolver.java index 49c21466e11..02cd62d9b40 100644 --- a/impl/src/main/java/org/jboss/weld/resolution/AbstractTypeSafeBeanResolver.java +++ b/impl/src/main/java/org/jboss/weld/resolution/AbstractTypeSafeBeanResolver.java @@ -110,9 +110,18 @@ public Set> apply(Set> from) { public Set> resolveAlternatives(Set> alternatives) { int highestPriority = Integer.MIN_VALUE; Set> selectedAlternativesWithHighestPriority = new HashSet>(); - for (Bean bean : alternatives) { - Integer priority = beanManager.getEnabled().getAlternativePriority(bean.getBeanClass()); + Integer priority; + if (bean instanceof AbstractProducerBean) { + // first check for explicit priority declaration on producers + priority = ((AbstractProducerBean) bean).getPriority(); + // if not found, fall back to priority on declaring bean + if (priority == null) { + priority = beanManager.getEnabled().getAlternativePriority(bean.getBeanClass()); + } + } else { + priority = beanManager.getEnabled().getAlternativePriority(bean.getBeanClass()); + } if (priority == null) { // not all the beans left are alternatives with a priority - we are not able to resolve return ImmutableSet.copyOf(alternatives); diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Alpha.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Alpha.java new file mode 100644 index 00000000000..12d96b975df --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Alpha.java @@ -0,0 +1,14 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +public class Alpha { + + private String s; + + public Alpha(String s) { + this.s = s; + } + + public String ping() { + return s; + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/AltBeanProducingAlternative.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/AltBeanProducingAlternative.java new file mode 100644 index 00000000000..5c719180723 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/AltBeanProducingAlternative.java @@ -0,0 +1,26 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +import jakarta.annotation.Priority; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Alternative; +import jakarta.enterprise.inject.Produces; + +@Alternative +@Priority(1) +@ApplicationScoped +public class AltBeanProducingAlternative { + + @Alternative + @Priority(20) // should override class-level priority value and hence end up having the highest priority + @Produces + @ProducedByMethod + Beta producer1() { + return new Beta(ProducerExplicitPriorityTest.ALT2); + } + + @Alternative + @Priority(20) // should override class-level priority value and hence end up having the highest priority + @Produces + @ProducedByField + Beta producer2 = new Beta(ProducerExplicitPriorityTest.ALT2); +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/AltBeanProducingPrioritizedNonAlternative.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/AltBeanProducingPrioritizedNonAlternative.java new file mode 100644 index 00000000000..1f3ca910635 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/AltBeanProducingPrioritizedNonAlternative.java @@ -0,0 +1,24 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +import jakarta.annotation.Priority; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Alternative; +import jakarta.enterprise.inject.Produces; + +@ApplicationScoped +@Alternative +@Priority(1) +public class AltBeanProducingPrioritizedNonAlternative { + + @Priority(20) // should override class-level priority value and hence end up having the highest priority + @Produces + @ProducedByMethod + Delta producer1() { + return new Delta(ProducerExplicitPriorityTest.ALT2); + } + + @Priority(20) // should override class-level priority value and hence end up having the highest priority + @Produces + @ProducedByField + Delta producer2 = new Delta(ProducerExplicitPriorityTest.ALT2); +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Beta.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Beta.java new file mode 100644 index 00000000000..0026de183f4 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Beta.java @@ -0,0 +1,14 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +public class Beta { + + private String s; + + public Beta(String s) { + this.s = s; + } + + public String ping() { + return s; + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Delta.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Delta.java new file mode 100644 index 00000000000..ecdf17e192c --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Delta.java @@ -0,0 +1,14 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +public class Delta { + + private String s; + + public Delta(String s) { + this.s = s; + } + + public String ping() { + return s; + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Gamma.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Gamma.java new file mode 100644 index 00000000000..9ed97558b75 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Gamma.java @@ -0,0 +1,14 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +public class Gamma { + + private String s; + + public Gamma(String s) { + this.s = s; + } + + public String ping() { + return s; + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/NonAltBeanProducingAlternative.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/NonAltBeanProducingAlternative.java new file mode 100644 index 00000000000..6fc4adb8c9a --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/NonAltBeanProducingAlternative.java @@ -0,0 +1,67 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +import jakarta.annotation.Priority; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Alternative; +import jakarta.enterprise.inject.Produces; + +@ApplicationScoped +public class NonAltBeanProducingAlternative { + + @Alternative + @Priority(10) + @Produces + @ProducedByMethod + Alpha producer1() { + return new Alpha(ProducerExplicitPriorityTest.ALT); + } + + @Alternative + @Priority(10) + @Produces + @ProducedByMethod + Beta producer2() { + return new Beta(ProducerExplicitPriorityTest.ALT); + } + + @Alternative + @Priority(10) + @Produces + @ProducedByField + Alpha producer3 = new Alpha(ProducerExplicitPriorityTest.ALT); + + @Alternative + @Priority(10) + @Produces + @ProducedByField + Beta producer4 = new Beta(ProducerExplicitPriorityTest.ALT); + + @Produces + @ProducedByMethod + @Alternative + @Priority(10) + Gamma producer5() { + return new Gamma(ProducerExplicitPriorityTest.ALT); + } + + @Produces + @ProducedByField + @Alternative + @Priority(10) + Gamma producer6 = new Gamma(ProducerExplicitPriorityTest.ALT); + + @Produces + @ProducedByMethod + @Alternative + @Priority(10) + Delta producer7() { + return new Delta(ProducerExplicitPriorityTest.ALT); + } + + @Produces + @ProducedByField + @Alternative + @Priority(10) + Delta producer8 = new Delta(ProducerExplicitPriorityTest.ALT); + +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/NonAltBeanWithPrioProducingAlternative.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/NonAltBeanWithPrioProducingAlternative.java new file mode 100644 index 00000000000..b9fdac9bd4c --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/NonAltBeanWithPrioProducingAlternative.java @@ -0,0 +1,23 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +import jakarta.annotation.Priority; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Alternative; +import jakarta.enterprise.inject.Produces; + +@ApplicationScoped +@Priority(500) +public class NonAltBeanWithPrioProducingAlternative { + + @Produces + @ProducedByMethod + @Alternative + Gamma producer5() { + return new Gamma(ProducerExplicitPriorityTest.ALT2); + } + + @Produces + @ProducedByField + @Alternative + Gamma producer6 = new Gamma(ProducerExplicitPriorityTest.ALT2); +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducedByField.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducedByField.java new file mode 100644 index 00000000000..1f665e1704c --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducedByField.java @@ -0,0 +1,11 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import jakarta.inject.Qualifier; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +public @interface ProducedByField { +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducedByMethod.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducedByMethod.java new file mode 100644 index 00000000000..bc568f1fe83 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducedByMethod.java @@ -0,0 +1,11 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import jakarta.inject.Qualifier; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +public @interface ProducedByMethod { +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducerExplicitPriorityTest.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducerExplicitPriorityTest.java new file mode 100644 index 00000000000..6724db451e8 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducerExplicitPriorityTest.java @@ -0,0 +1,87 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +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.Test; +import org.junit.runner.RunWith; + +@RunWith(Arquillian.class) +public class ProducerExplicitPriorityTest { + + @Deployment + public static Archive getDeployment() { + return ShrinkWrap.create(BeanArchive.class, Utils.getDeploymentNameAsHash(ProducerExplicitPriorityTest.class)) + .addPackage(ProducerExplicitPriorityTest.class.getPackage()); + } + + public static final String DEFAULT = "default"; + public static final String ALT = "alternative"; + public static final String ALT2 = "alternative2"; + + @Inject + @ProducedByMethod + Alpha alphaMethodProducer; + + @Inject + @ProducedByField + Alpha alphaFieldProducer; + + @Inject + @ProducedByMethod + Beta betaMethodProducer; + + @Inject + @ProducedByField + Beta betaFieldProducer; + + @Inject + @ProducedByMethod + Gamma gammaMethodProducer; + + @Inject + @ProducedByField + Gamma gammaFieldProducer; + + @Inject + @ProducedByMethod + Delta deltaMethodProducer; + + @Inject + @ProducedByField + Delta deltaFieldProducer; + + @Test + public void testAlternativeProducerWithPriority() { + assertNotNull(alphaMethodProducer); + assertNotNull(alphaFieldProducer); + + assertEquals(ALT, alphaMethodProducer.ping()); + assertEquals(ALT, alphaFieldProducer.ping()); + } + + @Test + public void testPriorityOnProducerOverPriorityOnClass() { + assertNotNull(betaMethodProducer); + assertNotNull(betaFieldProducer); + assertNotNull(gammaFieldProducer); + assertNotNull(gammaMethodProducer); + assertNotNull(deltaFieldProducer); + assertNotNull(deltaMethodProducer); + + assertEquals(ALT2, betaMethodProducer.ping()); + assertEquals(ALT2, betaFieldProducer.ping()); + assertEquals(ALT2, gammaFieldProducer.ping()); + assertEquals(ALT2, gammaMethodProducer.ping()); + assertEquals(ALT2, deltaFieldProducer.ping()); + assertEquals(ALT2, deltaMethodProducer.ping()); + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/RegularBeanProducer.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/RegularBeanProducer.java new file mode 100644 index 00000000000..380096ba390 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/RegularBeanProducer.java @@ -0,0 +1,49 @@ +package org.jboss.weld.tests.producer.alternative.priority; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; + +// produces standard (non-alternative) beans that should be replaced by alternatives +@ApplicationScoped +public class RegularBeanProducer { + + @Produces + @ProducedByMethod + Alpha producer1() { + return new Alpha(ProducerExplicitPriorityTest.DEFAULT); + } + + @Produces + @ProducedByMethod + Beta producer2() { + return new Beta(ProducerExplicitPriorityTest.DEFAULT); + } + + @Produces + @ProducedByField + Alpha producer3 = new Alpha(ProducerExplicitPriorityTest.DEFAULT); + + @Produces + @ProducedByField + Beta producer4 = new Beta(ProducerExplicitPriorityTest.DEFAULT); + + @Produces + @ProducedByMethod + Gamma producer5() { + return new Gamma(ProducerExplicitPriorityTest.DEFAULT); + } + + @Produces + @ProducedByField + Gamma producer6 = new Gamma(ProducerExplicitPriorityTest.DEFAULT); + + @Produces + @ProducedByMethod + Delta producer7() { + return new Delta(ProducerExplicitPriorityTest.DEFAULT); + } + + @Produces + @ProducedByField + Delta producer8 = new Delta(ProducerExplicitPriorityTest.DEFAULT); +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/Bar.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/Bar.java new file mode 100644 index 00000000000..340f7414e2f --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/Bar.java @@ -0,0 +1,13 @@ +package org.jboss.weld.tests.producer.alternative.priority.complex; + +public class Bar { + private String s; + + public Bar(String s) { + this.s = s; + } + + public String ping() { + return s; + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/Foo.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/Foo.java new file mode 100644 index 00000000000..19ce981b797 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/Foo.java @@ -0,0 +1,14 @@ +package org.jboss.weld.tests.producer.alternative.priority.complex; + +public class Foo { + + private String s; + + public Foo(String s) { + this.s = s; + } + + public String ping() { + return s; + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/GloballyEnabledAlt.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/GloballyEnabledAlt.java new file mode 100644 index 00000000000..69f0b5509fe --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/GloballyEnabledAlt.java @@ -0,0 +1,26 @@ +package org.jboss.weld.tests.producer.alternative.priority.complex; + +import jakarta.annotation.Priority; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Alternative; +import jakarta.enterprise.inject.Produces; + +@ApplicationScoped +@Alternative +@Priority(1) +public class GloballyEnabledAlt { + + @Produces + @Alternative + @Priority(50) + public Foo produceAltFoo() { + return new Foo(ProducerOnLocallyEnabledAltTest.ALT); + } + + @Produces + @Alternative + @Priority(50) + public Bar produceAltBar() { + return new Bar(ProducerOnLocallyEnabledAltTest.ALT); + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/LocallyEnabledAlternative.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/LocallyEnabledAlternative.java new file mode 100644 index 00000000000..abdb08f028a --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/LocallyEnabledAlternative.java @@ -0,0 +1,27 @@ +package org.jboss.weld.tests.producer.alternative.priority.complex; + +import jakarta.annotation.Priority; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Alternative; +import jakarta.enterprise.inject.Produces; + +@ApplicationScoped +@Alternative +// priority intentionally missing, enabled via beans.xml +// all producers declared within this class have the highest priority in this test's deployment +public class LocallyEnabledAlternative { + + @Produces + @Alternative + @Priority(100) + public Foo produceAltFoo() { + return new Foo(ProducerOnLocallyEnabledAltTest.ALT2); + } + + @Produces + // @Alternative deliberately left out + @Priority(100) + public Bar produceAltBar() { + return new Bar(ProducerOnLocallyEnabledAltTest.ALT2); + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/ProducerOnLocallyEnabledAltTest.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/ProducerOnLocallyEnabledAltTest.java new file mode 100644 index 00000000000..374f34c52c9 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/ProducerOnLocallyEnabledAltTest.java @@ -0,0 +1,45 @@ +package org.jboss.weld.tests.producer.alternative.priority.complex; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +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.Test; +import org.junit.runner.RunWith; + +@RunWith(Arquillian.class) +public class ProducerOnLocallyEnabledAltTest { + + public static final String DEFAULT = "default"; + public static final String ALT = "alternative"; + public static final String ALT2 = "alternative2"; + + @Deployment + public static Archive getDeployment() { + return ShrinkWrap.create(BeanArchive.class, Utils.getDeploymentNameAsHash(ProducerOnLocallyEnabledAltTest.class)) + .alternate(LocallyEnabledAlternative.class) + .addPackage(ProducerOnLocallyEnabledAltTest.class.getPackage()); + } + + @Inject + Bar bar; + + @Inject + Foo foo; + + @Test + public void testLocallyEnabledAlternativeHasHighestPrio() { + assertNotNull(bar); + assertNotNull(foo); + + assertEquals(ALT2, foo.ping()); + assertEquals(ALT2, bar.ping()); + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/RegularProducer.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/RegularProducer.java new file mode 100644 index 00000000000..8990e15f0ae --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/complex/RegularProducer.java @@ -0,0 +1,18 @@ +package org.jboss.weld.tests.producer.alternative.priority.complex; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; + +@ApplicationScoped +public class RegularProducer { + + @Produces + public Foo produceFoo() { + return new Foo(ProducerOnLocallyEnabledAltTest.DEFAULT); + } + + @Produces + public Bar produceBar() { + return new Bar(ProducerOnLocallyEnabledAltTest.DEFAULT); + } +}