#699 Unit test that config.yml values correspond to property defaults

- Create unit test
- Correct offending values
This commit is contained in:
ljacqu 2016-05-09 21:15:11 +02:00
parent 3673e15ff7
commit 223f56425b
6 changed files with 30 additions and 17 deletions

View File

@ -32,7 +32,7 @@ public class DatabaseSettings implements SettingsClass {
@Comment("Password about Database Connection Infos")
public static final Property<String> MYSQL_PASSWORD =
newProperty("DataSource.mySQLPassword", "123456");
newProperty("DataSource.mySQLPassword", "12345");
@Comment("Database Name, use with converters or as SQLITE database name")
public static final Property<String> MYSQL_DATABASE =

View File

@ -25,7 +25,7 @@ public class HooksSettings implements SettingsClass {
@Comment("Do we need to disable Essentials SocialSpy on join?")
public static final Property<Boolean> DISABLE_SOCIAL_SPY =
newProperty("Hooks.disableSocialSpy", false);
newProperty("Hooks.disableSocialSpy", true);
@Comment("Do we need to force /motd Essentials command on join?")
public static final Property<Boolean> USE_ESSENTIALS_MOTD =

View File

@ -19,12 +19,12 @@ public class ProtectionSettings implements SettingsClass {
@Comment({"Countries allowed to join the server and register, see http://dev.bukkit.org/bukkit-plugins/authme-reloaded/pages/countries-codes/ for countries' codes",
"PLEASE USE QUOTES!"})
public static final Property<List<String>> COUNTRIES_WHITELIST =
newListProperty("Protection.countries", "US", "GB", "A1");
newListProperty("Protection.countries", "US", "GB");
@Comment({"Countries not allowed to join the server and register",
"PLEASE USE QUOTES!"})
public static final Property<List<String>> COUNTRIES_BLACKLIST =
newListProperty("Protection.countriesBlacklist");
newListProperty("Protection.countriesBlacklist", "A1");
@Comment("Do we need to enable automatic antibot system?")
public static final Property<Boolean> ENABLE_ANTIBOT =

View File

@ -31,7 +31,7 @@ public class RestrictionSettings implements SettingsClass {
@Comment("Allowed commands for unauthenticated players")
public static final Property<List<String>> ALLOW_COMMANDS =
newListProperty("settings.restrictions.allowCommands",
"login", "register", "l", "reg", "email", "captcha");
"/login", "/register", "/l", "/reg", "/email", "/captcha");
@Comment({
"Max number of allowed registrations per IP",

View File

@ -108,12 +108,11 @@ settings:
# AllowedRestrctedUser field.
AllowRestrictedUser: false
# The restricted user feature will kick players listed below
# if they dont match of the defined ip address.
# if they don't match of the defined ip address.
# Example:
# AllowedRestrictedUser:
# - playername;127.0.0.1
AllowedRestrictedUser:
- playername;127.0.0.1
AllowedRestrictedUser: []
# Should unregistered players be kicked immediately?
kickNonRegistered: false
# Should players be kicked on wrong password?
@ -263,11 +262,11 @@ settings:
# Do we need to broadcast the welcome message to all server or only to the player? set true for server or false for player
broadcastWelcomeMessage: false
# Should we delay the join message and display it once the player has logged in?
delayJoinMessage: true
delayJoinMessage: false
# Should we remove join messages altogether?
removeJoinMessage: true
removeJoinMessage: false
# Should we remove leave messages?
removeLeaveMessage: true
removeLeaveMessage: false
# Do we need to add potion effect Blinding before login/register?
applyBlindEffect: false
# Do we need to prevent people to login with another case?
@ -307,7 +306,7 @@ BackupSystem:
# set Backup at every stop of Server
OnServerStop: true
# Windows only mysql installation Path
MysqlWindowsPath: 'C:\\Program Files\\MySQL\\MySQL Server 5.1\\'
MysqlWindowsPath: 'C:\Program Files\MySQL\MySQL Server 5.1\'
Security:
SQLProblem:
# Stop the server if we can't contact the sql database
@ -360,7 +359,7 @@ Email:
# Random password length
RecoveryPasswordLength: 8
# Email subject of password get
mailSubject: 'Your new AuthMe Password'
mailSubject: 'Your new AuthMe password'
# Like maxRegPerIp but with email
maxRegPerEmail: 1
# Recall players to add an email?

View File

@ -12,13 +12,14 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
/**
@ -56,9 +57,8 @@ public class ConfigFileConsistencyTest {
@Test
public void shouldNotHaveUnknownConfigs() {
// given
URL url = this.getClass().getResource(CONFIG_FILE);
File configFile = new File(url.getFile());
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
File configFile = TestHelper.getJarFile(CONFIG_FILE);
FileConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
Map<String, Object> allReadProperties = configuration.getValues(true);
Set<String> knownKeys = getAllKnownPropertyPaths();
@ -78,6 +78,20 @@ public class ConfigFileConsistencyTest {
}
}
@Test
public void shouldHaveValueCorrespondingToPropertyDefault() {
// given
File configFile = TestHelper.getJarFile(CONFIG_FILE);
FileConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
PropertyMap propertyMap = SettingsFieldRetriever.getAllPropertyFields();
// when / then
for (Property<?> property : propertyMap.keySet()) {
assertThat("Default value of '" + property.getPath() + "' in config.yml should be the same as in Property",
property.getFromFile(configuration), equalTo(property.getDefaultValue()));
}
}
private static Set<String> getAllKnownPropertyPaths() {
PropertyMap propertyMap = SettingsFieldRetriever.getAllPropertyFields();
Set<String> paths = new HashSet<>(propertyMap.size());