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