Search in sources :

Example 1 with PropertyReader

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()));
}
Also used : BukkitService(fr.xephi.authme.service.BukkitService) CommandHandler(fr.xephi.authme.command.CommandHandler) Management(fr.xephi.authme.process.Management) PasswordSecurity(fr.xephi.authme.security.PasswordSecurity) PropertyReader(ch.jalu.configme.resource.PropertyReader) DataSource(fr.xephi.authme.datasource.DataSource) BungeeReceiver(fr.xephi.authme.service.bungeecord.BungeeReceiver) PurgeService(fr.xephi.authme.task.purge.PurgeService) Injector(ch.jalu.injector.Injector) PropertyResource(ch.jalu.configme.resource.PropertyResource) AuthMeApi(fr.xephi.authme.api.v3.AuthMeApi) BlockListener(fr.xephi.authme.listener.BlockListener) PermissionsManager(fr.xephi.authme.permission.PermissionsManager) BungeeSender(fr.xephi.authme.service.bungeecord.BungeeSender) InjectorBuilder(ch.jalu.injector.InjectorBuilder) ProcessSyncPlayerLogin(fr.xephi.authme.process.login.ProcessSyncPlayerLogin) Settings(fr.xephi.authme.settings.Settings) Test(org.junit.Test)

Example 2 with PropertyReader

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

Example 3 with PropertyReader

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"));
}
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 PropertyReader

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("您已经可以在当前会话中执行任何敏感命令!"));
}
Also used : PropertyReader(ch.jalu.configme.resource.PropertyReader) File(java.io.File) Test(org.junit.Test)

Example 5 with PropertyReader

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

Aggregations

PropertyReader (ch.jalu.configme.resource.PropertyReader)13 Test (org.junit.Test)9 YamlFileReader (ch.jalu.configme.resource.YamlFileReader)7 File (java.io.File)7 PropertyResource (ch.jalu.configme.resource.PropertyResource)3 ArrayList (java.util.ArrayList)2 ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)1 StringProperty (ch.jalu.configme.properties.StringProperty)1 YamlFileResource (ch.jalu.configme.resource.YamlFileResource)1 Injector (ch.jalu.injector.Injector)1 InjectorBuilder (ch.jalu.injector.InjectorBuilder)1 AuthMeApi (fr.xephi.authme.api.v3.AuthMeApi)1 CommandHandler (fr.xephi.authme.command.CommandHandler)1 DataSource (fr.xephi.authme.datasource.DataSource)1 BlockListener (fr.xephi.authme.listener.BlockListener)1 MessageKey (fr.xephi.authme.message.MessageKey)1 MessageKeyConfigurationData (fr.xephi.authme.message.updater.MessageKeyConfigurationData)1 MigraterYamlFileResource (fr.xephi.authme.message.updater.MigraterYamlFileResource)1 PermissionsManager (fr.xephi.authme.permission.PermissionsManager)1 Management (fr.xephi.authme.process.Management)1