diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java index 91f280837..39a1e0276 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java @@ -280,8 +280,8 @@ public class WorldTimesTable extends UserIDTable { try { statement = prepareStatement(insertStatement); String[] gms = GMTimes.getGMKeyArray(); - for (UUID serverUUID : allSessions.keySet()) { - for (Map.Entry> entry : allSessions.get(serverUUID).entrySet()) { + for (Map> serverSessions : allSessions.values()) { + for (Map.Entry> entry : serverSessions.entrySet()) { UUID uuid = entry.getKey(); List sessions = entry.getValue(); for (Session session : sessions) { diff --git a/Plan/test/main/java/com/djrapitops/plan/database/DatabaseTest.java b/Plan/test/main/java/com/djrapitops/plan/database/DatabaseTest.java index 84b5c5cff..fa5ce2609 100644 --- a/Plan/test/main/java/com/djrapitops/plan/database/DatabaseTest.java +++ b/Plan/test/main/java/com/djrapitops/plan/database/DatabaseTest.java @@ -754,7 +754,7 @@ public class DatabaseTest { assertEquals(expected, kills); } - @Test // TODO Fix all issues with this test. + @Test public void testBackupAndRestore() throws SQLException, DatabaseInitException { SQLiteDB backup = new SQLiteDB(plan, "debug-backup" + MiscUtils.getTime()); backup.init(); @@ -787,4 +787,66 @@ public class DatabaseTest { assertFalse(backup.getServerTable().getBukkitServers().isEmpty()); assertFalse(securityTable.getUsers().isEmpty()); } + + @Test + public void testSaveWorldTimes() throws SQLException { + saveUserOne(); + WorldTimes worldTimes = createWorldTimes(); + WorldTimesTable worldTimesTable = db.getWorldTimesTable(); + worldTimesTable.saveWorldTimes(uuid, 1, worldTimes); + + Session session = new Session(1, 12345L, 23456L, 0, 0); + Map sessions = new HashMap<>(); + sessions.put(1, session); + worldTimesTable.addWorldTimesToSessions(uuid, sessions); + + assertEquals(worldTimes, session.getWorldTimes()); + } + + @Test + public void testSaveAllWorldTimes() throws SQLException { + saveUserOne(); + WorldTimes worldTimes = createWorldTimes(); + System.out.println(worldTimes); + WorldTimesTable worldTimesTable = db.getWorldTimesTable(); + Session session = new Session(1, 12345L, 23456L, 0, 0); + session.setWorldTimes(worldTimes); + + Map>> map = new HashMap<>(); + Map> sessionMap = new HashMap<>(); + List sessions = new ArrayList<>(); + sessions.add(session); + sessionMap.put(uuid, sessions); + map.put(Plan.getServerUUID(), sessionMap); + + worldTimesTable.saveWorldTimes(map); + + Map worldTimesBySessionID = worldTimesTable.getAllWorldTimesBySessionID(); + assertEquals(worldTimes, worldTimesBySessionID.get(1)); + } + + @Test + public void testSaveSessionsWorldTimes() throws SQLException { + SessionsTable sessionsTable = db.getSessionsTable(); + + saveUserOne(); + WorldTimes worldTimes = createWorldTimes(); + System.out.println(worldTimes); + Session session = new Session(1, 12345L, 23456L, 0, 0); + session.setWorldTimes(worldTimes); + + Map>> map = new HashMap<>(); + Map> sessionMap = new HashMap<>(); + List sessions = new ArrayList<>(); + sessions.add(session); + sessionMap.put(uuid, sessions); + UUID serverUUID = Plan.getServerUUID(); + map.put(serverUUID, sessionMap); + + sessionsTable.insertSessions(map, true); + + Map>> allSessions = sessionsTable.getAllSessions(true); + + assertEquals(worldTimes, allSessions.get(serverUUID).get(uuid).get(0).getWorldTimes()); + } }