use of fr.xephi.authme.datasource.DataSourceType 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.DataSourceType in project AuthMeReloaded by AuthMe.
the class AbstractDataSourceConverterTest method shouldThrowForDestinationTypeMismatch.
@Test
public void shouldThrowForDestinationTypeMismatch() {
// given
DataSource destination = mock(DataSource.class);
given(destination.getType()).willReturn(DataSourceType.MYSQL);
DataSourceType destinationType = DataSourceType.SQLITE;
DataSource source = mock(DataSource.class);
Converter converter = new DataSourceConverterTestImpl<>(source, destination, destinationType);
CommandSender sender = mock(CommandSender.class);
// when
converter.execute(sender);
// then
verify(sender).sendMessage(argThat(containsString("Please configure your connection to SQLITE")));
verify(destination, only()).getType();
verifyNoInteractions(source);
}
use of fr.xephi.authme.datasource.DataSourceType in project AuthMeReloaded by AuthMe.
the class AbstractDataSourceConverterTest method shouldHandleSourceThrowingException.
@Test
public void shouldHandleSourceThrowingException() {
// given
DataSource source = mock(DataSource.class);
DataSource destination = mock(DataSource.class);
DataSourceType destinationType = DataSourceType.SQLITE;
given(destination.getType()).willReturn(destinationType);
DataSourceConverterTestImpl<DataSource> converter = Mockito.spy(new DataSourceConverterTestImpl<>(source, destination, destinationType));
doThrow(IllegalStateException.class).when(converter).getSource();
CommandSender sender = mock(CommandSender.class);
// when
converter.execute(sender);
// then
verify(sender).sendMessage("The data source to convert from could not be initialized");
verify(destination, only()).getType();
verifyNoInteractions(source);
}
use of fr.xephi.authme.datasource.DataSourceType in project AuthMeReloaded by AuthMe.
the class AbstractDataSourceConverterTest method shouldConvertAndSkipExistingPlayers.
@Test
public void shouldConvertAndSkipExistingPlayers() {
// given
DataSource source = mock(DataSource.class);
DataSource destination = mock(DataSource.class);
DataSourceType destinationType = DataSourceType.MYSQL;
given(destination.getType()).willReturn(destinationType);
List<PlayerAuth> auths = Arrays.asList(mockAuthWithName("Steven"), mockAuthWithName("bobby"), mockAuthWithName("Jack"));
given(source.getAllAuths()).willReturn(auths);
given(destination.isAuthAvailable(auths.get(0).getNickname())).willReturn(true);
Converter converter = new DataSourceConverterTestImpl<>(source, destination, destinationType);
CommandSender sender = mock(CommandSender.class);
// when
converter.execute(sender);
// then
verify(destination).getType();
verify(destination, times(3)).isAuthAvailable(anyString());
verify(destination, times(2)).saveAuth(any(PlayerAuth.class));
verify(destination, times(2)).updateSession(any(PlayerAuth.class));
verify(destination, times(2)).updateQuitLoc(any(PlayerAuth.class));
verifyNoMoreInteractions(destination);
verify(sender).sendMessage(argThat(containsString(auths.get(0).getNickname())));
verify(sender).sendMessage(argThat(containsString("successfully converted")));
}
Aggregations