mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 03:27:37 +01:00
Merge branch '4.0.0-BungeeCord-Support' of https://github.com/Rsl1122/Plan-PlayerAnalytics
This commit is contained in:
commit
46893172a1
@ -372,6 +372,6 @@ public class UsersTable extends Table {
|
|||||||
|
|
||||||
public List<UserData> getUserData(List<UUID> uuids) {
|
public List<UserData> getUserData(List<UUID> uuids) {
|
||||||
// TODO Rewrite method for new UserData objects.
|
// TODO Rewrite method for new UserData objects.
|
||||||
return null;
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class AnalysisUtils {
|
|||||||
public static List<Long> transformSessionDataToLengths(Collection<SessionData> data) {
|
public static List<Long> transformSessionDataToLengths(Collection<SessionData> data) {
|
||||||
return data.stream()
|
return data.stream()
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.filter(SessionData::isValid)
|
.filter(session -> session.getLength() > 0)
|
||||||
.map(SessionData::getLength)
|
.map(SessionData::getLength)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,6 @@ package test.java.main.java.com.djrapitops.plan.data;
|
|||||||
|
|
||||||
import main.java.com.djrapitops.plan.data.SessionData;
|
import main.java.com.djrapitops.plan.data.SessionData;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
@ -36,87 +32,5 @@ public class SessionDataTest {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test
|
// TODO Rewrite
|
||||||
public void testEndSession() {
|
|
||||||
test.endSession(1L);
|
|
||||||
assertTrue("End not 1", test.getSessionEnd() == 1L);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetSessionStart() {
|
|
||||||
assertTrue("Start not 0", test.getSessionStart() == 0L);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testIsValid() {
|
|
||||||
test.endSession(1L);
|
|
||||||
assertTrue("Supposed to be valid.", test.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testInvalid() {
|
|
||||||
assertTrue("Supposed to be invalid.", !test.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testInvalid2() {
|
|
||||||
test = new SessionData(3);
|
|
||||||
test.endSession(2);
|
|
||||||
assertTrue("Supposed to be invalid.", !test.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testValid2() {
|
|
||||||
test = new SessionData(3);
|
|
||||||
test.endSession(3);
|
|
||||||
assertTrue("Supposed to be valid.", test.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testToString() {
|
|
||||||
String exp = "s:0 e:-1";
|
|
||||||
String result = test.toString();
|
|
||||||
assertEquals(exp, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetLength() {
|
|
||||||
long exp = 5L;
|
|
||||||
test.endSession(5L);
|
|
||||||
long result = test.getLength();
|
|
||||||
assertEquals(exp, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetLength2() {
|
|
||||||
long exp = 5L;
|
|
||||||
test = new SessionData(5L);
|
|
||||||
test.endSession(10L);
|
|
||||||
long result = test.getLength();
|
|
||||||
assertEquals(exp, result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import main.java.com.djrapitops.plan.Plan;
|
|||||||
import main.java.com.djrapitops.plan.data.UserData;
|
import main.java.com.djrapitops.plan.data.UserData;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
@ -32,4 +33,9 @@ public class UserDataTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// TestInit t = TestInit.init();
|
// TestInit t = TestInit.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
// TODO Rewrite
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package test.java.main.java.com.djrapitops.plan.data.cache;
|
package test.java.main.java.com.djrapitops.plan.data.cache;
|
||||||
|
|
||||||
import main.java.com.djrapitops.plan.data.SessionData;
|
|
||||||
import main.java.com.djrapitops.plan.data.cache.SessionCache;
|
import main.java.com.djrapitops.plan.data.cache.SessionCache;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -13,13 +12,8 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import test.java.utils.MockUtils;
|
|
||||||
import test.java.utils.TestInit;
|
import test.java.utils.TestInit;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
@ -42,20 +36,7 @@ public class SessionCacheTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartSession() {
|
public void test() {
|
||||||
UUID uuid = MockUtils.getPlayerUUID();
|
// TODO Rewrite
|
||||||
test.startSession(uuid);
|
|
||||||
assertTrue("Didn't contain new session", test.getActiveSessions().containsKey(uuid));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEndSession() {
|
|
||||||
UUID uuid = MockUtils.getPlayerUUID();
|
|
||||||
test.getActiveSessions().put(uuid, new SessionData(0));
|
|
||||||
test.endSession(uuid);
|
|
||||||
SessionData testSession = test.getActiveSessions().get(uuid);
|
|
||||||
assertTrue("Didn't end session", testSession.getSessionEnd() != -1);
|
|
||||||
assertTrue("Session length not positive", testSession.getLength() > 0L);
|
|
||||||
assertTrue("Session not valid", testSession.isValid());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
package test.java.main.java.com.djrapitops.plan.data.cache.queue;
|
package test.java.main.java.com.djrapitops.plan.data.cache.queue;
|
||||||
|
|
||||||
import main.java.com.djrapitops.plan.Plan;
|
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.data.cache.DataCache;
|
||||||
import main.java.com.djrapitops.plan.database.Database;
|
import main.java.com.djrapitops.plan.database.Database;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||||
@ -24,12 +22,9 @@ import test.java.utils.TestInit;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.powermock.api.mockito.PowerMockito.when;
|
import static org.powermock.api.mockito.PowerMockito.when;
|
||||||
|
|
||||||
// TODO Rewrite
|
// TODO Rewrite
|
||||||
@ -38,11 +33,6 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
|||||||
public class QueueTest {
|
public class QueueTest {
|
||||||
|
|
||||||
private final UUID uuid1 = MockUtils.getPlayerUUID();
|
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 DataCache handler;
|
||||||
private Database db;
|
private Database db;
|
||||||
@ -52,40 +42,12 @@ public class QueueTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
callsToSaveUserData = 0;
|
|
||||||
callsToGetUserData = 0;
|
|
||||||
TestInit t = TestInit.init();
|
TestInit t = TestInit.init();
|
||||||
Plan plan = t.getPlanMock();
|
Plan plan = t.getPlanMock();
|
||||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
||||||
@Override
|
@Override
|
||||||
public void startConnectionPingTask() {
|
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();
|
db.init();
|
||||||
when(plan.getDB()).thenReturn(db);
|
when(plan.getDB()).thenReturn(db);
|
||||||
@ -117,13 +79,10 @@ public class QueueTest {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
while (processCalls.size() < 1) {
|
// while (processCalls.size() < 1) {
|
||||||
if (errors.size() > 0) {
|
// if (errors.size() > 0) {
|
||||||
fail();
|
// fail();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
assertEquals(1, processCalls.size());
|
|
||||||
assertEquals(0, errors.size());
|
|
||||||
assertEquals(1, callsToGetUserData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.Plan;
|
||||||
import main.java.com.djrapitops.plan.data.TPS;
|
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.data.WebUser;
|
||||||
import main.java.com.djrapitops.plan.database.Database;
|
import main.java.com.djrapitops.plan.database.Database;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||||
@ -16,18 +15,14 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import test.java.utils.MockUtils;
|
|
||||||
import test.java.utils.RandomData;
|
import test.java.utils.RandomData;
|
||||||
import test.java.utils.TestInit;
|
import test.java.utils.TestInit;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertFalse;
|
import static junit.framework.TestCase.assertFalse;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@ -50,11 +45,6 @@ public class DatabaseCommitTest {
|
|||||||
public void startConnectionPingTask() {
|
public void startConnectionPingTask() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertBukkitDataToDB() {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
File f = new File(plan.getDataFolder(), "Errors.txt");
|
File f = new File(plan.getDataFolder(), "Errors.txt");
|
||||||
rows = FileUtil.lines(f).size();
|
rows = FileUtil.lines(f).size();
|
||||||
@ -102,26 +92,7 @@ public class DatabaseCommitTest {
|
|||||||
assertFalse(db.getTpsTable().getTPSData().isEmpty());
|
assertFalse(db.getTpsTable().getTPSData().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// TODO Commit tests for new Login save features.
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCommitToDBFile5() throws SQLException, PassEncryptUtil.CannotPerformOperationException {
|
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.Plan;
|
||||||
import main.java.com.djrapitops.plan.data.TPS;
|
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.Database;
|
||||||
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
|
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.databases.SQLiteDB;
|
||||||
import main.java.com.djrapitops.plan.database.tables.TPSTable;
|
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.MiscUtils;
|
||||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||||
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||||
@ -68,11 +66,6 @@ public class DatabaseTest {
|
|||||||
public void startConnectionPingTask() {
|
public void startConnectionPingTask() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertBukkitDataToDB() {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
File f = new File(plan.getDataFolder(), "Errors.txt");
|
File f = new File(plan.getDataFolder(), "Errors.txt");
|
||||||
rows = FileUtil.lines(f).size();
|
rows = FileUtil.lines(f).size();
|
||||||
@ -134,11 +127,6 @@ public class DatabaseTest {
|
|||||||
public void startConnectionPingTask() {
|
public void startConnectionPingTask() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertBukkitDataToDB() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}.getConfigName());
|
}.getConfigName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,22 +140,17 @@ public class DatabaseTest {
|
|||||||
public void startConnectionPingTask() {
|
public void startConnectionPingTask() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertBukkitDataToDB() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}.getName());
|
}.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test // TODO Rewrite
|
||||||
public void testRemoveAll() throws SQLException {
|
public void testRemoveAll() throws SQLException {
|
||||||
db.init();
|
db.init();
|
||||||
UserData data = MockUtils.mockUser();
|
// UserData data = MockUtils.mockUser();
|
||||||
db.saveUserData(data);
|
// db.saveUserData(data);
|
||||||
HashMap<String, Integer> c = new HashMap<>();
|
HashMap<String, Integer> c = new HashMap<>();
|
||||||
c.put("/plan", 1);
|
c.put("/plan", 1);
|
||||||
c.put("/tp", 4);
|
c.put("/tp", 4);
|
||||||
@ -208,13 +191,13 @@ public class DatabaseTest {
|
|||||||
/**
|
/**
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test // TODO Rewrite
|
||||||
public void testRemove() throws SQLException {
|
public void testRemove() throws SQLException {
|
||||||
db.init();
|
db.init();
|
||||||
UserData data = MockUtils.mockUser();
|
// UserData data = MockUtils.mockUser();
|
||||||
db.saveUserData(data);
|
// db.saveUserData(data);
|
||||||
assertTrue(db.removeAccount(data.getUuid().toString()));
|
// assertTrue(db.removeAccount(data.getUuid().toString()));
|
||||||
assertTrue("Contains the user", !db.wasSeenBefore(data.getUuid()));
|
// assertTrue("Contains the user", !db.wasSeenBefore(data.getUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -223,29 +206,6 @@ public class DatabaseTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore("Backup has to be rewritten")
|
@Ignore("Backup has to be rewritten")
|
||||||
public void testBackup() throws SQLException {
|
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
|
@Test
|
||||||
@Ignore("Backup has to be rewritten")
|
@Ignore("Backup has to be rewritten")
|
||||||
public void testRestore() throws SQLException {
|
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
|
@Test
|
||||||
@ -315,34 +241,4 @@ public class DatabaseTest {
|
|||||||
tpsTable.saveTPSData(expected);
|
tpsTable.saveTPSData(expected);
|
||||||
assertEquals(expected, tpsTable.getTPSData());
|
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,14 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package test.java.main.java.com.djrapitops.plan.utilities;
|
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.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -20,9 +12,6 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import test.java.utils.MockUtils;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
@ -51,58 +40,9 @@ public class NewPlayerCreatorTest {
|
|||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNewPlayer() {
|
public void test() {
|
||||||
IOfflinePlayer p = BukkitOfflinePlayer.wrap(MockUtils.mockPlayer2());
|
// TODO Rewrite
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -79,4 +79,9 @@ public class RandomData {
|
|||||||
int x = r.nextInt(clazz.getEnumConstants().length);
|
int x = r.nextInt(clazz.getEnumConstants().length);
|
||||||
return clazz.getEnumConstants()[x];
|
return clazz.getEnumConstants()[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<UserData> randomUserData() {
|
||||||
|
return new ArrayList<>();
|
||||||
|
// TODO Rewrite
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user