Search in sources :

Example 1 with Settings

use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.

the class SettingsProvider method get.

/**
     * Loads the plugin's settings.
     *
     * @return the settings instance, or null if it could not be constructed
     */
@Override
public Settings get() {
    File configFile = new File(dataFolder, "config.yml");
    if (!configFile.exists()) {
        FileUtils.create(configFile);
    }
    PropertyResource resource = new YamlFileResource(configFile);
    ConfigurationData configurationData = AuthMeSettingsRetriever.buildConfigurationData();
    return new Settings(dataFolder, resource, migrationService, configurationData);
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PropertyResource(ch.jalu.configme.resource.PropertyResource) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) File(java.io.File) Settings(fr.xephi.authme.settings.Settings)

Example 2 with Settings

use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.

the class HashAlgorithmIntegrationTest method setUpConfigAndInjector.

@BeforeClass
public static void setUpConfigAndInjector() {
    Settings settings = mock(Settings.class);
    given(settings.getProperty(HooksSettings.BCRYPT_LOG2_ROUND)).willReturn(8);
    given(settings.getProperty(SecuritySettings.DOUBLE_MD5_SALT_LENGTH)).willReturn(16);
    given(settings.getProperty(SecuritySettings.PBKDF2_NUMBER_OF_ROUNDS)).willReturn(10_000);
    injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme").create();
    injector.register(Settings.class, settings);
}
Also used : InjectorBuilder(ch.jalu.injector.InjectorBuilder) SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings) HooksSettings(fr.xephi.authme.settings.properties.HooksSettings) BeforeClass(org.junit.BeforeClass)

Example 3 with Settings

use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.

the class MessageFileHandlerProviderTest method shouldCreateHandler.

@Test
public void shouldCreateHandler() {
    // given
    String language = "fr";
    given(settings.getProperty(PluginSettings.MESSAGES_LANGUAGE)).willReturn(language);
    MessageFileHandlerProvider provider = Mockito.spy(handlerProvider);
    Function<String, String> fileFunction = lang -> "file_" + lang + ".txt";
    File file = new File(dataFolder, "some_file.txt");
    doReturn(file).when(provider).initializeFile(language, fileFunction);
    // when
    MessageFileHandler handler = provider.initializeHandler(fileFunction);
    // then
    assertThat(handler, not(nullValue()));
    verify(settings).getProperty(PluginSettings.MESSAGES_LANGUAGE);
    verify(provider).initializeFile(language, fileFunction);
}
Also used : BeforeClass(org.junit.BeforeClass) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Matchers.not(org.hamcrest.Matchers.not) DataFolder(fr.xephi.authme.initialization.DataFolder) Function(java.util.function.Function) Assert.assertThat(org.junit.Assert.assertThat) TestHelper.getJarFile(fr.xephi.authme.TestHelper.getJarFile) Files(com.google.common.io.Files) BDDMockito.given(org.mockito.BDDMockito.given) BeforeInjecting(ch.jalu.injector.testing.BeforeInjecting) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestHelper(fr.xephi.authme.TestHelper) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Mockito.doReturn(org.mockito.Mockito.doReturn) Description(org.hamcrest.Description) Settings(fr.xephi.authme.settings.Settings) InjectDelayed(ch.jalu.injector.testing.InjectDelayed) Test(org.junit.Test) IOException(java.io.IOException) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) Matcher(org.hamcrest.Matcher) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TemporaryFolder(org.junit.rules.TemporaryFolder) DelayedInjectionRunner(ch.jalu.injector.testing.DelayedInjectionRunner) TestHelper.getJarFile(fr.xephi.authme.TestHelper.getJarFile) File(java.io.File) Test(org.junit.Test)

Example 4 with Settings

use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.

the class AbstractResourceClosingTest method initializeSettings.

/** Initialize the settings mock and makes it return the default of any given property by default. */
@SuppressWarnings({ "unchecked", "rawtypes" })
@BeforeClass
public static void initializeSettings() throws IOException, ClassNotFoundException {
    settings = mock(Settings.class);
    given(settings.getProperty(any(Property.class))).willAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            return ((Property<?>) invocation.getArguments()[0]).getDefaultValue();
        }
    });
    TestHelper.setupLogger();
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Property(ch.jalu.configme.properties.Property) SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings) BeforeClass(org.junit.BeforeClass)

Example 5 with Settings

use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.

the class SQLiteIntegrationTest method initializeSettings.

/**
     * Set up the settings mock to return specific values for database settings and load {@link #sqlInitialize}.
     */
@SuppressWarnings({ "unchecked", "rawtypes" })
@BeforeClass
public static void initializeSettings() throws IOException, ClassNotFoundException {
    // Check that we have an implementation for SQLite
    Class.forName("org.sqlite.JDBC");
    settings = mock(Settings.class);
    when(settings.getProperty(any(Property.class))).thenAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return ((Property) invocation.getArguments()[0]).getDefaultValue();
        }
    });
    set(DatabaseSettings.MYSQL_DATABASE, "sqlite-test");
    set(DatabaseSettings.MYSQL_TABLE, "authme");
    TestHelper.setRealLogger();
    Path sqlInitFile = TestHelper.getJarPath(TestHelper.PROJECT_ROOT + "datasource/sql-initialize.sql");
    // Note ljacqu 20160221: It appears that we can only run one statement per Statement.execute() so we split
    // the SQL file by ";\n" as to get the individual statements
    sqlInitialize = new String(Files.readAllBytes(sqlInitFile)).split(";(\\r?)\\n");
}
Also used : Path(java.nio.file.Path) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Property(ch.jalu.configme.properties.Property) Settings(fr.xephi.authme.settings.Settings) DatabaseSettings(fr.xephi.authme.settings.properties.DatabaseSettings) BeforeClass(org.junit.BeforeClass)

Aggregations

Settings (fr.xephi.authme.settings.Settings)37 Test (org.junit.Test)23 SecuritySettings (fr.xephi.authme.settings.properties.SecuritySettings)21 PluginSettings (fr.xephi.authme.settings.properties.PluginSettings)12 BeforeClass (org.junit.BeforeClass)5 Property (ch.jalu.configme.properties.Property)4 InjectorBuilder (ch.jalu.injector.InjectorBuilder)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 File (java.io.File)3 Player (org.bukkit.entity.Player)3 Answer (org.mockito.stubbing.Answer)3 PropertyResource (ch.jalu.configme.resource.PropertyResource)2 Injector (ch.jalu.injector.Injector)2 FactoryDependencyHandler (fr.xephi.authme.initialization.factory.FactoryDependencyHandler)2 SingletonStoreDependencyHandler (fr.xephi.authme.initialization.factory.SingletonStoreDependencyHandler)2 DatabaseSettings (fr.xephi.authme.settings.properties.DatabaseSettings)2 HooksSettings (fr.xephi.authme.settings.properties.HooksSettings)2 Path (java.nio.file.Path)2 ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)1 YamlFileResource (ch.jalu.configme.resource.YamlFileResource)1