Search in sources :

Example 11 with Settings

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

the class SessionManagerTest method shouldNotAddSessionBecauseDisabled.

@Test
public void shouldNotAddSessionBecauseDisabled() {
    // given
    Settings settings = mockSettings(false, 10);
    SessionManager manager = new SessionManager(settings);
    String player = "playah";
    // when
    manager.addSession(player);
    // then
    assertThat(manager.hasSession(player), equalTo(false));
}
Also used : Settings(fr.xephi.authme.settings.Settings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Test(org.junit.Test)

Example 12 with Settings

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

the class SessionManagerTest method shouldNotPerformCleanup.

@Test
public void shouldNotPerformCleanup() {
    // given
    Settings settings = mockSettings(false, 1);
    SessionManager manager = new SessionManager(settings);
    ExpiringSet<String> expiringSet = mockExpiringSet();
    setSessionsMap(manager, expiringSet);
    // when
    manager.performCleanup();
    // then
    verify(expiringSet, never()).removeExpiredEntries();
}
Also used : Settings(fr.xephi.authme.settings.Settings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Test(org.junit.Test)

Example 13 with Settings

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

the class EncryptionMethodInfoGatherer method createInitializer.

@SuppressWarnings("unchecked")
private static Injector createInitializer() {
    Settings settings = mock(Settings.class);
    // Return the default value for any property
    when(settings.getProperty(any(Property.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Property<?> property = (Property<?>) invocation.getArguments()[0];
            return property.getDefaultValue();
        }
    });
    // By passing some bogus "package" to the constructor, the injector will throw if it needs to
    // instantiate any dependency other than what we provide.
    Injector injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme.security.crypts").create();
    injector.register(Settings.class, settings);
    return injector;
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Injector(ch.jalu.injector.Injector) InjectorBuilder(ch.jalu.injector.InjectorBuilder) Property(ch.jalu.configme.properties.Property) Settings(fr.xephi.authme.settings.Settings)

Example 14 with Settings

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

the class AuthMeInitializationTest method shouldInitializeAllServices.

@Test
public void shouldInitializeAllServices() {
    // given
    Settings settings = new Settings(dataFolder, mock(PropertyResource.class), null, buildConfigurationData());
    Injector injector = new InjectorBuilder().addHandlers(new FactoryDependencyHandler(), new SingletonStoreDependencyHandler()).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(BlockListener.class), not(nullValue()));
    assertThat(injector.getIfAvailable(CommandHandler.class), not(nullValue()));
    assertThat(injector.getIfAvailable(Management.class), not(nullValue()));
    assertThat(injector.getIfAvailable(NewAPI.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) DataSource(fr.xephi.authme.datasource.DataSource) PurgeService(fr.xephi.authme.task.purge.PurgeService) SingletonStoreDependencyHandler(fr.xephi.authme.initialization.factory.SingletonStoreDependencyHandler) Injector(ch.jalu.injector.Injector) PropertyResource(ch.jalu.configme.resource.PropertyResource) FactoryDependencyHandler(fr.xephi.authme.initialization.factory.FactoryDependencyHandler) BlockListener(fr.xephi.authme.listener.BlockListener) NewAPI(fr.xephi.authme.api.NewAPI) PermissionsManager(fr.xephi.authme.permission.PermissionsManager) InjectorBuilder(ch.jalu.injector.InjectorBuilder) ProcessSyncPlayerLogin(fr.xephi.authme.process.login.ProcessSyncPlayerLogin) Settings(fr.xephi.authme.settings.Settings) Test(org.junit.Test)

Example 15 with Settings

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

the class ConsoleLoggerTest method newSettings.

private static Settings newSettings(boolean logToFile, LogLevel logLevel) {
    Settings settings = mock(Settings.class);
    given(settings.getProperty(SecuritySettings.USE_LOGGING)).willReturn(logToFile);
    given(settings.getProperty(PluginSettings.LOG_LEVEL)).willReturn(logLevel);
    return settings;
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Settings(fr.xephi.authme.settings.Settings)

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