[Debt] Removed getServerUUID usage in Tests and Processors

This commit is contained in:
Rsl1122 2018-09-18 18:38:42 +03:00
parent f398c2a2c2
commit 062ecc86a7
8 changed files with 23 additions and 31 deletions

View File

@ -12,6 +12,7 @@ public interface CheckOperations {
boolean doesWebUserExists(String username); boolean doesWebUserExists(String username);
@Deprecated
default boolean isPlayerRegisteredOnThisServer(UUID player) { default boolean isPlayerRegisteredOnThisServer(UUID player) {
return isPlayerRegistered(player, ServerInfo.getServerUUID_Old()); return isPlayerRegistered(player, ServerInfo.getServerUUID_Old());
} }

View File

@ -2,7 +2,6 @@ package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.system.database.databases.operation.CheckOperations; import com.djrapitops.plan.system.database.databases.operation.CheckOperations;
import com.djrapitops.plan.system.database.databases.sql.SQLDB; import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.info.server.ServerInfo;
import java.util.UUID; import java.util.UUID;
@ -27,11 +26,6 @@ public class SQLCheckOps extends SQLOps implements CheckOperations {
return securityTable.userExists(username); return securityTable.userExists(username);
} }
@Override
public boolean isPlayerRegisteredOnThisServer(UUID player) {
return isPlayerRegistered(player, ServerInfo.getServerUUID_Old());
}
@Override @Override
public boolean isServerInDatabase(UUID serverUUID) { public boolean isServerInDatabase(UUID serverUUID) {
return serverTable.getServerID(serverUUID).isPresent(); return serverTable.getServerID(serverUUID).isPresent();

View File

@ -8,7 +8,6 @@ import com.djrapitops.plan.data.store.objects.Nickname;
import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.operation.SaveOperations; import com.djrapitops.plan.system.database.databases.operation.SaveOperations;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.CriticalRunnable; import com.djrapitops.plan.system.processing.CriticalRunnable;
import java.util.UUID; import java.util.UUID;
@ -29,13 +28,13 @@ public class NameProcessor implements CriticalRunnable {
private final DataCache dataCache; private final DataCache dataCache;
NameProcessor( NameProcessor(
UUID uuid, String playerName, String displayName, UUID uuid, String playerName, Nickname nickname,
Database database, Database database,
DataCache dataCache DataCache dataCache
) { ) {
this.uuid = uuid; this.uuid = uuid;
this.playerName = playerName; this.playerName = playerName;
this.nickname = new Nickname(displayName, System.currentTimeMillis(), ServerInfo.getServerUUID_Old()); this.nickname = nickname;
this.database = database; this.database = database;
this.dataCache = dataCache; this.dataCache = dataCache;
} }

View File

@ -7,7 +7,6 @@ package com.djrapitops.plan.system.processing.processors.player;
import com.djrapitops.plan.data.container.Ping; import com.djrapitops.plan.data.container.Ping;
import com.djrapitops.plan.data.store.objects.DateObj; import com.djrapitops.plan.data.store.objects.DateObj;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.CriticalRunnable; import com.djrapitops.plan.system.processing.CriticalRunnable;
import java.util.List; import java.util.List;
@ -24,15 +23,17 @@ import java.util.UUID;
public class PingInsertProcessor implements CriticalRunnable { public class PingInsertProcessor implements CriticalRunnable {
private final UUID uuid; private final UUID uuid;
private final UUID serverUUID;
private final List<DateObj<Integer>> pingList; private final List<DateObj<Integer>> pingList;
private final Database database; private final Database database;
public PingInsertProcessor( PingInsertProcessor(
UUID uuid, List<DateObj<Integer>> pingList, UUID uuid, UUID serverUUID, List<DateObj<Integer>> pingList,
Database database Database database
) { ) {
this.uuid = uuid; this.uuid = uuid;
this.serverUUID = serverUUID;
this.pingList = pingList; this.pingList = pingList;
this.database = database; this.database = database;
} }
@ -62,10 +63,7 @@ public class PingInsertProcessor implements CriticalRunnable {
int maxValue = max.getAsInt(); int maxValue = max.getAsInt();
Ping ping = new Ping(lastDate, ServerInfo.getServerUUID_Old(), Ping ping = new Ping(lastDate, serverUUID, minValue, maxValue, avgValue);
minValue,
maxValue,
avgValue);
database.save().ping(uuid, ping); database.save().ping(uuid, ping);
} }

View File

@ -1,9 +1,11 @@
package com.djrapitops.plan.system.processing.processors.player; package com.djrapitops.plan.system.processing.processors.player;
import com.djrapitops.plan.data.store.objects.DateObj; import com.djrapitops.plan.data.store.objects.DateObj;
import com.djrapitops.plan.data.store.objects.Nickname;
import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.cache.GeolocationCache; import com.djrapitops.plan.system.cache.GeolocationCache;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import dagger.Lazy; import dagger.Lazy;
@ -23,6 +25,7 @@ import java.util.function.Supplier;
public class PlayerProcessors { public class PlayerProcessors {
private final Lazy<Processing> processing; private final Lazy<Processing> processing;
private final Lazy<ServerInfo> serverInfo;
private final Lazy<Database> database; private final Lazy<Database> database;
private final Lazy<DataCache> dataCache; private final Lazy<DataCache> dataCache;
private final Lazy<GeolocationCache> geolocationCache; private final Lazy<GeolocationCache> geolocationCache;
@ -30,11 +33,13 @@ public class PlayerProcessors {
@Inject @Inject
public PlayerProcessors( public PlayerProcessors(
Lazy<Processing> processing, Lazy<Processing> processing,
Lazy<ServerInfo> serverInfo,
Lazy<Database> database, Lazy<Database> database,
Lazy<DataCache> dataCache, Lazy<DataCache> dataCache,
Lazy<GeolocationCache> geolocationCache Lazy<GeolocationCache> geolocationCache
) { ) {
this.processing = processing; this.processing = processing;
this.serverInfo = serverInfo;
this.database = database; this.database = database;
this.dataCache = dataCache; this.dataCache = dataCache;
this.geolocationCache = geolocationCache; this.geolocationCache = geolocationCache;
@ -61,11 +66,12 @@ public class PlayerProcessors {
} }
public NameProcessor nameProcessor(UUID uuid, String playerName, String displayName) { public NameProcessor nameProcessor(UUID uuid, String playerName, String displayName) {
return new NameProcessor(uuid, playerName, displayName, database.get(), dataCache.get()); Nickname nickname = new Nickname(displayName, System.currentTimeMillis(), serverInfo.get().getServerUUID());
return new NameProcessor(uuid, playerName, nickname, database.get(), dataCache.get());
} }
public PingInsertProcessor pingInsertProcessor(UUID uuid, List<DateObj<Integer>> pingList) { public PingInsertProcessor pingInsertProcessor(UUID uuid, List<DateObj<Integer>> pingList) {
return new PingInsertProcessor(uuid, pingList, database.get()); return new PingInsertProcessor(uuid, serverInfo.get().getServerUUID(), pingList, database.get());
} }
public RegisterProcessor registerProcessor(UUID uuid, Supplier<Long> registered, String name, Runnable... afterProcess) { public RegisterProcessor registerProcessor(UUID uuid, Supplier<Long> registered, String name, Runnable... afterProcess) {

View File

@ -7,7 +7,6 @@ package com.djrapitops.plan.system;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.info.server.ServerInfo;
import org.junit.*; import org.junit.*;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
@ -76,7 +75,7 @@ public class BungeeBukkitConnectionTest {
bukkitSystem = null; // TODO bukkitSystem = null; // TODO
bukkitSystem.enable(); bukkitSystem.enable();
bukkitUUID = ServerInfo.getServerUUID_Old(); bukkitUUID = null;
bungeeSystem = null; // TODO bungeeSystem = null; // TODO
@ -87,7 +86,7 @@ public class BungeeBukkitConnectionTest {
bungeeSystem.enable(); bungeeSystem.enable();
bungeeUUID = ServerInfo.getServerUUID_Old(); bungeeUUID = null;
System.out.println("------------------------------"); System.out.println("------------------------------");
System.out.println("Enable Complete"); System.out.println("Enable Complete");

View File

@ -22,7 +22,6 @@ import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB; import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
import com.djrapitops.plan.system.database.databases.sql.tables.*; import com.djrapitops.plan.system.database.databases.sql.tables.*;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.utilities.Base64Util; import com.djrapitops.plan.utilities.Base64Util;
import com.djrapitops.plan.utilities.SHA256Hash; import com.djrapitops.plan.utilities.SHA256Hash;
import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.TimeAmount;
@ -90,7 +89,7 @@ public class SQLiteTest {
db.remove().everything(); db.remove().everything();
ServerTable serverTable = db.getServerTable(); ServerTable serverTable = db.getServerTable();
serverTable.saveCurrentServerInfo(new Server(-1, TestConstants.SERVER_UUID, "ServerName", "", 20)); serverTable.saveCurrentServerInfo(new Server(-1, TestConstants.SERVER_UUID, "ServerName", "", 20));
assertEquals(ServerInfo.getServerUUID_Old(), TestConstants.SERVER_UUID); // assertEquals(ServerInfo.getServerUUID_Old(), TestConstants.SERVER_UUID); TODO check if assertion is required
System.out.println("-- Clear Complete --\n"); System.out.println("-- Clear Complete --\n");
} }
@ -395,7 +394,7 @@ public class SQLiteTest {
System.out.println(" " + entry.getValue()); System.out.println(" " + entry.getValue());
} }
List<Session> savedSessions = sessions.get(ServerInfo.getServerUUID_Old()); List<Session> savedSessions = sessions.get(serverUUID);
assertNotNull(savedSessions); assertNotNull(savedSessions);
assertEquals(1, savedSessions.size()); assertEquals(1, savedSessions.size());
@ -427,7 +426,7 @@ public class SQLiteTest {
assertEquals(playerUUID, userInfo.getUuid()); assertEquals(playerUUID, userInfo.getUuid());
assertEquals(123456789L, (long) usersTable.getRegisterDates().get(0)); assertEquals(123456789L, (long) usersTable.getRegisterDates().get(0));
assertEquals(123456789L, userInfo.getRegistered()); assertEquals(123456789L, userInfo.getRegistered());
assertEquals(1, userInfoTable.getServerUserCount(ServerInfo.getServerUUID_Old())); assertEquals(1, userInfoTable.getServerUserCount(serverUUID));
assertEquals("Waiting for Update..", userInfo.getName()); assertEquals("Waiting for Update..", userInfo.getName());
assertFalse(userInfo.isBanned()); assertFalse(userInfo.isBanned());
assertFalse(userInfo.isOperator()); assertFalse(userInfo.isOperator());
@ -803,7 +802,7 @@ public class SQLiteTest {
List<Session> sessions = new ArrayList<>(); List<Session> sessions = new ArrayList<>();
sessions.add(session); sessions.add(session);
sessionMap.put(playerUUID, sessions); sessionMap.put(playerUUID, sessions);
map.put(ServerInfo.getServerUUID_Old(), sessionMap); map.put(serverUUID, sessionMap);
worldTimesTable.saveWorldTimes(map); worldTimesTable.saveWorldTimes(map);
@ -826,7 +825,6 @@ public class SQLiteTest {
List<Session> sessions = new ArrayList<>(); List<Session> sessions = new ArrayList<>();
sessions.add(session); sessions.add(session);
sessionMap.put(playerUUID, sessions); sessionMap.put(playerUUID, sessions);
UUID serverUUID = ServerInfo.getServerUUID_Old();
map.put(serverUUID, sessionMap); map.put(serverUUID, sessionMap);
sessionsTable.insertSessions(map, true); sessionsTable.insertSessions(map, true);

View File

@ -4,15 +4,12 @@ import com.djrapitops.plan.Plan;
import com.djrapitops.plan.system.database.databases.sql.SQLDB; import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.tables.ServerTable; import com.djrapitops.plan.system.database.databases.sql.tables.ServerTable;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.StaticHolder;
import org.junit.*; import org.junit.*;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import utilities.TestConstants; import utilities.TestConstants;
import utilities.mocks.SystemMockUtil; import utilities.mocks.SystemMockUtil;
import static org.junit.Assert.assertEquals;
public class NetworkSettingsTest { public class NetworkSettingsTest {
@ClassRule @ClassRule
@ -46,7 +43,7 @@ public class NetworkSettingsTest {
db.remove().everything(); db.remove().everything();
ServerTable serverTable = db.getServerTable(); ServerTable serverTable = db.getServerTable();
serverTable.saveCurrentServerInfo(new Server(-1, TestConstants.SERVER_UUID, "ServerName", "", 20)); serverTable.saveCurrentServerInfo(new Server(-1, TestConstants.SERVER_UUID, "ServerName", "", 20));
assertEquals(ServerInfo.getServerUUID_Old(), TestConstants.SERVER_UUID); // assertEquals(ServerInfo.getServerUUID_Old(), TestConstants.SERVER_UUID); TODO check if assert is necessary.
} }
@Test @Test