-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-2768 support explicitly declaring @priority on producers
- Loading branch information
Showing
23 changed files
with
527 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,7 @@ public Bean<T> getBean() { | |
return ProducerField.this; | ||
} | ||
}); | ||
processExplicitPriority(); | ||
} | ||
|
||
@Override | ||
|
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 |
---|---|---|
|
@@ -97,6 +97,7 @@ public Bean<T> getBean() { | |
return ProducerMethod.this; | ||
} | ||
}); | ||
processExplicitPriority(); | ||
} | ||
|
||
@Override | ||
|
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
tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Alpha.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.producer.alternative.priority; | ||
|
||
public class Alpha { | ||
|
||
private String s; | ||
|
||
public Alpha(String s) { | ||
this.s = s; | ||
} | ||
|
||
public String ping() { | ||
return s; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../java/org/jboss/weld/tests/producer/alternative/priority/AltBeanProducingAlternative.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.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); | ||
} |
24 changes: 24 additions & 0 deletions
24
...s/weld/tests/producer/alternative/priority/AltBeanProducingPrioritizedNonAlternative.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,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); | ||
} |
14 changes: 14 additions & 0 deletions
14
tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Beta.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.producer.alternative.priority; | ||
|
||
public class Beta { | ||
|
||
private String s; | ||
|
||
public Beta(String s) { | ||
this.s = s; | ||
} | ||
|
||
public String ping() { | ||
return s; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Delta.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.producer.alternative.priority; | ||
|
||
public class Delta { | ||
|
||
private String s; | ||
|
||
public Delta(String s) { | ||
this.s = s; | ||
} | ||
|
||
public String ping() { | ||
return s; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests-arquillian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/Gamma.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.producer.alternative.priority; | ||
|
||
public class Gamma { | ||
|
||
private String s; | ||
|
||
public Gamma(String s) { | ||
this.s = s; | ||
} | ||
|
||
public String ping() { | ||
return s; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...va/org/jboss/weld/tests/producer/alternative/priority/NonAltBeanProducingAlternative.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,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); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...boss/weld/tests/producer/alternative/priority/NonAltBeanWithPrioProducingAlternative.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,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); | ||
} |
11 changes: 11 additions & 0 deletions
11
...ian/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducedByField.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,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 { | ||
} |
11 changes: 11 additions & 0 deletions
11
...an/src/test/java/org/jboss/weld/tests/producer/alternative/priority/ProducedByMethod.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,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 { | ||
} |
87 changes: 87 additions & 0 deletions
87
...java/org/jboss/weld/tests/producer/alternative/priority/ProducerExplicitPriorityTest.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,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()); | ||
} | ||
} |
Oops, something went wrong.