mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-26 22:49:51 +02:00
[Smell] Fix smells in CommonDBTest
- Introduced HtmlUtilities class accessible from PlanSystem, for utilities that may need injecting otherwise. - Used the new HtmlUtilities class for constructing AnalysisContainer.Factory for an ignored test (Smell) - Fixed the test that was now failing by removing AnalysisKeys.BAN_DATA - Inverted a test condition that was flipped - Changed some calls to TestConstants to class variables in CommonDBTest
This commit is contained in:
parent
e87a22ce59
commit
8d596b416a
|
@ -171,8 +171,6 @@ public class AnalysisKeys {
|
|||
public static final Key<Long> ANALYSIS_TIME_MONTH_AGO = new Key<>(Long.class, "ANALYSIS_TIME_MONTH_AGO");
|
||||
public static final Key<Map<UUID, String>> PLAYER_NAMES = new Key<>(new Type<Map<UUID, String>>() {}, "PLAYER_NAMES");
|
||||
public static final Key<TreeMap<Long, Map<String, Set<UUID>>>> ACTIVITY_DATA = CommonKeys.ACTIVITY_DATA;
|
||||
@Deprecated
|
||||
public static final Key<Set<UUID>> BAN_DATA = new Key<>(new Type<Set<UUID>>() {}, "BAN_DATA");
|
||||
public static final Key<TreeMap<Long, Integer>> UNIQUE_PLAYERS_PER_DAY = new Key<>(new Type<TreeMap<Long, Integer>>() {}, "UNIQUE_PLAYERS_PER_DAY");
|
||||
public static final Key<TreeMap<Long, Integer>> NEW_PLAYERS_PER_DAY = new Key<>(new Type<TreeMap<Long, Integer>>() {}, "NEW_PLAYERS_PER_DAY");
|
||||
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the LGNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* LGNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.system;
|
||||
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.structure.Accordions;
|
||||
import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class HtmlUtilities {
|
||||
|
||||
private final Lazy<Formatters> formatters;
|
||||
private final Lazy<HtmlTables> htmlTables;
|
||||
private final Lazy<Graphs> graphs;
|
||||
private final Lazy<Accordions> accordions;
|
||||
private final Lazy<AnalysisPluginsTabContentCreator> analysisPluginsTabContentCreator;
|
||||
|
||||
@Inject
|
||||
public HtmlUtilities(
|
||||
Lazy<Formatters> formatters,
|
||||
Lazy<HtmlTables> htmlTables,
|
||||
Lazy<Graphs> graphs,
|
||||
Lazy<Accordions> accordions,
|
||||
Lazy<AnalysisPluginsTabContentCreator> analysisPluginsTabContentCreator
|
||||
) {
|
||||
this.formatters = formatters;
|
||||
this.htmlTables = htmlTables;
|
||||
this.graphs = graphs;
|
||||
this.accordions = accordions;
|
||||
this.analysisPluginsTabContentCreator = analysisPluginsTabContentCreator;
|
||||
}
|
||||
|
||||
public Formatters getFormatters() {
|
||||
return formatters.get();
|
||||
}
|
||||
|
||||
public HtmlTables getHtmlTables() {
|
||||
return htmlTables.get();
|
||||
}
|
||||
|
||||
public Graphs getGraphs() {
|
||||
return graphs.get();
|
||||
}
|
||||
|
||||
public Accordions getAccordions() {
|
||||
return accordions.get();
|
||||
}
|
||||
|
||||
public AnalysisPluginsTabContentCreator getAnalysisPluginsTabContentCreator() {
|
||||
return analysisPluginsTabContentCreator.get();
|
||||
}
|
||||
}
|
|
@ -65,6 +65,7 @@ public class PlanSystem implements SubSystem {
|
|||
|
||||
private final ImportSystem importSystem;
|
||||
private final ExportSystem exportSystem;
|
||||
private final HtmlUtilities htmlUtilities;
|
||||
private final HookHandler hookHandler;
|
||||
private final PlanAPI planAPI;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
@ -85,6 +86,7 @@ public class PlanSystem implements SubSystem {
|
|||
Processing processing,
|
||||
ImportSystem importSystem,
|
||||
ExportSystem exportSystem,
|
||||
HtmlUtilities htmlUtilities,
|
||||
HookHandler hookHandler,
|
||||
PlanAPI planAPI,
|
||||
ErrorHandler errorHandler
|
||||
|
@ -103,6 +105,7 @@ public class PlanSystem implements SubSystem {
|
|||
this.processing = processing;
|
||||
this.importSystem = importSystem;
|
||||
this.exportSystem = exportSystem;
|
||||
this.htmlUtilities = htmlUtilities;
|
||||
this.hookHandler = hookHandler;
|
||||
this.planAPI = planAPI;
|
||||
this.errorHandler = errorHandler;
|
||||
|
@ -231,4 +234,8 @@ public class PlanSystem implements SubSystem {
|
|||
public LocaleSystem getLocaleSystem() {
|
||||
return localeSystem;
|
||||
}
|
||||
|
||||
public HtmlUtilities getHtmlUtilities() {
|
||||
return htmlUtilities;
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@ import static org.junit.Assert.*;
|
|||
/**
|
||||
* Contains all common Database Tests for all Database Types
|
||||
*
|
||||
* @author Fuzzlemann
|
||||
* @author Rsl1122 (Refactored into this class by Fuzzlemann)
|
||||
* @since 4.5.1
|
||||
*/
|
||||
public abstract class CommonDBTest {
|
||||
|
@ -109,8 +109,8 @@ public abstract class CommonDBTest {
|
|||
System.out.println("\n-- Clearing Test Database --");
|
||||
db.remove().everything();
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
serverTable.saveCurrentServerInfo(new Server(-1, TestConstants.SERVER_UUID, "ServerName", "", 20));
|
||||
assertEquals(db.getServerUUIDSupplier().get(), TestConstants.SERVER_UUID);
|
||||
serverTable.saveCurrentServerInfo(new Server(-1, serverUUID, "ServerName", "", 20));
|
||||
assertEquals(serverUUID, db.getServerUUIDSupplier().get());
|
||||
System.out.println("-- Clear Complete --\n");
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ public abstract class CommonDBTest {
|
|||
saveUserOne();
|
||||
NicknamesTable nickTable = db.getNicknamesTable();
|
||||
|
||||
Nickname expected = new Nickname("TestNickname", System.currentTimeMillis(), TestConstants.SERVER_UUID);
|
||||
Nickname expected = new Nickname("TestNickname", System.currentTimeMillis(), serverUUID);
|
||||
nickTable.saveUserName(playerUUID, expected);
|
||||
nickTable.saveUserName(playerUUID, expected);
|
||||
commitTest();
|
||||
|
@ -352,7 +352,7 @@ public abstract class CommonDBTest {
|
|||
saveTwoWorlds();
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
Session session = new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, 12345L, "", "");
|
||||
Session session = new Session(playerUUID, serverUUID, 12345L, "", "");
|
||||
session.endSession(22345L);
|
||||
session.setWorldTimes(createWorldTimes());
|
||||
session.setPlayerKills(createKills());
|
||||
|
@ -369,7 +369,6 @@ public abstract class CommonDBTest {
|
|||
assertEquals(expectedLength, sessionsTable.getPlaytime(playerUUID));
|
||||
assertEquals(0L, sessionsTable.getPlaytime(playerUUID, 30000L));
|
||||
|
||||
UUID serverUUID = TestConstants.SERVER_UUID;
|
||||
long playtimeOfServer = sessionsTable.getPlaytimeOfServer(serverUUID);
|
||||
assertEquals(expectedLength, playtimeOfServer);
|
||||
assertEquals(0L, sessionsTable.getPlaytimeOfServer(serverUUID, 30000L));
|
||||
|
@ -383,7 +382,7 @@ public abstract class CommonDBTest {
|
|||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
Session session = new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, 12345L, "", "");
|
||||
Session session = new Session(playerUUID, serverUUID, 12345L, "", "");
|
||||
session.endSession(22345L);
|
||||
session.setWorldTimes(createWorldTimes());
|
||||
session.setPlayerKills(createKills());
|
||||
|
@ -547,13 +546,13 @@ public abstract class CommonDBTest {
|
|||
userInfoTable.registerUserInfo(playerUUID, 223456789L);
|
||||
saveTwoWorlds();
|
||||
|
||||
Session session = new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, 12345L, "", "");
|
||||
Session session = new Session(playerUUID, serverUUID, 12345L, "", "");
|
||||
session.endSession(22345L);
|
||||
session.setWorldTimes(createWorldTimes());
|
||||
session.setPlayerKills(createKills());
|
||||
|
||||
sessionsTable.saveSession(playerUUID, session);
|
||||
nicknamesTable.saveUserName(playerUUID, new Nickname("TestNick", System.currentTimeMillis(), TestConstants.SERVER_UUID));
|
||||
nicknamesTable.saveUserName(playerUUID, new Nickname("TestNick", System.currentTimeMillis(), serverUUID));
|
||||
geoInfoTable.saveGeoInfo(playerUUID, new GeoInfo("1.2.3.4", "TestLoc", 223456789L, "3"));
|
||||
|
||||
assertTrue(usersTable.isRegistered(playerUUID));
|
||||
|
@ -613,13 +612,13 @@ public abstract class CommonDBTest {
|
|||
userInfoTable.registerUserInfo(playerUUID, 223456789L);
|
||||
saveTwoWorlds(database);
|
||||
|
||||
Session session = new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, 12345L, "", "");
|
||||
Session session = new Session(playerUUID, serverUUID, 12345L, "", "");
|
||||
session.endSession(22345L);
|
||||
session.setWorldTimes(createWorldTimes());
|
||||
session.setPlayerKills(createKills());
|
||||
|
||||
sessionsTable.saveSession(playerUUID, session);
|
||||
nicknamesTable.saveUserName(playerUUID, new Nickname("TestNick", System.currentTimeMillis(), TestConstants.SERVER_UUID));
|
||||
nicknamesTable.saveUserName(playerUUID, new Nickname("TestNick", System.currentTimeMillis(), serverUUID));
|
||||
geoInfoTable.saveGeoInfo(playerUUID, new GeoInfo("1.2.3.4", "TestLoc", 223456789L,
|
||||
new SHA256Hash("1.2.3.4").create()));
|
||||
|
||||
|
@ -651,7 +650,7 @@ public abstract class CommonDBTest {
|
|||
}
|
||||
|
||||
pingTable.insertPing(playerUUID, new Ping(
|
||||
System.currentTimeMillis(), TestConstants.SERVER_UUID,
|
||||
System.currentTimeMillis(), serverUUID,
|
||||
r.nextInt(), r.nextInt(), r.nextDouble()
|
||||
));
|
||||
|
||||
|
@ -670,7 +669,7 @@ public abstract class CommonDBTest {
|
|||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
Session session = new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, 12345L, "", "");
|
||||
Session session = new Session(playerUUID, serverUUID, 12345L, "", "");
|
||||
session.endSession(22345L);
|
||||
session.setWorldTimes(createWorldTimes());
|
||||
session.setPlayerKills(createKills());
|
||||
|
@ -753,7 +752,7 @@ public abstract class CommonDBTest {
|
|||
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
||||
worldTimesTable.saveWorldTimes(playerUUID, 1, worldTimes);
|
||||
|
||||
Session session = new Session(1, playerUUID, TestConstants.SERVER_UUID, 12345L, 23456L, 0, 0, 0);
|
||||
Session session = new Session(1, playerUUID, serverUUID, 12345L, 23456L, 0, 0, 0);
|
||||
Map<Integer, Session> sessions = new HashMap<>();
|
||||
sessions.put(1, session);
|
||||
worldTimesTable.addWorldTimesToSessions(playerUUID, sessions);
|
||||
|
@ -767,7 +766,7 @@ public abstract class CommonDBTest {
|
|||
WorldTimes worldTimes = createWorldTimes();
|
||||
System.out.println(worldTimes);
|
||||
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
||||
Session session = new Session(1, playerUUID, TestConstants.SERVER_UUID, 12345L, 23456L, 0, 0, 0);
|
||||
Session session = new Session(1, playerUUID, serverUUID, 12345L, 23456L, 0, 0, 0);
|
||||
session.setWorldTimes(worldTimes);
|
||||
|
||||
Map<UUID, Map<UUID, List<Session>>> map = new HashMap<>();
|
||||
|
@ -790,7 +789,7 @@ public abstract class CommonDBTest {
|
|||
saveUserOne();
|
||||
WorldTimes worldTimes = createWorldTimes();
|
||||
System.out.println(worldTimes);
|
||||
Session session = new Session(1, playerUUID, TestConstants.SERVER_UUID, 12345L, 23456L, 0, 0, 0);
|
||||
Session session = new Session(1, playerUUID, serverUUID, 12345L, 23456L, 0, 0, 0);
|
||||
session.setWorldTimes(worldTimes);
|
||||
|
||||
Map<UUID, Map<UUID, List<Session>>> map = new HashMap<>();
|
||||
|
@ -817,7 +816,7 @@ public abstract class CommonDBTest {
|
|||
@Test
|
||||
public void testGetServerWorldTimes() {
|
||||
testSaveSessionsWorldTimes();
|
||||
WorldTimes worldTimesOfServer = db.getWorldTimesTable().getWorldTimesOfServer(TestConstants.SERVER_UUID);
|
||||
WorldTimes worldTimesOfServer = db.getWorldTimesTable().getWorldTimesOfServer(serverUUID);
|
||||
assertEquals(createWorldTimes(), worldTimesOfServer);
|
||||
}
|
||||
|
||||
|
@ -834,7 +833,7 @@ public abstract class CommonDBTest {
|
|||
@Test
|
||||
public void testWorldTableGetWorldNamesNoException() throws NoSuchAlgorithmException {
|
||||
saveAllData(db);
|
||||
Set<String> worldNames = db.getWorldTable().getWorldNames(TestConstants.SERVER_UUID);
|
||||
Set<String> worldNames = db.getWorldTable().getWorldNames(serverUUID);
|
||||
assertEquals(new HashSet<>(worlds), worldNames);
|
||||
}
|
||||
|
||||
|
@ -907,7 +906,7 @@ public abstract class CommonDBTest {
|
|||
assertTrue(container.supports(PlayerKeys.PLAYER_KILL_COUNT));
|
||||
|
||||
assertFalse(container.supports(PlayerKeys.ACTIVE_SESSION));
|
||||
container.putRawData(PlayerKeys.ACTIVE_SESSION, new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, System.currentTimeMillis(), "TestWorld", "SURVIVAL"));
|
||||
container.putRawData(PlayerKeys.ACTIVE_SESSION, new Session(playerUUID, serverUUID, System.currentTimeMillis(), "TestWorld", "SURVIVAL"));
|
||||
assertTrue(container.supports(PlayerKeys.ACTIVE_SESSION));
|
||||
|
||||
long end = System.nanoTime();
|
||||
|
@ -923,7 +922,7 @@ public abstract class CommonDBTest {
|
|||
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));
|
||||
List<Nickname> expectedNicknames = Collections.singletonList(new Nickname("TestNick", -1, serverUUID));
|
||||
OptionalAssert.equals(expectedNicknames, container.getValue(PlayerKeys.NICKNAMES));
|
||||
|
||||
OptionalAssert.equals(false, container.getValue(PlayerKeys.OPERATOR));
|
||||
|
@ -936,7 +935,7 @@ public abstract class CommonDBTest {
|
|||
public void playerContainerSupportsAllPlayerKeys() throws NoSuchAlgorithmException, IllegalAccessException {
|
||||
saveAllData(db);
|
||||
|
||||
PlayerContainer playerContainer = db.fetch().getPlayerContainer(TestConstants.PLAYER_ONE_UUID);
|
||||
PlayerContainer playerContainer = db.fetch().getPlayerContainer(playerUUID);
|
||||
// Active sessions are added after fetching
|
||||
playerContainer.putRawData(PlayerKeys.ACTIVE_SESSION, RandomData.randomSession());
|
||||
|
||||
|
@ -945,6 +944,7 @@ public abstract class CommonDBTest {
|
|||
if (!Modifier.isPublic(field.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
// the field is static and no object is needed for access.
|
||||
Key key = (Key) field.get(null);
|
||||
if (!playerContainer.supports(key)) {
|
||||
unsupported.add(field.getName());
|
||||
|
@ -958,13 +958,14 @@ public abstract class CommonDBTest {
|
|||
public void serverContainerSupportsAllServerKeys() throws NoSuchAlgorithmException, IllegalAccessException {
|
||||
saveAllData(db);
|
||||
|
||||
ServerContainer serverContainer = db.fetch().getServerContainer(TestConstants.SERVER_UUID);
|
||||
ServerContainer serverContainer = db.fetch().getServerContainer(serverUUID);
|
||||
|
||||
List<String> unsupported = new ArrayList<>();
|
||||
for (Field field : ServerKeys.class.getDeclaredFields()) {
|
||||
if (!Modifier.isPublic(field.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
// the field is static and no object is needed for access.
|
||||
Key key = (Key) field.get(null);
|
||||
if (!serverContainer.supports(key)) {
|
||||
unsupported.add(field.getName());
|
||||
|
@ -975,18 +976,18 @@ public abstract class CommonDBTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void analysisContainerSupportsAllAnalysisKeys() throws IllegalAccessException, NoSuchAlgorithmException {
|
||||
serverContainerSupportsAllServerKeys();
|
||||
AnalysisContainer.Factory factory = null;
|
||||
AnalysisContainer.Factory factory = constructAnalysisContainerFactory();
|
||||
AnalysisContainer analysisContainer = factory.forServerContainer(
|
||||
db.fetch().getServerContainer(TestConstants.SERVER_UUID)
|
||||
db.fetch().getServerContainer(serverUUID)
|
||||
);
|
||||
List<String> unsupported = new ArrayList<>();
|
||||
Collection<String> unsupported = new ArrayList<>();
|
||||
for (Field field : AnalysisKeys.class.getDeclaredFields()) {
|
||||
if (!Modifier.isPublic(field.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
// the field is static and no object is needed for access.
|
||||
Key key = (Key) field.get(null);
|
||||
if (!analysisContainer.supports(key)) {
|
||||
unsupported.add(field.getName());
|
||||
|
@ -996,6 +997,22 @@ public abstract class CommonDBTest {
|
|||
assertTrue("Some keys are not supported by AnalysisContainer: AnalysisKeys." + unsupported.toString(), unsupported.isEmpty());
|
||||
}
|
||||
|
||||
private AnalysisContainer.Factory constructAnalysisContainerFactory() {
|
||||
return new AnalysisContainer.Factory(
|
||||
"1.0.0",
|
||||
system.getConfigSystem().getConfig(),
|
||||
system.getLocaleSystem().getLocale(),
|
||||
system.getConfigSystem().getTheme(),
|
||||
dbSystem,
|
||||
system.getServerInfo().getServerProperties(),
|
||||
system.getHtmlUtilities().getFormatters(),
|
||||
system.getHtmlUtilities().getGraphs(),
|
||||
system.getHtmlUtilities().getHtmlTables(),
|
||||
system.getHtmlUtilities().getAccordions(),
|
||||
system.getHtmlUtilities().getAnalysisPluginsTabContentCreator()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void networkContainerSupportsAllNetworkKeys() throws IllegalAccessException, NoSuchAlgorithmException {
|
||||
serverContainerSupportsAllServerKeys();
|
||||
|
@ -1040,11 +1057,11 @@ public abstract class CommonDBTest {
|
|||
UUID uuid = UUID.randomUUID();
|
||||
String userName = RandomData.randomString(10);
|
||||
db.getUsersTable().registerUser(uuid, 0L, userName);
|
||||
db.getUsersTable().registerUser(TestConstants.PLAYER_ONE_UUID, 1L, "Not random");
|
||||
db.getUsersTable().registerUser(playerUUID, 1L, "Not random");
|
||||
|
||||
String nickname = "2" + RandomData.randomString(10);
|
||||
db.getNicknamesTable().saveUserName(uuid, new Nickname(nickname, System.currentTimeMillis(), TestConstants.SERVER_UUID));
|
||||
db.getNicknamesTable().saveUserName(TestConstants.PLAYER_ONE_UUID, new Nickname("No nick", System.currentTimeMillis(), TestConstants.SERVER_UUID));
|
||||
db.getNicknamesTable().saveUserName(uuid, new Nickname(nickname, System.currentTimeMillis(), serverUUID));
|
||||
db.getNicknamesTable().saveUserName(playerUUID, new Nickname("No nick", System.currentTimeMillis(), serverUUID));
|
||||
|
||||
String search = "2";
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user