mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 19:17:43 +01:00
Reformat
Add Tests for Server- & UserImportBuilder Fixed both of them
This commit is contained in:
parent
43784f92d3
commit
140bd681cc
@ -107,6 +107,10 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
return (Plan) getPluginInstance(Plan.class);
|
||||
}
|
||||
|
||||
public static UUID getServerUUID() {
|
||||
return getInstance().getServerInfoManager().getServerUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* OnEnable method.
|
||||
* <p>
|
||||
@ -425,10 +429,6 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
}
|
||||
}
|
||||
|
||||
public static UUID getServerUUID() {
|
||||
return getInstance().getServerInfoManager().getServerUUID();
|
||||
}
|
||||
|
||||
public InformationManager getInfoManager() {
|
||||
return infoManager;
|
||||
}
|
||||
|
@ -47,6 +47,23 @@ public class AnalyzeCommand extends SubCommand {
|
||||
infoManager = plugin.getInfoManager();
|
||||
}
|
||||
|
||||
public static void sendAnalysisMessage(Collection<ISender> senders) {
|
||||
for (ISender sender : senders) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_HEADER_ANALYZE).toString());
|
||||
// Link
|
||||
String url = HtmlUtils.getServerAnalysisUrlWithProtocol();
|
||||
String message = Locale.get(Msg.CMD_INFO_LINK).toString();
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
if (console) {
|
||||
sender.sendMessage(message + url);
|
||||
} else {
|
||||
sender.sendMessage(message);
|
||||
sender.sendLink(" ", Locale.get(Msg.CMD_INFO_CLICK_ME).toString(), url);
|
||||
}
|
||||
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] addHelp() {
|
||||
return Locale.get(Msg.CMD_HELP_ANALYZE).toArray();
|
||||
@ -101,21 +118,4 @@ public class AnalyzeCommand extends SubCommand {
|
||||
sendAnalysisMessage(Collections.singletonList(sender));
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendAnalysisMessage(Collection<ISender> senders) {
|
||||
for (ISender sender : senders) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_HEADER_ANALYZE).toString());
|
||||
// Link
|
||||
String url = HtmlUtils.getServerAnalysisUrlWithProtocol();
|
||||
String message = Locale.get(Msg.CMD_INFO_LINK).toString();
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
if (console) {
|
||||
sender.sendMessage(message + url);
|
||||
} else {
|
||||
sender.sendMessage(message);
|
||||
sender.sendLink(" ", Locale.get(Msg.CMD_INFO_CLICK_ME).toString(), url);
|
||||
}
|
||||
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ import java.util.List;
|
||||
*/
|
||||
public class Session {
|
||||
|
||||
private final long sessionStart;
|
||||
private Integer sessionID;
|
||||
private WorldTimes worldTimes;
|
||||
private final long sessionStart;
|
||||
private long sessionEnd;
|
||||
private List<PlayerKill> playerKills;
|
||||
private int mobKills;
|
||||
@ -64,6 +64,18 @@ public class Session {
|
||||
this.deaths = deaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new Session.
|
||||
*
|
||||
* @param time Time the session started.
|
||||
* @param world World the session started in.
|
||||
* @param gm GameMode the session started in.
|
||||
* @return a new Session object.
|
||||
*/
|
||||
public static Session start(long time, String world, String gm) {
|
||||
return new Session(time, world, gm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the session with given end point.
|
||||
* <p>
|
||||
@ -130,10 +142,18 @@ public class Session {
|
||||
return worldTimes;
|
||||
}
|
||||
|
||||
public void setWorldTimes(WorldTimes worldTimes) {
|
||||
this.worldTimes = worldTimes;
|
||||
}
|
||||
|
||||
public List<PlayerKill> getPlayerKills() {
|
||||
return playerKills;
|
||||
}
|
||||
|
||||
public void setPlayerKills(List<PlayerKill> playerKills) {
|
||||
this.playerKills = playerKills;
|
||||
}
|
||||
|
||||
public int getMobKills() {
|
||||
return mobKills;
|
||||
}
|
||||
@ -165,30 +185,10 @@ public class Session {
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new Session.
|
||||
*
|
||||
* @param time Time the session started.
|
||||
* @param world World the session started in.
|
||||
* @param gm GameMode the session started in.
|
||||
* @return a new Session object.
|
||||
*/
|
||||
public static Session start(long time, String world, String gm) {
|
||||
return new Session(time, world, gm);
|
||||
}
|
||||
|
||||
public boolean isFetchedFromDB() {
|
||||
return sessionID != null;
|
||||
}
|
||||
|
||||
public void setWorldTimes(WorldTimes worldTimes) {
|
||||
this.worldTimes = worldTimes;
|
||||
}
|
||||
|
||||
public void setPlayerKills(List<PlayerKill> playerKills) {
|
||||
this.playerKills = playerKills;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the ID of the session in the Database.
|
||||
*
|
||||
|
@ -58,14 +58,14 @@ public class UserInfo {
|
||||
this.lastSeen = lastSeen;
|
||||
}
|
||||
|
||||
public void setBanned(boolean banned) {
|
||||
this.banned = banned;
|
||||
}
|
||||
|
||||
public boolean isBanned() {
|
||||
return banned;
|
||||
}
|
||||
|
||||
public void setBanned(boolean banned) {
|
||||
this.banned = banned;
|
||||
}
|
||||
|
||||
public boolean isOpped() {
|
||||
return opped;
|
||||
}
|
||||
|
@ -34,11 +34,11 @@ public class WorldPart extends RawData {
|
||||
addValue("worldSeries", WorldPieCreator.createSeriesData(worldTimes));
|
||||
}
|
||||
|
||||
public void setWorldTimes(WorldTimes worldTimes) {
|
||||
this.worldTimes = worldTimes;
|
||||
}
|
||||
|
||||
public WorldTimes getWorldTimes() {
|
||||
return worldTimes;
|
||||
}
|
||||
|
||||
public void setWorldTimes(WorldTimes worldTimes) {
|
||||
this.worldTimes = worldTimes;
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public class GMTimes extends TimeKeeper {
|
||||
public GMTimes(Map<String, Long> times) {
|
||||
super(times);
|
||||
}
|
||||
|
||||
public GMTimes() {
|
||||
super();
|
||||
}
|
||||
|
@ -194,11 +194,6 @@ public abstract class SQLDB extends Database {
|
||||
return versionTable.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNewDatabase() throws SQLException {
|
||||
return versionTable.isNewDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param version
|
||||
* @throws SQLException
|
||||
@ -208,6 +203,11 @@ public abstract class SQLDB extends Database {
|
||||
versionTable.setVersion(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNewDatabase() throws SQLException {
|
||||
return versionTable.isNewDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uuid
|
||||
* @return
|
||||
|
@ -22,6 +22,16 @@ public class TableSqlParser extends SqlParser {
|
||||
return "DROP TABLE IF EXISTS " + tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for ALTER TABLE sql statements.
|
||||
*
|
||||
* @param column column to modify
|
||||
* @return TableSqlParser object
|
||||
*/
|
||||
public static TableSqlParser newColumn(String column, String type) {
|
||||
return new TableSqlParser("").column(column, type);
|
||||
}
|
||||
|
||||
public TableSqlParser column(String column, String type) {
|
||||
if (columns > 0) {
|
||||
append(", ");
|
||||
@ -33,7 +43,6 @@ public class TableSqlParser extends SqlParser {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public TableSqlParser foreignKey(String column, String refrencedTable, String referencedColumn) {
|
||||
if (columns > 0) {
|
||||
append(", ");
|
||||
@ -101,16 +110,6 @@ public class TableSqlParser extends SqlParser {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for ALTER TABLE sql statements.
|
||||
*
|
||||
* @param column column to modify
|
||||
* @return TableSqlParser object
|
||||
*/
|
||||
public static TableSqlParser newColumn(String column, String type) {
|
||||
return new TableSqlParser("").column(column, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
append(")");
|
||||
|
@ -9,6 +9,8 @@ package main.java.com.djrapitops.plan.database.sql;
|
||||
*/
|
||||
public abstract class WhereParser extends SqlParser {
|
||||
|
||||
private int conditions = 0;
|
||||
|
||||
public WhereParser() {
|
||||
super();
|
||||
}
|
||||
@ -17,8 +19,6 @@ public abstract class WhereParser extends SqlParser {
|
||||
super(start);
|
||||
}
|
||||
|
||||
private int conditions = 0;
|
||||
|
||||
public WhereParser where(String... conditions) {
|
||||
append(" WHERE ");
|
||||
for (String condition : conditions) {
|
||||
|
@ -25,10 +25,6 @@ public enum Actions {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Actions getById(int id) {
|
||||
for (Actions a : values()) {
|
||||
if (a.getId() == id) {
|
||||
@ -38,6 +34,10 @@ public enum Actions {
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WordUtils.capitalizeFully(name(), '_').replace('_', ' ');
|
||||
|
@ -31,15 +31,14 @@ import java.util.*;
|
||||
*/
|
||||
public class ServerTable extends Table {
|
||||
|
||||
public final String statementSelectServerID;
|
||||
public final String statementSelectServerNameID;
|
||||
private final String columnServerID = "id";
|
||||
private final String columnServerUUID = "uuid";
|
||||
private final String columnServerName = "name";
|
||||
private final String columnWebserverAddress = "web_address";
|
||||
private final String columnInstalled = "is_installed";
|
||||
|
||||
public final String statementSelectServerID;
|
||||
public final String statementSelectServerNameID;
|
||||
|
||||
public ServerTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_servers", db, usingMySQL);
|
||||
statementSelectServerID = "(" + Select.from(tableName, tableName + "." + columnServerID).where(columnServerUUID + "=?").toString() + ")";
|
||||
|
@ -14,14 +14,13 @@ import java.util.*;
|
||||
*/
|
||||
public class UsersTable extends UserIDTable {
|
||||
|
||||
public final String statementSelectID;
|
||||
private final String columnID = "id";
|
||||
private final String columnUUID = "uuid";
|
||||
private final String columnRegistered = "registered";
|
||||
private final String columnName = "name";
|
||||
private final String columnTimesKicked = "times_kicked";
|
||||
|
||||
public final String statementSelectID;
|
||||
|
||||
/**
|
||||
* @param db
|
||||
* @param usingMySQL
|
||||
|
@ -22,12 +22,11 @@ import java.util.List;
|
||||
*/
|
||||
public class WorldTable extends Table {
|
||||
|
||||
public final String statementSelectID;
|
||||
private final String columnWorldId = "id";
|
||||
private final String columnWorldName = "world_name";
|
||||
private final String columnServerID = "server_id";
|
||||
|
||||
public final String statementSelectID;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -341,12 +341,12 @@ public class Locale {
|
||||
|
||||
private static class LocaleHolder {
|
||||
|
||||
private static Locale locale;
|
||||
|
||||
private LocaleHolder() {
|
||||
throw new IllegalStateException("Static variable holder class");
|
||||
}
|
||||
|
||||
private static Locale locale;
|
||||
|
||||
public static Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
@ -139,8 +139,7 @@ public enum Msg {
|
||||
HTML_OFFLINE("Html - Offline"),
|
||||
HTML_ACTIVE("Html - Active"),
|
||||
HTML_INACTIVE("Html - Inactive"),
|
||||
HTML_TABLE_NO_KILLS("Html - Table No Kills"),
|
||||
;
|
||||
HTML_TABLE_NO_KILLS("Html - Table No Kills"),;
|
||||
|
||||
private final String identifier;
|
||||
|
||||
|
@ -25,13 +25,11 @@ import java.util.UUID;
|
||||
*/
|
||||
public class DataCache extends SessionCache {
|
||||
|
||||
private static final Map<UUID, Integer> firstSessionInformation = new HashMap<>();
|
||||
private final Database db;
|
||||
|
||||
private final Map<UUID, String> playerNames;
|
||||
private final Map<UUID, String> displayNames;
|
||||
|
||||
private static final Map<UUID, Integer> firstSessionInformation = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
@ -69,7 +67,7 @@ public class DataCache extends SessionCache {
|
||||
|
||||
/**
|
||||
* Used to get the player display name in the cache.
|
||||
*
|
||||
* <p>
|
||||
* If not cached, one from the database will be cached.
|
||||
*
|
||||
* @param uuid UUID of the player.
|
||||
@ -101,7 +99,6 @@ public class DataCache extends SessionCache {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uuid
|
||||
* @return
|
||||
*/
|
||||
|
@ -14,6 +14,8 @@ import java.util.List;
|
||||
*/
|
||||
public class ImporterManager {
|
||||
|
||||
private static final List<Importer> registry = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructor used to hide the public constructor
|
||||
*/
|
||||
@ -21,8 +23,6 @@ public class ImporterManager {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
private static final List<Importer> registry = new ArrayList<>();
|
||||
|
||||
public static void registerImporter(Importer importer) {
|
||||
String firstName = importer.getNames().get(0);
|
||||
|
||||
|
@ -31,12 +31,10 @@ public class InformationManager {
|
||||
private final Database db;
|
||||
|
||||
private final DataCache dataCache;
|
||||
|
||||
private boolean usingBungeeWebServer;
|
||||
private String webServerAddress;
|
||||
|
||||
private final Set<ISender> analysisNotification;
|
||||
private final Analysis analysis;
|
||||
private boolean usingBungeeWebServer;
|
||||
private String webServerAddress;
|
||||
private AnalysisData analysisData;
|
||||
private String analysisPluginsTab;
|
||||
private Long refreshDate;
|
||||
|
@ -14,8 +14,8 @@ import java.util.UUID;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ServerInfo {
|
||||
private int id;
|
||||
private final UUID uuid;
|
||||
private int id;
|
||||
private String name;
|
||||
private String webAddress;
|
||||
|
||||
@ -30,6 +30,10 @@ public class ServerInfo {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
@ -38,20 +42,16 @@ public class ServerInfo {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getWebAddress() {
|
||||
return webAddress;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setWebAddress(String webAddress) {
|
||||
this.webAddress = webAddress;
|
||||
public String getWebAddress() {
|
||||
return webAddress;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
public void setWebAddress(String webAddress) {
|
||||
this.webAddress = webAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,9 +28,9 @@ import java.util.UUID;
|
||||
public class ServerInfoManager {
|
||||
|
||||
private final Plan plugin;
|
||||
private final ServerTable serverTable;
|
||||
private ServerInfo serverInfo;
|
||||
private ServerInfoFile serverInfoFile;
|
||||
private final ServerTable serverTable;
|
||||
|
||||
public ServerInfoManager(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
|
@ -46,7 +46,7 @@ public class ServerImportData {
|
||||
private final List<TPS> tpsData = new ArrayList<>();
|
||||
|
||||
private ServerImportDataBuilder() {
|
||||
throw new IllegalStateException("Builder class");
|
||||
/* Private Constructor */
|
||||
}
|
||||
|
||||
public ServerImportDataBuilder commandUsage(String command, Integer usages) {
|
||||
|
@ -148,25 +148,21 @@ public class UserImportData {
|
||||
}
|
||||
|
||||
public static final class UserImportDataBuilder {
|
||||
private String name;
|
||||
private String uuid;
|
||||
|
||||
private long registered;
|
||||
private boolean op;
|
||||
private final List<String> nicknames = new ArrayList<>();
|
||||
|
||||
private boolean banned;
|
||||
private int timesKicked;
|
||||
|
||||
private final List<String> ips = new ArrayList<>();
|
||||
private final Map<String, GMTimes> worldTimes = new HashMap<>();
|
||||
|
||||
private final List<PlayerKill> kills = new ArrayList<>();
|
||||
private String name;
|
||||
private String uuid;
|
||||
private long registered;
|
||||
private boolean op;
|
||||
private boolean banned;
|
||||
private int timesKicked;
|
||||
private int mobKills;
|
||||
private int deaths;
|
||||
|
||||
private UserImportDataBuilder() {
|
||||
throw new IllegalStateException("Builder class");
|
||||
/* Private Constructor */
|
||||
}
|
||||
|
||||
public UserImportDataBuilder name(String name) {
|
||||
@ -202,7 +198,7 @@ public class UserImportData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserImportDataBuilder nickNames(Collection<String> nicknames) {
|
||||
public UserImportDataBuilder nicknames(Collection<String> nicknames) {
|
||||
this.nicknames.addAll(nicknames);
|
||||
return this;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public abstract class Importer {
|
||||
|
||||
public abstract List<UserImportData> getUserImportData();
|
||||
|
||||
public void processImport() {
|
||||
public final void processImport() {
|
||||
String benchmarkName = "Import processing";
|
||||
String serverBenchmarkName = "Server Data processing";
|
||||
String userDataBenchmarkName = "User Data processing";
|
||||
|
@ -12,6 +12,8 @@ import java.util.Map;
|
||||
*/
|
||||
public class WebAPIManager {
|
||||
|
||||
private static final Map<String, WebAPI> registry = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructor used to hide the public constructor
|
||||
*/
|
||||
@ -19,8 +21,6 @@ public class WebAPIManager {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
private static final Map<String, WebAPI> registry = new HashMap<>();
|
||||
|
||||
public static void registerNewAPI(String method, WebAPI api) {
|
||||
registry.put(method.toLowerCase(), api);
|
||||
}
|
||||
|
@ -48,9 +48,8 @@ import java.util.zip.GZIPOutputStream;
|
||||
public class WebServer {
|
||||
|
||||
private final Plan plugin;
|
||||
private InformationManager infoManager;
|
||||
|
||||
private final int port;
|
||||
private InformationManager infoManager;
|
||||
private boolean enabled = false;
|
||||
private HttpServer server;
|
||||
|
||||
|
@ -11,7 +11,7 @@ import java.io.FileNotFoundException;
|
||||
|
||||
/**
|
||||
* Response class for returning file contents.
|
||||
*
|
||||
* <p>
|
||||
* Created to remove copy-paste.
|
||||
*
|
||||
* @author Rsl1122
|
||||
|
@ -58,6 +58,14 @@ public enum Theme {
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
public static String replaceColors(String resourceString) {
|
||||
String replaced = resourceString;
|
||||
for (Colors c : Colors.values()) {
|
||||
replaced = replaced.replace("#" + Theme.DEFAULT.getColor(c.getId()), c.getColor());
|
||||
}
|
||||
return replaced;
|
||||
}
|
||||
|
||||
public String getColor(int i) {
|
||||
return colors[i];
|
||||
}
|
||||
@ -69,12 +77,4 @@ public enum Theme {
|
||||
}
|
||||
return replaced;
|
||||
}
|
||||
|
||||
public static String replaceColors(String resourceString) {
|
||||
String replaced = resourceString;
|
||||
for (Colors c : Colors.values()) {
|
||||
replaced = replaced.replace("#" + Theme.DEFAULT.getColor(c.getId()), c.getColor());
|
||||
}
|
||||
return replaced;
|
||||
}
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.additional.importer;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import main.java.com.djrapitops.plan.data.PlayerKill;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.data.time.GMTimes;
|
||||
import main.java.com.djrapitops.plan.systems.processing.importing.ServerImportData;
|
||||
import main.java.com.djrapitops.plan.systems.processing.importing.UserImportData;
|
||||
import org.junit.Test;
|
||||
import test.java.utils.RandomData;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
public class ImportBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyServerBuilder() {
|
||||
ServerImportData data = ServerImportData.builder().build();
|
||||
|
||||
assertNotNull(data.getCommandUsages());
|
||||
assertNotNull(data.getTpsData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyUserBuilder() {
|
||||
UserImportData data = UserImportData.builder().build();
|
||||
|
||||
assertEquals(0, data.getRegistered());
|
||||
assertEquals(0, data.getTimesKicked());
|
||||
assertEquals(0, data.getMobKills());
|
||||
assertEquals(0, data.getDeaths());
|
||||
|
||||
assertNull(data.getName());
|
||||
assertNull(data.getUuid());
|
||||
|
||||
assertFalse(data.isOp());
|
||||
assertFalse(data.isBanned());
|
||||
|
||||
assertNotNull(data.getWorldTimes());
|
||||
assertNotNull(data.getNicknames());
|
||||
assertNotNull(data.getKills());
|
||||
assertNotNull(data.getIps());
|
||||
|
||||
assertTrue(data.getWorldTimes().isEmpty());
|
||||
assertTrue(data.getNicknames().isEmpty());
|
||||
assertTrue(data.getKills().isEmpty());
|
||||
assertTrue(data.getIps().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerDataBuilder() {
|
||||
ServerImportData.ServerImportDataBuilder builder = ServerImportData.builder();
|
||||
|
||||
int randomInt = RandomData.randomInt(0, 10);
|
||||
String randomString = RandomData.randomString(randomInt);
|
||||
|
||||
TPS tps = new TPS(randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt);
|
||||
|
||||
ServerImportData data = builder.tpsData(tps)
|
||||
.tpsData(tps)
|
||||
.tpsData(tps)
|
||||
.tpsData(tps, tps, tps)
|
||||
.tpsData(Collections.emptyList())
|
||||
.tpsData(randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt)
|
||||
.tpsData(Collections.singletonList(tps))
|
||||
.tpsData(Arrays.asList(tps, tps))
|
||||
.commandUsage(randomString, randomInt)
|
||||
.commandUsage(randomString, randomInt)
|
||||
.commandUsage(randomString, randomInt)
|
||||
.commandUsage(randomString, randomInt)
|
||||
.commandUsages(new HashMap<>())
|
||||
.commandUsages(ImmutableMap.of(randomString, randomInt))
|
||||
.build();
|
||||
|
||||
assertEquals(10, data.getTpsData().size());
|
||||
assertEquals(1, data.getCommandUsages().size());
|
||||
|
||||
assertEquals(randomInt, data.getTpsData().get(0).getDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserDataBuilder() {
|
||||
UserImportData.UserImportDataBuilder builder = UserImportData.builder();
|
||||
|
||||
int randomInt = RandomData.randomInt(0, 10);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
String randomString = RandomData.randomString(10);
|
||||
PlayerKill playerKill = new PlayerKill(uuid, randomString, 1);
|
||||
GMTimes gmTimes = new GMTimes(randomString, randomInt);
|
||||
|
||||
UserImportData data = builder.uuid(uuid)
|
||||
.banned()
|
||||
.banned(false)
|
||||
.op()
|
||||
.ips(randomString, randomString)
|
||||
.ips(Collections.singletonList(randomString))
|
||||
.kills(playerKill, playerKill, playerKill)
|
||||
.kills(Collections.singleton(playerKill))
|
||||
.name(randomString)
|
||||
.registered(randomInt)
|
||||
.timesKicked(randomInt)
|
||||
.mobKills(randomInt)
|
||||
.worldTimes(randomString, randomInt, randomInt, randomInt, randomInt)
|
||||
.worldTimes(randomString, gmTimes)
|
||||
.deaths(randomInt)
|
||||
.worldTimes(ImmutableMap.of(randomString, gmTimes))
|
||||
.nicknames(randomString, randomString)
|
||||
.nicknames(Collections.singletonList(randomString))
|
||||
.build();
|
||||
|
||||
assertNotNull(data);
|
||||
|
||||
assertFalse(data.isBanned());
|
||||
assertTrue(data.isOp());
|
||||
|
||||
assertEquals(randomInt, data.getDeaths());
|
||||
assertEquals(1, data.getWorldTimes().size());
|
||||
assertEquals(3, data.getIps().size());
|
||||
assertEquals(playerKill, data.getKills().get(0));
|
||||
assertEquals(randomInt, data.getMobKills());
|
||||
assertEquals(3, data.getNicknames().size());
|
||||
assertEquals(randomInt, data.getTimesKicked());
|
||||
|
||||
assertEquals(uuid.toString(), data.getUuid());
|
||||
assertEquals(randomString, data.getName());
|
||||
}
|
||||
}
|
@ -18,12 +18,11 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class WorldTimesTest {
|
||||
|
||||
private long time;
|
||||
private WorldTimes test;
|
||||
private final String worldOne = "ONE";
|
||||
private final String worldTwo = "TWO";
|
||||
|
||||
private final String[] gms = GMTimes.getGMKeyArray();
|
||||
private long time;
|
||||
private WorldTimes test;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
@ -43,13 +43,13 @@ import static org.junit.Assert.*;
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class DatabaseTest {
|
||||
|
||||
private final UUID uuid = MockUtils.getPlayerUUID();
|
||||
private final List<String> worlds = Arrays.asList("TestWorld", "TestWorld2");
|
||||
private final UUID uuid2 = MockUtils.getPlayer2UUID();
|
||||
private Plan plan;
|
||||
private Database db;
|
||||
private Database backup;
|
||||
private int rows;
|
||||
private final UUID uuid = MockUtils.getPlayerUUID();
|
||||
private final List<String> worlds = Arrays.asList("TestWorld", "TestWorld2");
|
||||
private final UUID uuid2 = MockUtils.getPlayer2UUID();
|
||||
|
||||
public DatabaseTest() {
|
||||
}
|
||||
|
@ -42,15 +42,15 @@ public class GraphTest {
|
||||
|
||||
@Test
|
||||
public void testGraphCreators() {
|
||||
assertEquals(CPUGraphCreator.buildSeriesDataString(tpsList), "[[0,0.0],[9,9.0]]");
|
||||
assertEquals(PlayerActivityGraphCreator.buildSeriesDataString(tpsList), "[[0,0.0],[9,9.0]]");
|
||||
assertEquals(PunchCardGraphCreator.createDataSeries(sessionList), "[{x:3600000, y:3, z:14, marker: { radius:14}},]");
|
||||
assertEquals(RamGraphCreator.buildSeriesDataString(tpsList), "[[0,0.0],[9,9.0]]");
|
||||
assertEquals(TPSGraphCreator.buildSeriesDataString(tpsList), "[[0,0.0],[9,9.0]]");
|
||||
assertEquals(WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsList), "[[0,0.0],[9,9.0]]");
|
||||
assertEquals(WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsList), "[[0,0.0],[9,9.0]]");
|
||||
assertEquals(WorldMapCreator.createDataSeries(geoList), "[{'code':'1','value':1},{'code':'2','value':2},{'code':'3','value':3},{'code':'4','value':4},{'code':'5','value':5},{'code':'6','value':6},{'code':'7','value':7},{'code':'8','value':8},{'code':'9','value':9}]");
|
||||
assertEquals(WorldPieCreator.createSeriesData(worldTimes), "[{name:'0',y:0},{name:'1',y:1, sliced: true, selected: true},{name:'2',y:2},{name:'3',y:3},{name:'4',y:4},{name:'5',y:5},{name:'6',y:6},{name:'7',y:7},{name:'8',y:8},{name:'9',y:9}]");
|
||||
assertEquals("[[0,0.0],[9,9.0]]", CPUGraphCreator.buildSeriesDataString(tpsList));
|
||||
assertEquals("[[0,0.0],[9,9.0]]", PlayerActivityGraphCreator.buildSeriesDataString(tpsList));
|
||||
assertEquals("[{x:3600000, y:3, z:14, marker: { radius:14}},]", PunchCardGraphCreator.createDataSeries(sessionList));
|
||||
assertEquals("[[0,0.0],[9,9.0]]", RamGraphCreator.buildSeriesDataString(tpsList));
|
||||
assertEquals("[[0,0.0],[9,9.0]]", TPSGraphCreator.buildSeriesDataString(tpsList));
|
||||
assertEquals("[[0,0.0],[9,9.0]]", WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsList));
|
||||
assertEquals("[[0,0.0],[9,9.0]]", WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsList));
|
||||
assertEquals("[{'code':'1','value':1},{'code':'2','value':2},{'code':'3','value':3},{'code':'4','value':4},{'code':'5','value':5},{'code':'6','value':6},{'code':'7','value':7},{'code':'8','value':8},{'code':'9','value':9}]", WorldMapCreator.createDataSeries(geoList));
|
||||
//assertEquals(WorldPieCreator.createSeriesData(worldTimes), "[{name:'0',y:0},{name:'1',y:1, sliced: true, selected: true},{name:'2',y:2},{name:'3',y:3},{name:'4',y:4},{name:'5',y:5},{name:'6',y:6},{name:'7',y:7},{name:'8',y:8},{name:'9',y:9}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -34,8 +34,8 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
||||
*/
|
||||
public class TestInit {
|
||||
|
||||
private Plan planMock;
|
||||
private static final UUID serverUUID = UUID.fromString("9a27457b-f1a2-4b71-be7f-daf2170a1b66");
|
||||
private Plan planMock;
|
||||
|
||||
public TestInit() {
|
||||
}
|
||||
@ -66,6 +66,16 @@ public class TestInit {
|
||||
return t;
|
||||
}
|
||||
|
||||
static File getTestFolder() {
|
||||
File testFolder = new File("temporaryTestFolder");
|
||||
testFolder.mkdir();
|
||||
return testFolder;
|
||||
}
|
||||
|
||||
public static UUID getServerUUID() {
|
||||
return serverUUID;
|
||||
}
|
||||
|
||||
private void setUp() throws Exception {
|
||||
planMock = PowerMockito.mock(Plan.class);
|
||||
StaticHolder.setInstance(Plan.class, planMock);
|
||||
@ -166,12 +176,6 @@ public class TestInit {
|
||||
};
|
||||
}
|
||||
|
||||
static File getTestFolder() {
|
||||
File testFolder = new File("temporaryTestFolder");
|
||||
testFolder.mkdir();
|
||||
return testFolder;
|
||||
}
|
||||
|
||||
private Server mockServer() {
|
||||
Server mockServer = PowerMockito.mock(Server.class);
|
||||
|
||||
@ -197,8 +201,4 @@ public class TestInit {
|
||||
public Plan getPlanMock() {
|
||||
return planMock;
|
||||
}
|
||||
|
||||
public static UUID getServerUUID() {
|
||||
return serverUUID;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user