Removed a bunch of deprecated methods:

- TransferOperations#getServerPlayerIsOnlineOn & related methods
- AnalysisUtils new and unique player calculation methods
- Session getter methods
- getColumnID, getColumnUUID, getColumnName in various Tables
- AstractPieChart#createSeries
- HtmlUtils#replacePlaceholders
This commit is contained in:
Rsl1122 2018-07-12 13:30:30 +03:00
parent fd65f00487
commit e974e987d9
19 changed files with 48 additions and 306 deletions

View File

@ -81,7 +81,6 @@ public class ShutdownHook extends Thread {
db.init();
}
try {
Log.debug("Shutdown: Saving a session: " + session.getSessionStart());
db.save().session(uuid, session);
} catch (DBOpException e) {
Log.toLog(this.getClass(), e);

View File

@ -141,54 +141,14 @@ public class Session extends DataContainer implements DateHolder {
return getUnsafe(SessionKeys.START);
}
/**
* Get the start of the session.
*
* @return Epoch millisecond the session started.
*/
@Deprecated
public long getSessionStart() {
return getUnsafe(SessionKeys.START);
}
/**
* Get the end of the session.
*
* @return Epoch millisecond the session ended.
*/
@Deprecated
public long getSessionEnd() {
return getValue(SessionKeys.END).orElse(-1L);
}
@Deprecated
public WorldTimes getWorldTimes() {
return getValue(SessionKeys.WORLD_TIMES).orElse(null);
}
public void setWorldTimes(WorldTimes worldTimes) {
putRawData(SessionKeys.WORLD_TIMES, worldTimes);
}
@Deprecated
public List<PlayerKill> getPlayerKills() {
return getValue(SessionKeys.PLAYER_KILLS).orElse(new ArrayList<>());
}
public void setPlayerKills(List<PlayerKill> playerKills) {
putRawData(SessionKeys.PLAYER_KILLS, playerKills);
}
@Deprecated
public int getMobKills() {
return mobKills;
}
@Deprecated
public int getDeaths() {
return deaths;
}
public boolean isFetchedFromDB() {
return supports(SessionKeys.DB_ID);
}
@ -197,27 +157,6 @@ public class Session extends DataContainer implements DateHolder {
afkTime += timeAFK;
}
@Deprecated
public long getAfkLength() {
return afkTime;
}
@Deprecated
public long getActiveLength() {
return getLength() - getAfkLength();
}
/**
* Used to get the ID of the session in the Database.
*
* @return ID if present.
* @throws NullPointerException if Session was not fetched from DB. Check {@code isFetchedFromDB} first.
*/
@Deprecated
public int getSessionID() {
return getValue(SessionKeys.DB_ID).orElseThrow(() -> new NullPointerException("Session not fetched from DB."));
}
public void setSessionID(int sessionID) {
putRawData(SessionKeys.DB_ID, sessionID);
}

View File

@ -5,7 +5,6 @@
package com.djrapitops.plan.system.database.databases.operation;
import java.util.Optional;
import java.util.UUID;
/**
* Operations for transferring data via Database to another server.
@ -22,8 +21,5 @@ public interface TransferOperations {
// Get
@Deprecated
Optional<UUID> getServerPlayerIsOnlineOn(UUID playerUUID);
Optional<String> getEncodedConfigSettings();
}

View File

@ -8,7 +8,6 @@ import com.djrapitops.plan.system.database.databases.operation.TransferOperation
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import java.util.Optional;
import java.util.UUID;
/**
* TransferOperations for MySQL Database.
@ -21,11 +20,6 @@ public class SQLTransferOps extends SQLOps implements TransferOperations {
super(db);
}
@Override
public Optional<UUID> getServerPlayerIsOnlineOn(UUID playerUUID) {
return transferTable.getServerPlayerIsOnline(playerUUID);
}
@Override
public void storeConfigSettings(String encodedSettingString) {
transferTable.storeConfigSettings(encodedSettingString);

View File

@ -116,7 +116,7 @@ public class KillsTable extends UserIDTable {
UUID victim = UUID.fromString(uuidS);
long date = set.getLong(Col.DATE.get());
String weapon = set.getString(Col.WEAPON.get());
session.getPlayerKills().add(new PlayerKill(victim, weapon, date));
session.getUnsafe(SessionKeys.PLAYER_KILLS).add(new PlayerKill(victim, weapon, date));
}
return null;
}
@ -258,7 +258,7 @@ public class KillsTable extends UserIDTable {
for (UUID serverUUID : map.keySet()) {
for (List<Session> sessions : map.get(serverUUID).values()) {
for (Session session : sessions) {
List<PlayerKill> playerKills = playerKillsBySessionID.get(session.getSessionID());
List<PlayerKill> playerKills = playerKillsBySessionID.get(session.getUnsafe(SessionKeys.DB_ID));
if (playerKills != null) {
session.setPlayerKills(playerKills);
}
@ -283,9 +283,9 @@ public class KillsTable extends UserIDTable {
List<Session> sessions = entry.getValue();
// Every session
for (Session session : sessions) {
int sessionID = session.getSessionID();
int sessionID = session.getUnsafe(SessionKeys.DB_ID);
// Every kill
for (PlayerKill kill : session.getPlayerKills()) {
for (PlayerKill kill : session.getUnsafe(SessionKeys.PLAYER_KILLS)) {
UUID victim = kill.getVictim();
long date = kill.getDate();
String weapon = kill.getWeapon();

View File

@ -43,11 +43,6 @@ public class ServerTable extends Table {
Col.INSTALLED,
Col.MAX_PLAYERS);
}
@Deprecated
public String getColumnID() {
return Col.SERVER_ID.get();
}
public final String statementSelectServerID;
public final String statementSelectServerNameID;
@ -316,11 +311,6 @@ public class ServerTable extends Table {
});
}
@Deprecated
public String getColumnUUID() {
return Col.SERVER_UUID.get();
}
public void insertAllServers(List<Server> allServer) {
if (Verify.isEmpty(allServer)) {
return;

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.system.database.databases.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.keys.SessionKeys;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement;
import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement;
@ -28,6 +29,9 @@ public class SessionsTable extends UserIDTable {
public static final String TABLE_NAME = "plan_sessions";
private final ServerTable serverTable;
private String insertStatement;
public SessionsTable(SQLDB db) {
super(TABLE_NAME, db);
serverTable = db.getServerTable();
@ -45,9 +49,6 @@ public class SessionsTable extends UserIDTable {
+ serverTable.statementSelectServerID + ")";
}
private final ServerTable serverTable;
private String insertStatement;
@Override
public void createTable() throws DBInitException {
createTable(TableSqlParser.createTable(this.tableName)
@ -83,8 +84,8 @@ public class SessionsTable extends UserIDTable {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, uuid.toString());
statement.setLong(2, session.getSessionStart());
statement.setLong(3, session.getSessionEnd());
statement.setLong(2, session.getUnsafe(SessionKeys.START));
statement.setLong(3, session.getValue(SessionKeys.END).orElse(System.currentTimeMillis()));
}
@Override
@ -112,8 +113,8 @@ public class SessionsTable extends UserIDTable {
throw new IllegalStateException("Session was not Saved!");
}
db.getWorldTimesTable().saveWorldTimes(uuid, sessionID, session.getWorldTimes());
db.getKillsTable().savePlayerKills(uuid, sessionID, session.getPlayerKills());
db.getWorldTimesTable().saveWorldTimes(uuid, sessionID, session.getUnsafe(SessionKeys.WORLD_TIMES));
db.getKillsTable().savePlayerKills(uuid, sessionID, session.getUnsafe(SessionKeys.PLAYER_KILLS));
}
/**
@ -129,11 +130,11 @@ public class SessionsTable extends UserIDTable {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, uuid.toString());
statement.setLong(2, session.getSessionStart());
statement.setLong(3, session.getSessionEnd());
statement.setInt(4, session.getDeaths());
statement.setInt(5, session.getMobKills());
statement.setLong(6, session.getAfkLength());
statement.setLong(2, session.getUnsafe(SessionKeys.START));
statement.setLong(3, session.getUnsafe(SessionKeys.END));
statement.setInt(4, session.getUnsafe(SessionKeys.DEATH_COUNT));
statement.setInt(5, session.getUnsafe(SessionKeys.MOB_KILL_COUNT));
statement.setLong(6, session.getUnsafe(SessionKeys.AFK_TIME));
statement.setString(7, ServerInfo.getServerUUID().toString());
}
});
@ -222,7 +223,9 @@ public class SessionsTable extends UserIDTable {
public Map<UUID, List<Session>> getSessions(UUID uuid) {
Map<UUID, List<Session>> sessions = getSessionInformation(uuid);
Map<Integer, Session> allSessions = sessions.values().stream().flatMap(Collection::stream).collect(Collectors.toMap(Session::getSessionID, Function.identity()));
Map<Integer, Session> allSessions = sessions.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toMap(s -> s.getUnsafe(SessionKeys.DB_ID), Function.identity()));
db.getKillsTable().addKillsToSessions(uuid, allSessions);
db.getKillsTable().addDeathsToSessions(uuid, allSessions);
@ -434,11 +437,6 @@ public class SessionsTable extends UserIDTable {
return getSessionCount(uuid, serverUUID, 0L);
}
@Deprecated
public String getColumnID() {
return Col.ID.get();
}
public Map<UUID, List<Session>> getSessionInfoOfServer(UUID serverUUID) {
String usersIDColumn = usersTable + "." + UsersTable.Col.ID;
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID + " as uuid";
@ -650,11 +648,11 @@ public class SessionsTable extends UserIDTable {
for (Session session : sessions) {
statement.setString(1, uuid.toString());
statement.setLong(2, session.getSessionStart());
statement.setLong(3, session.getSessionEnd());
statement.setInt(4, session.getDeaths());
statement.setInt(5, session.getMobKills());
statement.setLong(6, session.getAfkLength());
statement.setLong(2, session.getUnsafe(SessionKeys.START));
statement.setLong(3, session.getUnsafe(SessionKeys.END));
statement.setInt(4, session.getUnsafe(SessionKeys.DEATH_COUNT));
statement.setInt(5, session.getUnsafe(SessionKeys.MOB_KILL_COUNT));
statement.setLong(6, session.getUnsafe(SessionKeys.AFK_TIME));
statement.setString(7, serverUUID.toString());
statement.addBatch();
}
@ -715,15 +713,15 @@ public class SessionsTable extends UserIDTable {
}
Session savedSession = savedSessionsByStart.get(start).get(0);
sessionEntry.getValue().forEach(
session -> session.setSessionID(savedSession.getSessionID())
session -> session.setSessionID(savedSession.getUnsafe(SessionKeys.DB_ID))
);
}
}
private Map<Long, List<Session>> turnToMapByStart(List<Session> sessions) {
Map<Long, List<Session>> sessionsByStart = new HashMap<>();
Map<Long, List<Session>> sessionsByStart = new TreeMap<>();
for (Session session : sessions) {
long start = session.getSessionStart();
long start = session.getUnsafe(SessionKeys.START);
List<Session> sorted = sessionsByStart.getOrDefault(start, new ArrayList<>());
sorted.add(session);
sessionsByStart.put(start, sorted);

View File

@ -18,7 +18,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Optional;
import java.util.UUID;
/**
* Table that is in charge of transferring data between network servers.
@ -100,33 +99,6 @@ public class TransferTable extends Table {
});
}
@Deprecated
public Optional<UUID> getServerPlayerIsOnline(UUID playerUUID) {
String serverIDColumn = serverTable + "." + ServerTable.Col.SERVER_ID;
String serverUUIDColumn = serverTable + "." + ServerTable.Col.SERVER_UUID + " as s_uuid";
String sql = "SELECT " +
serverUUIDColumn +
" FROM " + tableName +
" INNER JOIN " + serverTable + " on " + serverIDColumn + "=" + Col.SENDER_ID +
" WHERE " + Col.EXTRA_VARIABLES + "=?" +
" ORDER BY " + Col.EXPIRY + " LIMIT 1";
return query(new QueryStatement<Optional<UUID>>(sql, 1) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, playerUUID.toString());
}
@Override
public Optional<UUID> processResults(ResultSet set) throws SQLException {
if (set.next()) {
return Optional.of(UUID.fromString(set.getString("s_uuid")));
}
return Optional.empty();
}
});
}
public void storeConfigSettings(String encodedSettingString) {
execute(new ExecStatement(insertStatementNoParts) {
@Override

View File

@ -90,22 +90,6 @@ public class UsersTable extends UserIDTable {
});
}
/**
* @return the name of the column that inherits the ID.
*/
@Deprecated
public String getColumnID() {
return Col.ID.get();
}
/**
* @return the name of the column that inherits the UUID.
*/
@Deprecated
public String getColumnUUID() {
return Col.UUID.get();
}
/**
* Get UUID of a player.
*
@ -291,11 +275,6 @@ public class UsersTable extends UserIDTable {
});
}
@Deprecated
public String getColumnName() {
return Col.USER_NAME.get();
}
public Map<UUID, UserInfo> getUsers() {
String sql = Select.all(tableName).toString();

View File

@ -3,6 +3,7 @@ package com.djrapitops.plan.system.database.databases.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.keys.SessionKeys;
import com.djrapitops.plan.data.time.GMTimes;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
@ -123,7 +124,7 @@ public class WorldTimesTable extends UserIDTable {
gmMap.put(gms[3], set.getLong(Col.SPECTATOR.get()));
GMTimes gmTimes = new GMTimes(gmMap);
session.getWorldTimes().setGMTimesForWorld(worldName, gmTimes);
session.getUnsafe(SessionKeys.WORLD_TIMES).setGMTimesForWorld(worldName, gmTimes);
}
return null;
}
@ -293,7 +294,7 @@ public class WorldTimesTable extends UserIDTable {
for (UUID serverUUID : map.keySet()) {
for (List<Session> sessions : map.get(serverUUID).values()) {
for (Session session : sessions) {
WorldTimes worldTimes = worldTimesBySessionID.get(session.getSessionID());
WorldTimes worldTimes = worldTimesBySessionID.get(session.getUnsafe(SessionKeys.DB_ID));
if (worldTimes != null) {
session.setWorldTimes(worldTimes);
}
@ -310,7 +311,7 @@ public class WorldTimesTable extends UserIDTable {
.map(Map::values)
.flatMap(Collection::stream)
.flatMap(Collection::stream)
.map(Session::getWorldTimes)
.map(s -> s.getUnsafe(SessionKeys.WORLD_TIMES))
.map(WorldTimes::getWorldTimes)
.map(Map::keySet)
.flatMap(Collection::stream)
@ -331,9 +332,10 @@ public class WorldTimesTable extends UserIDTable {
List<Session> sessions = entry.getValue();
// Every Session
for (Session session : sessions) {
int sessionID = session.getSessionID();
int sessionID = session.getUnsafe(SessionKeys.DB_ID);
// Every WorldTimes
for (Map.Entry<String, GMTimes> worldTimesEntry : session.getWorldTimes().getWorldTimes().entrySet()) {
for (Map.Entry<String, GMTimes> worldTimesEntry : session.getUnsafe(SessionKeys.WORLD_TIMES)
.getWorldTimes().entrySet()) {
String worldName = worldTimesEntry.getKey();
GMTimes gmTimes = worldTimesEntry.getValue();
statement.setString(1, uuid.toString());

View File

@ -22,36 +22,6 @@ public class AnalysisUtils {
/* static method class.*/
}
@Deprecated
public static long getNewPlayers(List<Long> registered, long scale, long now) {
long newPlayers = 0;
if (!registered.isEmpty()) {
newPlayers = registered.stream()
.filter(Objects::nonNull)
.filter(reg -> reg > now - scale)
.count();
}
// Filters out register dates before scale
return newPlayers;
}
@Deprecated
public static int getUniquePlayers(Map<UUID, List<Session>> sessions, long after) {
Set<UUID> uuids = new HashSet<>();
for (Map.Entry<UUID, List<Session>> entry : sessions.entrySet()) {
UUID uuid = entry.getKey();
for (Session session : entry.getValue()) {
if (session.getSessionStart() >= after) {
uuids.add(uuid);
break;
}
}
}
return uuids.size();
}
/**
* Transforms the session start list into a list of int arrays.
* <p>

View File

@ -2,10 +2,6 @@ package com.djrapitops.plan.utilities.html;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.Settings;
import org.apache.commons.text.StringSubstitutor;
import java.io.Serializable;
import java.util.Map;
/**
* @author Rsl1122
@ -19,21 +15,6 @@ public class HtmlUtils {
throw new IllegalStateException("Utility class");
}
/**
* Replaces ${placeholder} placeholders.
*
* @param html Html to replace placeholders from
* @param replaceMap Placeholders and values
* @return Html with placeholders replaced
* @deprecated Use {@link com.djrapitops.plan.data.store.mutators.formatting.PlaceholderReplacer} instead.
*/
@Deprecated
public static String replacePlaceholders(String html, Map<String, Serializable> replaceMap) {
StringSubstitutor sub = new StringSubstitutor(replaceMap);
sub.setEnableSubstitutionInVariables(true);
return sub.replace(html);
}
/**
* Used to get the WebServer's IP with Port.
*

View File

@ -6,6 +6,7 @@
package com.djrapitops.plan.utilities.html.graphs;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.keys.SessionKeys;
import com.djrapitops.plan.utilities.analysis.AnalysisUtils;
import java.util.Collection;
@ -74,7 +75,7 @@ public class PunchCardGraph implements HighChart {
private static List<Long> getSessionStarts(Collection<Session> data) {
return data.stream()
.filter(Objects::nonNull)
.map(Session::getSessionStart)
.map(s -> s.getUnsafe(SessionKeys.START))
.sorted()
.collect(Collectors.toList());
}

View File

@ -8,6 +8,7 @@ import com.djrapitops.plan.data.container.PlayerKill;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.containers.PlayerContainer;
import com.djrapitops.plan.data.store.keys.PlayerKeys;
import com.djrapitops.plan.data.store.keys.SessionKeys;
import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
import com.djrapitops.plan.system.settings.theme.Theme;
@ -93,11 +94,11 @@ public class PlayerCalendar {
String length = timeFormatter.apply(session.getLength());
series.append(",{title: 'Session: ").append(length)
.append("',start:").append(session.getSessionStart())
.append(",end:").append(session.getSessionEnd())
.append("',start:").append(session.getUnsafe(SessionKeys.START))
.append(",end:").append(session.getUnsafe(SessionKeys.END))
.append("}");
for (PlayerKill kill : session.getPlayerKills()) {
for (PlayerKill kill : session.getUnsafe(SessionKeys.PLAYER_KILLS)) {
long time = kill.getDate();
series.append(",{title: 'Killed: ").append(kill.getVictim())

View File

@ -27,11 +27,6 @@ public class AbstractPieChart implements HighChart {
this.slices = slices;
}
@Deprecated
public static String createSeries(List<PieSlice> slices) {
return new AbstractPieChart(slices).toHighChartsSeries();
}
@Override
public String toHighChartsSeries() {
StringBuilder seriesBuilder = new StringBuilder("[");

View File

@ -15,10 +15,7 @@ import com.djrapitops.plan.data.store.containers.AnalysisContainer;
import com.djrapitops.plan.data.store.containers.NetworkContainer;
import com.djrapitops.plan.data.store.containers.PlayerContainer;
import com.djrapitops.plan.data.store.containers.ServerContainer;
import com.djrapitops.plan.data.store.keys.AnalysisKeys;
import com.djrapitops.plan.data.store.keys.NetworkKeys;
import com.djrapitops.plan.data.store.keys.PlayerKeys;
import com.djrapitops.plan.data.store.keys.ServerKeys;
import com.djrapitops.plan.data.store.keys.*;
import com.djrapitops.plan.data.store.objects.Nickname;
import com.djrapitops.plan.data.time.GMTimes;
import com.djrapitops.plan.data.time.WorldTimes;
@ -359,7 +356,7 @@ public class SQLiteTest {
long expectedLength = 10000L;
assertEquals(expectedLength, session.getLength());
assertEquals(expectedLength, session.getWorldTimes().getTotal());
assertEquals(expectedLength, session.getUnsafe(SessionKeys.WORLD_TIMES).getTotal());
SessionsTable sessionsTable = db.getSessionsTable();
sessionsTable.saveSession(playerUUID, session);
@ -786,7 +783,7 @@ public class SQLiteTest {
sessions.put(1, session);
worldTimesTable.addWorldTimesToSessions(playerUUID, sessions);
assertEquals(worldTimes, session.getWorldTimes());
assertEquals(worldTimes, session.getUnsafe(SessionKeys.WORLD_TIMES));
}
@Test
@ -833,7 +830,7 @@ public class SQLiteTest {
Map<UUID, Map<UUID, List<Session>>> allSessions = sessionsTable.getAllSessions(true);
assertEquals(worldTimes, allSessions.get(serverUUID).get(playerUUID).get(0).getWorldTimes());
assertEquals(worldTimes, allSessions.get(serverUUID).get(playerUUID).get(0).getUnsafe(SessionKeys.WORLD_TIMES));
}
@Test

View File

@ -1,40 +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 com.djrapitops.plan.utilities.analysis;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* @author Rsl1122
*/
public class AnalysisUtilsTest {
@Test
public void testGetNewPlayers() {
List<Long> registered = Arrays.asList(5L, 1L);
long scale = 8L;
long now = 10L;
long result = AnalysisUtils.getNewPlayers(registered, scale, now);
assertEquals(1L, result);
}
@Test
public void testGetNewPlayersEmpty() {
long scale = 1L;
long now = 2L;
long result = AnalysisUtils.getNewPlayers(Collections.emptyList(), scale, now);
assertEquals(0L, result);
}
}

View File

@ -5,6 +5,7 @@ import com.djrapitops.plan.data.container.GeoInfo;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.data.container.UserInfo;
import com.djrapitops.plan.data.store.keys.SessionKeys;
import com.djrapitops.plan.system.settings.locale.Message;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.PassEncryptUtil;
@ -37,12 +38,12 @@ public class ComparatorTest {
public void sessionDataComparator() {
List<Session> sessions = RandomData.randomSessions();
List<Long> expected = sessions.stream().map(Session::getSessionStart)
List<Long> expected = sessions.stream().map(s -> s.getUnsafe(SessionKeys.START))
.sorted(Long::compare).collect(Collectors.toList());
Collections.reverse(expected);
sessions.sort(new SessionStartComparator());
List<Long> result = sessions.stream().map(Session::getSessionStart).collect(Collectors.toList());
List<Long> result = sessions.stream().map(s -> s.getUnsafe(SessionKeys.START)).collect(Collectors.toList());
assertEquals(expected, result);
}

View File

@ -5,49 +5,16 @@
*/
package com.djrapitops.plan.utilities.html;
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import utilities.RandomData;
import java.io.Serializable;
import java.util.Map;
import static org.junit.Assert.assertEquals;
/**
* @author Rsl1122
*/
//@RunWith(PowerMockRunner.class)
//@PrepareForTest(JavaPlugin.class)
public class HtmlUtilsTest {
@Test
public void testReplacePlaceholders() {
String randomString = RandomData.randomString(100);
String randomIdentifier = RandomData.randomString(5);
String html = "${" + randomIdentifier + "}" + randomString;
Map<String, Serializable> replaceMap = ImmutableMap.of(randomIdentifier, "Success");
String expResult = "Success" + randomString;
String result = HtmlUtils.replacePlaceholders(html, replaceMap);
assertEquals(expResult, result);
}
@Test
public void testReplacePlaceholdersBackslash() {
String randomIdentifier = RandomData.randomString(5);
Map<String, Serializable> replace = ImmutableMap.of(randomIdentifier, "/\\");
String expResult = "/\\ alright /\\";
String result = HtmlUtils.replacePlaceholders("${" + randomIdentifier + "} alright ${" + randomIdentifier + "}", replace);
assertEquals(result, expResult);
}
@Test
public void testRemoveXSS() {
String randomString = RandomData.randomString(10);