Search in sources :

Example 1 with PlayerCache

use of fr.xephi.authme.data.auth.PlayerCache in project AuthMeReloaded by AuthMe.

the class MySqlDefaultChangerTest method shouldLeaveMySqlFieldToNullOnInitialization.

@Test
public void shouldLeaveMySqlFieldToNullOnInitialization() {
    // given
    DataSource dataSource = mock(DataSource.class);
    PlayerCache playerCache = mock(PlayerCache.class);
    CacheDataSource cacheDataSource = new CacheDataSource(dataSource, playerCache);
    MySqlDefaultChanger defaultChanger = createDefaultChanger(cacheDataSource);
    // when
    defaultChanger.setMySqlField();
    // then
    assertThat(ReflectionTestUtils.getFieldValue(MySqlDefaultChanger.class, defaultChanger, "mySql"), nullValue());
}
Also used : CacheDataSource(fr.xephi.authme.datasource.CacheDataSource) PlayerCache(fr.xephi.authme.data.auth.PlayerCache) CacheDataSource(fr.xephi.authme.datasource.CacheDataSource) DataSource(fr.xephi.authme.datasource.DataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) Test(org.junit.Test)

Example 2 with PlayerCache

use of fr.xephi.authme.data.auth.PlayerCache in project AuthMeReloaded by AuthMe.

the class AsynchronousLoginTest method shouldNotForceLoginForCanceledEvent.

@Test
public void shouldNotForceLoginForCanceledEvent() {
    // given
    String name = "oscar";
    String ip = "1.1.1.245";
    Player player = mockPlayer(name);
    TestHelper.mockPlayerIp(player, ip);
    given(playerCache.isAuthenticated(name)).willReturn(false);
    PlayerAuth auth = PlayerAuth.builder().name(name).build();
    given(dataSource.getAuth(name)).willReturn(auth);
    given(commonService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
    given(commonService.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
    doReturn(false).when(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(any(Player.class), anyString());
    doAnswer((Answer<Void>) invocation -> {
        ((AuthMeAsyncPreLoginEvent) invocation.getArgument(0)).setCanLogin(false);
        return null;
    }).when(bukkitService).callEvent(any(AuthMeAsyncPreLoginEvent.class));
    // when
    asynchronousLogin.forceLogin(player);
    // then
    verify(playerCache, only()).isAuthenticated(name);
    verify(dataSource, only()).getAuth(name);
    verify(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(player, ip);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Player(org.bukkit.entity.Player) RestrictionSettings(fr.xephi.authme.settings.properties.RestrictionSettings) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Assert.assertThat(org.junit.Assert.assertThat) Answer(org.mockito.stubbing.Answer) CommonService(fr.xephi.authme.service.CommonService) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) BDDMockito.given(org.mockito.BDDMockito.given) VerificationModeFactory.only(org.mockito.internal.verification.VerificationModeFactory.only) DataSource(fr.xephi.authme.datasource.DataSource) Spy(org.mockito.Spy) Mockito.doAnswer(org.mockito.Mockito.doAnswer) TestHelper(fr.xephi.authme.TestHelper) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Mockito.doReturn(org.mockito.Mockito.doReturn) PlayerStatePermission(fr.xephi.authme.permission.PlayerStatePermission) InjectMocks(org.mockito.InjectMocks) LimboService(fr.xephi.authme.data.limbo.LimboService) BukkitService(fr.xephi.authme.service.BukkitService) DatabaseSettings(fr.xephi.authme.settings.properties.DatabaseSettings) Test(org.junit.Test) MessageKey(fr.xephi.authme.message.MessageKey) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) AuthMeAsyncPreLoginEvent(fr.xephi.authme.events.AuthMeAsyncPreLoginEvent) Matchers.equalTo(org.hamcrest.Matchers.equalTo) HooksSettings(fr.xephi.authme.settings.properties.HooksSettings) PlayerCache(fr.xephi.authme.data.auth.PlayerCache) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) Player(org.bukkit.entity.Player) AuthMeAsyncPreLoginEvent(fr.xephi.authme.events.AuthMeAsyncPreLoginEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 3 with PlayerCache

use of fr.xephi.authme.data.auth.PlayerCache in project AuthMeReloaded by AuthMe.

the class DebugSectionUtilsTest method shouldUnwrapCacheDataSource.

@Test
public void shouldUnwrapCacheDataSource() {
    // given
    DataSource source = mock(DataSource.class);
    PlayerCache playerCache = mock(PlayerCache.class);
    CacheDataSource cacheDataSource = new CacheDataSource(source, playerCache);
    // when
    DataSource result = DebugSectionUtils.unwrapSourceFromCacheDataSource(cacheDataSource);
    // then
    assertThat(result, equalTo(source));
}
Also used : CacheDataSource(fr.xephi.authme.datasource.CacheDataSource) PlayerCache(fr.xephi.authme.data.auth.PlayerCache) CacheDataSource(fr.xephi.authme.datasource.CacheDataSource) DataSource(fr.xephi.authme.datasource.DataSource) Test(org.junit.Test)

Aggregations

PlayerCache (fr.xephi.authme.data.auth.PlayerCache)3 DataSource (fr.xephi.authme.datasource.DataSource)3 Test (org.junit.Test)3 CacheDataSource (fr.xephi.authme.datasource.CacheDataSource)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 TestHelper (fr.xephi.authme.TestHelper)1 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)1 LimboService (fr.xephi.authme.data.limbo.LimboService)1 AuthMeAsyncPreLoginEvent (fr.xephi.authme.events.AuthMeAsyncPreLoginEvent)1 MessageKey (fr.xephi.authme.message.MessageKey)1 PlayerStatePermission (fr.xephi.authme.permission.PlayerStatePermission)1 BukkitService (fr.xephi.authme.service.BukkitService)1 CommonService (fr.xephi.authme.service.CommonService)1 DatabaseSettings (fr.xephi.authme.settings.properties.DatabaseSettings)1 HooksSettings (fr.xephi.authme.settings.properties.HooksSettings)1 PluginSettings (fr.xephi.authme.settings.properties.PluginSettings)1 RestrictionSettings (fr.xephi.authme.settings.properties.RestrictionSettings)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Player (org.bukkit.entity.Player)1