Search in sources :

Example 1 with ConfigurationData

use of ch.jalu.configme.configurationdata.ConfigurationData 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 2 with ConfigurationData

use of ch.jalu.configme.configurationdata.ConfigurationData in project AuthMeReloaded by AuthMe.

the class AuthMeSettingsRetrieverTest method shouldReturnAllProperties.

@Test
public void shouldReturnAllProperties() {
    // given / when
    ConfigurationData configurationData = AuthMeSettingsRetriever.buildConfigurationData();
    // then
    // Note ljacqu 20161123: Check that the number of properties returned corresponds to what we expect with
    // an error margin of 10: this prevents us from having to adjust the test every time the config is changed.
    // If this test fails, replace the first argument in closeTo() with the new number of properties
    assertThat((double) configurationData.getProperties().size(), closeTo(160, 10));
}
Also used : ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) Test(org.junit.Test)

Example 3 with ConfigurationData

use of ch.jalu.configme.configurationdata.ConfigurationData in project AuthMeReloaded by AuthMe.

the class SettingsClassConsistencyTest method shouldHaveAllClassesInConfigurationData.

/**
     * Checks that {@link AuthMeSettingsRetriever} returns a ConfigurationData with all
     * available SettingsHolder classes.
     */
@Test
public void shouldHaveAllClassesInConfigurationData() {
    // given
    long totalProperties = classes.stream().map(Class::getDeclaredFields).flatMap(Arrays::stream).filter(field -> Property.class.isAssignableFrom(field.getType())).count();
    // when
    ConfigurationData configData = AuthMeSettingsRetriever.buildConfigurationData();
    // then
    assertThat("ConfigurationData should have " + totalProperties + " properties (as found manually)", configData.getProperties(), hasSize((int) totalProperties));
}
Also used : Arrays(java.util.Arrays) ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass) Set(java.util.Set) Test(org.junit.Test) Field(java.lang.reflect.Field) ReflectionTestUtils(fr.xephi.authme.ReflectionTestUtils) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) Property(ch.jalu.configme.properties.Property) Modifier(java.lang.reflect.Modifier) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SettingsHolder(ch.jalu.configme.SettingsHolder) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.fail(org.junit.Assert.fail) TestHelper(fr.xephi.authme.TestHelper) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) Arrays(java.util.Arrays) Test(org.junit.Test)

Aggregations

ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)3 Test (org.junit.Test)2 SettingsHolder (ch.jalu.configme.SettingsHolder)1 Property (ch.jalu.configme.properties.Property)1 PropertyResource (ch.jalu.configme.resource.PropertyResource)1 YamlFileResource (ch.jalu.configme.resource.YamlFileResource)1 ClassCollector (fr.xephi.authme.ClassCollector)1 ReflectionTestUtils (fr.xephi.authme.ReflectionTestUtils)1 TestHelper (fr.xephi.authme.TestHelper)1 Settings (fr.xephi.authme.settings.Settings)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 Modifier (java.lang.reflect.Modifier)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Matchers.hasSize (org.hamcrest.Matchers.hasSize)1 Assert.assertThat (org.junit.Assert.assertThat)1