Search in sources :

Example 6 with PlayerManager

use of com.alessiodp.parties.common.players.PlayerManager 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();
    }
}
Also used : PlayerManager(com.alessiodp.parties.common.players.PlayerManager) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao) H2PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) PartyManager(com.alessiodp.parties.common.parties.PartyManager) PartiesSQLDispatcher(com.alessiodp.parties.common.storage.dispatchers.PartiesSQLDispatcher) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) SQLitePlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao) H2PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.H2PlayersDao) PostgreSQLPlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao) PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao) SQLitePlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao) PostgreSQLPlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao) Test(org.junit.jupiter.api.Test)

Example 7 with PlayerManager

use of com.alessiodp.parties.common.players.PlayerManager in project Parties by AlessioDP.

the class SQLDispatcherTest method player.

private void player(PartiesSQLDispatcher dispatcher, PlayersDao dao, boolean remove) {
    PartyPlayerImpl player = initializePlayer(mockPlugin, UUID.randomUUID());
    PartyPlayerImpl mockPlayer = mock(PartyPlayerImpl.class);
    doReturn(CompletableFuture.completedFuture(null)).when(mockPlayer).updatePlayer();
    PlayerManager mockPlayerManager = mock(PlayerManager.class);
    when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
    when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> initializePlayer(mockPlugin, mock.getArgument(0)));
    player.setAccessible(true);
    player.setMuted(true);
    player.setAccessible(false);
    assertEquals(dao.countAll(), 0);
    dispatcher.updatePlayer(player);
    assertEquals(dao.countAll(), 1);
    PartyPlayerImpl newPlayer = dispatcher.getPlayer(player.getPlayerUUID());
    assertEquals(player, newPlayer);
    // Player remove
    if (remove) {
        player.setAccessible(true);
        player.setMuted(false);
        player.setAccessible(false);
        dispatcher.updatePlayer(player);
        assertEquals(dao.countAll(), 0);
    }
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PlayerManager(com.alessiodp.parties.common.players.PlayerManager)

Example 8 with PlayerManager

use of com.alessiodp.parties.common.players.PlayerManager in project Parties by AlessioDP.

the class SQLDispatcherTest method testMultipleOperations.

@Test
public void testMultipleOperations() {
    PartiesSQLDispatcher dispatcher = getSQLDispatcherH2();
    PartiesDao dao = dispatcher.getConnectionFactory().getJdbi().onDemand(H2PartiesDao.class);
    ArrayList<CompletableFuture<?>> lst = new ArrayList<>();
    final int concurrentOperations = 20;
    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)));
    for (int c = 0; c < concurrentOperations; c++) {
        int finalC = c;
        lst.add(CompletableFuture.runAsync(() -> {
            PartyImpl party = initializeParty(mockPlugin, UUID.randomUUID());
            PartyPlayerImpl player = initializePlayer(mockPlugin, UUID.randomUUID());
            party.setAccessible(true);
            party.setup("test-" + finalC, 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);
            dispatcher.updateParty(party);
            try (MockedStatic<ADPPlugin> staticPlugin = mockStatic(ADPPlugin.class)) {
                // Make a try with resource mock static for the completable future
                when(ADPPlugin.getInstance()).thenReturn(mockPlugin);
                Party sameParty = dispatcher.getParty(party.getId());
                assertEquals(sameParty, party);
            }
        }));
    }
    lst.forEach(CompletableFuture::join);
    assertEquals(concurrentOperations, dao.countAll());
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao) H2PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) PlayerManager(com.alessiodp.parties.common.players.PlayerManager) MockedStatic(org.mockito.MockedStatic) PartiesSQLDispatcher(com.alessiodp.parties.common.storage.dispatchers.PartiesSQLDispatcher) ArrayList(java.util.ArrayList) ADPPlugin(com.alessiodp.core.common.ADPPlugin) CompletableFuture(java.util.concurrent.CompletableFuture) Party(com.alessiodp.parties.api.interfaces.Party) PartyManager(com.alessiodp.parties.common.parties.PartyManager) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) Test(org.junit.jupiter.api.Test)

Aggregations

PlayerManager (com.alessiodp.parties.common.players.PlayerManager)8 PartyManager (com.alessiodp.parties.common.parties.PartyManager)6 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)5 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)3 Test (org.junit.jupiter.api.Test)3 ADPPlugin (com.alessiodp.core.common.ADPPlugin)2 PartiesSQLDispatcher (com.alessiodp.parties.common.storage.dispatchers.PartiesSQLDispatcher)2 H2PartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao)2 PartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao)2 PostgreSQLPartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao)2 SQLitePartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao)2 LoggerManager (com.alessiodp.core.common.logging.LoggerManager)1 OfflineUser (com.alessiodp.core.common.user.OfflineUser)1 Party (com.alessiodp.parties.api.interfaces.Party)1 ColorManager (com.alessiodp.parties.common.parties.ColorManager)1 PartiesYAMLDispatcher (com.alessiodp.parties.common.storage.dispatchers.PartiesYAMLDispatcher)1 H2PlayersDao (com.alessiodp.parties.common.storage.sql.dao.players.H2PlayersDao)1 PlayersDao (com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao)1 PostgreSQLPlayersDao (com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao)1 SQLitePlayersDao (com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao)1