Search in sources :

Example 1 with PartyManager

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();
}
Also used : PartiesYAMLDispatcher(com.alessiodp.parties.common.storage.dispatchers.PartiesYAMLDispatcher) PlayerManager(com.alessiodp.parties.common.players.PlayerManager) PartyManager(com.alessiodp.parties.common.parties.PartyManager) Test(org.junit.jupiter.api.Test)

Example 2 with PartyManager

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);
    }
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PlayerManager(com.alessiodp.parties.common.players.PlayerManager) PartyManager(com.alessiodp.parties.common.parties.PartyManager) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 3 with PartyManager

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);
}
Also used : PlayerManager(com.alessiodp.parties.common.players.PlayerManager) PartyManager(com.alessiodp.parties.common.parties.PartyManager) LoggerManager(com.alessiodp.core.common.logging.LoggerManager) OfflineUser(com.alessiodp.core.common.user.OfflineUser) ColorManager(com.alessiodp.parties.common.parties.ColorManager) ADPPlugin(com.alessiodp.core.common.ADPPlugin) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with PartyManager

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);
    }
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PlayerManager(com.alessiodp.parties.common.players.PlayerManager) PartyManager(com.alessiodp.parties.common.parties.PartyManager) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 5 with PartyManager

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();
    }
}
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)

Aggregations

PartyManager (com.alessiodp.parties.common.parties.PartyManager)6 PlayerManager (com.alessiodp.parties.common.players.PlayerManager)6 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)3 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)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