-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
34 additions
and
17 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
2 changes: 1 addition & 1 deletion
2
...api/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
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 |
---|---|---|
@@ -1 +1 @@ | ||
com.microprofile.samples.services.number.config.StaticConfigSource | ||
#com.microprofile.samples.services.number.config.StaticConfigSource |
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 @@ | ||
generation.prefix=BK |
46 changes: 31 additions & 15 deletions
46
...i/src/test/java/com/microprofile/samples/services/number/config/GenerationPrefixTest.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 |
---|---|---|
@@ -1,30 +1,46 @@ | ||
package com.microprofile.samples.services.number.config; | ||
|
||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigValue; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.inject.Inject; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.microprofile.samples.services.number.config.GenerationPrefix.BK; | ||
import static com.microprofile.samples.services.number.config.GenerationPrefix.MV; | ||
import static com.microprofile.samples.services.number.config.GenerationPrefix.UN; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@QuarkusTest | ||
@TestProfile(GenerationPrefixTest.TestProfile.class) | ||
class GenerationPrefixTest { | ||
@Inject | ||
Config config; | ||
|
||
@Test | ||
void prefix() { | ||
assertEquals(BK, ConfigProvider.getConfig().getValue("generation.prefix", GenerationPrefix.class)); | ||
} | ||
assertEquals(BK, config.getValue("generation.prefix", GenerationPrefix.class)); | ||
ConfigValue configValue = config.getConfigValue("generation.prefix"); | ||
|
||
@Test | ||
void override() { | ||
System.setProperty("generation.prefix", "MV"); | ||
assertEquals(MV, ConfigProvider.getConfig().getValue("generation.prefix", GenerationPrefix.class)); | ||
System.clearProperty("generation.prefix"); | ||
assertTrue(configValue.getSourceName().contains("config.properties")); | ||
assertEquals("config.properties", config.getConfigValue("smallrye.config.locations").getValue()); | ||
} | ||
|
||
@Test | ||
void undefined() { | ||
System.setProperty("generation.prefix", "X"); | ||
assertEquals(UN, ConfigProvider.getConfig().getValue("generation.prefix", GenerationPrefix.class)); | ||
System.clearProperty("generation.prefix"); | ||
public static class TestProfile implements QuarkusTestProfile { | ||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
Map<String, String> configs = new HashMap<>(); | ||
configs.put("smallrye.config.locations", "config.properties"); | ||
return configs; | ||
} | ||
|
||
@Override | ||
public String getConfigProfile() { | ||
return "test"; | ||
} | ||
} | ||
} |