当前位置: 首页>>代码示例>>Java>>正文


Java ImmutableEnvironment类代码示例

本文整理汇总了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();
}
 
开发者ID:cfg4j,项目名称:cfg4j-sample-apps,代码行数:23,代码来源:ConfigBeans.java

示例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();
}
 
开发者ID:cfg4j,项目名称:cfg4j-sample-apps,代码行数:21,代码来源:ConfigBeans.java

示例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();
}
 
开发者ID:cfg4j,项目名称:cfg4j-sample-apps,代码行数:25,代码来源:ConfigBeans.java

示例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();
}
 
开发者ID:cfg4j,项目名称:cfg4j-sample-apps,代码行数:22,代码来源:ConfigBeans.java

示例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"));
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:8,代码来源:MergeConfigurationSourceTest.java

示例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"));
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:8,代码来源:MergeConfigurationSourceTest.java

示例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"));
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:10,代码来源:MergeConfigurationSourceTest.java

示例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"));
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:9,代码来源:MergeConfigurationSourceTest.java

示例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();
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:14,代码来源:FilesConfigurationSourceTest.java

示例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"));
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:33,代码来源:EnvironmentVariablesConfigurationSourceTest.java

示例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);
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:8,代码来源:ClasspathConfigurationSourceTest.java

示例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);
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:10,代码来源:SimpleConfigurationProviderGetPropertyTest.java

示例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"));
  }
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:9,代码来源:GitConfigurationSourceIntegrationTest.java

示例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"));
  }
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:9,代码来源:GitConfigurationSourceIntegrationTest.java

示例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"));
  }
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:8,代码来源:GitConfigurationSourceIntegrationTest.java


注:本文中的org.cfg4j.source.context.environment.ImmutableEnvironment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。