Search in sources :

Example 1 with PlainMigrationService

use of ch.jalu.configme.migration.PlainMigrationService in project AuthMeReloaded by AuthMe.

the class SettingsIntegrationTest method shouldLoadAndReadAllProperties.

@Test
public void shouldLoadAndReadAllProperties() throws IOException {
    // given
    PropertyResource resource = new YamlFileResource(copyFileFromResources(COMPLETE_FILE));
    // Pass another, non-existent file to check if the settings had to be rewritten
    File newFile = temporaryFolder.newFile();
    // when / 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, "Custom sys name").put(TestConfiguration.RATIO_ORDER, TestEnum.FIRST).put(TestConfiguration.RATIO_FIELDS, Arrays.asList("Australia", "Burundi", "Colombia")).put(TestConfiguration.VERSION_NUMBER, 2492).put(TestConfiguration.SKIP_BORING_FEATURES, false).put(TestConfiguration.BORING_COLORS, Arrays.asList("beige", "gray")).put(TestConfiguration.DUST_LEVEL, 2).put(TestConfiguration.USE_COOL_FEATURES, true).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()));
    }
    assertThat(newFile.length(), equalTo(0L));
}
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 2 with PlainMigrationService

use of ch.jalu.configme.migration.PlainMigrationService 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

PlainMigrationService (ch.jalu.configme.migration.PlainMigrationService)2 Property (ch.jalu.configme.properties.Property)2 PropertyResource (ch.jalu.configme.resource.PropertyResource)2 YamlFileResource (ch.jalu.configme.resource.YamlFileResource)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 TestHelper.getJarFile (fr.xephi.authme.TestHelper.getJarFile)2 File (java.io.File)2 Map (java.util.Map)2 Test (org.junit.Test)2