mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 11:08:08 +01:00
Add Graph Tests
This commit is contained in:
parent
68f8159027
commit
7de5072bc5
@ -32,7 +32,6 @@ public class MySQLDB extends SQLDB {
|
||||
String port = config.getString("Database.MySQL.Port");
|
||||
String database = config.getString("Database.MySQL.Database");
|
||||
|
||||
|
||||
dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "/" + database + "?rewriteBatchedStatements=true");
|
||||
|
||||
String username = config.getString("Database.MySQL.User");
|
||||
|
@ -1,11 +1,8 @@
|
||||
package main.java.com.djrapitops.plan.ui.html.graphs;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.Point;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -27,12 +24,4 @@ public class PlayerActivityGraphCreator {
|
||||
.collect(Collectors.toList());
|
||||
return SeriesCreator.seriesGraph(points, true);
|
||||
}
|
||||
|
||||
public static String buildSeriesDataStringSessions(Collection<Session> sessions) {
|
||||
List<Point> points = sessions.stream()
|
||||
.map(session -> new Point[]{new Point(session.getSessionStart(), 1), new Point(session.getSessionEnd(), 0)})
|
||||
.flatMap(Arrays::stream)
|
||||
.collect(Collectors.toList());
|
||||
return SeriesCreator.seriesGraph(points, true, false);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.utilities.analysis;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
@ -25,4 +27,18 @@ public class Point {
|
||||
public String toString() {
|
||||
return "{x:" + x + " y:" + y + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Point point = (Point) o;
|
||||
return Double.compare(point.x, x) == 0 &&
|
||||
Double.compare(point.y, y) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(x, y);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.ui.graphs;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.ui.html.graphs.*;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.Point;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import test.java.utils.RandomData;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
public class GraphTest {
|
||||
|
||||
private List<TPS> tpsList = new ArrayList<>();
|
||||
private List<Session> sessionList = new ArrayList<>();
|
||||
private Map<String, Integer> geoList = new HashMap<>();
|
||||
private Map<String, Long> worldTimes = new HashMap<>();
|
||||
|
||||
private List<Point> points = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
tpsList.add(new TPS(i, i, i, i, i, i, i));
|
||||
sessionList.add(new Session(i, (long) i, (long) i, i, i));
|
||||
geoList.put(String.valueOf(i), i);
|
||||
worldTimes.put(String.valueOf(i), (long) i);
|
||||
}
|
||||
|
||||
points = RandomData.randomPoints();
|
||||
}
|
||||
|
||||
@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}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSeriesCreator() {
|
||||
String result = SeriesCreator.seriesGraph(points, false, false);
|
||||
String[] splittedResult = result.split(",");
|
||||
|
||||
Map<String, String> expected = new LinkedHashMap<>();
|
||||
|
||||
String key = null;
|
||||
for (String resultString : splittedResult) {
|
||||
resultString = resultString.replaceAll("[\\[\\]]", "");
|
||||
|
||||
if (key == null) {
|
||||
key = resultString;
|
||||
} else {
|
||||
expected.put(key, resultString);
|
||||
key = null;
|
||||
}
|
||||
}
|
||||
|
||||
int i2 = 0;
|
||||
for (Map.Entry<String, String> entry : expected.entrySet()) {
|
||||
String expectedX = entry.getKey();
|
||||
String expectedY = entry.getValue();
|
||||
|
||||
Point point = points.get(i2);
|
||||
|
||||
assertEquals("Given X does not match expected X", expectedX, String.valueOf((long) point.getX()));
|
||||
assertEquals("Given Y does not match expected Y", expectedY, String.valueOf(point.getY()));
|
||||
|
||||
i2++;
|
||||
}
|
||||
}
|
||||
}
|
@ -20,22 +20,13 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class NewPlayerCreatorTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public NewPlayerCreatorTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ public class PassEncryptTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
String password = RandomData.randomString(RandomData.randomInt(1, 50));
|
||||
String password = RandomData.randomString(RandomData.randomInt(1, 20));
|
||||
PASSWORD_MAP.put(password, PassEncryptUtil.createHash(password));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -23,18 +23,12 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
||||
*/
|
||||
public class MockUtils {
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static World mockWorld() {
|
||||
World mockWorld = Mockito.mock(World.class);
|
||||
when(mockWorld.toString()).thenReturn("World");
|
||||
return mockWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static IPlayer mockIPlayer() {
|
||||
return Fetch.wrapBukkit(mockPlayer());
|
||||
}
|
||||
@ -54,16 +48,10 @@ public class MockUtils {
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static UUID getPlayerUUID() {
|
||||
return UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static IPlayer mockIPlayer2() {
|
||||
return Fetch.wrapBukkit(mockPlayer2());
|
||||
}
|
||||
@ -83,9 +71,6 @@ public class MockUtils {
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static UUID getPlayer2UUID() {
|
||||
return UUID.fromString("ec94a954-1fa1-445b-b09b-9b698519af80");
|
||||
}
|
||||
@ -97,9 +82,6 @@ public class MockUtils {
|
||||
return uuids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static IPlayer mockBrokenPlayer() {
|
||||
Player p = PowerMockito.mock(Player.class);
|
||||
when(p.getGameMode()).thenReturn(GameMode.SURVIVAL);
|
||||
@ -114,9 +96,6 @@ public class MockUtils {
|
||||
return Fetch.wrapBukkit(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static CommandSender mockConsoleSender() {
|
||||
return PowerMockito.mock(CommandSender.class);
|
||||
}
|
||||
|
@ -34,12 +34,6 @@ public class TestInit {
|
||||
|
||||
private Plan planMock;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public TestInit() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Init locale with empty messages.
|
||||
* <p>
|
||||
|
Loading…
Reference in New Issue
Block a user