mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-28 12:07:35 +01:00
Created a better test dataset
This commit is contained in:
parent
9fbf354cdd
commit
8a13f1d792
@ -604,6 +604,11 @@ public abstract class CommonDBTest {
|
||||
assertFalse("All users were deleted!! D:", found.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverBaseUserQueriesDoesNotReturnDuplicateUsers() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKillTableGetKillsOfServer() {
|
||||
saveUserOne();
|
||||
|
@ -26,10 +26,12 @@ import java.util.UUID;
|
||||
public class TestConstants {
|
||||
|
||||
public static final UUID SERVER_UUID = UUID.fromString("e4ec2edd-e0ed-3c58-a87d-8a9021899479");
|
||||
public static final UUID SERVER_TWO_UUID = UUID.fromString("c4ec2edd-e0ed-3c58-a87d-8a9024791899");
|
||||
public static final UUID PLAYER_ONE_UUID = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
public static final UUID PLAYER_TWO_UUID = UUID.fromString("ec94a954-1fa1-445b-b09b-9b698519af80");
|
||||
|
||||
public static final String PLAYER_ONE_NAME = "Test_Player_one";
|
||||
public static final String PLAYER_TWO_NAME = "Test_Player_two";
|
||||
|
||||
public static final String WORLD_ONE_NAME = "World One";
|
||||
|
||||
|
177
Plan/common/src/test/java/utilities/TestData.java
Normal file
177
Plan/common/src/test/java/utilities/TestData.java
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* 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 GNU 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
|
||||
* GNU 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 utilities;
|
||||
|
||||
import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
import com.djrapitops.plan.db.access.transactions.StoreServerInformationTransaction;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.db.access.transactions.events.*;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Class for saving test data to a database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TestData {
|
||||
|
||||
private static UUID playerUUID = TestConstants.PLAYER_ONE_UUID;
|
||||
private static UUID player2UUID = TestConstants.PLAYER_TWO_UUID;
|
||||
private static UUID serverUUID = TestConstants.SERVER_UUID;
|
||||
private static UUID server2UUID = TestConstants.SERVER_TWO_UUID;
|
||||
private static String playerName = TestConstants.PLAYER_ONE_NAME;
|
||||
private static String player2Name = TestConstants.PLAYER_TWO_NAME;
|
||||
|
||||
private static String[] serverWorldNames = new String[]{
|
||||
TestConstants.WORLD_ONE_NAME, "World Two", "world"
|
||||
};
|
||||
private static String[] server2WorldNames = new String[]{
|
||||
"Foo", "Bar", "Z"
|
||||
};
|
||||
|
||||
private static long playerFirstJoin = 1234500L;
|
||||
private static long playerSecondJoin = 234000L;
|
||||
|
||||
private static List<Session> playerSessions = createSessionsForPlayer(playerUUID);
|
||||
private static List<Session> player2Sessions = createSessionsForPlayer(player2UUID);
|
||||
|
||||
private static List<GeoInfo> playerGeoInfo = createGeoInfoForPlayer();
|
||||
|
||||
private static List<GeoInfo> createGeoInfoForPlayer() {
|
||||
List<GeoInfo> geoInfos = new ArrayList<>();
|
||||
|
||||
try {
|
||||
geoInfos.add(new GeoInfo(InetAddress.getByName("1.2.3.4"), "Not Known", playerFirstJoin));
|
||||
geoInfos.add(new GeoInfo(InetAddress.getByName("43b9:416b:3cb2:649d:ebaf:872:d89a:343d"), "Not Known", playerFirstJoin));
|
||||
geoInfos.add(new GeoInfo(InetAddress.getByName("127.0.0.1"), "Local Machine", playerFirstJoin));
|
||||
geoInfos.add(new GeoInfo(InetAddress.getByName("181.103.227.78"), "Argentina", playerFirstJoin));
|
||||
} catch (UnknownHostException | NoSuchAlgorithmException e) {
|
||||
Logger.getGlobal().log(Level.WARNING, e, () -> "Failed to create GeoInfo");
|
||||
}
|
||||
|
||||
return geoInfos;
|
||||
}
|
||||
|
||||
private static List<Session> createSessionsForPlayer(UUID uuid) {
|
||||
List<Session> sessions = new ArrayList<>();
|
||||
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
|
||||
Session sessionOne = new Session(uuid, serverUUID, playerFirstJoin, serverWorldNames[0], gms[0]);
|
||||
|
||||
UUID otherUUID = uuid.equals(playerUUID) ? player2UUID : playerUUID;
|
||||
sessionOne.playerKilled(new PlayerKill(otherUUID, "Iron Sword", 1234750L));
|
||||
sessionOne.playerKilled(new PlayerKill(otherUUID, "Gold Sword", 1234800L));
|
||||
|
||||
sessionOne.endSession(1235000L); // Length 500ms
|
||||
sessions.add(sessionOne);
|
||||
|
||||
Session sessionTwo = new Session(uuid, server2UUID, playerSecondJoin, server2WorldNames[0], gms[1]);
|
||||
sessionTwo.changeState(server2WorldNames[1], gms[0], 334000L); // Length 100s
|
||||
sessionTwo.endSession(434000L); // Length 200s
|
||||
sessions.add(sessionTwo);
|
||||
|
||||
return sessions;
|
||||
}
|
||||
|
||||
public static Transaction storeServers() {
|
||||
return new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
executeOther(new StoreServerInformationTransaction(new Server(-1, serverUUID, "Server 1", "", 20)));
|
||||
executeOther(new StoreServerInformationTransaction(new Server(-1, server2UUID, "Server 2", "", 50)));
|
||||
|
||||
for (String worldName : serverWorldNames) {
|
||||
executeOther(new WorldNameStoreTransaction(serverUUID, worldName));
|
||||
}
|
||||
for (String worldName : server2WorldNames) {
|
||||
executeOther(new WorldNameStoreTransaction(server2UUID, worldName));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Transaction storePlayerOneData() {
|
||||
return new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
executeOther(new PlayerRegisterTransaction(playerUUID, () -> playerFirstJoin, playerName));
|
||||
executeOther(new PlayerServerRegisterTransaction(playerUUID, () -> playerFirstJoin, playerName, serverUUID));
|
||||
executeOther(new PlayerServerRegisterTransaction(playerUUID, () -> playerSecondJoin, playerName, server2UUID));
|
||||
|
||||
for (GeoInfo geoInfo : playerGeoInfo) {
|
||||
executeOther(new GeoInfoStoreTransaction(playerUUID, geoInfo));
|
||||
}
|
||||
|
||||
for (Session session : playerSessions) {
|
||||
executeOther(new SessionEndTransaction(session));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Transaction storePlayerTwoData() {
|
||||
return new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
executeOther(new PlayerRegisterTransaction(player2UUID, () -> playerFirstJoin, player2Name));
|
||||
executeOther(new PlayerServerRegisterTransaction(player2UUID, () -> playerFirstJoin, player2Name, serverUUID));
|
||||
executeOther(new PlayerServerRegisterTransaction(player2UUID, () -> playerSecondJoin, player2Name, server2UUID));
|
||||
|
||||
for (GeoInfo geoInfo : playerGeoInfo) {
|
||||
executeOther(new GeoInfoStoreTransaction(player2UUID, geoInfo));
|
||||
}
|
||||
|
||||
for (Session session : player2Sessions) {
|
||||
executeOther(new SessionEndTransaction(session));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static String[] getServerWorldNames() {
|
||||
return serverWorldNames;
|
||||
}
|
||||
|
||||
public static String[] getServer2WorldNames() {
|
||||
return server2WorldNames;
|
||||
}
|
||||
|
||||
public static List<Session> getPlayerSessions() {
|
||||
return playerSessions;
|
||||
}
|
||||
|
||||
public static List<Session> getPlayer2Sessions() {
|
||||
return player2Sessions;
|
||||
}
|
||||
|
||||
public static List<GeoInfo> getPlayerGeoInfo() {
|
||||
return playerGeoInfo;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user