-
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.
Add support for sub-interfaces in @ConfigProperties
Fixes: #10511
- Loading branch information
Showing
4 changed files
with
222 additions
and
23 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
53 changes: 53 additions & 0 deletions
53
...rc/test/java/io/quarkus/arc/test/configproperties/InterfaceWithOtherConfigPrefixTest.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,53 @@ | ||
package io.quarkus.arc.test.configproperties; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
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.config.ConfigProperties; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class InterfaceWithOtherConfigPrefixTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(DummyBean.class, DummyProperties.class, Other.class) | ||
.addAsResource(new StringAsset("dummy.other.name=test"), "application.properties")); | ||
|
||
@Inject | ||
DummyBean dummyBean; | ||
|
||
@Test | ||
public void testConfiguredValues() { | ||
Other other = dummyBean.dummyProperties.getOther(); | ||
assertNotNull(other); | ||
assertEquals("test", other.getName()); | ||
} | ||
|
||
@Singleton | ||
public static class DummyBean { | ||
|
||
@Inject | ||
public DummyProperties dummyProperties; | ||
} | ||
|
||
@ConfigProperties | ||
public interface DummyProperties { | ||
|
||
Other getOther(); | ||
} | ||
|
||
public interface Other { | ||
|
||
String getName(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
.../java/io/quarkus/arc/test/configproperties/InterfaceWithSubinterfaceConfigPrefixTest.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,75 @@ | ||
package io.quarkus.arc.test.configproperties; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
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.config.ConfigProperties; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class InterfaceWithSubinterfaceConfigPrefixTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(DummyBean.class, DummyProperties.class, DummyProperties.SubDummy.class) | ||
.addAsResource(new StringAsset( | ||
"dummy.name=quarkus\ndummy.boolWD=true\ndummy.sub-dummy.foo=bar\ndummy.sub-dummy.other=some"), | ||
"application.properties")); | ||
|
||
@Inject | ||
DummyBean dummyBean; | ||
|
||
@Test | ||
public void testConfiguredValues() { | ||
assertEquals("quarkus", dummyBean.dummyProperties.getName()); | ||
assertTrue(dummyBean.dummyProperties.isBoolWithDef()); | ||
DummyProperties.SubDummy subDummy = dummyBean.dummyProperties.getSubDummy(); | ||
assertNotNull(subDummy); | ||
assertEquals("some", subDummy.getOther()); | ||
assertEquals("bar", subDummy.getFooBar()); | ||
assertEquals(Arrays.asList(1, 2, 3), subDummy.getNumbers()); | ||
} | ||
|
||
@Singleton | ||
public static class DummyBean { | ||
|
||
@Inject | ||
public DummyProperties dummyProperties; | ||
} | ||
|
||
@ConfigProperties(prefix = "dummy") | ||
public interface DummyProperties { | ||
|
||
String getName(); | ||
|
||
@ConfigProperty(name = "boolWD", defaultValue = "false") | ||
boolean isBoolWithDef(); | ||
|
||
SubDummy getSubDummy(); | ||
|
||
interface SubDummy { | ||
|
||
@ConfigProperty(defaultValue = "1,2,3") | ||
Collection<Integer> getNumbers(); | ||
|
||
@ConfigProperty(name = "foo") | ||
String getFooBar(); | ||
|
||
String getOther(); | ||
} | ||
} | ||
} |