mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 03:27:37 +01:00
Removed HandlingInfo tests
Fixed Compile issues
This commit is contained in:
parent
a86cb16226
commit
8f8d61279c
@ -6,8 +6,6 @@
|
||||
package test.java.main.java.com.djrapitops.plan.data.cache.queue;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCache;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
@ -24,12 +22,9 @@ import test.java.utils.TestInit;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
// TODO Rewrite
|
||||
@ -38,11 +33,6 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
||||
public class QueueTest {
|
||||
|
||||
private final UUID uuid1 = MockUtils.getPlayerUUID();
|
||||
private final UserData data1 = MockUtils.mockUserWithMoreData();
|
||||
private final UserData data2 = new UserData(MockUtils.mockIPlayer2());
|
||||
|
||||
private int callsToSaveUserData;
|
||||
private int callsToGetUserData;
|
||||
|
||||
private DataCache handler;
|
||||
private Database db;
|
||||
@ -52,40 +42,12 @@ public class QueueTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
callsToSaveUserData = 0;
|
||||
callsToGetUserData = 0;
|
||||
TestInit t = TestInit.init();
|
||||
Plan plan = t.getPlanMock();
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertBukkitDataToDB() {
|
||||
}
|
||||
|
||||
private UserData getData(UUID uuid) {
|
||||
UserData data;
|
||||
if (uuid.equals(uuid1)) {
|
||||
data = data1;
|
||||
} else {
|
||||
data = data2;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveUserDataToProcessors(UUID uuid, Collection<DBCallableProcessor> processors) throws SQLException {
|
||||
callsToGetUserData++;
|
||||
UserData data = getData(uuid);
|
||||
processors.forEach(processor -> processor.process(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserData(UserData data) throws SQLException {
|
||||
callsToSaveUserData++;
|
||||
}
|
||||
};
|
||||
db.init();
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
@ -117,13 +79,10 @@ public class QueueTest {
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
while (processCalls.size() < 1) {
|
||||
if (errors.size() > 0) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
assertEquals(1, processCalls.size());
|
||||
assertEquals(0, errors.size());
|
||||
assertEquals(1, callsToGetUserData);
|
||||
// while (processCalls.size() < 1) {
|
||||
// if (errors.size() > 0) {
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.ChatInfo;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import test.java.utils.MockUtils;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ChatInfoTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testProcessNick() {
|
||||
UserData data = MockUtils.mockUser();
|
||||
String expected = "TestNicknameChatInfo";
|
||||
ChatInfo i = new ChatInfo(data.getUuid(), expected);
|
||||
i.process(data);
|
||||
assertTrue("Didn't add nickname", data.getNicknames().contains(expected));
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.DeathInfo;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import test.java.utils.MockUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DeathInfoTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DeathInfoTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() {
|
||||
UserData data = MockUtils.mockUser();
|
||||
DeathInfo i = new DeathInfo(data.getUuid());
|
||||
i.process(data);
|
||||
assertEquals(1, data.getDeaths());
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.InfoType;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class HandlingInfoTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public HandlingInfoTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGetUuid() {
|
||||
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L) {
|
||||
@Override
|
||||
public void process(UserData data) {
|
||||
|
||||
}
|
||||
};
|
||||
assertEquals(uuid, i.getUuid());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGetType() {
|
||||
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L) {
|
||||
@Override
|
||||
public void process(UserData data) {
|
||||
|
||||
}
|
||||
};
|
||||
assertEquals(InfoType.CHAT, i.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGetTime() {
|
||||
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L) {
|
||||
@Override
|
||||
public void process(UserData data) {
|
||||
|
||||
}
|
||||
};
|
||||
assertEquals(10L, i.getTime());
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KickInfo;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.Before;
|
||||
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.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class KickInfoTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public KickInfoTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit.init();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() {
|
||||
UserData data = MockUtils.mockUser();
|
||||
KickInfo i = new KickInfo(data.getUuid());
|
||||
i.process(data);
|
||||
assertEquals(1, data.getTimesKicked());
|
||||
}
|
||||
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KillInfo;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.Before;
|
||||
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.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class KillInfoTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public KillInfoTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit t = TestInit.init();
|
||||
Plan plan = t.getPlanMock();
|
||||
Database db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UsersTable getUsersTable() {
|
||||
return new UsersTable(null, false) {
|
||||
@Override
|
||||
public int getUserId(UUID uuid) {
|
||||
if (uuid.equals(MockUtils.getPlayerUUID())) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() throws SQLException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
Player dead = MockUtils.mockPlayer2();
|
||||
KillInfo i = new KillInfo(data.getUuid(), 10L, dead, "TestWeapon");
|
||||
i.process(data);
|
||||
KillData expected = new KillData(dead.getUniqueId(), 1, "TestWeapon", 10L);
|
||||
assertTrue("Didn't add the kill", data.getPlayerKills().size() == 1);
|
||||
KillData result = data.getPlayerKills().get(0);
|
||||
assertEquals(expected.getDate(), result.getDate());
|
||||
assertEquals(expected.getVictim(), result.getVictim());
|
||||
assertEquals(expected.getVictimUserID(), result.getVictimUserID());
|
||||
assertEquals(expected.getWeapon(), result.getWeapon());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Test
|
||||
public void testProcessMobKill() throws SQLException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
KillInfo i = new KillInfo(data.getUuid(), 10L, null, "TestWeapon");
|
||||
i.process(data);
|
||||
assertTrue("Added a kill", data.getPlayerKills().isEmpty());
|
||||
assertEquals(1, data.getMobKills());
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.LoginInfo;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.Before;
|
||||
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.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class LoginInfoTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public LoginInfoTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() throws UnknownHostException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
InetAddress ip = InetAddress.getByName("137.19.188.146");
|
||||
long time = 10L;
|
||||
int loginTimes = data.getLoginTimes();
|
||||
String nick = "TestProcessLoginInfo";
|
||||
LoginInfo i = new LoginInfo(data.getUuid(), time, ip, true, nick, "CREATIVE", 1, "World");
|
||||
i.process(data);
|
||||
assertTrue("LastPlayed wrong: " + data.getLastPlayed(), data.getLastPlayed() == time);
|
||||
assertTrue("Ip not added", data.getIps().contains(ip));
|
||||
assertTrue("Logintimes not +1", data.getLoginTimes() == loginTimes + 1);
|
||||
assertTrue("Nick not added", data.getNicknames().contains(nick));
|
||||
assertTrue("Nick not last nick", data.getLastNick().equals(nick));
|
||||
String geo = data.getGeolocation();
|
||||
assertTrue("Wrong location " + geo, geo.equals("United States"));
|
||||
assertEquals("CREATIVE", data.getGmTimes().getState());
|
||||
// TODO assertEquals("World", data.getWorldTimes().getState());
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class LogoutInfoTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public LogoutInfoTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test //TODO Rewrite
|
||||
public void testProcess() {
|
||||
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.ReloadInfo;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.Before;
|
||||
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.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class ReloadInfoTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ReloadInfoTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() throws UnknownHostException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
InetAddress ip = InetAddress.getByName("137.19.188.146");
|
||||
long time = MiscUtils.getTime();
|
||||
int loginTimes = data.getLoginTimes();
|
||||
String nick = "TestProcessLoginInfo";
|
||||
ReloadInfo i = new ReloadInfo(data.getUuid(), time, ip, true, nick, "CREATIVE", "World");
|
||||
i.process(data);
|
||||
assertTrue("LastPlayed wrong: " + data.getLastPlayed(), data.getLastPlayed() == time);
|
||||
assertTrue("Ip not added", data.getIps().contains(ip));
|
||||
assertTrue("Login times is not the same", data.getLoginTimes() == loginTimes);
|
||||
assertTrue("Nick not added", data.getNicknames().contains(nick));
|
||||
assertEquals(nick, data.getLastNick());
|
||||
assertEquals("United States", data.getGeolocation());
|
||||
assertEquals("CREATIVE", data.getGmTimes().getState());
|
||||
// TODO assertEquals("World", data.getWorldTimes().getState());
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package test.java.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.UserData;
|
||||
import main.java.com.djrapitops.plan.data.WebUser;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
@ -16,18 +15,14 @@ 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.MockUtils;
|
||||
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.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -50,11 +45,6 @@ public class DatabaseCommitTest {
|
||||
public void startConnectionPingTask() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
};
|
||||
File f = new File(plan.getDataFolder(), "Errors.txt");
|
||||
rows = FileUtil.lines(f).size();
|
||||
@ -102,26 +92,7 @@ public class DatabaseCommitTest {
|
||||
assertFalse(db.getTpsTable().getTPSData().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitToDBFile3() throws SQLException {
|
||||
db.init();
|
||||
UserData userData = MockUtils.mockUser();
|
||||
db.saveUserData(userData);
|
||||
db.close();
|
||||
db.init();
|
||||
assertFalse(db.getUserDataForUUIDS(Collections.singletonList(MockUtils.getPlayerUUID())).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitToDBFile4() throws SQLException {
|
||||
db.init();
|
||||
List<UserData> data = RandomData.randomUserData();
|
||||
List<UUID> uuids = data.stream().map(UserData::getUuid).collect(Collectors.toList());
|
||||
db.saveMultipleUserData(data);
|
||||
db.close();
|
||||
db.init();
|
||||
assertFalse(db.getUserDataForUUIDS(uuids).isEmpty());
|
||||
}
|
||||
// TODO Commit tests for new Login save features.
|
||||
|
||||
@Test
|
||||
public void testCommitToDBFile5() throws SQLException, PassEncryptUtil.CannotPerformOperationException {
|
||||
|
@ -7,12 +7,10 @@ package test.java.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.UserData;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.database.tables.TPSTable;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
@ -68,11 +66,6 @@ public class DatabaseTest {
|
||||
public void startConnectionPingTask() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
};
|
||||
File f = new File(plan.getDataFolder(), "Errors.txt");
|
||||
rows = FileUtil.lines(f).size();
|
||||
@ -134,11 +127,6 @@ public class DatabaseTest {
|
||||
public void startConnectionPingTask() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
}.getConfigName());
|
||||
}
|
||||
|
||||
@ -152,22 +140,17 @@ public class DatabaseTest {
|
||||
public void startConnectionPingTask() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
}.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Test
|
||||
@Test // TODO Rewrite
|
||||
public void testRemoveAll() throws SQLException {
|
||||
db.init();
|
||||
UserData data = MockUtils.mockUser();
|
||||
db.saveUserData(data);
|
||||
// UserData data = MockUtils.mockUser();
|
||||
// db.saveUserData(data);
|
||||
HashMap<String, Integer> c = new HashMap<>();
|
||||
c.put("/plan", 1);
|
||||
c.put("/tp", 4);
|
||||
@ -208,13 +191,13 @@ public class DatabaseTest {
|
||||
/**
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Test
|
||||
@Test // TODO Rewrite
|
||||
public void testRemove() throws SQLException {
|
||||
db.init();
|
||||
UserData data = MockUtils.mockUser();
|
||||
db.saveUserData(data);
|
||||
assertTrue(db.removeAccount(data.getUuid().toString()));
|
||||
assertTrue("Contains the user", !db.wasSeenBefore(data.getUuid()));
|
||||
// UserData data = MockUtils.mockUser();
|
||||
// db.saveUserData(data);
|
||||
// assertTrue(db.removeAccount(data.getUuid().toString()));
|
||||
// assertTrue("Contains the user", !db.wasSeenBefore(data.getUuid()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,29 +206,6 @@ public class DatabaseTest {
|
||||
@Test
|
||||
@Ignore("Backup has to be rewritten")
|
||||
public void testBackup() throws SQLException {
|
||||
db.init();
|
||||
UserData data = MockUtils.mockUser();
|
||||
UserData data2 = MockUtils.mockUser2();
|
||||
List<UserData> list = new ArrayList<>();
|
||||
list.add(data);
|
||||
list.add(data2);
|
||||
db.saveMultipleUserData(list);
|
||||
backup = new SQLiteDB(plan, "debug-backup") {
|
||||
@Override
|
||||
public void startConnectionPingTask() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
};
|
||||
backup.init();
|
||||
ManageUtils.clearAndCopy(backup, db);
|
||||
Set<UUID> savedUUIDs = backup.getSavedUUIDs();
|
||||
assertTrue("Didn't contain 1", savedUUIDs.contains(data.getUuid()));
|
||||
assertTrue("Didn't contain 2", savedUUIDs.contains(data2.getUuid()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -255,41 +215,7 @@ public class DatabaseTest {
|
||||
@Test
|
||||
@Ignore("Backup has to be rewritten")
|
||||
public void testRestore() throws SQLException {
|
||||
db.init();
|
||||
UserData data = MockUtils.mockUser();
|
||||
UserData data2 = MockUtils.mockUser2();
|
||||
List<UserData> list = new ArrayList<>();
|
||||
list.add(data);
|
||||
list.add(data2);
|
||||
db.saveMultipleUserData(list);
|
||||
HashMap<String, Integer> c = new HashMap<>();
|
||||
c.put("/plan", 1);
|
||||
c.put("/tp", 4);
|
||||
c.put("/pla", 7);
|
||||
c.put("/help", 21);
|
||||
db.saveCommandUse(c);
|
||||
backup = new SQLiteDB(plan, "debug-backup") {
|
||||
@Override
|
||||
public void startConnectionPingTask() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
};
|
||||
backup.init();
|
||||
ManageUtils.clearAndCopy(backup, db);
|
||||
ManageUtils.clearAndCopy(db, backup);
|
||||
Set<UUID> savedUUIDs = db.getSavedUUIDs();
|
||||
assertTrue("Didn't contain 1", savedUUIDs.contains(data.getUuid()));
|
||||
assertTrue("Didn't contain 2", savedUUIDs.contains(data2.getUuid()));
|
||||
Map<String, Integer> commandUse = db.getCommandUse();
|
||||
assertTrue("Doesn't contain /plan", commandUse.containsKey("/plan"));
|
||||
assertTrue("Doesn't contain /tp", commandUse.containsKey("/tp"));
|
||||
assertTrue("Doesn't contain /pla", commandUse.containsKey("/pla"));
|
||||
assertTrue("Doesn't contain /help", commandUse.containsKey("/help"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -315,34 +241,4 @@ public class DatabaseTest {
|
||||
tpsTable.saveTPSData(expected);
|
||||
assertEquals(expected, tpsTable.getTPSData());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Changed clean limit.")
|
||||
public void testTPSClean() throws SQLException {
|
||||
db.init();
|
||||
TPSTable tpsTable = db.getTpsTable();
|
||||
List<TPS> expected = new ArrayList<>();
|
||||
Random r = new Random();
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
int availableProcessors = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors();
|
||||
final double averageCPUUsage = MathUtils.round(operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0);
|
||||
|
||||
final long usedMemory = 51231251254L;
|
||||
final int entityCount = 6123;
|
||||
final int chunksLoaded = 2134;
|
||||
|
||||
expected.add(new TPS(now, r.nextDouble(), r.nextInt(100000000), averageCPUUsage, usedMemory, entityCount, chunksLoaded));
|
||||
expected.add(new TPS(now - 1000L, r.nextDouble(), r.nextInt(100000000), averageCPUUsage, usedMemory, entityCount, chunksLoaded));
|
||||
expected.add(new TPS(now - 3000L, r.nextDouble(), r.nextInt(100000000), averageCPUUsage, usedMemory, entityCount, chunksLoaded));
|
||||
expected.add(new TPS(now - (690000L * 1000L), r.nextDouble(), r.nextInt(100000000), averageCPUUsage, usedMemory, entityCount, chunksLoaded));
|
||||
TPS tooOldTPS = new TPS(now - (691400L * 1000L), r.nextDouble(), r.nextInt(100000000), averageCPUUsage, usedMemory, entityCount, chunksLoaded);
|
||||
|
||||
expected.add(tooOldTPS);
|
||||
tpsTable.saveTPSData(expected);
|
||||
tpsTable.clean();
|
||||
expected.remove(tooOldTPS);
|
||||
assertEquals(expected, tpsTable.getTPSData());
|
||||
}
|
||||
}
|
||||
|
@ -5,24 +5,12 @@
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import com.djrapitops.plugin.utilities.player.Gamemode;
|
||||
import com.djrapitops.plugin.utilities.player.IOfflinePlayer;
|
||||
import com.djrapitops.plugin.utilities.player.IPlayer;
|
||||
import com.djrapitops.plugin.utilities.player.bukkit.BukkitOfflinePlayer;
|
||||
import com.djrapitops.plugin.utilities.player.bukkit.BukkitPlayer;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.NewPlayerCreator;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
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.MockUtils;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
@ -50,59 +38,6 @@ public class NewPlayerCreatorTest {
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCreateNewPlayer() {
|
||||
IOfflinePlayer p = BukkitOfflinePlayer.wrap(MockUtils.mockPlayer2());
|
||||
UserData result = NewPlayerCreator.createNewOfflinePlayer(p);
|
||||
UserData exp = new UserData(p);
|
||||
exp.getGmTimes().setState("SURVIVAL");
|
||||
exp.setLastPlayed(MiscUtils.getTime());
|
||||
exp.setPlayTime(0);
|
||||
exp.setTimesKicked(0);
|
||||
exp.setLoginTimes(0);
|
||||
exp.setDeaths(0);
|
||||
exp.setMobKills(0);
|
||||
assertTrue(exp.equals(result));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCreateNewOfflinePlayer() {
|
||||
IPlayer p = BukkitPlayer.wrap(MockUtils.mockPlayer2());
|
||||
UserData result = NewPlayerCreator.createNewPlayer(p);
|
||||
UserData exp = new UserData(p);
|
||||
exp.getGmTimes().setState("SPECTATOR");
|
||||
exp.setLastPlayed(MiscUtils.getTime());
|
||||
exp.setPlayTime(0);
|
||||
exp.setTimesKicked(0);
|
||||
exp.setLoginTimes(0);
|
||||
exp.setDeaths(0);
|
||||
exp.setMobKills(0);
|
||||
assertTrue(exp.equals(result));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCreateNewPlayerWithGameMode() {
|
||||
IOfflinePlayer p = BukkitOfflinePlayer.wrap(MockUtils.mockPlayer());
|
||||
UserData result = NewPlayerCreator.createNewPlayer(p, Gamemode.CREATIVE);
|
||||
UserData exp = new UserData(p);
|
||||
exp.getGmTimes().setState("CREATIVE");
|
||||
exp.setLastPlayed(MiscUtils.getTime());
|
||||
exp.setPlayTime(0);
|
||||
exp.setTimesKicked(0);
|
||||
exp.setLoginTimes(0);
|
||||
exp.setDeaths(0);
|
||||
exp.setMobKills(0);
|
||||
assertTrue(exp.equals(result));
|
||||
}
|
||||
//TODO Rewrite
|
||||
|
||||
}
|
||||
|
@ -79,4 +79,9 @@ public class RandomData {
|
||||
int x = r.nextInt(clazz.getEnumConstants().length);
|
||||
return clazz.getEnumConstants()[x];
|
||||
}
|
||||
|
||||
public static List<UserData> randomUserData() {
|
||||
return new ArrayList<>();
|
||||
// TODO Rewrite
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user