-
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 #10007 from manovotn/issue9941
Make it possible to mark beans as unremovable via MP config.
- Loading branch information
Showing
8 changed files
with
177 additions
and
2 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
11 changes: 11 additions & 0 deletions
11
extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/Charlie.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 io.quarkus.arc.test.unused; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class Charlie { | ||
|
||
public String ping() { | ||
return "ok"; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/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,17 @@ | ||
package io.quarkus.arc.test.unused; | ||
|
||
/** | ||
* Not a bean on its own but has a producer | ||
*/ | ||
public class Delta { | ||
|
||
private String s; | ||
|
||
public Delta(String s) { | ||
this.s = s; | ||
} | ||
|
||
public String ping() { | ||
return s; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ProducerBean.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,17 @@ | ||
package io.quarkus.arc.test.unused; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
|
||
@ApplicationScoped | ||
@Unremovable | ||
public class ProducerBean { | ||
|
||
@Produces | ||
@ApplicationScoped | ||
Delta produceDelta() { | ||
return new Delta("ok"); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/UnusedExclusionTest.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,59 @@ | ||
package io.quarkus.arc.test.unused; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
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.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ArcContainer; | ||
import io.quarkus.arc.InstanceHandle; | ||
import io.quarkus.arc.test.unused.subpackage.Beta; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class UnusedExclusionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(UnusedExclusionTest.class, Alpha.class, Beta.class, Charlie.class, Delta.class, | ||
ProducerBean.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.arc.unremovable-types=io.quarkus.arc.test.unused.UnusedExclusionTest$Alpha,io.quarkus.arc.test.unused.subpackage.**,io.quarkus.arc.test.unused.Charlie,Delta"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testBeansWereNotRemoved() { | ||
ArcContainer container = Arc.container(); | ||
String expectedBeanResponse = "ok"; | ||
InstanceHandle<Alpha> alphaInstance = container.instance(Alpha.class); | ||
Assertions.assertTrue(alphaInstance.isAvailable()); | ||
Assertions.assertEquals(expectedBeanResponse, alphaInstance.get().ping()); | ||
|
||
InstanceHandle<Beta> betaInstance = container.instance(Beta.class); | ||
Assertions.assertTrue(betaInstance.isAvailable()); | ||
Assertions.assertEquals(expectedBeanResponse, betaInstance.get().ping()); | ||
|
||
InstanceHandle<Charlie> charlieInstance = container.instance(Charlie.class); | ||
Assertions.assertTrue(charlieInstance.isAvailable()); | ||
Assertions.assertEquals(expectedBeanResponse, charlieInstance.get().ping()); | ||
|
||
InstanceHandle<Delta> deltaInstance = container.instance(Delta.class); | ||
Assertions.assertTrue(deltaInstance.isAvailable()); | ||
Assertions.assertEquals(expectedBeanResponse, deltaInstance.get().ping()); | ||
} | ||
|
||
// unused bean, won't be removed | ||
@ApplicationScoped | ||
static class Alpha { | ||
|
||
public String ping() { | ||
return "ok"; | ||
} | ||
|
||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/subpackage/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 io.quarkus.arc.test.unused.subpackage; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
/** | ||
* Another unused bean that shouldn't be removed. | ||
*/ | ||
@ApplicationScoped | ||
public class Beta { | ||
|
||
public String ping() { | ||
return "ok"; | ||
} | ||
} |