本文整理汇总了Java中org.cfg4j.source.context.environment.ImmutableEnvironment类的典型用法代码示例。如果您正苦于以下问题:Java ImmutableEnvironment类的具体用法?Java ImmutableEnvironment怎么用?Java ImmutableEnvironment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImmutableEnvironment类属于org.cfg4j.source.context.environment包,在下文中一共展示了ImmutableEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configurationProvider
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Bean
public ConfigurationProvider configurationProvider() {
// Specify which files to load. Configuration from both files will be merged.
ConfigFilesProvider configFilesProvider = () -> Collections.singletonList(Paths.get("application.yaml"));
// Use local files as configuration store
ConfigurationSource source = new FilesConfigurationSource(configFilesProvider);
// Use relative paths
Environment environment = new ImmutableEnvironment(filesPath);
// Reload configuration every 500 milliseconds
ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(500, TimeUnit.MILLISECONDS);
// Create provider
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.withReloadStrategy(reloadStrategy)
.withEnvironment(environment)
.withMetrics(metricRegistry, "firstProvider.")
.build();
}
示例2: configurationProvider
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Bean
public ConfigurationProvider configurationProvider() {
// Use Git repository as configuration store
ConfigurationSource source = new GitConfigurationSourceBuilder()
.withRepositoryURI(configRepoPath)
.build();
// Select branch to use (use new DefaultEnvironment()) for master
Environment environment = new ImmutableEnvironment(branch);
// Reload configuration every 5 seconds
ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS);
// Create provider
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.withEnvironment(environment)
.withReloadStrategy(reloadStrategy)
.build();
}
示例3: configurationProvider
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Bean
public ConfigurationProvider configurationProvider() {
// Specify which files to load. Configuration from both files will be merged.
ConfigFilesProvider configFilesProvider = () -> Arrays.asList(Paths.get("application.properties"), Paths.get("otherConfig.properties"));
// Use Git repository as configuration store
ConfigurationSource source = new GitConfigurationSourceBuilder()
.withRepositoryURI(configRepoPath)
.withConfigFilesProvider(configFilesProvider)
.build();
// Select branch to use (use new DefaultEnvironment()) for master
Environment environment = new ImmutableEnvironment(branch);
// Reload configuration every 5 seconds
ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS);
// Create provider
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.withEnvironment(environment)
.withReloadStrategy(reloadStrategy)
.build();
}
示例4: configurationProvider
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Bean
public ConfigurationProvider configurationProvider() {
// Specify which files to load. Configuration from both files will be merged.
ConfigFilesProvider configFilesProvider = () -> Arrays.asList(Paths.get("application.yaml"), Paths.get("otherConfig.properties"));
// Use local files as configuration store
ConfigurationSource source = new FilesConfigurationSource(configFilesProvider);
// Use relative paths
Environment environment = new ImmutableEnvironment(filesPath);
// Reload configuration every 5 seconds
ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS);
// Create provider
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.withReloadStrategy(reloadStrategy)
.withEnvironment(environment)
.build();
}
示例5: getConfigurationThrowsWhenOneOfSourcesThrowsOnMissingEnvironment
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Test
public void getConfigurationThrowsWhenOneOfSourcesThrowsOnMissingEnvironment() throws Exception {
when(underlyingSources[1].getConfiguration(Matchers.<Environment>any())).thenThrow(new MissingEnvironmentException(""));
expectedException.expect(MissingEnvironmentException.class);
mergeConfigurationSource.getConfiguration(new ImmutableEnvironment("test"));
}
示例6: getConfigurationThrowsWhenOneOfSourcesThrows
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Test
public void getConfigurationThrowsWhenOneOfSourcesThrows() throws Exception {
when(underlyingSources[3].getConfiguration(Matchers.<Environment>any())).thenThrow(new IllegalStateException());
expectedException.expect(IllegalStateException.class);
mergeConfigurationSource.getConfiguration(new ImmutableEnvironment("test"));
}
示例7: getConfigurationMergesConfigurations
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Test
public void getConfigurationMergesConfigurations() throws Exception {
Environment environment = new ImmutableEnvironment("test");
sourcesWithProps(environment, "prop1", "value1", "prop2", "value2");
assertThat(mergeConfigurationSource.getConfiguration(environment)).containsOnly(MapEntry.entry("prop1", "value1"),
MapEntry.entry("prop2", "value2"));
}
示例8: getConfigurationMergesConfigurationsWithCollidingKeys
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Test
public void getConfigurationMergesConfigurationsWithCollidingKeys() throws Exception {
Environment environment = new ImmutableEnvironment("test");
sourcesWithProps(environment, "prop", "value1", "prop", "value2");
assertThat(mergeConfigurationSource.getConfiguration(environment)).containsOnly(MapEntry.entry("prop", "value2"));
}
示例9: setUp
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
fileRepo = new TempConfigurationFileRepo("org.cfg4j-test-repo");
fileRepo.changeProperty(Paths.get("application.properties"), "some.setting", "masterValue");
fileRepo.changeProperty(Paths.get("otherConfig.properties"), "otherConfig.setting", "masterValue");
fileRepo.changeProperty(Paths.get("malformed.properties"), "otherConfig.setting", "\\uzzzzz");
fileRepo.changeProperty(Paths.get("otherApplicationConfigs/application.properties"), "some.setting", "otherAppSetting");
environment = new ImmutableEnvironment(fileRepo.dirPath.toString());
source = new FilesConfigurationSource();
source.init();
}
示例10: returnsAllVariablesInNamespace
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Test
public void returnsAllVariablesInNamespace() throws Exception {
// Given
EnvironmentVariablesConfigurationSource mockSource = new EnvironmentVariablesConfigurationSource();
PowerMockito.mockStatic(System.class);
final String namespace = "APPLICATION_NAME";
Environment nameSpaced = new ImmutableEnvironment(namespace);
Environment nameSpaceTrailingUnderscore = new ImmutableEnvironment(namespace + "_");
Map<String, String> mockEnv = new HashMap<String, String>() {{
put("PATH", "/usr/bin");
put(namespace + "_PROFILE", "PROD");
put(namespace + "_USER", "TEST");
}};
// When
Mockito.when(System.getenv()).thenReturn(mockEnv);
mockSource.init();
// Then
Properties config = mockSource.getConfiguration(nameSpaced);
assertThat(config.containsKey("PROFILE"));
assertThat(config.containsKey("USER"));
assertThat(!config.containsKey("PATH"));
// Then
Properties configUnderscoreEnv = mockSource.getConfiguration(nameSpaceTrailingUnderscore);
assertThat(configUnderscoreEnv.containsKey("PROFILE"));
assertThat(configUnderscoreEnv.containsKey("USER"));
assertThat(!configUnderscoreEnv.containsKey("PATH"));
}
示例11: getConfigurationDisallowsLeadingSlashInClasspathLocation
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Test
public void getConfigurationDisallowsLeadingSlashInClasspathLocation() throws Exception {
Environment environment = new ImmutableEnvironment("/otherApplicationConfigs");
expectedException.expect(MissingEnvironmentException.class);
source.getConfiguration(environment);
}
示例12: getPropertyReturnsPropertyForProperEnvironment
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Test
public void getPropertyReturnsPropertyForProperEnvironment() throws Exception {
when(configurationSource.getConfiguration(environment)).thenReturn(propertiesWith("some.property", "1"));
when(configurationSource.getConfiguration(new ImmutableEnvironment("test_env"))).thenReturn(propertiesWith("some.property", "2"));
Integer property = simpleConfigurationProvider.getProperty("some.property", Integer.class);
assertThat(property).isEqualTo(1);
}
示例13: getConfigurationReadsConfigFromGivenBranch
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Test
public void getConfigurationReadsConfigFromGivenBranch() throws Exception {
try (GitConfigurationSource gitConfigurationSource = getSourceForRemoteRepoWithDefaults()) {
Environment environment = new ImmutableEnvironment(TEST_ENV_BRANCH);
assertThat(gitConfigurationSource.getConfiguration(environment)).contains(MapEntry.entry("some.setting", "testValue"));
}
}
示例14: getConfigurationReadsFromGivenPath
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Test
public void getConfigurationReadsFromGivenPath() throws Exception {
try (GitConfigurationSource gitConfigurationSource = getSourceForRemoteRepoWithDefaults()) {
Environment environment = new ImmutableEnvironment("/otherApplicationConfigs/");
assertThat(gitConfigurationSource.getConfiguration(environment)).contains(MapEntry.entry("some.setting", "otherAppSetting"));
}
}
示例15: getConfigurationThrowsOnMissingBranch
import org.cfg4j.source.context.environment.ImmutableEnvironment; //导入依赖的package包/类
@Test
public void getConfigurationThrowsOnMissingBranch() throws Exception {
try (GitConfigurationSource gitConfigurationSource = getSourceForRemoteRepoWithDefaults()) {
expectedException.expect(MissingEnvironmentException.class);
gitConfigurationSource.getConfiguration(new ImmutableEnvironment("nonExistentBranch"));
}
}