-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8296 from mkouba/issue-8135
ArC - select alternatives through the MicroProfile Config
- Loading branch information
Showing
23 changed files
with
701 additions
and
197 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
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
12 changes: 12 additions & 0 deletions
12
extensions/arc/deployment/src/test/java/io/quarkus/arc/test/alternatives/Foo.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,12 @@ | ||
package io.quarkus.arc.test.alternatives; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class Foo { | ||
|
||
public String ping() { | ||
return getClass().getName(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
extensions/arc/deployment/src/test/java/io/quarkus/arc/test/alternatives/Producers.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,19 @@ | ||
package io.quarkus.arc.test.alternatives; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Alternative; | ||
import javax.enterprise.inject.Produces; | ||
|
||
@ApplicationScoped | ||
class Producers { | ||
|
||
@Alternative | ||
@Produces | ||
static final int CHARLIE = 10; | ||
|
||
@Produces | ||
@Alternative | ||
public String bravo() { | ||
return "bravo"; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ployment/src/test/java/io/quarkus/arc/test/alternatives/SelectedAlternativesFqcnTest.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 io.quarkus.arc.test.alternatives; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Alternative; | ||
import javax.enterprise.inject.Instance; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.alternatives.bar.Bar; | ||
import io.quarkus.arc.test.alternatives.bar.MyStereotype; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class SelectedAlternativesFqcnTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(SelectedAlternativesFqcnTest.class, Alpha.class, Producers.class, Foo.class, Bar.class, | ||
MyStereotype.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.arc.selected-alternatives=io.quarkus.arc.test.alternatives.SelectedAlternativesFqcnTest$Alpha,io.quarkus.arc.test.alternatives.Producers,io.quarkus.arc.test.alternatives.bar.MyStereotype"), | ||
"application.properties")); | ||
|
||
@Inject | ||
Instance<Alpha> alpha; | ||
|
||
@Inject | ||
Instance<String> bravo; | ||
|
||
@Inject | ||
Instance<Integer> charlie; | ||
|
||
@Inject | ||
Instance<Foo> foo; | ||
|
||
@Test | ||
public void testSelectedAlternatives() { | ||
assertTrue(alpha.isResolvable()); | ||
assertEquals("ok", alpha.get().ping()); | ||
assertTrue(bravo.isResolvable()); | ||
assertEquals("bravo", bravo.get()); | ||
assertTrue(charlie.isResolvable()); | ||
assertEquals(10, charlie.get()); | ||
// Note that we should get Bar because it's annotated with an alternative stereotype selected in app properties | ||
assertTrue(foo.isResolvable()); | ||
assertEquals(Bar.class.getName(), foo.get().ping()); | ||
} | ||
|
||
@Alternative | ||
@ApplicationScoped | ||
static class Alpha { | ||
|
||
public String ping() { | ||
return "ok"; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.