use of ch.jalu.configme.resource.YamlFileReader 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.YamlFileReader 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.YamlFileReader in project AuthMeReloaded by AuthMe.
the class MessageUpdaterTest method shouldPerformNewerMigrations.
@Test
public void shouldPerformNewerMigrations() throws IOException {
// given
File messagesFile = temporaryFolder.newFile();
Files.copy(TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "message/messages_test2.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.TWO_FACTOR_CREATE.getKey()), equalTo("Old 2fa create text"));
// from pre-5.5 key
assertThat(reader.getString(MessageKey.WRONG_PASSWORD.getKey()), equalTo("test2 - wrong password"));
// from messages_en.yml
assertThat(reader.getString(MessageKey.SECOND.getKey()), equalTo("second"));
}
use of ch.jalu.configme.resource.YamlFileReader in project AuthMeReloaded by AuthMe.
the class TranslationsGatherer method processMessagesFile.
private void processMessagesFile(String code, File file) {
PropertyReader reader = new YamlFileReader(file);
int availableMessages = 0;
for (MessageKey key : MessageKey.values()) {
if (reader.contains(key.getKey())) {
++availableMessages;
}
}
translationInfo.add(new TranslationInfo(code, (double) availableMessages / MessageKey.values().length));
}
use of ch.jalu.configme.resource.YamlFileReader in project AuthMeReloaded by AuthMe.
the class MessagesFileConsistencyTest method shouldHaveAllMessages.
@Test
public void shouldHaveAllMessages() {
File file = TestHelper.getJarFile("/" + MESSAGES_FILE);
PropertyReader reader = new YamlFileReader(file);
List<String> errors = new ArrayList<>();
for (MessageKey messageKey : MessageKey.values()) {
validateMessage(messageKey, reader, errors);
}
if (!errors.isEmpty()) {
fail("Validation errors in " + MESSAGES_FILE + ":\n- " + String.join("\n- ", errors));
}
}
Aggregations