gpt4 book ai didi

org.cfg4j.source.context.propertiesprovider.YamlBasedPropertiesProvider类的使用及代码示例

转载 作者:知者 更新时间:2024-03-16 02:31:31 24 4
gpt4 key购买 nike

本文整理了Java中org.cfg4j.source.context.propertiesprovider.YamlBasedPropertiesProvider类的一些代码示例,展示了YamlBasedPropertiesProvider类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlBasedPropertiesProvider类的具体详情如下:
包路径:org.cfg4j.source.context.propertiesprovider.YamlBasedPropertiesProvider
类名称:YamlBasedPropertiesProvider

YamlBasedPropertiesProvider介绍

[英]PropertiesProvider that interprets given stream as YAML file.
[中]将给定流解释为YAML文件的PropertiesProvider。

代码示例

代码示例来源:origin: cfg4j/cfg4j

/**
 * Construct {@link ConfigurationSource} backed by files. File paths should by provided by
 * {@link ConfigFilesProvider} and will be treated as relative paths to the environment provided in
 * {@link #getConfiguration(Environment)} calls (see corresponding javadoc for detail). Configuration
 * file type is detected using file extension (see {@link PropertiesProviderSelector}).
 *
 * @param configFilesProvider {@link ConfigFilesProvider} supplying a list of configuration files to use
 */
public FilesConfigurationSource(ConfigFilesProvider configFilesProvider) {
 this(configFilesProvider, new PropertiesProviderSelector(
   new PropertyBasedPropertiesProvider(), new YamlBasedPropertiesProvider(), new JsonBasedPropertiesProvider()
 ));
}

代码示例来源:origin: cfg4j/cfg4j

/**
 * Get {@link Properties} for a given {@code inputStream} treating it as a YAML file.
 *
 * @param inputStream input stream representing YAML file
 * @return properties representing values from {@code inputStream}
 * @throws IllegalStateException when unable to read properties
 */
@Override
public Properties getProperties(InputStream inputStream) {
 requireNonNull(inputStream);
 Yaml yaml = new Yaml();
 Properties properties = new Properties();
 try (Reader reader = new UnicodeReader(inputStream)) {
  Object object = yaml.load(reader);
  if (object != null) {
   Map<String, Object> yamlAsMap = convertToMap(object);
   properties.putAll(flatten(yamlAsMap));
  }
  return properties;
 } catch (IOException | ScannerException e) {
  throw new IllegalStateException("Unable to load yaml configuration from provided stream", e);
 }
}

代码示例来源:origin: cfg4j/cfg4j

@Test
void supportsEmptyDocument() throws Exception {
 String path = "org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_supportsEmptyDocument.yaml";
 try (InputStream input = getClass().getClassLoader().getResourceAsStream(path)) {
  assertThat(provider.getProperties(input)).isEmpty();
 }
}

代码示例来源:origin: cfg4j/cfg4j

value = convertToMap(value);
} else if (value instanceof Collection) {
 ArrayList<Map<String, Object>> collection = new ArrayList<>();
  collection.add(convertToMap(element));

代码示例来源:origin: cfg4j/cfg4j

@Test
 void throwsOnNullInput() throws Exception {
  String path = "org/cfg4j/source/propertiesprovider/nonexistent.json";

  try (InputStream input = getClass().getClassLoader().getResourceAsStream(path)) {
   assertThatThrownBy(() -> provider.getProperties(input)).isExactlyInstanceOf(NullPointerException.class);
  }
 }
}

代码示例来源:origin: cfg4j/cfg4j

/**
 * Construct {@link ConfigurationSource} backed by classpath files. File paths should by provided by
 * {@link ConfigFilesProvider} and will be treated as relative paths to the environment provided in
 * {@link #getConfiguration(Environment)} calls (see corresponding javadoc for detail). Configuration
 * file type is detected using file extension (see {@link PropertiesProviderSelector}).
 *
 * @param configFilesProvider {@link ConfigFilesProvider} supplying a list of configuration files to use
 */
public ClasspathConfigurationSource(ConfigFilesProvider configFilesProvider) {
 this(configFilesProvider, new PropertiesProviderSelector(
   new PropertyBasedPropertiesProvider(), new YamlBasedPropertiesProvider(), new JsonBasedPropertiesProvider()
 ));
}

代码示例来源:origin: cfg4j/cfg4j

@Test
void throwsForNonYamlFile() throws Exception {
 String path = "org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_throwsForNonYamlFile.yaml";
 try (InputStream input = getClass().getClassLoader().getResourceAsStream(path)) {
  assertThatThrownBy(() -> provider.getProperties(input)).isExactlyInstanceOf(IllegalStateException.class);
 }
}

代码示例来源:origin: cfg4j/cfg4j

@BeforeEach
void setUp() {
 provider = new YamlBasedPropertiesProvider();
}

代码示例来源:origin: cfg4j/cfg4j

@Test
void readsTextBlock() throws Exception {
 String path = "org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_readsTextBlock.yaml";
 try (InputStream input = getClass().getClassLoader().getResourceAsStream(path)) {
  assertThat(provider.getProperties(input)).containsExactly(MapEntry.entry("content", "I'm just a text block document"));
 }
}

代码示例来源:origin: cfg4j/cfg4j

/**
 * Construct {@link GitConfigurationSource}s builder
 * <p>
 * Default setup (override using with*() methods)
 * <ul>
 * <li>BranchResolver: {@link FirstTokenBranchResolver}</li>
 * <li>PathResolver: {@link AllButFirstTokenPathResolver}</li>
 * <li>ConfigFilesProvider: {@link DefaultConfigFilesProvider}</li>
 * <li>tmpPath: System.getProperty("java.io.tmpdir")</li>
 * <li>tmpRepoPrefix: "cfg4j-config-git-config-repository"</li>
 * <li>propertiesProviderSelector: {@link PropertiesProviderSelector} with {@link PropertyBasedPropertiesProvider}
 * and {@link YamlBasedPropertiesProvider} providers</li>
 * </ul>
 */
public GitConfigurationSourceBuilder() {
 branchResolver = new FirstTokenBranchResolver();
 pathResolver = new AllButFirstTokenPathResolver();
 tmpPath = Paths.get(System.getProperty("java.io.tmpdir"));
 tmpRepoPrefix = "cfg4j-git-config-repository";
 configFilesProvider = new DefaultConfigFilesProvider();
 propertiesProviderSelector = new PropertiesProviderSelector(
   new PropertyBasedPropertiesProvider(), new YamlBasedPropertiesProvider(), new JsonBasedPropertiesProvider()
 );
}

代码示例来源:origin: cfg4j/cfg4j

@Test
void readsSingleValues() throws Exception {
 String path = "org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_readsSingleValues.yaml";
 try (InputStream input = getClass().getClassLoader().getResourceAsStream(path)) {
  assertThat(provider.getProperties(input)).containsOnly(MapEntry.entry("setting", "masterValue"),
    MapEntry.entry("integerSetting", 42));
 }
}

代码示例来源:origin: cfg4j/cfg4j

@Test
void readsNestedValues() throws Exception {
 String path = "org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_readsNestedValues.yaml";
 try (InputStream input = getClass().getClassLoader().getResourceAsStream(path)) {
  assertThat(provider.getProperties(input)).containsOnly(MapEntry.entry("some.setting", "masterValue"),
    MapEntry.entry("some.integerSetting", 42));
 }
}

代码示例来源:origin: cfg4j/cfg4j

@Test
void readsLists() throws Exception {
 String path = "org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_readsLists.yaml";
 try (InputStream input = getClass().getClassLoader().getResourceAsStream(path)) {
  assertThat(provider.getProperties(input)).containsOnly(MapEntry.entry("whitelist", "a,b,33"),
    MapEntry.entry("blacklist", "x,y,z"));
 }
}

代码示例来源:origin: cfg4j/cfg4j

@Test
void supportsReferences() throws Exception {
 String path = "org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_supportsReferences.yaml";
 try (InputStream input = getClass().getClassLoader().getResourceAsStream(path)) {
  assertThat(provider.getProperties(input)).containsOnly(
    MapEntry.entry("wheelA.radius", "25cm"), MapEntry.entry("wheelA.color", "black"),
    MapEntry.entry("wheelB.radius", "25cm"), MapEntry.entry("wheelB.color", "black")
  );
 }
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com