Search in sources :

Example 1 with YamlFileReader

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));
    }
}
Also used : YamlFileReader(ch.jalu.configme.resource.YamlFileReader) ArrayList(java.util.ArrayList) PropertyReader(ch.jalu.configme.resource.PropertyReader) Test(org.junit.Test)

Example 2 with YamlFileReader

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"));
}
Also used : YamlFileReader(ch.jalu.configme.resource.YamlFileReader) PropertyReader(ch.jalu.configme.resource.PropertyReader) File(java.io.File) Test(org.junit.Test)

Example 3 with YamlFileReader

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"));
}
Also used : YamlFileReader(ch.jalu.configme.resource.YamlFileReader) PropertyReader(ch.jalu.configme.resource.PropertyReader) File(java.io.File) Test(org.junit.Test)

Example 4 with YamlFileReader

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));
}
Also used : YamlFileReader(ch.jalu.configme.resource.YamlFileReader) MessageKey(fr.xephi.authme.message.MessageKey) PropertyReader(ch.jalu.configme.resource.PropertyReader)

Example 5 with YamlFileReader

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));
    }
}
Also used : YamlFileReader(ch.jalu.configme.resource.YamlFileReader) ArrayList(java.util.ArrayList) PropertyReader(ch.jalu.configme.resource.PropertyReader) File(java.io.File) Test(org.junit.Test)

Aggregations

PropertyReader (ch.jalu.configme.resource.PropertyReader)7 YamlFileReader (ch.jalu.configme.resource.YamlFileReader)7 Test (org.junit.Test)6 File (java.io.File)5 ArrayList (java.util.ArrayList)2 MessageKey (fr.xephi.authme.message.MessageKey)1