Search in sources :

Example 51 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class FileDispatcherTest method insertOneParty.

private void insertOneParty(PartiesYAMLDispatcher dispatcher, String partyName, int numberOfPlayers, int kills, double experience) {
    PartyImpl mockParty = mock(PartyImpl.class);
    doReturn(CompletableFuture.completedFuture(null)).when(mockParty).updateParty();
    PartyPlayerImpl mockPlayer = mock(PartyPlayerImpl.class);
    doReturn(CompletableFuture.completedFuture(null)).when(mockPlayer).updatePlayer();
    PartyImpl party = initializeParty(UUID.randomUUID());
    Set<UUID> members = new HashSet<>();
    for (int c = 0; c < numberOfPlayers; c++) {
        PartyPlayerImpl player = initializePlayer(UUID.randomUUID());
        members.add(player.getPlayerUUID());
        player.setAccessible(true);
        player.setPartyId(party.getId());
        player.setAccessible(false);
        dispatcher.updatePlayer(player);
    }
    party.setAccessible(true);
    party.setup(partyName, members.iterator().next().toString());
    party.setKills(kills);
    party.setExperience(experience);
    party.setMembers(members);
    party.setAccessible(false);
    dispatcher.updateParty(party);
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) UUID(java.util.UUID) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) HashSet(java.util.HashSet)

Example 52 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class FileDispatcherTest method listFixed.

private void listFixed(PartiesYAMLDispatcher dispatcher) {
    PartyImpl party = initializeParty(UUID.randomUUID());
    party.setAccessible(true);
    party.setup("test3", null);
    party.setDescription("description");
    party.setAccessible(false);
    assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("parties").getKeys(false).size(), 1);
    assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("map-parties-by-name").getKeys(false).size(), 1);
    dispatcher.updateParty(party);
    assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("parties").getKeys(false).size(), 2);
    assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("map-parties-by-name").getKeys(false).size(), 2);
    assertEquals(party, dispatcher.getParty(party.getId()));
    assertEquals(party, dispatcher.getPartyByName(party.getName()));
    Set<PartyImpl> list = dispatcher.getListFixed();
    assertEquals(1, list.size());
    assertEquals(party, list.iterator().next());
}
Also used : PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 53 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class MigrationsTest method database2_6_X_YAML.

private void database2_6_X_YAML(PartiesYAMLDispatcher dispatcher) {
    dispatcher.init();
    PartyImpl party = dispatcher.getPartyByName("test");
    assertNotNull(party);
    assertEquals("test description", party.getDescription());
    assertEquals(2, party.getMembers().size());
    // Leader check
    assertNotNull(party.getLeader());
    PartyPlayerImpl leader = dispatcher.getPlayer(party.getLeader());
    assertNotNull(leader);
    assertEquals(party.getId(), leader.getPartyId());
    // Home check
    assertEquals(1, party.getHomes().size());
    assertTrue(party.getHomes().stream().findFirst().isPresent());
    assertEquals("default", party.getHomes().stream().findFirst().get().getName());
    // Another party
    assertNotNull(dispatcher.getPartyByName("test2"));
    dispatcher.stop();
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 54 with PartyImpl

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

Example 55 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class SQLDispatcherTest method countParties.

private void countParties(PartiesSQLDispatcher dispatcher, PartiesDao dao) {
    ConfigParties.ADDITIONAL_LIST_HIDDENPARTIES = Collections.emptyList();
    PartyImpl party = initializeParty(mockPlugin, UUID.randomUUID());
    party.setAccessible(true);
    party.setup("test3", null);
    party.setDescription("description");
    party.setAccessible(false);
    assertEquals(dao.countAll(), 1);
    assertEquals(dispatcher.getListPartiesNumber(), 1);
    dispatcher.updateParty(party);
    assertEquals(dao.countAll(), 2);
    assertEquals(dispatcher.getListPartiesNumber(), 2);
}
Also used : PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)106 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)75 User (com.alessiodp.core.common.user.User)39 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)31 ADPPlugin (com.alessiodp.core.common.ADPPlugin)11 UUID (java.util.UUID)11 ConfigMain (com.alessiodp.parties.common.configuration.data.ConfigMain)10 ConfigParties (com.alessiodp.parties.common.configuration.data.ConfigParties)10 PartiesPlugin (com.alessiodp.parties.common.PartiesPlugin)9 PartiesConstants (com.alessiodp.parties.common.configuration.PartiesConstants)9 PartyHomeImpl (com.alessiodp.parties.common.parties.objects.PartyHomeImpl)8 LinkedList (java.util.LinkedList)8 LinkedHashSet (java.util.LinkedHashSet)7 List (java.util.List)7 HashMap (java.util.HashMap)6 ADPMainCommand (com.alessiodp.core.common.commands.utils.ADPMainCommand)5 CommandData (com.alessiodp.core.common.commands.utils.CommandData)5 OfflineUser (com.alessiodp.core.common.user.OfflineUser)5 CommonCommands (com.alessiodp.parties.common.commands.list.CommonCommands)5 PartiesSubCommand (com.alessiodp.parties.common.commands.utils.PartiesSubCommand)5