Search in sources :

Example 11 with YamlFileResource

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

the class UpdateConfigPageTask method executeDefault.

@Override
public void executeDefault() {
    File config = null;
    try {
        // Create empty temporary .yml file and save the config to it
        config = File.createTempFile("authme-config-", ".yml");
        SettingsManager settingsManager = new SettingsManager(new YamlFileResource(config), null, AuthMeSettingsRetriever.buildConfigurationData());
        settingsManager.save();
        // Get the contents and generate template file
        TagValueHolder tagValueHolder = TagValueHolder.create().put("config", FileIoUtils.readFromFile(config.toPath()));
        FileIoUtils.generateFileFromTemplate(TEMPLATE_FILE, OUTPUT_FILE, tagValueHolder);
        System.out.println("Wrote to '" + OUTPUT_FILE + "'");
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } finally {
        FileUtils.delete(config);
    }
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) SettingsManager(ch.jalu.configme.SettingsManager) TagValueHolder(tools.utils.TagValueHolder) IOException(java.io.IOException) File(java.io.File)

Example 12 with YamlFileResource

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

the class SettingsIntegrationTest method shouldWriteMissingProperties.

@Test
public void shouldWriteMissingProperties() {
    // given/when
    File file = copyFileFromResources(INCOMPLETE_FILE);
    PropertyResource resource = new YamlFileResource(file);
    // Expectation: File is rewritten to since it does not have all configurations
    new Settings(testPluginFolder, resource, new PlainMigrationService(), CONFIG_DATA);
    // Load the settings again -> checks that what we wrote can be loaded again
    resource = new YamlFileResource(file);
    // then
    Settings settings = new Settings(testPluginFolder, resource, new PlainMigrationService(), CONFIG_DATA);
    Map<Property<?>, Object> expectedValues = ImmutableMap.<Property<?>, Object>builder().put(TestConfiguration.DURATION_IN_SECONDS, 22).put(TestConfiguration.SYSTEM_NAME, "[TestDefaultValue]").put(TestConfiguration.RATIO_ORDER, TestEnum.SECOND).put(TestConfiguration.RATIO_FIELDS, Arrays.asList("Australia", "Burundi", "Colombia")).put(TestConfiguration.VERSION_NUMBER, 32046).put(TestConfiguration.SKIP_BORING_FEATURES, false).put(TestConfiguration.BORING_COLORS, Collections.EMPTY_LIST).put(TestConfiguration.DUST_LEVEL, -1).put(TestConfiguration.USE_COOL_FEATURES, false).put(TestConfiguration.COOL_OPTIONS, Arrays.asList("Dinosaurs", "Explosions", "Big trucks")).build();
    for (Map.Entry<Property<?>, Object> entry : expectedValues.entrySet()) {
        assertThat("Property '" + entry.getKey().getPath() + "' has expected value", settings.getProperty(entry.getKey()), equalTo(entry.getValue()));
    }
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PlainMigrationService(ch.jalu.configme.migration.PlainMigrationService) PropertyResource(ch.jalu.configme.resource.PropertyResource) File(java.io.File) TestHelper.getJarFile(fr.xephi.authme.TestHelper.getJarFile) Property(ch.jalu.configme.properties.Property) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 13 with YamlFileResource

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

the class SettingsMigrationServiceTest method shouldPerformMigrations.

@Test
public void shouldPerformMigrations() 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
    Settings settings = new Settings(dataFolder, resource, migrationService, AuthMeSettingsRetriever.buildConfigurationData());
    // then
    assertThat(settings.getProperty(ALLOWED_NICKNAME_CHARACTERS), equalTo(ALLOWED_NICKNAME_CHARACTERS.getDefaultValue()));
    assertThat(settings.getProperty(DELAY_JOIN_MESSAGE), equalTo(true));
    assertThat(settings.getProperty(FORCE_SPAWN_LOCATION_AFTER_LOGIN), equalTo(true));
    assertThat(settings.getProperty(FORCE_SPAWN_ON_WORLDS), contains("survival", "survival_nether", "creative"));
    assertThat(settings.getProperty(LOG_LEVEL), equalTo(LogLevel.INFO));
    assertThat(settings.getProperty(REGISTRATION_TYPE), equalTo(RegistrationType.EMAIL));
    assertThat(settings.getProperty(REGISTER_SECOND_ARGUMENT), equalTo(RegisterSecondaryArgument.CONFIRMATION));
    assertThat(settings.getProperty(ENABLE_PERMISSION_CHECK), equalTo(true));
    assertThat(settings.getProperty(REGISTERED_GROUP), equalTo("unLoggedinGroup"));
    assertThat(settings.getProperty(UNREGISTERED_GROUP), equalTo(""));
    // Check migration of old setting to email.html
    assertThat(Files.readLines(new File(dataFolder, "email.html"), StandardCharsets.UTF_8), contains("Dear <playername />, <br /><br /> This is your new AuthMe password for the server " + "<br /><br /> <servername /> : <br /><br /> <generatedpass /><br /><image /><br />Do not forget to " + "change password after login! <br /> /changepassword <generatedpass /> newPassword"));
}
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)

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