Search in sources :

Example 6 with YamlFileResource

use of ch.jalu.configme.resource.YamlFileResource in project AuthMeReloaded by AuthMe.

the class SettingsIntegrationTest method shouldReloadSettings.

@Test
public void shouldReloadSettings() throws IOException {
    // given
    File configFile = temporaryFolder.newFile();
    PropertyResource resource = new YamlFileResource(configFile);
    Settings settings = new Settings(testPluginFolder, resource, null, CONFIG_DATA);
    // when
    // default value
    assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER), equalTo(TestEnum.SECOND));
    Files.copy(getJarFile(COMPLETE_FILE), configFile);
    settings.reload();
    // then
    assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER), equalTo(TestEnum.FIRST));
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PropertyResource(ch.jalu.configme.resource.PropertyResource) File(java.io.File) TestHelper.getJarFile(fr.xephi.authme.TestHelper.getJarFile) Test(org.junit.Test)

Example 7 with YamlFileResource

use of ch.jalu.configme.resource.YamlFileResource in project AuthMeReloaded by AuthMe.

the class SettingsMigrationServiceTest method shouldKeepOldForceCommandSettings.

@Test
public void shouldKeepOldForceCommandSettings() throws IOException {
    // given
    File dataFolder = temporaryFolder.newFolder();
    File configFile = new File(dataFolder, "config.yml");
    Files.copy(getJarFile(OLD_CONFIG_FILE), configFile);
    PropertyResource resource = new YamlFileResource(configFile);
    SettingsMigrationService migrationService = new SettingsMigrationService(dataFolder);
    // when
    migrationService.performMigrations(resource, AuthMeSettingsRetriever.buildConfigurationData().getProperties());
    // then
    assertThat(migrationService.getOnLoginCommands(), contains("spawn"));
    assertThat(migrationService.getOnLoginConsoleCommands(), contains("sethome %p:lastloc", "msg %p Welcome back"));
    assertThat(migrationService.getOnRegisterCommands(), contains("me registers", "msg CONSOLE hi"));
    assertThat(migrationService.getOnRegisterConsoleCommands(), contains("sethome %p:regloc"));
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PropertyResource(ch.jalu.configme.resource.PropertyResource) TestHelper.getJarFile(fr.xephi.authme.TestHelper.getJarFile) File(java.io.File) Test(org.junit.Test)

Example 8 with YamlFileResource

use of ch.jalu.configme.resource.YamlFileResource in project AuthMeReloaded by AuthMe.

the class CommandManager method reload.

@Override
public void reload() {
    File file = new File(dataFolder, "commands.yml");
    FileUtils.copyFileFromResource(file, "commands.yml");
    SettingsManager settingsManager = new SettingsManager(new YamlFileResource(file), commandMigrationService, CommandSettingsHolder.class);
    CommandConfig commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS);
    onJoinCommands = newReplacer(commandConfig.getOnJoin());
    onLoginCommands = newReplacer(commandConfig.getOnLogin());
    onSessionLoginCommands = newReplacer(commandConfig.getOnSessionLogin());
    onRegisterCommands = newReplacer(commandConfig.getOnRegister());
    onUnregisterCommands = newReplacer(commandConfig.getOnUnregister());
    onLogoutCommands = newReplacer(commandConfig.getOnLogout());
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) SettingsManager(ch.jalu.configme.SettingsManager) File(java.io.File)

Example 9 with YamlFileResource

use of ch.jalu.configme.resource.YamlFileResource in project AuthMeReloaded by AuthMe.

the class CommandMigrationServiceTest method shouldRewriteIncompleteFile.

@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));
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PropertyResource(ch.jalu.configme.resource.PropertyResource) File(java.io.File) Test(org.junit.Test)

Example 10 with YamlFileResource

use of ch.jalu.configme.resource.YamlFileResource in project AuthMeReloaded by AuthMe.

the class CommandMigrationServiceTest method shouldRewriteForEmptyFile.

@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));
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PropertyResource(ch.jalu.configme.resource.PropertyResource) File(java.io.File) Test(org.junit.Test)

Aggregations

YamlFileResource (ch.jalu.configme.resource.YamlFileResource)13 File (java.io.File)13 PropertyResource (ch.jalu.configme.resource.PropertyResource)10 Test (org.junit.Test)9 TestHelper.getJarFile (fr.xephi.authme.TestHelper.getJarFile)5 SettingsManager (ch.jalu.configme.SettingsManager)3 PlainMigrationService (ch.jalu.configme.migration.PlainMigrationService)2 Property (ch.jalu.configme.properties.Property)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)1 Settings (fr.xephi.authme.settings.Settings)1 CommandConfig (fr.xephi.authme.settings.commandconfig.CommandConfig)1 IOException (java.io.IOException)1 TagValueHolder (tools.utils.TagValueHolder)1