use of com.alessiodp.parties.common.parties.PartyManager in project Parties by AlessioDP.
the class FileDispatcherTest method testListParties.
@Test
public void testListParties() {
PartyManager mockPartyManager = mock(PartyManager.class);
when(mockPlugin.getPartyManager()).thenReturn(mockPartyManager);
when(mockPartyManager.initializeParty(any())).thenAnswer((mock) -> initializeParty(mock.getArgument(0)));
PlayerManager mockPlayerManager = mock(PlayerManager.class);
when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> initializePlayer(mock.getArgument(0)));
PartiesYAMLDispatcher dispatcher = getFileDispatcher();
populateWithParties(dispatcher);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
}
use of com.alessiodp.parties.common.parties.PartyManager in project Parties by AlessioDP.
the class FileDispatcherTest method party.
private void party(PartiesYAMLDispatcher dispatcher, boolean remove) {
PartyImpl party = initializeParty(UUID.randomUUID());
PartyPlayerImpl player = initializePlayer(UUID.randomUUID());
PartyImpl mockParty = mock(party.getClass());
doReturn(CompletableFuture.completedFuture(null)).when(mockParty).updateParty();
PartyPlayerImpl mockPlayer = mock(player.getClass());
doReturn(CompletableFuture.completedFuture(null)).when(mockPlayer).updatePlayer();
PartyManager mockPartyManager = mock(PartyManager.class);
when(mockPlugin.getPartyManager()).thenReturn(mockPartyManager);
when(mockPartyManager.initializeParty(any())).thenAnswer((mock) -> initializeParty(mock.getArgument(0)));
PlayerManager mockPlayerManager = mock(PlayerManager.class);
when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> initializePlayer(mock.getArgument(0)));
party.setAccessible(true);
party.setup("test", player.getPlayerUUID().toString());
party.setDescription("description");
party.setKills(10);
party.setMembers(Collections.singleton(player.getPlayerUUID()));
party.setAccessible(false);
player.setAccessible(true);
player.setPartyId(party.getId());
player.setAccessible(false);
dispatcher.updatePlayer(player);
assertNull(dispatcher.getDatabase().getYaml().getConfigurationSection("parties"));
assertNull(dispatcher.getDatabase().getYaml().getConfigurationSection("map-parties-by-name"));
dispatcher.updateParty(party);
assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("parties").getKeys(false).size(), 1);
assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("map-parties-by-name").getKeys(false).size(), 1);
PartyImpl newParty = dispatcher.getParty(party.getId());
assertEquals(party, newParty);
// Party remove
if (remove) {
dispatcher.removeParty(party);
assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("parties").getKeys(false).size(), 0);
assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("map-parties-by-name").getKeys(false).size(), 0);
}
}
use of com.alessiodp.parties.common.parties.PartyManager in project Parties by AlessioDP.
the class MigrationsTest method setUp.
@BeforeAll
public static void setUp(@TempDir Path tempDir) {
LoggerManager mockLoggerManager = mock(LoggerManager.class);
when(mockPlugin.getLoggerManager()).thenReturn(mockLoggerManager);
when(mockPlugin.getPluginFallbackName()).thenReturn("parties");
when(mockPlugin.getFolder()).thenReturn(tempDir);
when(mockPlugin.getResource(anyString())).thenAnswer((mock) -> ClassLoader.getSystemResourceAsStream(mock.getArgument(0)));
when(mockLoggerManager.isDebugEnabled()).thenReturn(true);
// Mock managers for player/party initialization
ColorManager mockColorManager = mock(ColorManager.class);
when(mockPlugin.getColorManager()).thenReturn(mockColorManager);
when(mockColorManager.searchColorByName(anyString())).thenReturn(null);
PlayerManager mockPlayerManager = mock(PlayerManager.class);
when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> SQLDispatcherTest.initializePlayer(mockPlugin, mock.getArgument(0)));
PartyManager mockPartyManager = mock(PartyManager.class);
when(mockPlugin.getPartyManager()).thenReturn(mockPartyManager);
when(mockPartyManager.initializeParty(any())).thenAnswer((mock) -> SQLDispatcherTest.initializeParty(mockPlugin, mock.getArgument(0)));
// Mock names
OfflineUser mockOfflineUser = mock(OfflineUser.class);
when(mockPlugin.getOfflinePlayer(any())).thenReturn(mockOfflineUser);
when(mockOfflineUser.getName()).thenReturn("Dummy");
ConfigMain.STORAGE_SETTINGS_GENERAL_SQL_PREFIX = "test_";
staticPlugin = Mockito.mockStatic(ADPPlugin.class);
when(ADPPlugin.getInstance()).thenReturn(mockPlugin);
}
use of com.alessiodp.parties.common.parties.PartyManager in project Parties by AlessioDP.
the class SQLDispatcherTest method party.
private void party(PartiesSQLDispatcher dispatcher, PartiesDao dao, boolean remove) {
PartyImpl party = initializeParty(mockPlugin, UUID.randomUUID());
PartyPlayerImpl player = initializePlayer(mockPlugin, UUID.randomUUID());
PartyImpl mockParty = mock(PartyImpl.class);
doReturn(CompletableFuture.completedFuture(null)).when(mockParty).updateParty();
PartyPlayerImpl mockPlayer = mock(PartyPlayerImpl.class);
doReturn(CompletableFuture.completedFuture(null)).when(mockPlayer).updatePlayer();
PartyManager mockPartyManager = mock(PartyManager.class);
when(mockPlugin.getPartyManager()).thenReturn(mockPartyManager);
when(mockPartyManager.initializeParty(any())).thenAnswer((mock) -> initializeParty(mockPlugin, mock.getArgument(0)));
PlayerManager mockPlayerManager = mock(PlayerManager.class);
when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> initializePlayer(mockPlugin, mock.getArgument(0)));
party.setAccessible(true);
party.setup("test", player.getPlayerUUID().toString());
party.setDescription("description");
party.setKills(10);
party.setMembers(Collections.singleton(player.getPlayerUUID()));
party.setAccessible(false);
player.setAccessible(true);
player.setPartyId(party.getId());
player.setAccessible(false);
dispatcher.updatePlayer(player);
assertEquals(dao.countAll(), 0);
dispatcher.updateParty(party);
assertEquals(dao.countAll(), 1);
assertEquals(party, dispatcher.getParty(party.getId()));
assertEquals(party, dispatcher.getPartyByName(party.getName()));
// Party remove
if (remove) {
dispatcher.removeParty(party);
assertEquals(dao.countAll(), 0);
}
}
use of com.alessiodp.parties.common.parties.PartyManager in project Parties by AlessioDP.
the class SQLDispatcherTest method testListParties.
@Test
public void testListParties(@TempDir Path tempDir) {
PartyManager mockPartyManager = mock(PartyManager.class);
when(mockPlugin.getPartyManager()).thenReturn(mockPartyManager);
when(mockPartyManager.initializeParty(any())).thenAnswer((mock) -> initializeParty(mockPlugin, mock.getArgument(0)));
PlayerManager mockPlayerManager = mock(PlayerManager.class);
when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> initializePlayer(mockPlugin, mock.getArgument(0)));
PartiesSQLDispatcher dispatcher = getSQLDispatcherH2();
PartiesDao daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(H2PartiesDao.class);
PlayersDao daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(H2PlayersDao.class);
populateWithParties(dispatcher, daoParties, daoPlayers);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
dispatcher = getSQLDispatcherSQLite(tempDir);
daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(SQLitePartiesDao.class);
daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(SQLitePlayersDao.class);
populateWithParties(dispatcher, daoParties, daoPlayers);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
dispatcher = getSQLDispatcherMySQL(mockPlugin);
if (dispatcher != null) {
daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(PartiesDao.class);
daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(PlayersDao.class);
populateWithParties(dispatcher, daoParties, daoPlayers);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
}
dispatcher = getSQLDispatcherMariaDB(mockPlugin);
if (dispatcher != null) {
daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(PartiesDao.class);
daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(PlayersDao.class);
populateWithParties(dispatcher, daoParties, daoPlayers);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
}
dispatcher = getSQLDispatcherPostgreSQL(mockPlugin);
if (dispatcher != null) {
daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(PostgreSQLPartiesDao.class);
daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(PostgreSQLPlayersDao.class);
populateWithParties(dispatcher, daoParties, daoPlayers);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
}
}
Aggregations