use of ch.jalu.configme.resource.PropertyReader in project AuthMeReloaded by AuthMe.
the class AuthMeInitializationTest method shouldInitializeAllServices.
@Test
public void shouldInitializeAllServices() {
// given
PropertyReader reader = mock(PropertyReader.class);
PropertyResource resource = mock(PropertyResource.class);
given(resource.createReader()).willReturn(reader);
Settings settings = new Settings(dataFolder, resource, null, buildConfigurationData());
TestHelper.setupLogger();
Injector injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme").create();
injector.provide(DataFolder.class, dataFolder);
injector.register(Server.class, server);
injector.register(PluginManager.class, pluginManager);
injector.register(AuthMe.class, authMe);
injector.register(Settings.class, settings);
injector.register(DataSource.class, mock(DataSource.class));
injector.register(BukkitService.class, mock(BukkitService.class));
// when
authMe.instantiateServices(injector);
authMe.registerEventListeners(injector);
// then
// Take a few samples and ensure that they are not null
assertThat(injector.getIfAvailable(AuthMeApi.class), not(nullValue()));
assertThat(injector.getIfAvailable(BlockListener.class), not(nullValue()));
assertThat(injector.getIfAvailable(BungeeReceiver.class), not(nullValue()));
assertThat(injector.getIfAvailable(BungeeSender.class), not(nullValue()));
assertThat(injector.getIfAvailable(CommandHandler.class), not(nullValue()));
assertThat(injector.getIfAvailable(Management.class), not(nullValue()));
assertThat(injector.getIfAvailable(PasswordSecurity.class), not(nullValue()));
assertThat(injector.getIfAvailable(PermissionsManager.class), not(nullValue()));
assertThat(injector.getIfAvailable(ProcessSyncPlayerLogin.class), not(nullValue()));
assertThat(injector.getIfAvailable(PurgeService.class), not(nullValue()));
}
use of ch.jalu.configme.resource.PropertyReader in project AuthMeReloaded by AuthMe.
the class MessageFilePlaceholderTest method shouldHaveAllPlaceholders.
@Test
public void shouldHaveAllPlaceholders() {
// given
PropertyReader reader = new YamlFileReader(messagesFile);
List<String> errors = new ArrayList<>(0);
// when
for (MessageKey key : MessageKey.values()) {
List<String> missingTags = findMissingTags(key, reader);
if (!missingTags.isEmpty()) {
errors.add("Message key '" + key + "' should have tags: " + String.join(", ", missingTags));
}
}
// then
if (!errors.isEmpty()) {
fail("Errors while validating '" + messagesFilename + "':\n- " + String.join("\n- ", errors));
}
}
use of ch.jalu.configme.resource.PropertyReader in project AuthMeReloaded by AuthMe.
the class MessageUpdaterTest method shouldMigrateOldEntries.
@Test
public void shouldMigrateOldEntries() throws IOException {
// given
File messagesFile = temporaryFolder.newFile();
Files.copy(TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "message/messages_en_old.yml"), messagesFile);
// when
boolean wasChanged = messageUpdater.migrateAndSave(messagesFile, DEFAULT_MESSAGES_FILE, DEFAULT_MESSAGES_FILE);
// then
assertThat(wasChanged, equalTo(true));
PropertyReader reader = new YamlFileReader(messagesFile);
assertThat(reader.getString(MessageKey.PASSWORD_MATCH_ERROR.getKey()), equalTo("Password error message"));
assertThat(reader.getString(MessageKey.INVALID_NAME_CHARACTERS.getKey()), equalTo("not valid username: Allowed chars are %valid_chars"));
assertThat(reader.getString(MessageKey.INVALID_OLD_EMAIL.getKey()), equalTo("Email (old) is not valid!!"));
assertThat(reader.getString(MessageKey.CAPTCHA_WRONG_ERROR.getKey()), equalTo("The captcha code is %captcha_code for you"));
assertThat(reader.getString(MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED.getKey()), equalTo("Now type /captcha %captcha_code"));
assertThat(reader.getString(MessageKey.SECONDS.getKey()), equalTo("seconds in plural"));
}
use of ch.jalu.configme.resource.PropertyReader in project AuthMeReloaded by AuthMe.
the class MigraterYamlFileResourceTest method shouldReadChineseFile.
@Test
public void shouldReadChineseFile() {
// given
File file = TestHelper.getJarFile(CHINESE_MESSAGES_FILE);
MigraterYamlFileResource resource = new MigraterYamlFileResource(file);
// when
PropertyReader reader = resource.createReader();
// then
assertThat(reader.getString("first"), equalTo("错误的密码"));
assertThat(reader.getString("second"), equalTo("为了验证您的身份,您需要将一个电子邮件地址与您的帐户绑定!"));
assertThat(reader.getString("third"), equalTo("您已经可以在当前会话中执行任何敏感命令!"));
}
use of ch.jalu.configme.resource.PropertyReader in project AuthMeReloaded by AuthMe.
the class MigraterYamlFileResourceTest method shouldWriteWithCorrectCharset.
@Test
public void shouldWriteWithCorrectCharset() throws IOException {
// given
File file = temporaryFolder.newFile();
Files.copy(TestHelper.getJarFile(CHINESE_MESSAGES_FILE), file);
MigraterYamlFileResource resource = new MigraterYamlFileResource(file);
ConfigurationData configurationData = buildConfigurationData();
configurationData.initializeValues(resource.createReader());
String newMessage = "您当前并没有任何邮箱与该账号绑定";
configurationData.setValue(new StringProperty("third", ""), newMessage);
// when
resource.exportProperties(configurationData);
// then
PropertyReader reader = resource.createReader();
assertThat(reader.getString("first"), equalTo("错误的密码"));
assertThat(reader.getString("second"), equalTo("为了验证您的身份,您需要将一个电子邮件地址与您的帐户绑定!"));
assertThat(reader.getString("third"), equalTo(newMessage));
}
Aggregations