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);
}
}
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()));
}
}
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"));
}
Aggregations