Search in sources :

Example 1 with PlayerManager

use of com.alessiodp.parties.common.players.PlayerManager 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 PlayerManager

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

the class FileDispatcherTest method player.

private void player(PartiesYAMLDispatcher dispatcher) {
    PartyPlayerImpl player = initializePlayer(UUID.randomUUID());
    PartyPlayerImpl mockPlayer = mock(player.getClass());
    doReturn(CompletableFuture.completedFuture(null)).when(mockPlayer).updatePlayer();
    PlayerManager mockPlayerManager = mock(PlayerManager.class);
    when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
    when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> initializePlayer(mock.getArgument(0)));
    player.setAccessible(true);
    player.setMuted(true);
    player.setAccessible(false);
    assertNull(dispatcher.getDatabase().getYaml().getConfigurationSection("players"));
    dispatcher.updatePlayer(player);
    assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("players").getKeys(false).size(), 1);
    PartyPlayerImpl newPlayer = dispatcher.getPlayer(player.getPlayerUUID());
    assertEquals(player, newPlayer);
    // Player remove
    player.setAccessible(true);
    player.setMuted(false);
    player.setAccessible(false);
    dispatcher.updatePlayer(player);
    assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("players").getKeys(false).size(), 0);
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PlayerManager(com.alessiodp.parties.common.players.PlayerManager)

Example 3 with PlayerManager

use of com.alessiodp.parties.common.players.PlayerManager 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 4 with PlayerManager

use of com.alessiodp.parties.common.players.PlayerManager 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 5 with PlayerManager

use of com.alessiodp.parties.common.players.PlayerManager 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)

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