Skip to content

Commit

Permalink
Change AfterTypeDiscoveryTest to avoid assumptions about how many tot…
Browse files Browse the repository at this point in the history
…al components are in test deployment.
  • Loading branch information
manovotn committed Jul 27, 2022
1 parent dcb6fc0 commit b4ce6fe
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ public void observeAfterTypeDiscovery(@Observes AfterTypeDiscovery event, BeanMa
}
// The order of decorators reverted
Collections.reverse(event.getDecorators());
// Remove first alternative - AlphaAlternative
event.getAlternatives().remove(0);
// Remove first alternative based on index - AlphaAlternative
// There can be more alternatives in the deployment, calculate index first
for (int i = 0; i < event.getAlternatives().size(); i++) {
if (event.getAlternatives().get(i).equals(AlphaAlternative.class)) {
event.getAlternatives().remove(i);
}
}

// add Baz annotatedType via AnnotatedTypeConfigurator
event.addAnnotatedType(Baz.class, AfterTypeDiscoveryObserver.class.getName() + ":" + Baz.class.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.jboss.cdi.tck.cdi.Sections.TYPE_DISCOVERY_STEPS;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

import jakarta.enterprise.context.RequestScoped;
Expand All @@ -44,6 +45,8 @@
import org.jboss.test.audit.annotations.SpecVersion;
import org.testng.annotations.Test;

import java.util.List;

/**
* @author Martin Kouba
*/
Expand Down Expand Up @@ -78,20 +81,61 @@ public void testInitialInterceptors() {
@Test
@SpecAssertions({ @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "b"), @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "ha") })
public void testInitialAlternatives() {
assertEquals(extension.getAlternatives().size(), 3);
assertEquals(extension.getAlternatives().get(0), AlphaAlternative.class);
assertEquals(extension.getAlternatives().get(1), EchoAlternative.class);
assertEquals(extension.getAlternatives().get(2), DeltaAlternative.class);
// frameworks might add their own alternatives, we cannot assert positions in list but rather just ordering
assertTrue(extension.getAlternatives().size() >= 3);
List<Class<?>> alternatives = extension.getAlternatives();
Integer alphaAltIndex = null;
Integer echoAltIndex = null;
Integer deltaAltIndex = null;
for (int i = 0; i < alternatives.size(); i++) {
if (alternatives.get(i).equals(AlphaAlternative.class)) {
alphaAltIndex = i;
}
if (alternatives.get(i).equals(EchoAlternative.class)) {
echoAltIndex = i;
}
if (alternatives.get(i).equals(DeltaAlternative.class)) {
deltaAltIndex = i;
}
}
assertNotNull(alphaAltIndex);
assertNotNull(echoAltIndex);
assertNotNull(deltaAltIndex);
assertTrue(alphaAltIndex < echoAltIndex);
assertTrue(echoAltIndex < deltaAltIndex);
}

@Test
@SpecAssertions({ @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "d"), @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "hc") })
public void testInitialDecorators() {
assertEquals(extension.getDecorators().size(), 4);
assertEquals(extension.getDecorators().get(0), AlphaDecorator.class);
assertEquals(extension.getDecorators().get(1), BravoDecorator.class);
assertEquals(extension.getDecorators().get(2), EchoDecorator.class);
assertEquals(extension.getDecorators().get(3), DeltaDecorator.class);
// frameworks might add their own decorators, we cannot assert positions in list but rather just ordering
assertTrue(extension.getDecorators().size() >= 4);
List<Class<?>> decorators = extension.getDecorators();
Integer alphaDecIndex = null;
Integer bravoDecIndex = null;
Integer echoDecIndex = null;
Integer deltaDecIndex = null;
for (int i = 0; i < decorators.size(); i++) {
if (decorators.get(i).equals(AlphaDecorator.class)) {
alphaDecIndex = i;
}
if (decorators.get(i).equals(BravoDecorator.class)) {
bravoDecIndex = i;
}
if (decorators.get(i).equals(EchoDecorator.class)) {
echoDecIndex = i;
}
if (decorators.get(i).equals(DeltaDecorator.class)) {
deltaDecIndex = i;
}
}
assertNotNull(alphaDecIndex);
assertNotNull(bravoDecIndex);
assertNotNull(echoDecIndex);
assertNotNull(deltaDecIndex);
assertTrue(alphaDecIndex < bravoDecIndex);
assertTrue(bravoDecIndex < echoDecIndex);
assertTrue(echoDecIndex < deltaDecIndex);
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.jboss.cdi.tck.TestGroups.CDI_FULL;
import static org.jboss.cdi.tck.cdi.Sections.AFTER_TYPE_DISCOVERY;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

import jakarta.inject.Inject;
Expand All @@ -37,6 +38,8 @@
import org.jboss.test.audit.annotations.SpecAssertions;
import org.testng.annotations.Test;

import java.util.List;

/**
* Complementary test to AfterTypeDiscoveryTest using the same classes but focusing on mass operations on List
*
Expand Down Expand Up @@ -74,21 +77,57 @@ public void testInitialInterceptors() {
@SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "b"),
@SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "ha") })
public void testInitialAlternatives() {
assertEquals(extension.getAlternatives().size(), 3);
assertEquals(extension.getAlternatives().get(0), AlphaAlternative.class);
assertEquals(extension.getAlternatives().get(1), BetaAlternative.class);
assertEquals(extension.getAlternatives().get(2), GammaAlternative.class);
// frameworks might add their own alternatives, we cannot assert positions in list but rather just ordering
assertTrue(extension.getAlternatives().size() >= 3);
List<Class<?>> alternatives = extension.getAlternatives();
Integer alphaAltIndex = null;
Integer betaLatIndex = null;
Integer gammaAltIndex = null;
for (int i = 0; i < alternatives.size(); i++) {
if (alternatives.get(i).equals(AlphaAlternative.class)) {
alphaAltIndex = i;
}
if (alternatives.get(i).equals(BetaAlternative.class)) {
betaLatIndex = i;
}
if (alternatives.get(i).equals(GammaAlternative.class)) {
gammaAltIndex = i;
}
}
assertNotNull(alphaAltIndex);
assertNotNull(betaLatIndex);
assertNotNull(gammaAltIndex);
assertTrue(alphaAltIndex < betaLatIndex);
assertTrue(betaLatIndex < gammaAltIndex);
}

@Test
@SpecAssertions({
@SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "d"),
@SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "hc") })
public void testInitialDecorators() {
assertEquals(extension.getDecorators().size(), 3);
assertEquals(extension.getDecorators().get(0), AlphaDecorator.class);
assertEquals(extension.getDecorators().get(1), BetaDecorator.class);
assertEquals(extension.getDecorators().get(2), GammaDecorator.class);
// frameworks might add their own decorators, we cannot assert positions in list but rather just ordering
assertTrue(extension.getDecorators().size() >= 3);
List<Class<?>> decorators = extension.getDecorators();
Integer alphaDecIndex = null;
Integer betaDecIndex = null;
Integer gammaDecIndex = null;
for (int i = 0; i < decorators.size(); i++) {
if (decorators.get(i).equals(AlphaDecorator.class)) {
alphaDecIndex = i;
}
if (decorators.get(i).equals(BetaDecorator.class)) {
betaDecIndex = i;
}
if (decorators.get(i).equals(GammaDecorator.class)) {
gammaDecIndex = i;
}
}
assertNotNull(alphaDecIndex);
assertNotNull(betaDecIndex);
assertNotNull(gammaDecIndex);
assertTrue(alphaDecIndex < betaDecIndex);
assertTrue(betaDecIndex < gammaDecIndex);
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
Expand Down

0 comments on commit b4ce6fe

Please sign in to comment.