Test for KillsTable getPlayerKills(serverUUID) method & fix for it.

This commit is contained in:
Rsl1122 2017-09-02 17:10:00 +03:00
parent e78dea9cd9
commit b82b1dd97e
2 changed files with 27 additions and 7 deletions

View File

@ -156,17 +156,18 @@ public class KillsTable extends UserIDTable {
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet set = null; ResultSet set = null;
try { try {
String usersIDColumn = usersTable + "." + usersTable.getColumnID(); String usersVictimIDColumn = usersTable + "." + usersTable.getColumnID();
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as victim_uuid"; String usersKillerIDColumn = "a." + usersTable.getColumnID();
String usersUUIDColumn2 = usersTable + "." + usersTable.getColumnUUID() + " as killer_uuid"; String usersVictimUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as victim_uuid";
String usersKillerUUIDColumn = "a." + usersTable.getColumnUUID() + " as killer_uuid";
statement = prepareStatement("SELECT " + statement = prepareStatement("SELECT " +
columnDate + ", " + columnDate + ", " +
columnWeapon + ", " + columnWeapon + ", " +
usersUUIDColumn + ", " + usersVictimUUIDColumn + ", " +
usersUUIDColumn2 + usersKillerUUIDColumn +
" FROM " + tableName + " FROM " + tableName +
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnVictimUserID + " JOIN " + usersTable + " on " + usersVictimIDColumn + "=" + columnVictimUserID +
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnKillerUserID); " JOIN " + usersTable + " a on " + usersKillerIDColumn + "=" + columnKillerUserID);
statement.setFetchSize(10000); statement.setFetchSize(10000);
set = statement.executeQuery(); set = statement.executeQuery();

View File

@ -704,4 +704,23 @@ public class DatabaseTest {
assertFalse(sSessions.isEmpty()); assertFalse(sSessions.isEmpty());
assertEquals(session, sSessions.get(0)); assertEquals(session, sSessions.get(0));
} }
@Test
public void testKillTableGetKillsOfServer() throws SQLException, DatabaseInitException {
saveUserOne();
saveUserTwo();
KillsTable killsTable = db.getKillsTable();
List<PlayerKill> expected = createKills();
killsTable.savePlayerKills(uuid, 1, expected);
commitTest();
Map<UUID, List<PlayerKill>> playerKills = killsTable.getPlayerKills();
List<PlayerKill> kills = playerKills.get(uuid);
assertFalse(playerKills.isEmpty());
assertNotNull(kills);
assertFalse(kills.isEmpty());
assertEquals(expected, kills);
}
} }