mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-05 02:09:50 +01:00
Kick count, tests for the added Keys, equals methods, test fixes
This commit is contained in:
parent
efda292a37
commit
efb1e33673
@ -66,11 +66,22 @@ public class GeoInfo {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GeoInfo geoInfo = (GeoInfo) o;
|
||||
return Objects.equal(ip, geoInfo.ip) &&
|
||||
Objects.equal(geolocation, geoInfo.geolocation);
|
||||
Objects.equal(geolocation, geoInfo.geolocation) &&
|
||||
Objects.equal(ipHash, geoInfo.ipHash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(ip, geolocation);
|
||||
return Objects.hashCode(ip, geolocation, ipHash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GeoInfo{" +
|
||||
"ip='" + ip + '\'' +
|
||||
", geolocation='" + geolocation + '\'' +
|
||||
", ipHash='" + ipHash + '\'' +
|
||||
", lastUsed=" + lastUsed +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -22,6 +22,6 @@ public class PlayerKeys {
|
||||
|
||||
public static final Key<Long> REGISTERED = new Key<>(Long.class, "registered");
|
||||
|
||||
public static final Key<DateMap<UUID>> KICKS = new Key<>(new Type<DateMap<UUID>>() {}, "kicks");
|
||||
public static final Key<Integer> KICK_COUNT = new Key<>(Integer.class, "kick_count");
|
||||
public static final Key<DateMap<GeoInfo>> GEO_INFO = new Key<>(new Type<DateMap<GeoInfo>>() {}, "geo_info");
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.djrapitops.plan.data.store.objects;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -30,4 +31,29 @@ public class Nickname {
|
||||
public UUID getServerUUID() {
|
||||
return serverUUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Nickname{" +
|
||||
"name='" + name + '\'' +
|
||||
", lastUsed=" + lastUsed +
|
||||
", serverUUID=" + serverUUID +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Nickname)) return false;
|
||||
Nickname nickname = (Nickname) o;
|
||||
return lastUsed == nickname.lastUsed &&
|
||||
Objects.equals(name, nickname.name) &&
|
||||
Objects.equals(serverUUID, nickname.serverUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(name, lastUsed, serverUUID);
|
||||
}
|
||||
}
|
@ -475,9 +475,11 @@ public class UsersTable extends UserIDTable {
|
||||
if (set.next()) {
|
||||
long registered = set.getLong(Col.REGISTERED.get());
|
||||
String name = set.getString(Col.USER_NAME.get());
|
||||
int timesKicked = set.getInt(Col.TIMES_KICKED.get());
|
||||
|
||||
container.putRawData(PlayerKeys.REGISTERED, registered);
|
||||
container.putRawData(PlayerKeys.NAME, name);
|
||||
container.putRawData(PlayerKeys.KICK_COUNT, timesKicked);
|
||||
}
|
||||
|
||||
return container;
|
||||
@ -489,6 +491,7 @@ public class UsersTable extends UserIDTable {
|
||||
returnValue.putRawData(PlayerKeys.UUID, uuid);
|
||||
returnValue.putSupplier(PlayerKeys.REGISTERED, () -> returnValue.getUnsafe(key).getUnsafe(PlayerKeys.REGISTERED));
|
||||
returnValue.putSupplier(PlayerKeys.NAME, () -> returnValue.getUnsafe(key).getUnsafe(PlayerKeys.NAME));
|
||||
returnValue.putSupplier(PlayerKeys.KICK_COUNT, () -> returnValue.getUnsafe(key).getUnsafe(PlayerKeys.KICK_COUNT));
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ package com.djrapitops.plan.system.info.server;
|
||||
|
||||
import com.djrapitops.plan.PlanBungee;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
@ -38,7 +38,7 @@ public class BungeeServerInfo extends ServerInfo {
|
||||
} else {
|
||||
server = registerBungeeInfo(db);
|
||||
}
|
||||
} catch (DBException e) {
|
||||
} catch (DBOpException e) {
|
||||
throw new EnableException("Failed to read Server information from Database.");
|
||||
}
|
||||
return server;
|
||||
|
@ -16,8 +16,6 @@ import java.util.TimeZone;
|
||||
*/
|
||||
public class FormatUtils {
|
||||
|
||||
private static final DecimalFormat df = new DecimalFormat(Settings.FORMAT_DECIMALS.toString());
|
||||
|
||||
/**
|
||||
* Constructor used to hide the public constructor
|
||||
*/
|
||||
@ -210,7 +208,7 @@ public class FormatUtils {
|
||||
* @return String format of the double.
|
||||
*/
|
||||
public static String cutDecimals(double d) {
|
||||
return df.format(d);
|
||||
return new DecimalFormat(Settings.FORMAT_DECIMALS.toString()).format(d);
|
||||
}
|
||||
|
||||
public static String formatIP(String ip) {
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.djrapitops.plan.data.container;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Test for functionality of GeoInfo object.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class GeoInfoTest {
|
||||
|
||||
@Test
|
||||
public void automaticallyHidesLast16Bits() throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
String test = "1.2.3.4";
|
||||
String expected = "1.2.xx.xx";
|
||||
String result = new GeoInfo(test, "Irrelevant", 3).getIp();
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
@ -3,11 +3,14 @@ package com.djrapitops.plan.system.cache;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.BukkitSystem;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plugin.StaticHolder;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import utilities.Teardown;
|
||||
import utilities.mocks.BukkitMockUtil;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -25,6 +28,7 @@ public class GeolocationCacheTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
Teardown.resetSettingsTempValues();
|
||||
BukkitMockUtil mockUtil = BukkitMockUtil.setUp()
|
||||
.withDataFolder(temporaryFolder.getRoot())
|
||||
.withLogging()
|
||||
@ -35,14 +39,24 @@ public class GeolocationCacheTest {
|
||||
StaticHolder.saveInstance(GeolocationCacheTest.class, planMock.getClass());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
Teardown.resetSettingsTempValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeolocationCache() throws EnableException {
|
||||
Settings.WEBSERVER_PORT.setTemporaryValue(9005);
|
||||
BukkitSystem system = new BukkitSystem(planMock);
|
||||
system.enable();
|
||||
try {
|
||||
system.enable();
|
||||
|
||||
String expected = "Germany";
|
||||
String result = GeolocationCache.getCountry("141.52.255.1");
|
||||
assertEquals(expected, result);
|
||||
String expected = "Germany";
|
||||
String result = GeolocationCache.getCountry("141.52.255.1");
|
||||
assertEquals(expected, result);
|
||||
} finally {
|
||||
system.disable();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -13,6 +13,8 @@ import com.djrapitops.plan.data.WebUser;
|
||||
import com.djrapitops.plan.data.container.*;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.objects.DateMap;
|
||||
import com.djrapitops.plan.data.store.objects.Nickname;
|
||||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
@ -39,7 +41,6 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@ -226,6 +227,7 @@ public class SQLiteTest {
|
||||
|
||||
private void saveUserOne(SQLDB database) {
|
||||
database.getUsersTable().registerUser(playerUUID, 123456789L, "Test");
|
||||
database.getUsersTable().kicked(playerUUID);
|
||||
}
|
||||
|
||||
private void saveUserTwo() {
|
||||
@ -237,7 +239,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActionsTable() throws SQLException {
|
||||
public void testActionsTable() {
|
||||
saveUserOne();
|
||||
ActionsTable actionsTable = db.getActionsTable();
|
||||
|
||||
@ -251,7 +253,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPTable() throws SQLException, DBInitException {
|
||||
public void testIPTable() throws DBInitException {
|
||||
saveUserOne();
|
||||
GeoInfoTable geoInfoTable = db.getGeoInfoTable();
|
||||
|
||||
@ -276,7 +278,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNicknamesTable() throws SQLException, DBInitException {
|
||||
public void testNicknamesTable() throws DBInitException {
|
||||
saveUserOne();
|
||||
NicknamesTable nickTable = db.getNicknamesTable();
|
||||
|
||||
@ -357,7 +359,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionPlaytimeSaving() throws SQLException, DBInitException {
|
||||
public void testSessionPlaytimeSaving() throws DBInitException {
|
||||
saveTwoWorlds();
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
@ -388,7 +390,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionSaving() throws SQLException, DBInitException {
|
||||
public void testSessionSaving() throws DBInitException {
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
@ -453,7 +455,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfoTableRegisterRegistered() throws SQLException, DBInitException {
|
||||
public void testUserInfoTableRegisterRegistered() throws DBInitException {
|
||||
saveUserOne();
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
assertTrue(usersTable.isRegistered(playerUUID));
|
||||
@ -512,7 +514,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsersTableUpdateName() throws SQLException, DBInitException {
|
||||
public void testUsersTableUpdateName() throws DBInitException {
|
||||
saveUserOne();
|
||||
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
@ -529,10 +531,10 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsersTableKickSaving() throws SQLException, DBInitException {
|
||||
public void testUsersTableKickSaving() throws DBInitException {
|
||||
saveUserOne();
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
assertEquals(0, usersTable.getTimesKicked(playerUUID));
|
||||
assertEquals(1, usersTable.getTimesKicked(playerUUID));
|
||||
|
||||
int random = new Random().nextInt(20);
|
||||
|
||||
@ -540,11 +542,11 @@ public class SQLiteTest {
|
||||
usersTable.kicked(playerUUID);
|
||||
}
|
||||
commitTest();
|
||||
assertEquals(random + 1, usersTable.getTimesKicked(playerUUID));
|
||||
assertEquals(random + 2, usersTable.getTimesKicked(playerUUID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemovalSingleUser() throws SQLException {
|
||||
public void testRemovalSingleUser() {
|
||||
saveUserTwo();
|
||||
|
||||
UserInfoTable userInfoTable = db.getUserInfoTable();
|
||||
@ -580,7 +582,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemovalEverything() throws SQLException, UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
public void testRemovalEverything() throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
UserInfoTable userInfoTable = db.getUserInfoTable();
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
SessionsTable sessionsTable = db.getSessionsTable();
|
||||
@ -712,7 +714,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionTableGetInfoOfServer() throws SQLException, DBInitException {
|
||||
public void testSessionTableGetInfoOfServer() throws DBInitException {
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
@ -739,7 +741,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKillTableGetKillsOfServer() throws SQLException, DBInitException {
|
||||
public void testKillTableGetKillsOfServer() throws DBInitException {
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
@ -758,7 +760,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackupAndRestore() throws SQLException, DBException, UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
public void testBackupAndRestore() throws DBException, UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
System.out.println("- Creating Backup Database -");
|
||||
SQLiteDB backup = new SQLiteDB("debug-backup" + System.currentTimeMillis());
|
||||
backup.init();
|
||||
@ -793,7 +795,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveWorldTimes() throws SQLException {
|
||||
public void testSaveWorldTimes() {
|
||||
saveUserOne();
|
||||
WorldTimes worldTimes = createWorldTimes();
|
||||
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
||||
@ -808,7 +810,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveAllWorldTimes() throws SQLException {
|
||||
public void testSaveAllWorldTimes() {
|
||||
saveUserOne();
|
||||
WorldTimes worldTimes = createWorldTimes();
|
||||
System.out.println(worldTimes);
|
||||
@ -830,7 +832,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveSessionsWorldTimes() throws SQLException {
|
||||
public void testSaveSessionsWorldTimes() {
|
||||
SessionsTable sessionsTable = db.getSessionsTable();
|
||||
|
||||
saveUserOne();
|
||||
@ -855,14 +857,14 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserWorldTimes() throws SQLException {
|
||||
public void testGetUserWorldTimes() {
|
||||
testSaveSessionsWorldTimes();
|
||||
WorldTimes worldTimesOfUser = db.getWorldTimesTable().getWorldTimesOfUser(playerUUID);
|
||||
assertEquals(createWorldTimes(), worldTimesOfUser);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServerWorldTimes() throws SQLException {
|
||||
public void testGetServerWorldTimes() {
|
||||
testSaveSessionsWorldTimes();
|
||||
WorldTimes worldTimesOfServer = db.getWorldTimesTable().getWorldTimesOfServer(TestConstants.SERVER_UUID);
|
||||
assertEquals(createWorldTimes(), worldTimesOfServer);
|
||||
@ -896,7 +898,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldTableGetWorldNamesNoException() throws SQLException, UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
public void testWorldTableGetWorldNamesNoException() throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
saveAllData(db);
|
||||
Set<String> worldNames = db.getWorldTable().getWorldNames(TestConstants.SERVER_UUID);
|
||||
assertEquals(new HashSet<>(worlds), worldNames);
|
||||
@ -942,7 +944,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldTableAlterV16() throws SQLException {
|
||||
public void testWorldTableAlterV16() {
|
||||
saveUserOne();
|
||||
new Table("test", db) {
|
||||
@Override
|
||||
@ -1030,7 +1032,7 @@ public class SQLiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewContainerForPlayer() throws UnsupportedEncodingException, SQLException, NoSuchAlgorithmException {
|
||||
public void testNewContainerForPlayer() throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
saveAllData(db);
|
||||
|
||||
long start = System.nanoTime();
|
||||
@ -1040,7 +1042,10 @@ public class SQLiteTest {
|
||||
assertTrue(container.supports(PlayerKeys.UUID));
|
||||
assertTrue(container.supports(PlayerKeys.REGISTERED));
|
||||
assertTrue(container.supports(PlayerKeys.NAME));
|
||||
assertTrue(container.supports(PlayerKeys.KICK_COUNT));
|
||||
|
||||
assertTrue(container.supports(PlayerKeys.GEO_INFO));
|
||||
assertTrue(container.supports(PlayerKeys.NICKNAMES));
|
||||
|
||||
long end = System.nanoTime();
|
||||
|
||||
@ -1049,5 +1054,14 @@ public class SQLiteTest {
|
||||
OptionalAssert.equals(playerUUID, container.getValue(PlayerKeys.UUID));
|
||||
OptionalAssert.equals(123456789L, container.getValue(PlayerKeys.REGISTERED));
|
||||
OptionalAssert.equals("Test", container.getValue(PlayerKeys.NAME));
|
||||
OptionalAssert.equals(1, container.getValue(PlayerKeys.KICK_COUNT));
|
||||
|
||||
DateMap<GeoInfo> expectedGeoInfo = GeoInfo.intoDateMap(
|
||||
Collections.singletonList(new GeoInfo("1.2.3.4", "TestLoc", 223456789, "ZpT4PJ9HbaMfXfa8xSADTn5X1CHSR7nTT0ntv8hKdkw="))
|
||||
);
|
||||
OptionalAssert.equals(expectedGeoInfo, container.getValue(PlayerKeys.GEO_INFO));
|
||||
|
||||
List<Nickname> expectedNicknames = Collections.singletonList(new Nickname("TestNick", -1, TestConstants.SERVER_UUID));
|
||||
OptionalAssert.equals(expectedNicknames, container.getValue(PlayerKeys.NICKNAMES));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user