-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for declaring @priority on producers
- Loading branch information
Showing
16 changed files
with
475 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/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.cdi.tck.tests.alternative.selection.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
...a/org/jboss/cdi/tck/tests/alternative/selection/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.cdi.tck.tests.alternative.selection.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
...i/tck/tests/alternative/selection/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.cdi.tck.tests.alternative.selection.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
impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/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.cdi.tck.tests.alternative.selection.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
impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/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.cdi.tck.tests.alternative.selection.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
impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/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.cdi.tck.tests.alternative.selection.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
...rg/jboss/cdi/tck/tests/alternative/selection/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.cdi.tck.tests.alternative.selection.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
.../cdi/tck/tests/alternative/selection/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.cdi.tck.tests.alternative.selection.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
...src/main/java/org/jboss/cdi/tck/tests/alternative/selection/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.cdi.tck.tests.alternative.selection.priority; | ||
|
||
import jakarta.inject.Qualifier; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Qualifier | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ProducedByField { | ||
} |
11 changes: 11 additions & 0 deletions
11
...rc/main/java/org/jboss/cdi/tck/tests/alternative/selection/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.cdi.tck.tests.alternative.selection.priority; | ||
|
||
import jakarta.inject.Qualifier; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Qualifier | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ProducedByMethod { | ||
} |
90 changes: 90 additions & 0 deletions
90
.../org/jboss/cdi/tck/tests/alternative/selection/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,90 @@ | ||
package org.jboss.cdi.tck.tests.alternative.selection.priority; | ||
|
||
import static org.jboss.cdi.tck.cdi.Sections.DECLARING_SELECTED_ALTERNATIVES_APPLICATION; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNotNull; | ||
|
||
import jakarta.inject.Inject; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.cdi.tck.AbstractTest; | ||
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.test.audit.annotations.SpecAssertion; | ||
import org.jboss.test.audit.annotations.SpecAssertions; | ||
import org.jboss.test.audit.annotations.SpecVersion; | ||
import org.testng.annotations.Test; | ||
|
||
@SpecVersion(spec = "cdi", version = "4.1") | ||
public class ProducerExplicitPriorityTest extends AbstractTest { | ||
|
||
public static final String DEFAULT = "default"; | ||
public static final String ALT = "alternative"; | ||
public static final String ALT2 = "alternative2"; | ||
|
||
@Deployment | ||
public static WebArchive createTestArchive() { | ||
return new WebArchiveBuilder().withTestClassPackage(ProducerExplicitPriorityTest.class).build(); | ||
} | ||
|
||
@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 | ||
@SpecAssertions({@SpecAssertion(section = DECLARING_SELECTED_ALTERNATIVES_APPLICATION, id = "ca"), | ||
@SpecAssertion(section = DECLARING_SELECTED_ALTERNATIVES_APPLICATION, id = "cb")}) | ||
public void testAlternativeProducerWithPriority() { | ||
assertNotNull(alphaMethodProducer); | ||
assertNotNull(alphaFieldProducer); | ||
|
||
assertEquals(alphaMethodProducer.ping(), ALT); | ||
assertEquals(alphaFieldProducer.ping(), ALT); | ||
} | ||
|
||
@Test | ||
@SpecAssertion(section = DECLARING_SELECTED_ALTERNATIVES_APPLICATION, id = "dd") | ||
public void testPriorityOnProducerOverPriorityOnClass() { | ||
assertNotNull(betaMethodProducer); | ||
assertNotNull(betaFieldProducer); | ||
assertNotNull(gammaFieldProducer); | ||
assertNotNull(gammaMethodProducer); | ||
assertNotNull(deltaFieldProducer); | ||
assertNotNull(deltaMethodProducer); | ||
|
||
assertEquals(betaMethodProducer.ping(), ALT2); | ||
assertEquals(betaFieldProducer.ping(), ALT2); | ||
assertEquals(gammaFieldProducer.ping(), ALT2); | ||
assertEquals(gammaMethodProducer.ping(), ALT2); | ||
assertEquals(deltaFieldProducer.ping(), ALT2); | ||
assertEquals(deltaMethodProducer.ping(), ALT2); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/RegularBeanProducer.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,49 @@ | ||
package org.jboss.cdi.tck.tests.alternative.selection.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); | ||
} |
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
Oops, something went wrong.