mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 09:00:28 +08:00
Moved Commit tests to DatabaseTest (new method in each test)
This commit is contained in:
parent
a7715aa4eb
commit
f514edfc8b
@ -1,103 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.database;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.data.WebUser;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.RandomData;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class DatabaseCommitTest {
|
||||
|
||||
private Plan plan;
|
||||
private SQLDB db;
|
||||
private int rows;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit t = TestInit.init();
|
||||
plan = t.getPlanMock();
|
||||
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime());
|
||||
db.init();
|
||||
|
||||
File file = new File(plan.getDataFolder(), "Errors.txt");
|
||||
rows = FileUtil.lines(file).size();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws IOException, SQLException {
|
||||
db.close();
|
||||
|
||||
File f = new File(plan.getDataFolder(), "Errors.txt");
|
||||
List<String> lines = FileUtil.lines(f);
|
||||
int rowsAgain = lines.size();
|
||||
if (rowsAgain > 0) {
|
||||
for (String line : lines) {
|
||||
System.out.println(line);
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Errors were caught.", rows == rowsAgain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExceptionWhenCommitEmpty() throws Exception {
|
||||
db.init();
|
||||
|
||||
db.commit(db.getConnection());
|
||||
db.commit(db.getConnection());
|
||||
db.commit(db.getConnection());
|
||||
}
|
||||
|
||||
@Ignore("//TODO")
|
||||
@Test
|
||||
public void testCommitToDBFile() throws Exception {
|
||||
db.init();
|
||||
}
|
||||
|
||||
@Ignore("//TODO")
|
||||
@Test
|
||||
public void testCommitToDBFile2() throws Exception {
|
||||
db.init();
|
||||
List<TPS> tps = RandomData.randomTPS();
|
||||
// db.getTpsTable().saveTPSData(tps);
|
||||
db.close();
|
||||
db.init();
|
||||
assertFalse(db.getTpsTable().getTPSData().isEmpty());
|
||||
}
|
||||
|
||||
// TODO Commit tests for new Login save features.
|
||||
|
||||
@Test
|
||||
public void testCommitToDBFile5() throws Exception {
|
||||
db.init();
|
||||
WebUser webUser = new WebUser("Test", "SHA1:rioegnorgiengoieng:oiegnoeigneo:352", 0);
|
||||
db.getSecurityTable().addNewUser(webUser);
|
||||
db.close();
|
||||
db.init();
|
||||
assertEquals(webUser, db.getSecurityTable().getWebUser("Test"));
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import main.java.com.djrapitops.plan.data.*;
|
||||
import main.java.com.djrapitops.plan.data.time.GMTimes;
|
||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.database.tables.*;
|
||||
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
|
||||
@ -91,6 +92,15 @@ public class DatabaseTest {
|
||||
db.init();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExceptionWhenCommitEmpty() throws Exception {
|
||||
db.init();
|
||||
|
||||
db.commit(((SQLDB) db).getConnection());
|
||||
db.commit(((SQLDB) db).getConnection());
|
||||
db.commit(((SQLDB) db).getConnection());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSQLiteGetConfigName() {
|
||||
assertEquals("sqlite", db.getConfigName());
|
||||
@ -112,7 +122,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveCommandUse() throws SQLException {
|
||||
public void testSaveCommandUse() throws SQLException, DatabaseInitException {
|
||||
CommandUseTable commandUseTable = db.getCommandUseTable();
|
||||
Map<String, Integer> expected = new HashMap<>();
|
||||
|
||||
@ -139,7 +149,7 @@ public class DatabaseTest {
|
||||
commandUseTable.commandUsed("roiergbnougbierubieugbeigubeigubgierbgeugeg");
|
||||
}
|
||||
|
||||
expected.remove("roiergbnougbierubieugbeigubeigubgierbgeugeg");
|
||||
commitTest();
|
||||
|
||||
Map<String, Integer> commandUse = db.getCommandUse();
|
||||
assertEquals(expected, commandUse);
|
||||
@ -207,6 +217,8 @@ public class DatabaseTest {
|
||||
tpsTable.insertTPS(tps);
|
||||
}
|
||||
|
||||
commitTest();
|
||||
|
||||
assertEquals(expected, tpsTable.getTPSData());
|
||||
}
|
||||
|
||||
@ -233,7 +245,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPTable() throws SQLException {
|
||||
public void testIPTable() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
IPsTable ipsTable = db.getIpsTable();
|
||||
|
||||
@ -242,6 +254,7 @@ public class DatabaseTest {
|
||||
|
||||
ipsTable.saveIP(uuid, expectedIP, expectedGeoLoc);
|
||||
ipsTable.saveIP(uuid, expectedIP, expectedGeoLoc);
|
||||
commitTest();
|
||||
|
||||
List<String> ips = ipsTable.getIps(uuid);
|
||||
assertEquals(1, ips.size());
|
||||
@ -258,13 +271,14 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test // Does not test getting sessions from another server.
|
||||
public void testNicknamesTable() throws SQLException {
|
||||
public void testNicknamesTable() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
NicknamesTable nickTable = db.getNicknamesTable();
|
||||
|
||||
String expected = "TestNickname";
|
||||
nickTable.saveUserName(uuid, expected);
|
||||
nickTable.saveUserName(uuid, expected);
|
||||
commitTest();
|
||||
|
||||
List<String> nicknames = nickTable.getNicknames(uuid);
|
||||
assertEquals(1, nicknames.size());
|
||||
@ -275,10 +289,12 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecurityTable() throws SQLException {
|
||||
public void testSecurityTable() throws SQLException, DatabaseInitException {
|
||||
SecurityTable securityTable = db.getSecurityTable();
|
||||
WebUser expected = new WebUser("Test", "RandomGarbageBlah", 0);
|
||||
securityTable.addNewUser(expected);
|
||||
commitTest();
|
||||
|
||||
assertTrue(securityTable.userExists("Test"));
|
||||
WebUser test = securityTable.getWebUser("Test");
|
||||
assertEquals(expected, test);
|
||||
@ -296,11 +312,13 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldTable() throws SQLException {
|
||||
public void testWorldTable() throws SQLException, DatabaseInitException {
|
||||
WorldTable worldTable = db.getWorldTable();
|
||||
List<String> worlds = Arrays.asList("Test", "Test2", "Test3");
|
||||
worldTable.saveWorlds(worlds);
|
||||
|
||||
commitTest();
|
||||
|
||||
List<String> saved = worldTable.getWorlds();
|
||||
assertEquals(worlds, saved);
|
||||
}
|
||||
@ -330,7 +348,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionPlaytimeSaving() throws SQLException {
|
||||
public void testSessionPlaytimeSaving() throws SQLException, DatabaseInitException {
|
||||
saveTwoWorlds();
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
@ -346,6 +364,8 @@ public class DatabaseTest {
|
||||
SessionsTable sessionsTable = db.getSessionsTable();
|
||||
sessionsTable.saveSession(uuid, session);
|
||||
|
||||
commitTest();
|
||||
|
||||
assertEquals(expectedLength, sessionsTable.getPlaytime(uuid));
|
||||
assertEquals(0L, sessionsTable.getPlaytime(uuid, 30000L));
|
||||
|
||||
@ -358,7 +378,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionSaving() throws SQLException {
|
||||
public void testSessionSaving() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
@ -370,6 +390,8 @@ public class DatabaseTest {
|
||||
SessionsTable sessionsTable = db.getSessionsTable();
|
||||
sessionsTable.saveSession(uuid, session);
|
||||
|
||||
commitTest();
|
||||
|
||||
Map<String, List<Session>> sessions = sessionsTable.getSessions(uuid);
|
||||
|
||||
for (Map.Entry<String, List<Session>> entry : sessions.entrySet()) {
|
||||
@ -394,7 +416,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfoTableRegisterUnRegistered() throws SQLException {
|
||||
public void testUserInfoTableRegisterUnRegistered() throws SQLException, DatabaseInitException {
|
||||
UserInfoTable userInfoTable = db.getUserInfoTable();
|
||||
assertFalse(userInfoTable.isRegistered(uuid));
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
@ -402,6 +424,8 @@ public class DatabaseTest {
|
||||
|
||||
userInfoTable.registerUserInfo(uuid, 123456789L);
|
||||
|
||||
commitTest();
|
||||
|
||||
assertTrue(usersTable.isRegistered(uuid));
|
||||
assertTrue(userInfoTable.isRegistered(uuid));
|
||||
|
||||
@ -415,7 +439,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfoTableRegisterRegistered() throws SQLException {
|
||||
public void testUserInfoTableRegisterRegistered() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
assertTrue(usersTable.isRegistered(uuid));
|
||||
@ -424,6 +448,7 @@ public class DatabaseTest {
|
||||
assertFalse(userInfoTable.isRegistered(uuid));
|
||||
|
||||
userInfoTable.registerUserInfo(uuid, 223456789L);
|
||||
commitTest();
|
||||
|
||||
assertTrue(usersTable.isRegistered(uuid));
|
||||
assertTrue(userInfoTable.isRegistered(uuid));
|
||||
@ -440,24 +465,29 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfoTableUpdateBannedOpped() throws SQLException {
|
||||
public void testUserInfoTableUpdateBannedOpped() throws SQLException, DatabaseInitException {
|
||||
UserInfoTable userInfoTable = db.getUserInfoTable();
|
||||
userInfoTable.registerUserInfo(uuid, 223456789L);
|
||||
assertTrue(userInfoTable.isRegistered(uuid));
|
||||
|
||||
userInfoTable.updateOpAndBanStatus(uuid, true, true);
|
||||
commitTest();
|
||||
|
||||
UserInfo userInfo = userInfoTable.getUserInfo(uuid);
|
||||
assertTrue(userInfo.isBanned());
|
||||
assertTrue(userInfo.isOpped());
|
||||
|
||||
userInfoTable.updateOpAndBanStatus(uuid, false, true);
|
||||
commitTest();
|
||||
|
||||
userInfo = userInfoTable.getUserInfo(uuid);
|
||||
|
||||
assertTrue(userInfo.isBanned());
|
||||
assertFalse(userInfo.isOpped());
|
||||
|
||||
userInfoTable.updateOpAndBanStatus(uuid, false, false);
|
||||
commitTest();
|
||||
|
||||
userInfo = userInfoTable.getUserInfo(uuid);
|
||||
|
||||
assertFalse(userInfo.isBanned());
|
||||
@ -465,13 +495,16 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsersTableUpdateName() throws SQLException {
|
||||
public void testUsersTableUpdateName() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
|
||||
assertEquals(uuid, usersTable.getUuidOf("Test"));
|
||||
usersTable.updateName(uuid, "NewName");
|
||||
|
||||
commitTest();
|
||||
|
||||
assertNull(usersTable.getUuidOf("Test"));
|
||||
|
||||
assertEquals("NewName", usersTable.getPlayerName(uuid));
|
||||
@ -479,7 +512,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsersTableKickSaving() throws SQLException {
|
||||
public void testUsersTableKickSaving() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
assertEquals(0, usersTable.getTimesKicked(uuid));
|
||||
@ -489,7 +522,7 @@ public class DatabaseTest {
|
||||
for (int i = 0; i < random + 1; i++) {
|
||||
usersTable.kicked(uuid);
|
||||
}
|
||||
|
||||
commitTest();
|
||||
assertEquals(random + 1, usersTable.getTimesKicked(uuid));
|
||||
}
|
||||
|
||||
@ -602,7 +635,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerTableBungeeSave() throws SQLException {
|
||||
public void testServerTableBungeeSave() throws SQLException, DatabaseInitException {
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
|
||||
Optional<ServerInfo> bungeeInfo = serverTable.getBungeeInfo();
|
||||
@ -612,6 +645,8 @@ public class DatabaseTest {
|
||||
ServerInfo bungeeCord = new ServerInfo(-1, bungeeUUID, "BungeeCord", "Random:1234", 20);
|
||||
serverTable.saveCurrentServerInfo(bungeeCord);
|
||||
|
||||
commitTest();
|
||||
|
||||
bungeeCord.setId(2);
|
||||
|
||||
bungeeInfo = serverTable.getBungeeInfo();
|
||||
@ -624,7 +659,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerTableBungee() throws SQLException {
|
||||
public void testServerTableBungee() throws SQLException, DatabaseInitException {
|
||||
testServerTableBungeeSave();
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
|
||||
@ -637,4 +672,9 @@ public class DatabaseTest {
|
||||
Map<UUID, Long> lastSeen = db.getSessionsTable().getLastSeenForAllPlayers();
|
||||
assertTrue(lastSeen.isEmpty());
|
||||
}
|
||||
|
||||
private void commitTest() throws DatabaseInitException, SQLException {
|
||||
db.close();
|
||||
db.init();
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,11 @@
|
||||
*/
|
||||
package test.java.utils;
|
||||
|
||||
import main.java.com.djrapitops.plan.database.DatabaseTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import main.java.com.djrapitops.plan.database.DatabaseCommitTest;
|
||||
import main.java.com.djrapitops.plan.database.DatabaseTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -18,7 +17,7 @@ import java.io.IOException;
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({DatabaseCommitTest.class, DatabaseTest.class})
|
||||
@Suite.SuiteClasses({DatabaseTest.class})
|
||||
public class DBTestSuite {
|
||||
@BeforeClass
|
||||
public static void setUp() throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user