|
| 1 | +package org.jboss.cdi.tck.tests.alternative.selection.priority; |
| 2 | + |
| 3 | +import static org.jboss.cdi.tck.cdi.Sections.DECLARING_SELECTED_ALTERNATIVES_APPLICATION; |
| 4 | +import static org.testng.Assert.assertEquals; |
| 5 | +import static org.testng.Assert.assertNotNull; |
| 6 | + |
| 7 | +import jakarta.inject.Inject; |
| 8 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 9 | +import org.jboss.cdi.tck.AbstractTest; |
| 10 | +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; |
| 11 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 12 | +import org.jboss.test.audit.annotations.SpecAssertion; |
| 13 | +import org.jboss.test.audit.annotations.SpecAssertions; |
| 14 | +import org.jboss.test.audit.annotations.SpecVersion; |
| 15 | +import org.testng.annotations.Test; |
| 16 | + |
| 17 | +@SpecVersion(spec = "cdi", version = "4.1") |
| 18 | +public class ProducerExplicitPriorityTest extends AbstractTest { |
| 19 | + |
| 20 | + public static final String DEFAULT = "default"; |
| 21 | + public static final String ALT = "alternative"; |
| 22 | + public static final String ALT2 = "alternative2"; |
| 23 | + |
| 24 | + @Deployment |
| 25 | + public static WebArchive createTestArchive() { |
| 26 | + return new WebArchiveBuilder().withTestClassPackage(ProducerExplicitPriorityTest.class).build(); |
| 27 | + } |
| 28 | + |
| 29 | + @Inject |
| 30 | + @ProducedByMethod |
| 31 | + Alpha alphaMethodProducer; |
| 32 | + |
| 33 | + @Inject |
| 34 | + @ProducedByField |
| 35 | + Alpha alphaFieldProducer; |
| 36 | + |
| 37 | + @Inject |
| 38 | + @ProducedByMethod |
| 39 | + Beta betaMethodProducer; |
| 40 | + |
| 41 | + @Inject |
| 42 | + @ProducedByField |
| 43 | + Beta betaFieldProducer; |
| 44 | + |
| 45 | + @Inject |
| 46 | + @ProducedByMethod |
| 47 | + Gamma gammaMethodProducer; |
| 48 | + |
| 49 | + @Inject |
| 50 | + @ProducedByField |
| 51 | + Gamma gammaFieldProducer; |
| 52 | + |
| 53 | + @Inject |
| 54 | + @ProducedByMethod |
| 55 | + Delta deltaMethodProducer; |
| 56 | + |
| 57 | + @Inject |
| 58 | + @ProducedByField |
| 59 | + Delta deltaFieldProducer; |
| 60 | + |
| 61 | + |
| 62 | + @Test |
| 63 | + @SpecAssertions({@SpecAssertion(section = DECLARING_SELECTED_ALTERNATIVES_APPLICATION, id = "ca"), |
| 64 | + @SpecAssertion(section = DECLARING_SELECTED_ALTERNATIVES_APPLICATION, id = "cb")}) |
| 65 | + public void testAlternativeProducerWithPriority() { |
| 66 | + assertNotNull(alphaMethodProducer); |
| 67 | + assertNotNull(alphaFieldProducer); |
| 68 | + |
| 69 | + assertEquals(alphaMethodProducer.ping(), ALT); |
| 70 | + assertEquals(alphaFieldProducer.ping(), ALT); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + @SpecAssertion(section = DECLARING_SELECTED_ALTERNATIVES_APPLICATION, id = "dd") |
| 75 | + public void testPriorityOnProducerOverPriorityOnClass() { |
| 76 | + assertNotNull(betaMethodProducer); |
| 77 | + assertNotNull(betaFieldProducer); |
| 78 | + assertNotNull(gammaFieldProducer); |
| 79 | + assertNotNull(gammaMethodProducer); |
| 80 | + assertNotNull(deltaFieldProducer); |
| 81 | + assertNotNull(deltaMethodProducer); |
| 82 | + |
| 83 | + assertEquals(betaMethodProducer.ping(), ALT2); |
| 84 | + assertEquals(betaFieldProducer.ping(), ALT2); |
| 85 | + assertEquals(gammaFieldProducer.ping(), ALT2); |
| 86 | + assertEquals(gammaMethodProducer.ping(), ALT2); |
| 87 | + assertEquals(deltaFieldProducer.ping(), ALT2); |
| 88 | + assertEquals(deltaMethodProducer.ping(), ALT2); |
| 89 | + } |
| 90 | +} |
0 commit comments