#927 Update code to recent changes in ConfigMe
This commit is contained in:
parent
c7bb7b460e
commit
36dfab636a
@ -67,7 +67,7 @@ public class Initializer {
|
|||||||
List<PropertyEntry> knownProperties = AuthMeSettingsRetriever.getAllPropertyFields();
|
List<PropertyEntry> knownProperties = AuthMeSettingsRetriever.getAllPropertyFields();
|
||||||
|
|
||||||
if (FileUtils.copyFileFromResource(configFile, "config.yml")) {
|
if (FileUtils.copyFileFromResource(configFile, "config.yml")) {
|
||||||
return new Settings(authMe.getDataFolder(), knownProperties, resource, migrationService);
|
return new Settings(authMe.getDataFolder(), resource, migrationService, knownProperties);
|
||||||
}
|
}
|
||||||
throw new Exception("Could not copy config.yml from JAR to plugin folder");
|
throw new Exception("Could not copy config.yml from JAR to plugin folder");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,13 +33,13 @@ public class Settings extends SettingsManager {
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param pluginFolder the AuthMe plugin folder
|
* @param pluginFolder the AuthMe plugin folder
|
||||||
* @param knownProperties collection of all available settings
|
|
||||||
* @param resource the property resource to read and write properties to
|
* @param resource the property resource to read and write properties to
|
||||||
* @param migrationService migration service to check the settings file with
|
* @param migrationService migration service to check the settings file with
|
||||||
|
* @param knownProperties collection of all available settings
|
||||||
*/
|
*/
|
||||||
public Settings(File pluginFolder, List<PropertyEntry> knownProperties, PropertyResource resource,
|
public Settings(File pluginFolder, PropertyResource resource, MigrationService migrationService,
|
||||||
MigrationService migrationService) {
|
List<PropertyEntry> knownProperties) {
|
||||||
super(knownProperties, resource, migrationService);
|
super(resource, migrationService, knownProperties);
|
||||||
this.pluginFolder = pluginFolder;
|
this.pluginFolder = pluginFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,12 +22,10 @@ public final class AuthMeSettingsRetriever {
|
|||||||
* @return list of all known properties
|
* @return list of all known properties
|
||||||
*/
|
*/
|
||||||
public static List<PropertyEntry> getAllPropertyFields() {
|
public static List<PropertyEntry> getAllPropertyFields() {
|
||||||
SettingsFieldRetriever retriever = new SettingsFieldRetriever(
|
return SettingsFieldRetriever.getAllProperties(
|
||||||
DatabaseSettings.class, ConverterSettings.class, PluginSettings.class,
|
DatabaseSettings.class, ConverterSettings.class, PluginSettings.class,
|
||||||
RestrictionSettings.class, EmailSettings.class, HooksSettings.class,
|
RestrictionSettings.class, EmailSettings.class, HooksSettings.class,
|
||||||
ProtectionSettings.class, PurgeSettings.class, SecuritySettings.class,
|
ProtectionSettings.class, PurgeSettings.class, SecuritySettings.class,
|
||||||
RegistrationSettings.class, BackupSettings.class);
|
RegistrationSettings.class, BackupSettings.class);
|
||||||
|
|
||||||
return retriever.getAllPropertyFields();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,7 +94,8 @@ public class AuthMeInitializationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldInitializeAllServices() {
|
public void shouldInitializeAllServices() {
|
||||||
// given
|
// given
|
||||||
Settings settings = new Settings(dataFolder, getAllPropertyFields(), mock(PropertyResource.class), alwaysFulfilled());
|
Settings settings =
|
||||||
|
new Settings(dataFolder, mock(PropertyResource.class), alwaysFulfilled(), getAllPropertyFields());
|
||||||
|
|
||||||
Injector injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme").create();
|
Injector injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme").create();
|
||||||
injector.provide(DataFolder.class, dataFolder);
|
injector.provide(DataFolder.class, dataFolder);
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package fr.xephi.authme.settings;
|
|||||||
import com.github.authme.configme.migration.PlainMigrationService;
|
import com.github.authme.configme.migration.PlainMigrationService;
|
||||||
import com.github.authme.configme.properties.Property;
|
import com.github.authme.configme.properties.Property;
|
||||||
import com.github.authme.configme.propertymap.PropertyEntry;
|
import com.github.authme.configme.propertymap.PropertyEntry;
|
||||||
|
import com.github.authme.configme.propertymap.SettingsFieldRetriever;
|
||||||
import com.github.authme.configme.resource.PropertyResource;
|
import com.github.authme.configme.resource.PropertyResource;
|
||||||
import com.github.authme.configme.resource.YamlFileResource;
|
import com.github.authme.configme.resource.YamlFileResource;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
@ -36,7 +37,7 @@ public class SettingsIntegrationTest {
|
|||||||
/** File name of the sample config missing certain {@link TestConfiguration} values. */
|
/** 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 final String INCOMPLETE_FILE = TestHelper.PROJECT_ROOT + "settings/config-incomplete-sample.yml";
|
||||||
|
|
||||||
private static List<PropertyEntry> propertyMap = TestConfiguration.generatePropertyMap();
|
private static List<PropertyEntry> knownProperties = SettingsFieldRetriever.getAllProperties(TestConfiguration.class);
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
@ -61,8 +62,8 @@ public class SettingsIntegrationTest {
|
|||||||
File newFile = temporaryFolder.newFile();
|
File newFile = temporaryFolder.newFile();
|
||||||
|
|
||||||
// when / then
|
// when / then
|
||||||
Settings settings = new Settings(testPluginFolder, propertyMap, resource,
|
Settings settings = new Settings(testPluginFolder, resource,
|
||||||
new PlainMigrationService());
|
new PlainMigrationService(), knownProperties);
|
||||||
Map<Property<?>, Object> expectedValues = ImmutableMap.<Property<?>, Object>builder()
|
Map<Property<?>, Object> expectedValues = ImmutableMap.<Property<?>, Object>builder()
|
||||||
.put(TestConfiguration.DURATION_IN_SECONDS, 22)
|
.put(TestConfiguration.DURATION_IN_SECONDS, 22)
|
||||||
.put(TestConfiguration.SYSTEM_NAME, "Custom sys name")
|
.put(TestConfiguration.SYSTEM_NAME, "Custom sys name")
|
||||||
@ -88,14 +89,14 @@ public class SettingsIntegrationTest {
|
|||||||
File file = copyFileFromResources(INCOMPLETE_FILE);
|
File file = copyFileFromResources(INCOMPLETE_FILE);
|
||||||
PropertyResource resource = new YamlFileResource(file);
|
PropertyResource resource = new YamlFileResource(file);
|
||||||
// Expectation: File is rewritten to since it does not have all configurations
|
// Expectation: File is rewritten to since it does not have all configurations
|
||||||
new Settings(testPluginFolder, propertyMap, resource, new PlainMigrationService());
|
new Settings(testPluginFolder, resource, new PlainMigrationService(), knownProperties);
|
||||||
|
|
||||||
// Load the settings again -> checks that what we wrote can be loaded again
|
// Load the settings again -> checks that what we wrote can be loaded again
|
||||||
resource = new YamlFileResource(file);
|
resource = new YamlFileResource(file);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Settings settings = new Settings(testPluginFolder, propertyMap, resource,
|
Settings settings = new Settings(testPluginFolder, resource,
|
||||||
new PlainMigrationService());
|
new PlainMigrationService(), knownProperties);
|
||||||
Map<Property<?>, Object> expectedValues = ImmutableMap.<Property<?>, Object>builder()
|
Map<Property<?>, Object> expectedValues = ImmutableMap.<Property<?>, Object>builder()
|
||||||
.put(TestConfiguration.DURATION_IN_SECONDS, 22)
|
.put(TestConfiguration.DURATION_IN_SECONDS, 22)
|
||||||
.put(TestConfiguration.SYSTEM_NAME, "[TestDefaultValue]")
|
.put(TestConfiguration.SYSTEM_NAME, "[TestDefaultValue]")
|
||||||
@ -118,8 +119,8 @@ public class SettingsIntegrationTest {
|
|||||||
public void shouldReloadSettings() throws IOException {
|
public void shouldReloadSettings() throws IOException {
|
||||||
// given
|
// given
|
||||||
PropertyResource resource = new YamlFileResource(temporaryFolder.newFile());
|
PropertyResource resource = new YamlFileResource(temporaryFolder.newFile());
|
||||||
Settings settings = new Settings(testPluginFolder, propertyMap, resource,
|
Settings settings = new Settings(testPluginFolder, resource,
|
||||||
TestSettingsMigrationServices.alwaysFulfilled());
|
TestSettingsMigrationServices.alwaysFulfilled(), knownProperties);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER),
|
assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER),
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package fr.xephi.authme.settings;
|
|||||||
import com.github.authme.configme.migration.PlainMigrationService;
|
import com.github.authme.configme.migration.PlainMigrationService;
|
||||||
import com.github.authme.configme.properties.Property;
|
import com.github.authme.configme.properties.Property;
|
||||||
import com.github.authme.configme.propertymap.PropertyEntry;
|
import com.github.authme.configme.propertymap.PropertyEntry;
|
||||||
|
import com.github.authme.configme.propertymap.SettingsFieldRetriever;
|
||||||
import com.github.authme.configme.resource.PropertyResource;
|
import com.github.authme.configme.resource.PropertyResource;
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
@ -38,6 +39,9 @@ import static org.mockito.Mockito.when;
|
|||||||
* Unit tests for {@link Settings}.
|
* Unit tests for {@link Settings}.
|
||||||
*/
|
*/
|
||||||
public class SettingsTest {
|
public class SettingsTest {
|
||||||
|
|
||||||
|
private final List<PropertyEntry> knownProperties =
|
||||||
|
SettingsFieldRetriever.getAllProperties(TestConfiguration.class);
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
@ -58,7 +62,7 @@ public class SettingsTest {
|
|||||||
// given
|
// given
|
||||||
PropertyResource resource = mock(PropertyResource.class);
|
PropertyResource resource = mock(PropertyResource.class);
|
||||||
List<PropertyEntry> knownProperties = Collections.emptyList();
|
List<PropertyEntry> knownProperties = Collections.emptyList();
|
||||||
Settings settings = new Settings(testPluginFolder, knownProperties, resource, new PlainMigrationService());
|
Settings settings = new Settings(testPluginFolder, resource, new PlainMigrationService(), knownProperties);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String defaultFile = settings.getDefaultMessagesFile();
|
String defaultFile = settings.getDefaultMessagesFile();
|
||||||
@ -81,8 +85,8 @@ public class SettingsTest {
|
|||||||
PropertyResource resource = mock(PropertyResource.class);
|
PropertyResource resource = mock(PropertyResource.class);
|
||||||
given(resource.contains(anyString())).willReturn(true);
|
given(resource.contains(anyString())).willReturn(true);
|
||||||
setReturnValue(resource, MESSAGES_LANGUAGE, languageCode);
|
setReturnValue(resource, MESSAGES_LANGUAGE, languageCode);
|
||||||
Settings settings = new Settings(testPluginFolder, TestConfiguration.generatePropertyMap(),
|
Settings settings = new Settings(testPluginFolder, resource,
|
||||||
resource, TestSettingsMigrationServices.alwaysFulfilled());
|
TestSettingsMigrationServices.alwaysFulfilled(), knownProperties);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
File messagesFile = settings.getMessagesFile();
|
File messagesFile = settings.getMessagesFile();
|
||||||
@ -98,8 +102,8 @@ public class SettingsTest {
|
|||||||
PropertyResource resource = mock(PropertyResource.class);
|
PropertyResource resource = mock(PropertyResource.class);
|
||||||
given(resource.contains(anyString())).willReturn(true);
|
given(resource.contains(anyString())).willReturn(true);
|
||||||
setReturnValue(resource, MESSAGES_LANGUAGE, "doesntexist");
|
setReturnValue(resource, MESSAGES_LANGUAGE, "doesntexist");
|
||||||
Settings settings = new Settings(testPluginFolder, TestConfiguration.generatePropertyMap(),
|
Settings settings = new Settings(testPluginFolder, resource,
|
||||||
resource, TestSettingsMigrationServices.alwaysFulfilled());
|
TestSettingsMigrationServices.alwaysFulfilled(), knownProperties);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
File messagesFile = settings.getMessagesFile();
|
File messagesFile = settings.getMessagesFile();
|
||||||
@ -119,8 +123,8 @@ public class SettingsTest {
|
|||||||
|
|
||||||
PropertyResource resource = mock(PropertyResource.class);
|
PropertyResource resource = mock(PropertyResource.class);
|
||||||
setReturnValue(resource, RegistrationSettings.USE_WELCOME_MESSAGE, true);
|
setReturnValue(resource, RegistrationSettings.USE_WELCOME_MESSAGE, true);
|
||||||
Settings settings = new Settings(testPluginFolder, TestConfiguration.generatePropertyMap(),
|
Settings settings = new Settings(testPluginFolder, resource,
|
||||||
resource, TestSettingsMigrationServices.alwaysFulfilled());
|
TestSettingsMigrationServices.alwaysFulfilled(), knownProperties);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<String> result = settings.getWelcomeMessage();
|
List<String> result = settings.getWelcomeMessage();
|
||||||
@ -140,8 +144,8 @@ public class SettingsTest {
|
|||||||
Files.write(emailFile.toPath(), emailMessage.getBytes());
|
Files.write(emailFile.toPath(), emailMessage.getBytes());
|
||||||
|
|
||||||
PropertyResource resource = mock(PropertyResource.class);
|
PropertyResource resource = mock(PropertyResource.class);
|
||||||
Settings settings = new Settings(testPluginFolder, TestConfiguration.generatePropertyMap(),
|
Settings settings = new Settings(testPluginFolder, resource,
|
||||||
resource, TestSettingsMigrationServices.alwaysFulfilled());
|
TestSettingsMigrationServices.alwaysFulfilled(), knownProperties);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String result = settings.getEmailMessage();
|
String result = settings.getEmailMessage();
|
||||||
|
|||||||
@ -2,11 +2,7 @@ package fr.xephi.authme.settings.properties;
|
|||||||
|
|
||||||
import com.github.authme.configme.SettingsHolder;
|
import com.github.authme.configme.SettingsHolder;
|
||||||
import com.github.authme.configme.properties.Property;
|
import com.github.authme.configme.properties.Property;
|
||||||
import com.github.authme.configme.propertymap.PropertyEntry;
|
|
||||||
import fr.xephi.authme.ReflectionTestUtils;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.github.authme.configme.properties.PropertyInitializer.newListProperty;
|
import static com.github.authme.configme.properties.PropertyInitializer.newListProperty;
|
||||||
@ -50,23 +46,4 @@ public final class TestConfiguration implements SettingsHolder {
|
|||||||
|
|
||||||
private TestConfiguration() {
|
private TestConfiguration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a property map with all properties in {@link TestConfiguration}.
|
|
||||||
*
|
|
||||||
* @return The generated property map
|
|
||||||
*/
|
|
||||||
public static List<PropertyEntry> generatePropertyMap() {
|
|
||||||
List<PropertyEntry> properties = new ArrayList<>();
|
|
||||||
for (Field field : TestConfiguration.class.getDeclaredFields()) {
|
|
||||||
Object fieldValue = ReflectionTestUtils.getFieldValue(TestConfiguration.class, null, field.getName());
|
|
||||||
if (fieldValue instanceof Property<?>) {
|
|
||||||
Property<?> property = (Property<?>) fieldValue;
|
|
||||||
String[] comments = new String[]{"Comment for '" + property.getPath() + "'"};
|
|
||||||
properties.add(new PropertyEntry(property, comments));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user