Upgrade to ConfigMe 0.2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.github.authme.configme.knownproperties.PropertyEntry;
|
||||
import com.github.authme.configme.knownproperties.ConfigurationData;
|
||||
import com.github.authme.configme.migration.MigrationService;
|
||||
import com.github.authme.configme.migration.PlainMigrationService;
|
||||
import com.github.authme.configme.properties.Property;
|
||||
@@ -16,10 +16,10 @@ import org.junit.Test;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -42,7 +42,8 @@ public class ConfigFileConsistencyTest {
|
||||
MigrationService migration = new PlainMigrationService();
|
||||
|
||||
// when
|
||||
boolean result = migration.checkAndMigrate(resource, AuthMeSettingsRetriever.getAllPropertyFields());
|
||||
boolean result = migration.checkAndMigrate(
|
||||
resource, AuthMeSettingsRetriever.buildConfigurationData().getProperties());
|
||||
|
||||
// then
|
||||
if (result) {
|
||||
@@ -86,23 +87,19 @@ public class ConfigFileConsistencyTest {
|
||||
// given
|
||||
File configFile = TestHelper.getJarFile(CONFIG_FILE);
|
||||
PropertyResource resource = new YamlFileResource(configFile);
|
||||
List<PropertyEntry> knownProperties = AuthMeSettingsRetriever.getAllPropertyFields();
|
||||
ConfigurationData configurationData = AuthMeSettingsRetriever.buildConfigurationData();
|
||||
|
||||
// when / then
|
||||
for (PropertyEntry propertyEntry : knownProperties) {
|
||||
Property<?> property = propertyEntry.getProperty();
|
||||
for (Property<?> property : configurationData.getProperties()) {
|
||||
assertThat("Default value of '" + property.getPath() + "' in config.yml should be the same as in Property",
|
||||
property.getValue(resource).equals(property.getDefaultValue()), equalTo(true));
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<String> getAllKnownPropertyPaths() {
|
||||
List<PropertyEntry> knownProperties = AuthMeSettingsRetriever.getAllPropertyFields();
|
||||
Set<String> paths = new HashSet<>(knownProperties.size());
|
||||
for (PropertyEntry propertyEntry : knownProperties) {
|
||||
paths.add(propertyEntry.getProperty().getPath());
|
||||
}
|
||||
return paths;
|
||||
return AuthMeSettingsRetriever.buildConfigurationData()
|
||||
.getProperties().stream()
|
||||
.map(Property::getPath)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.github.authme.configme.knownproperties.PropertyEntry;
|
||||
import com.github.authme.configme.knownproperties.PropertyFieldsCollector;
|
||||
import com.github.authme.configme.knownproperties.ConfigurationData;
|
||||
import com.github.authme.configme.knownproperties.ConfigurationDataBuilder;
|
||||
import com.github.authme.configme.migration.PlainMigrationService;
|
||||
import com.github.authme.configme.properties.Property;
|
||||
import com.github.authme.configme.resource.PropertyResource;
|
||||
@@ -21,7 +21,6 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static fr.xephi.authme.TestHelper.getJarFile;
|
||||
@@ -38,8 +37,8 @@ public class SettingsIntegrationTest {
|
||||
/** File name of the sample config missing certain {@link TestConfiguration} values. */
|
||||
private static final String INCOMPLETE_FILE = TestHelper.PROJECT_ROOT + "settings/config-incomplete-sample.yml";
|
||||
|
||||
private static List<PropertyEntry> knownProperties =
|
||||
PropertyFieldsCollector.getAllProperties(TestConfiguration.class);
|
||||
private static ConfigurationData CONFIG_DATA =
|
||||
ConfigurationDataBuilder.collectData(TestConfiguration.class);
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@@ -65,7 +64,7 @@ public class SettingsIntegrationTest {
|
||||
|
||||
// when / then
|
||||
Settings settings = new Settings(testPluginFolder, resource,
|
||||
new PlainMigrationService(), knownProperties);
|
||||
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")
|
||||
@@ -91,14 +90,14 @@ public class SettingsIntegrationTest {
|
||||
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(), knownProperties);
|
||||
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(), knownProperties);
|
||||
new PlainMigrationService(), CONFIG_DATA);
|
||||
Map<Property<?>, Object> expectedValues = ImmutableMap.<Property<?>, Object>builder()
|
||||
.put(TestConfiguration.DURATION_IN_SECONDS, 22)
|
||||
.put(TestConfiguration.SYSTEM_NAME, "[TestDefaultValue]")
|
||||
@@ -123,7 +122,7 @@ public class SettingsIntegrationTest {
|
||||
File configFile = temporaryFolder.newFile();
|
||||
PropertyResource resource = new YamlFileResource(configFile);
|
||||
Settings settings = new Settings(testPluginFolder, resource,
|
||||
TestSettingsMigrationServices.alwaysFulfilled(), knownProperties);
|
||||
TestSettingsMigrationServices.alwaysFulfilled(), CONFIG_DATA);
|
||||
|
||||
// when
|
||||
assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER), equalTo(TestEnum.SECOND)); // default value
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.github.authme.configme.knownproperties.PropertyEntry;
|
||||
import com.github.authme.configme.knownproperties.ConfigurationData;
|
||||
import com.github.authme.configme.resource.PropertyResource;
|
||||
import com.github.authme.configme.resource.YamlFileResource;
|
||||
import com.google.common.io.Files;
|
||||
@@ -12,7 +12,6 @@ import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayWithSize;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -41,12 +40,12 @@ public class SettingsMigrationServiceTest {
|
||||
// given
|
||||
copyConfigToTestFolder();
|
||||
PropertyResource resource = new YamlFileResource(configTestFile);
|
||||
List<PropertyEntry> propertyMap = AuthMeSettingsRetriever.getAllPropertyFields();
|
||||
ConfigurationData configurationData = AuthMeSettingsRetriever.buildConfigurationData();
|
||||
assumeThat(testFolder.listFiles(), arrayWithSize(1));
|
||||
SettingsMigrationService migrationService = new SettingsMigrationService(testFolder);
|
||||
|
||||
// when
|
||||
boolean result = migrationService.checkAndMigrate(resource, propertyMap);
|
||||
boolean result = migrationService.checkAndMigrate(resource, configurationData.getProperties());
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.github.authme.configme.knownproperties.PropertyEntry;
|
||||
import com.github.authme.configme.knownproperties.PropertyFieldsCollector;
|
||||
import com.github.authme.configme.knownproperties.ConfigurationData;
|
||||
import com.github.authme.configme.knownproperties.ConfigurationDataBuilder;
|
||||
import com.github.authme.configme.resource.PropertyResource;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
@@ -15,7 +15,6 @@ import org.junit.rules.TemporaryFolder;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayContaining;
|
||||
import static org.hamcrest.Matchers.arrayWithSize;
|
||||
@@ -29,8 +28,8 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class SettingsTest {
|
||||
|
||||
private static final List<PropertyEntry> knownProperties =
|
||||
PropertyFieldsCollector.getAllProperties(TestConfiguration.class);
|
||||
private static final ConfigurationData CONFIG_DATA =
|
||||
ConfigurationDataBuilder.collectData(TestConfiguration.class);
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@@ -57,7 +56,7 @@ public class SettingsTest {
|
||||
PropertyResource resource = mock(PropertyResource.class);
|
||||
given(resource.getBoolean(RegistrationSettings.USE_WELCOME_MESSAGE.getPath())).willReturn(true);
|
||||
Settings settings = new Settings(testPluginFolder, resource,
|
||||
TestSettingsMigrationServices.alwaysFulfilled(), knownProperties);
|
||||
TestSettingsMigrationServices.alwaysFulfilled(), CONFIG_DATA);
|
||||
|
||||
// when
|
||||
String[] result = settings.getWelcomeMessage();
|
||||
@@ -77,7 +76,7 @@ public class SettingsTest {
|
||||
|
||||
PropertyResource resource = mock(PropertyResource.class);
|
||||
Settings settings = new Settings(testPluginFolder, resource,
|
||||
TestSettingsMigrationServices.alwaysFulfilled(), knownProperties);
|
||||
TestSettingsMigrationServices.alwaysFulfilled(), CONFIG_DATA);
|
||||
|
||||
// when
|
||||
String result = settings.getPasswordEmailMessage();
|
||||
|
||||
Reference in New Issue
Block a user