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


Java ConfigurationDataBuilder类代码示例

本文整理汇总了Java中ch.jalu.configme.configurationdata.ConfigurationDataBuilder的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationDataBuilder类的具体用法?Java ConfigurationDataBuilder怎么用?Java ConfigurationDataBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConfigurationDataBuilder类属于ch.jalu.configme.configurationdata包,在下文中一共展示了ConfigurationDataBuilder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateUserInfo

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
public String generateUserInfo() {
    SettingsManager settingsManager = new SettingsManager(new YamlFileResource(configFile),
        new PlainMigrationService(), ConfigurationDataBuilder.collectData(DemoSettings.class));
    UserBase userBase = settingsManager.getProperty(DemoSettings.USER_BASE);

    User richie = userBase.getRichie();
    String savedLocationInfo = richie.getSavedLocations().entrySet().stream()
        .map(entry -> entry.getKey() + " " + entry.getValue())
        .collect(Collectors.joining(", "));
    String info = "Saved locations of Richie: " + savedLocationInfo;

    info += "\nNicknames of Bob: " + String.join(", ", userBase.getBobby().getNicknames());

    Country country = settingsManager.getProperty(DemoSettings.COUNTRY);
    info += "\nCountry '" + country.getName() + "' has neighbors: " + String.join(", ", country.getNeighbors());
    return info;
}
 
开发者ID:AuthMe,项目名称:ConfigMe,代码行数:18,代码来源:BeanPropertiesDemo.java

示例2: shouldWrapIoExceptionInConfigMeException

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
@Test
public void shouldWrapIoExceptionInConfigMeException() throws IOException {
    // given
    File file = copyFileFromResources(INCOMPLETE_FILE);
    PropertyResource resource = new YamlFileResource(file);
    file.delete();
    // Hacky: the only way we can easily provoke an IOException is by deleting the file and creating a folder
    // with the same name...
    temporaryFolder.newFolder(file.getName());

    // when / then
    try {
        resource.exportProperties(ConfigurationDataBuilder.collectData(TestConfiguration.class));
        fail("Expected ConfigMeException to be thrown");
    } catch (ConfigMeException e) {
        assertThat(e.getCause(), instanceOf(IOException.class));
    }
}
 
开发者ID:AuthMe,项目名称:ConfigMe,代码行数:19,代码来源:YamlFileResourceTest.java

示例3: shouldExportConfigurationWithExpectedComments

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
@Test
public void shouldExportConfigurationWithExpectedComments() throws IOException {
    // given
    File file = copyFileFromResources(COMPLETE_FILE);
    PropertyResource resource = new YamlFileResource(file);
    ConfigurationData configurationData = ConfigurationDataBuilder.collectData(TestConfiguration.class);

    // when
    resource.exportProperties(configurationData);

    // then
    // The IDE likes manipulating the whitespace in the expected file. As long as it's handled outside of an IDE
    // this test should be fine.
    assertThat(Files.readAllLines(file.toPath()),
        equalTo(Files.readAllLines(getJarPath("/config-export-expected.yml"))));
}
 
开发者ID:AuthMe,项目名称:ConfigMe,代码行数:17,代码来源:YamlFileResourceTest.java

示例4: shouldSetOptionalPropertyCorrectly

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
@Test
public void shouldSetOptionalPropertyCorrectly() {
    // given
    File file = copyFileFromResources("/config-sample.yml", temporaryFolder);
    PropertyResource resource = new YamlFileResource(file);
    SettingsManager settingsManager =
        new SettingsManager(resource, null, ConfigurationDataBuilder.collectData(TestConfiguration.class));
    OptionalProperty<Integer> intOptional = new OptionalProperty<>(newProperty("version", 65));
    // assumption
    assertThat(intOptional.getValue(resource), equalTo(Optional.of(2492)));

    // when
    settingsManager.setProperty(intOptional, Optional.empty());

    // then
    assertThat(intOptional.getValue(resource), equalTo(Optional.empty()));

    // when (2)
    settingsManager.setProperty(intOptional, Optional.of(43));

    // then (2)
    assertThat(intOptional.getValue(resource), equalTo(Optional.of(43)));
}
 
开发者ID:AuthMe,项目名称:ConfigMe,代码行数:24,代码来源:SettingsManagerTest.java

示例5: shouldMigrateOldOtherAccountsCommand

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
@Test
public void shouldMigrateOldOtherAccountsCommand() {
    // given
    given(settingsMigrationService.hasOldOtherAccountsCommand()).willReturn(true);
    given(settingsMigrationService.getOldOtherAccountsCommand())
        .willReturn("helpop %playername% (%playerip%) has other accounts!");
    given(settingsMigrationService.getOldOtherAccountsCommandThreshold()).willReturn(3);
    File commandFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/commandconfig/commands.complete.yml");
    PropertyResource resource = new YamlFileResource(commandFile);

    // when
    commandMigrationService.checkAndMigrate(
        resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());

    // then
    Map<String, OnLoginCommand> onLoginCommands = CommandSettingsHolder.COMMANDS.getValue(resource).getOnLogin();
    assertThat(onLoginCommands, aMapWithSize(6)); // 5 in the file + the newly migrated on
    OnLoginCommand newCommand = getUnknownOnLoginCommand(onLoginCommands);
    assertThat(newCommand.getCommand(), equalTo("helpop %p (%ip) has other accounts!"));
    assertThat(newCommand.getExecutor(), equalTo(Executor.CONSOLE));
    assertThat(newCommand.getIfNumberOfAccountsAtLeast().get(), equalTo(3));
    assertThat(newCommand.getIfNumberOfAccountsLessThan().isPresent(), equalTo(false));
}
 
开发者ID:AuthMe,项目名称:AuthMeReloaded,代码行数:24,代码来源:CommandMigrationServiceTest.java

示例6: shouldWriteMissingProperties

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
@Test
public void shouldWriteMissingProperties() {
    // given
    File file = copyFileFromResources(INCOMPLETE_FILE);
    YamlFileResource resource = new YamlFileResource(file);
    ConfigurationData configurationData = ConfigurationDataBuilder.collectData(TestConfiguration.class);

    // when
    resource.exportProperties(configurationData);

    // then
    // Load file again to make sure what we wrote can be read again
    resource = new YamlFileResource(file);
    Map<Property<?>, Object> expected = new HashMap<>();
    expected.put(TestConfiguration.DURATION_IN_SECONDS, 22);
    expected.put(TestConfiguration.SYSTEM_NAME, "[TestDefaultValue]");
    expected.put(TestConfiguration.RATIO_ORDER, "SECOND");
    expected.put(TestConfiguration.RATIO_FIELDS, Arrays.asList("Australia", "Burundi", "Colombia"));
    expected.put(TestConfiguration.VERSION_NUMBER, 32046);
    expected.put(TestConfiguration.SKIP_BORING_FEATURES, false);
    expected.put(TestConfiguration.BORING_COLORS, Collections.EMPTY_LIST);
    expected.put(TestConfiguration.DUST_LEVEL, -1);
    expected.put(TestConfiguration.USE_COOL_FEATURES, false);
    expected.put(TestConfiguration.COOL_OPTIONS, Arrays.asList("Dinosaurs", "Explosions", "Big trucks"));
    for (Map.Entry<Property<?>, Object> entry : expected.entrySet()) {
        // Check with resource#getObject to make sure the values were persisted to the file
        // If we go through Property objects they may fall back to their default values
        String propertyPath = entry.getKey().getPath();
        assertThat("Property '" + propertyPath + "' has expected value",
            resource.getObject(propertyPath), equalTo(entry.getValue()));
    }
}
 
开发者ID:AuthMe,项目名称:ConfigMe,代码行数:33,代码来源:YamlFileResourceTest.java

示例7: buildConfigurationData

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
/**
 * Builds the configuration data for all property fields in AuthMe {@link SettingsHolder} classes.
 *
 * @return configuration data
 */
public static ConfigurationData buildConfigurationData() {
    return ConfigurationDataBuilder.collectData(
        DatabaseSettings.class,  PluginSettings.class,    RestrictionSettings.class,
        EmailSettings.class,     HooksSettings.class,     ProtectionSettings.class,
        PurgeSettings.class,     SecuritySettings.class,  RegistrationSettings.class,
        LimboSettings.class,     BackupSettings.class,    ConverterSettings.class);
}
 
开发者ID:AuthMe,项目名称:AuthMeReloaded,代码行数:13,代码来源:AuthMeSettingsRetriever.java

示例8: shouldLoadWithNoMigrations

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
@Test
public void shouldLoadWithNoMigrations() {
    // given
    File commandFile = TestHelper.getJarFile("/commands.yml");
    PropertyResource resource = new YamlFileResource(commandFile);

    // when
    boolean result = commandMigrationService.checkAndMigrate(
        resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());

    // then
    assertThat(result, equalTo(false));
    verify(settingsMigrationService).hasOldOtherAccountsCommand();
}
 
开发者ID:AuthMe,项目名称:AuthMeReloaded,代码行数:15,代码来源:CommandYmlConsistencyTest.java

示例9: shouldRewriteForEmptyFile

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
@Test
public void shouldRewriteForEmptyFile() {
    // given
    File commandFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/commandconfig/commands.empty.yml");
    PropertyResource resource = new YamlFileResource(commandFile);

    // when
    boolean result = commandMigrationService.checkAndMigrate(
        resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());

    // then
    assertThat(result, equalTo(true));
}
 
开发者ID:AuthMe,项目名称:AuthMeReloaded,代码行数:14,代码来源:CommandMigrationServiceTest.java

示例10: shouldRewriteIncompleteFile

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
@Test
public void shouldRewriteIncompleteFile() {
    // given
    File commandFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/commandconfig/commands.incomplete.yml");
    PropertyResource resource = new YamlFileResource(commandFile);

    // when
    boolean result = commandMigrationService.checkAndMigrate(
        resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());

    // then
    assertThat(result, equalTo(true));
}
 
开发者ID:AuthMe,项目名称:AuthMeReloaded,代码行数:14,代码来源:CommandMigrationServiceTest.java

示例11: shouldNotChangeCompleteFile

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
@Test
public void shouldNotChangeCompleteFile() {
    // given
    File commandFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/commandconfig/commands.complete.yml");
    PropertyResource resource = new YamlFileResource(commandFile);

    // when
    boolean result = commandMigrationService.checkAndMigrate(
        resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());

    // then
    assertThat(result, equalTo(false));
}
 
开发者ID:AuthMe,项目名称:AuthMeReloaded,代码行数:14,代码来源:CommandMigrationServiceTest.java

示例12: shouldProperlyExportAnyValues

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
/** Verifies that "difficult cases" such as apostrophes in strings etc. are handled properly. */
@Test
public void shouldProperlyExportAnyValues() {
    // given
    File file = copyFileFromResources(DIFFICULT_FILE);
    YamlFileResource resource = new YamlFileResource(file);

    // Properties
    List<Property<?>> properties = new ArrayList<>(Arrays.asList(
        newProperty("more.string1", "it's a text with some \\'apostrophes'"),
        newProperty("more.string2", "\tthis one\nhas some\nnew '' lines-test")));
    properties.addAll(ConfigurationDataBuilder.collectData(TestConfiguration.class).getProperties());
    ConfigurationData configData = new ConfigurationData(properties);

    // when
    new SettingsManager(resource, new PlainMigrationService(), configData);
    // Save and load again
    resource.exportProperties(configData);
    resource.reload();

    // then
    assertThat(resource.getObject(TestConfiguration.DUST_LEVEL.getPath()), not(nullValue()));

    Map<Property<?>, Object> expected = new HashMap<>();
    expected.put(TestConfiguration.DURATION_IN_SECONDS, 20);
    expected.put(TestConfiguration.SYSTEM_NAME, "A 'test' name");
    expected.put(TestConfiguration.RATIO_ORDER, "FOURTH");
    expected.put(TestConfiguration.RATIO_FIELDS, Arrays.asList("Australia\\", "\tBurundi'", "Colombia?\n''"));
    expected.put(TestConfiguration.VERSION_NUMBER, -1337);
    expected.put(TestConfiguration.SKIP_BORING_FEATURES, false);
    expected.put(TestConfiguration.BORING_COLORS, Arrays.asList("it's a difficult string!", "gray\nwith new lines\n"));
    expected.put(TestConfiguration.DUST_LEVEL, -1);
    expected.put(TestConfiguration.USE_COOL_FEATURES, true);
    expected.put(TestConfiguration.COOL_OPTIONS, Collections.EMPTY_LIST);
    expected.put(properties.get(0), properties.get(0).getDefaultValue());
    expected.put(properties.get(1), properties.get(1).getDefaultValue());

    for (Map.Entry<Property<?>, Object> entry : expected.entrySet()) {
        assertThat("Property '" + entry.getKey().getPath() + "' has expected value",
            resource.getObject(entry.getKey().getPath()), equalTo(entry.getValue()));
    }
}
 
开发者ID:AuthMe,项目名称:ConfigMe,代码行数:43,代码来源:YamlFileResourceTest.java

示例13: SettingsManager

import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param resource the property resource to read and write properties to
 * @param migrationService migration service to check the property resource with
 * @param settingsClasses classes whose Property fields make up all known properties
 */
@SafeVarargs
public SettingsManager(PropertyResource resource, @Nullable MigrationService migrationService,
                       Class<? extends SettingsHolder>... settingsClasses) {
    this(resource, migrationService, ConfigurationDataBuilder.collectData(settingsClasses));
}
 
开发者ID:AuthMe,项目名称:ConfigMe,代码行数:13,代码来源:SettingsManager.java


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