Search in sources :

Example 6 with PropertyResource

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

Example 7 with PropertyResource

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);
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PropertyResource(ch.jalu.configme.resource.PropertyResource) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) File(java.io.File) Settings(fr.xephi.authme.settings.Settings)

Example 8 with PropertyResource

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

Example 9 with PropertyResource

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));
}
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 PropertyResource

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

Aggregations

PropertyResource (ch.jalu.configme.resource.PropertyResource)12 File (java.io.File)12 Test (org.junit.Test)11 YamlFileResource (ch.jalu.configme.resource.YamlFileResource)10 TestHelper.getJarFile (fr.xephi.authme.TestHelper.getJarFile)5 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