Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a core test for non-alternative producers on alternative beans #500

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jboss.cdi.tck.tests.alternative.selection;

import jakarta.annotation.Priority;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Alternative;
import jakarta.enterprise.inject.Produces;

@ApplicationScoped
@Alternative
@Priority(100)
public class AlternativeDeltaProducer1 {

@Produces
public Delta produce() {
return new Delta(SelectedAlternative03Test.ALT1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jboss.cdi.tck.tests.alternative.selection;

import jakarta.annotation.Priority;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Alternative;
import jakarta.enterprise.inject.Produces;

@ApplicationScoped
@Alternative
@Priority(200)
public class AlternativeDeltaProducer2 {

@Produces
public Delta produce() {
return new Delta(SelectedAlternative03Test.ALT2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jboss.cdi.tck.tests.alternative.selection;

import jakarta.enterprise.inject.Vetoed;

@Vetoed
public class Delta {

String s;

public Delta(String s) {
this.s = s;
}

public String ping() {
return s;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jboss.cdi.tck.tests.alternative.selection;

import static org.jboss.cdi.tck.cdi.Sections.UNSATISFIED_AND_AMBIG_DEPENDENCIES;

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.SpecVersion;
import org.testng.Assert;
import org.testng.annotations.Test;

@SpecVersion(spec = "cdi", version = "4.1")
public class SelectedAlternative03Test extends AbstractTest {

public static final String DEFAULT = "default";
public static final String ALT1 = "alt1";
public static final String ALT2 = "alt2";

@Deployment
public static WebArchive createTestArchive() {
return new WebArchiveBuilder()
.withTestClass(SelectedAlternative03Test.class)
.withClasses(Delta.class, StandardDeltaProducer.class, AlternativeDeltaProducer1.class,
AlternativeDeltaProducer2.class).build();
}

@Inject
Delta delta;

@Test
@SpecAssertion(section = UNSATISFIED_AND_AMBIG_DEPENDENCIES, id = "cb")
public void testMultipleAlternativeBeansWithProducers() {
Assert.assertNotNull(delta);
Assert.assertEquals(delta.ping(), ALT2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jboss.cdi.tck.tests.alternative.selection;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;

@ApplicationScoped
public class StandardDeltaProducer {

@Produces
public Delta produce() {
return new Delta(SelectedAlternative03Test.DEFAULT);
}
}
Loading