use of ch.jalu.configme.resource.PropertyResource in project AuthMeReloaded by AuthMe.
the class SettingsTest method shouldLoadRecoveryCodeMessage.
@Test
public void shouldLoadRecoveryCodeMessage() throws IOException {
// given
String emailMessage = "Your recovery code is %code.";
File emailFile = new File(testPluginFolder, "recovery_code_email.html");
createFile(emailFile);
Files.write(emailFile.toPath(), emailMessage.getBytes());
PropertyResource resource = mock(PropertyResource.class);
Settings settings = new Settings(testPluginFolder, resource, null, CONFIG_DATA);
// when
String result = settings.getRecoveryCodeEmailMessage();
// then
assertThat(result, equalTo(emailMessage));
}
use of ch.jalu.configme.resource.PropertyResource in project AuthMeReloaded by AuthMe.
the class SettingsProvider method get.
/**
* Loads the plugin's settings.
*
* @return the settings instance, or null if it could not be constructed
*/
@Override
public Settings get() {
File configFile = new File(dataFolder, "config.yml");
if (!configFile.exists()) {
FileUtils.create(configFile);
}
PropertyResource resource = new YamlFileResource(configFile);
ConfigurationData configurationData = AuthMeSettingsRetriever.buildConfigurationData();
return new Settings(dataFolder, resource, migrationService, configurationData);
}
use of ch.jalu.configme.resource.PropertyResource 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));
}
use of ch.jalu.configme.resource.PropertyResource 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));
}
use of ch.jalu.configme.resource.PropertyResource 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()));
}
}
Aggregations