use of fr.xephi.authme.datasource.DataSource 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());
}
use of fr.xephi.authme.datasource.DataSource 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);
}
use of fr.xephi.authme.datasource.DataSource in project AuthMeReloaded by AuthMe.
the class DataSourceProvider method createDataSource.
/**
* Sets up the data source.
*
* @return the constructed data source
* @throws SQLException when initialization of a SQL data source failed
*/
private DataSource createDataSource() throws SQLException {
DataSourceType dataSourceType = settings.getProperty(DatabaseSettings.BACKEND);
DataSource dataSource;
switch(dataSourceType) {
case MYSQL:
dataSource = new MySQL(settings, mySqlExtensionsFactory);
break;
case POSTGRESQL:
dataSource = new PostgreSqlDataSource(settings, mySqlExtensionsFactory);
break;
case SQLITE:
dataSource = new SQLite(settings, dataFolder);
break;
default:
throw new UnsupportedOperationException("Unknown data source type '" + dataSourceType + "'");
}
if (settings.getProperty(DatabaseSettings.USE_CACHING)) {
dataSource = new CacheDataSource(dataSource, playerCache);
}
if (DataSourceType.SQLITE.equals(dataSourceType)) {
checkDataSourceSize(dataSource);
}
return dataSource;
}
use of fr.xephi.authme.datasource.DataSource 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));
}
use of fr.xephi.authme.datasource.DataSource in project AuthMeReloaded by AuthMe.
the class ForceFlatToSqliteTest method shouldConvertToSqlite.
@Test
public void shouldConvertToSqlite() {
// given
DataSource dataSource = mock(DataSource.class);
given(dataSource.getType()).willReturn(DataSourceType.MYSQL);
ForceFlatToSqlite converter = new ForceFlatToSqlite(flatFile, dataSource);
// when
converter.execute(null);
// then
ArgumentCaptor<PlayerAuth> authCaptor = ArgumentCaptor.forClass(PlayerAuth.class);
verify(dataSource, times(7)).saveAuth(authCaptor.capture());
List<PlayerAuth> auths = authCaptor.getAllValues();
assertThat(auths, hasItem(hasAuthBasicData("bobby", "Player", "your@email.com", "123.45.67.89")));
assertThat(auths, hasItem(hasAuthLocation(1.05, 2.1, 4.2, "world", 0, 0)));
assertThat(auths, hasItem(hasAuthBasicData("user", "Player", "user@example.org", "34.56.78.90")));
assertThat(auths, hasItem(hasAuthLocation(124.1, 76.3, -127.8, "nether", 0, 0)));
assertThat(auths, hasItem(hasAuthBasicData("eightfields", "Player", "your@email.com", "6.6.6.66")));
assertThat(auths, hasItem(hasAuthLocation(8.8, 17.6, 26.4, "eightworld", 0, 0)));
}
Aggregations