mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 03:27:37 +01:00
Updated most tests in 'common' to JUnit 5
Not included: - CommonDBTest (abstract) and it's extensions. JUnit 5 does not support recursive test discovery. Different method needs to be implemented for these to move over.
This commit is contained in:
parent
74bf3901bc
commit
cbdaa3255a
@ -24,7 +24,6 @@ import java.util.Map;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DataContainer implementation that stores everything in {@link Supplier} objects.
|
* DataContainer implementation that stores everything in {@link Supplier} objects.
|
||||||
@ -129,6 +128,11 @@ public class SupplierDataContainer implements DataContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Key, Object> getMap() {
|
public Map<Key, Object> getMap() {
|
||||||
return map.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get()));
|
// Fetches all objects from their Suppliers.
|
||||||
|
Map<Key, Object> objectMap = new HashMap<>();
|
||||||
|
for (Map.Entry<Key, Supplier> entry : map.entrySet()) {
|
||||||
|
objectMap.put(entry.getKey(), entry.getValue().get());
|
||||||
|
}
|
||||||
|
return objectMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -40,7 +40,9 @@ import java.net.InetAddress;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
@ -150,7 +152,12 @@ public class GeolocationCache implements SubSystem {
|
|||||||
try {
|
try {
|
||||||
checkDB();
|
checkDB();
|
||||||
|
|
||||||
try (DatabaseReader reader = new DatabaseReader.Builder(geolocationDB).build()) {
|
try (
|
||||||
|
// See https://github.com/maxmind/MaxMind-DB-Reader-java#file-lock-on-windows
|
||||||
|
// for why InputStream is being used here instead.
|
||||||
|
InputStream in = Files.newInputStream(geolocationDB.toPath());
|
||||||
|
DatabaseReader reader = new DatabaseReader.Builder(in).build()
|
||||||
|
) {
|
||||||
InetAddress inetAddress = InetAddress.getByName(ipAddress);
|
InetAddress inetAddress = InetAddress.getByName(ipAddress);
|
||||||
|
|
||||||
CountryResponse response = reader.country(inetAddress);
|
CountryResponse response = reader.country(inetAddress);
|
||||||
@ -178,9 +185,10 @@ public class GeolocationCache implements SubSystem {
|
|||||||
InputStream in = downloadSite.openStream();
|
InputStream in = downloadSite.openStream();
|
||||||
GZIPInputStream gzipIn = new GZIPInputStream(in);
|
GZIPInputStream gzipIn = new GZIPInputStream(in);
|
||||||
ReadableByteChannel rbc = Channels.newChannel(gzipIn);
|
ReadableByteChannel rbc = Channels.newChannel(gzipIn);
|
||||||
FileOutputStream fos = new FileOutputStream(geolocationDB.getAbsoluteFile())
|
FileOutputStream fos = new FileOutputStream(geolocationDB.getAbsoluteFile());
|
||||||
|
FileChannel channel = fos.getChannel()
|
||||||
) {
|
) {
|
||||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
channel.transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ import static org.mockito.Mockito.when;
|
|||||||
*/
|
*/
|
||||||
@RunWith(JUnitPlatform.class)
|
@RunWith(JUnitPlatform.class)
|
||||||
@ExtendWith(PrintExtension.class)
|
@ExtendWith(PrintExtension.class)
|
||||||
public class ShutdownSaveTest {
|
class ShutdownSaveTest {
|
||||||
|
|
||||||
private boolean shutdownStatus;
|
private boolean shutdownStatus;
|
||||||
private ServerShutdownSave underTest;
|
private ServerShutdownSave underTest;
|
||||||
|
@ -17,47 +17,50 @@
|
|||||||
package com.djrapitops.plan.data;
|
package com.djrapitops.plan.data;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.container.PlayerKill;
|
import com.djrapitops.plan.data.container.PlayerKill;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link PlayerKill}.
|
* Tests for {@link PlayerKill}.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class PlayerKillTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class PlayerKillTest {
|
||||||
|
|
||||||
private String weapon = RandomData.randomString(10);
|
private String weapon = RandomData.randomString(10);
|
||||||
private UUID testUUID = UUID.randomUUID();
|
private UUID testUUID = UUID.randomUUID();
|
||||||
private PlayerKill underTest = new PlayerKill(testUUID, weapon, 100L);
|
private PlayerKill underTest = new PlayerKill(testUUID, weapon, 100L);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void victimUUIDIsReturned() {
|
void victimUUIDIsReturned() {
|
||||||
assertEquals(testUUID, underTest.getVictim());
|
assertEquals(testUUID, underTest.getVictim());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dateIsReturned() {
|
void dateIsReturned() {
|
||||||
assertEquals(100L, underTest.getDate());
|
assertEquals(100L, underTest.getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void weaponIsReturned() {
|
void weaponIsReturned() {
|
||||||
assertEquals(weapon, underTest.getWeapon());
|
assertEquals(weapon, underTest.getWeapon());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noVictimFound() {
|
void noVictimFound() {
|
||||||
assertFalse(underTest.getVictimName().isPresent());
|
assertFalse(underTest.getVictimName().isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void victimFound() {
|
void victimFound() {
|
||||||
String expectedName = "Test Victim";
|
String expectedName = "Test Victim";
|
||||||
PlayerKill underTest = new PlayerKill(testUUID, weapon, 100L, expectedName);
|
PlayerKill underTest = new PlayerKill(testUUID, weapon, 100L, expectedName);
|
||||||
assertEquals("Test Victim", underTest.getVictimName().orElse("Unknown"));
|
assertEquals("Test Victim", underTest.getVictimName().orElse("Unknown"));
|
||||||
|
@ -18,15 +18,18 @@ package com.djrapitops.plan.data.cache;
|
|||||||
|
|
||||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
|
|
||||||
import static junit.framework.TestCase.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fuzzlemann
|
* @author Fuzzlemann
|
||||||
*/
|
*/
|
||||||
public class ResponseCacheTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class ResponseCacheTest {
|
||||||
private final String IDENTIFIER = RandomData.randomString(10);
|
private final String IDENTIFIER = RandomData.randomString(10);
|
||||||
private final String RESPONSE_STRING = RandomData.randomString(10);
|
private final String RESPONSE_STRING = RandomData.randomString(10);
|
||||||
private final Response RESPONSE = new Response() {
|
private final Response RESPONSE = new Response() {
|
||||||
@ -37,7 +40,7 @@ public class ResponseCacheTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCache() {
|
void responseIsCachedIfNotFoundDuringLoad() {
|
||||||
assertFalse(ResponseCache.isCached(IDENTIFIER));
|
assertFalse(ResponseCache.isCached(IDENTIFIER));
|
||||||
|
|
||||||
Response response = ResponseCache.loadResponse(IDENTIFIER, () -> RESPONSE);
|
Response response = ResponseCache.loadResponse(IDENTIFIER, () -> RESPONSE);
|
||||||
@ -47,7 +50,7 @@ public class ResponseCacheTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClearCache() {
|
void responseIsClearedWhenCacheIsCleared() {
|
||||||
ResponseCache.cacheResponse(IDENTIFIER, () -> RESPONSE);
|
ResponseCache.cacheResponse(IDENTIFIER, () -> RESPONSE);
|
||||||
assertTrue(ResponseCache.isCached(IDENTIFIER));
|
assertTrue(ResponseCache.isCached(IDENTIFIER));
|
||||||
|
|
||||||
|
@ -16,23 +16,26 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.data.container;
|
package com.djrapitops.plan.data.container;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for functionality of GeoInfo object.
|
* Test for functionality of GeoInfo object.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class GeoInfoTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class GeoInfoTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void automaticallyHidesLast16Bits() throws NoSuchAlgorithmException, UnknownHostException {
|
void automaticallyHidesLast16Bits() throws NoSuchAlgorithmException, UnknownHostException {
|
||||||
InetAddress test = InetAddress.getByName("1.2.3.4");
|
InetAddress test = InetAddress.getByName("1.2.3.4");
|
||||||
String expected = "1.2.xx.xx";
|
String expected = "1.2.xx.xx";
|
||||||
String result = new GeoInfo(test, "Irrelevant", 3).getIp();
|
String result = new GeoInfo(test, "Irrelevant", 3).getIp();
|
||||||
@ -41,7 +44,7 @@ public class GeoInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatIP() throws UnknownHostException {
|
void testFormatIP() throws UnknownHostException {
|
||||||
InetAddress ip = InetAddress.getByName("1.2.3.4");
|
InetAddress ip = InetAddress.getByName("1.2.3.4");
|
||||||
InetAddress ip2 = InetAddress.getByName("1.2.3.26");
|
InetAddress ip2 = InetAddress.getByName("1.2.3.26");
|
||||||
InetAddress ip3 = InetAddress.getByName("1.2.3.235");
|
InetAddress ip3 = InetAddress.getByName("1.2.3.235");
|
||||||
@ -53,7 +56,7 @@ public class GeoInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatIPv6() throws UnknownHostException {
|
void testFormatIPv6() throws UnknownHostException {
|
||||||
InetAddress ip = InetAddress.getByName("1234:1234:1234:1234:1234:1234:1234:1234%0");
|
InetAddress ip = InetAddress.getByName("1234:1234:1234:1234:1234:1234:1234:1234%0");
|
||||||
String expected = "1234:1234:1234:xx..";
|
String expected = "1234:1234:1234:xx..";
|
||||||
|
|
||||||
|
@ -18,26 +18,29 @@ package com.djrapitops.plan.data.container;
|
|||||||
|
|
||||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||||
import com.djrapitops.plan.data.time.WorldTimes;
|
import com.djrapitops.plan.data.time.WorldTimes;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.TestConstants;
|
import utilities.TestConstants;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link Session} {@link com.djrapitops.plan.data.store.containers.DataContainer}.
|
* Test for {@link Session} {@link com.djrapitops.plan.data.store.containers.DataContainer}.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class SessionTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class SessionTest {
|
||||||
|
|
||||||
private final UUID serverUUID = TestConstants.SERVER_UUID;
|
private final UUID serverUUID = TestConstants.SERVER_UUID;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void safeStartKeyConstructor() {
|
void safeStartKeyConstructor() {
|
||||||
for (int i = 0; i < 10000; i++) {
|
for (int i = 0; i < 10000; i++) {
|
||||||
Session session = new Session(null, serverUUID, System.currentTimeMillis(), null, null);
|
Session session = new Session(null, serverUUID, System.currentTimeMillis(), null, null);
|
||||||
|
|
||||||
@ -47,7 +50,7 @@ public class SessionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void safeStartKeyDBConstructor() {
|
void safeStartKeyDBConstructor() {
|
||||||
for (int i = 0; i < 10000; i++) {
|
for (int i = 0; i < 10000; i++) {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
Session session = new Session(-1, null, null, time, time + 1, 0, 0, 0);
|
Session session = new Session(-1, null, null, time, time + 1, 0, 0, 0);
|
||||||
@ -58,7 +61,7 @@ public class SessionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void killsAreAdded() {
|
void killsAreAdded() {
|
||||||
Session session = new Session(null, serverUUID, System.currentTimeMillis(), "", "");
|
Session session = new Session(null, serverUUID, System.currentTimeMillis(), "", "");
|
||||||
|
|
||||||
Optional<List<PlayerKill>> beforeOptional = session.getValue(SessionKeys.PLAYER_KILLS);
|
Optional<List<PlayerKill>> beforeOptional = session.getValue(SessionKeys.PLAYER_KILLS);
|
||||||
@ -77,7 +80,7 @@ public class SessionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void killsAreAdded2() {
|
void killsAreAdded2() {
|
||||||
Session session = new Session(null, serverUUID, System.currentTimeMillis(), "", "");
|
Session session = new Session(null, serverUUID, System.currentTimeMillis(), "", "");
|
||||||
|
|
||||||
session.playerKilled(new PlayerKill(TestConstants.PLAYER_TWO_UUID, "Weapon", System.currentTimeMillis()));
|
session.playerKilled(new PlayerKill(TestConstants.PLAYER_TWO_UUID, "Weapon", System.currentTimeMillis()));
|
||||||
@ -90,7 +93,7 @@ public class SessionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void worldTimesWorks() {
|
void worldTimesWorks() {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
Session session = new Session(null, serverUUID, time, "One", "Survival");
|
Session session = new Session(null, serverUUID, time, "One", "Survival");
|
||||||
session.changeState("Two", "Three", time + 5L);
|
session.changeState("Two", "Three", time + 5L);
|
||||||
|
@ -16,51 +16,54 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.data.store;
|
package com.djrapitops.plan.data.store;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Equals test for Key objects.
|
* Equals test for Key objects.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class KeyTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class KeyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void twoInstancesAreEqual() {
|
void twoInstancesAreEqual() {
|
||||||
Key<Integer> testKey = new Key<>(Integer.class, "test");
|
Key<Integer> testKey = new Key<>(Integer.class, "test");
|
||||||
Key<Integer> testKey2 = new Key<>(Integer.class, "test");
|
Key<Integer> testKey2 = new Key<>(Integer.class, "test");
|
||||||
assertEquals(testKey, testKey2);
|
assertEquals(testKey, testKey2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void twoComplexInstancesAreEqual() {
|
void twoComplexInstancesAreEqual() {
|
||||||
Key<List<Integer>> testKey = new Key<>(new Type<List<Integer>>() {}, "test");
|
Key<List<Integer>> testKey = new Key<>(new Type<List<Integer>>() {}, "test");
|
||||||
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
||||||
assertEquals(testKey, testKey2);
|
assertEquals(testKey, testKey2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void twoComplexInstancesAreNotEqual() {
|
void twoComplexInstancesAreNotEqual() {
|
||||||
Key<List<Long>> testKey = new Key<>(new Type<List<Long>>() {}, "test");
|
Key<List<Long>> testKey = new Key<>(new Type<List<Long>>() {}, "test");
|
||||||
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
||||||
assertNotEquals(testKey, testKey2);
|
assertNotEquals(testKey, testKey2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void twoComplexInstancesAreNotEqual2() {
|
void twoComplexInstancesAreNotEqual2() {
|
||||||
Key<ArrayList<Integer>> testKey = new Key<>(new Type<ArrayList<Integer>>() {}, "test");
|
Key<ArrayList<Integer>> testKey = new Key<>(new Type<ArrayList<Integer>>() {}, "test");
|
||||||
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
||||||
assertNotEquals(testKey, testKey2);
|
assertNotEquals(testKey, testKey2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void twoInstancesAreNotEqual() {
|
void twoInstancesAreNotEqual() {
|
||||||
Key<Integer> testKey = new Key<>(Integer.class, "test");
|
Key<Integer> testKey = new Key<>(Integer.class, "test");
|
||||||
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
||||||
assertNotEquals(testKey, testKey2);
|
assertNotEquals(testKey, testKey2);
|
||||||
|
@ -17,22 +17,25 @@
|
|||||||
package com.djrapitops.plan.data.store.containers;
|
package com.djrapitops.plan.data.store.containers;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.store.Key;
|
import com.djrapitops.plan.data.store.Key;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link SupplierDataContainer} programming errors.
|
* Test for {@link SupplierDataContainer} programming errors.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class SupplierDataContainerTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class SupplierDataContainerTest {
|
||||||
|
|
||||||
private static final Key<String> TEST_KEY = new Key<>(String.class, "TEST_KEY");
|
private static final Key<String> TEST_KEY = new Key<>(String.class, "TEST_KEY");
|
||||||
private static final Key<String> TEST_KEY_COPY = new Key<>(String.class, "TEST_KEY");
|
private static final Key<String> TEST_KEY_COPY = new Key<>(String.class, "TEST_KEY");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void safeUnsafeKeySupplierSameObject() {
|
void safeUnsafeKeySupplierSameObject() {
|
||||||
DataContainer container = new SupplierDataContainer();
|
DataContainer container = new SupplierDataContainer();
|
||||||
container.putSupplier(TEST_KEY, () -> "Success");
|
container.putSupplier(TEST_KEY, () -> "Success");
|
||||||
|
|
||||||
@ -40,7 +43,7 @@ public class SupplierDataContainerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void safeUnsafeKeySupplierDifferentObject() {
|
void safeUnsafeKeySupplierDifferentObject() {
|
||||||
DataContainer container = new SupplierDataContainer();
|
DataContainer container = new SupplierDataContainer();
|
||||||
container.putSupplier(TEST_KEY, () -> "Success");
|
container.putSupplier(TEST_KEY, () -> "Success");
|
||||||
|
|
||||||
@ -48,7 +51,7 @@ public class SupplierDataContainerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void safeUnsafeKeyRawSameObject() {
|
void safeUnsafeKeyRawSameObject() {
|
||||||
DataContainer container = new SupplierDataContainer();
|
DataContainer container = new SupplierDataContainer();
|
||||||
container.putRawData(TEST_KEY, "Success");
|
container.putRawData(TEST_KEY, "Success");
|
||||||
|
|
||||||
@ -56,7 +59,7 @@ public class SupplierDataContainerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void safeUnsafeKeyRawDifferentObject() {
|
void safeUnsafeKeyRawDifferentObject() {
|
||||||
DataContainer container = new SupplierDataContainer();
|
DataContainer container = new SupplierDataContainer();
|
||||||
container.putRawData(TEST_KEY, "Success");
|
container.putRawData(TEST_KEY, "Success");
|
||||||
|
|
||||||
@ -64,7 +67,7 @@ public class SupplierDataContainerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void safeUnsafeKeyRawNull() {
|
void safeUnsafeKeyRawNull() {
|
||||||
DataContainer container = new SupplierDataContainer();
|
DataContainer container = new SupplierDataContainer();
|
||||||
container.putRawData(TEST_KEY, null);
|
container.putRawData(TEST_KEY, null);
|
||||||
|
|
||||||
@ -73,7 +76,7 @@ public class SupplierDataContainerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void safeUnsafeKeyNullSupplier() {
|
void safeUnsafeKeyNullSupplier() {
|
||||||
DataContainer container = new SupplierDataContainer();
|
DataContainer container = new SupplierDataContainer();
|
||||||
container.putSupplier(TEST_KEY, null);
|
container.putSupplier(TEST_KEY, null);
|
||||||
|
|
||||||
@ -81,7 +84,7 @@ public class SupplierDataContainerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void safeUnsafeKeySupplierNull() {
|
void safeUnsafeKeySupplierNull() {
|
||||||
DataContainer container = new SupplierDataContainer();
|
DataContainer container = new SupplierDataContainer();
|
||||||
container.putSupplier(TEST_KEY, () -> null);
|
container.putSupplier(TEST_KEY, () -> null);
|
||||||
|
|
||||||
@ -90,7 +93,7 @@ public class SupplierDataContainerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cachingSupplier() {
|
void cachingSupplier() {
|
||||||
DataContainer container = new SupplierDataContainer();
|
DataContainer container = new SupplierDataContainer();
|
||||||
String firstObj = "First";
|
String firstObj = "First";
|
||||||
String secondObj = "Second";
|
String secondObj = "Second";
|
||||||
|
@ -19,8 +19,10 @@ package com.djrapitops.plan.data.store.mutators;
|
|||||||
import com.djrapitops.plan.data.container.TPS;
|
import com.djrapitops.plan.data.container.TPS;
|
||||||
import com.djrapitops.plan.data.container.builders.TPSBuilder;
|
import com.djrapitops.plan.data.container.builders.TPSBuilder;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
import com.djrapitops.plugin.api.TimeAmount;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -28,20 +30,21 @@ import java.util.List;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link TPSMutator}
|
* Tests for {@link TPSMutator}
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class TPSMutatorTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class TPSMutatorTest {
|
||||||
|
|
||||||
private List<TPS> testData;
|
private static List<TPS> testData;
|
||||||
private long time;
|
private static long time;
|
||||||
|
|
||||||
@Before
|
@BeforeAll
|
||||||
public void setUp() {
|
static void setUpTestData() {
|
||||||
testData = new ArrayList<>();
|
testData = new ArrayList<>();
|
||||||
|
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
@ -63,14 +66,14 @@ public class TPSMutatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noDownTimeIsCorrect() {
|
void noDowntimeIsCorrect() {
|
||||||
long expected = 0;
|
long expected = 0;
|
||||||
long result = new TPSMutator(testData).serverDownTime();
|
long result = new TPSMutator(testData).serverDownTime();
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noDownTimeOnSingleEntry() {
|
void noDowntimeOnSingleEntry() {
|
||||||
long expected = 0;
|
long expected = 0;
|
||||||
long result = new TPSMutator(Collections.singletonList(
|
long result = new TPSMutator(Collections.singletonList(
|
||||||
TPSBuilder.get().date(time - TimeUnit.DAYS.toMillis(1L))
|
TPSBuilder.get().date(time - TimeUnit.DAYS.toMillis(1L))
|
||||||
@ -87,7 +90,7 @@ public class TPSMutatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fullDownTime() {
|
void fullDowntime() {
|
||||||
long periodLength = TimeUnit.MINUTES.toMillis(5L);
|
long periodLength = TimeUnit.MINUTES.toMillis(5L);
|
||||||
long expected = TimeAmount.MONTH.toMillis(2L) - periodLength;
|
long expected = TimeAmount.MONTH.toMillis(2L) - periodLength;
|
||||||
|
|
||||||
@ -102,7 +105,7 @@ public class TPSMutatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filteredFullMonthDownTime() {
|
void filteredFullMonthDowntime() {
|
||||||
long periodLength = TimeUnit.MINUTES.toMillis(5L);
|
long periodLength = TimeUnit.MINUTES.toMillis(5L);
|
||||||
long expected = TimeAmount.MONTH.toMillis(1L) - periodLength;
|
long expected = TimeAmount.MONTH.toMillis(1L) - periodLength;
|
||||||
|
|
||||||
@ -120,7 +123,7 @@ public class TPSMutatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filteredFullMonthDownTimeWhenRandomOrder() {
|
void filteredFullMonthDowntimeWhenRandomOrder() {
|
||||||
long periodLength = TimeUnit.MINUTES.toMillis(5L);
|
long periodLength = TimeUnit.MINUTES.toMillis(5L);
|
||||||
long expected = TimeAmount.MONTH.toMillis(1L) - periodLength;
|
long expected = TimeAmount.MONTH.toMillis(1L) - periodLength;
|
||||||
|
|
||||||
@ -140,7 +143,7 @@ public class TPSMutatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filterWorksCorrectly() {
|
void filterWorksCorrectly() {
|
||||||
long monthAgo = time - TimeAmount.MONTH.toMillis(1L);
|
long monthAgo = time - TimeAmount.MONTH.toMillis(1L);
|
||||||
List<TPS> filtered = new TPSMutator(testData).filterDataBetween(monthAgo, time).all();
|
List<TPS> filtered = new TPSMutator(testData).filterDataBetween(monthAgo, time).all();
|
||||||
|
|
||||||
|
@ -19,11 +19,13 @@ package com.djrapitops.plan.data.store.mutators.formatting;
|
|||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.system.settings.paths.FormatSettings;
|
import com.djrapitops.plan.system.settings.paths.FormatSettings;
|
||||||
import com.djrapitops.plan.utilities.formatting.DecimalFormatter;
|
import com.djrapitops.plan.utilities.formatting.DecimalFormatter;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,12 +33,13 @@ import static org.mockito.Mockito.when;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class DecimalFormatterTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class DecimalFormatterTest {
|
||||||
|
|
||||||
private DecimalFormatter underTest;
|
private DecimalFormatter underTest;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUpFormatter() {
|
||||||
PlanConfig config = Mockito.mock(PlanConfig.class);
|
PlanConfig config = Mockito.mock(PlanConfig.class);
|
||||||
when(config.get(FormatSettings.DECIMALS)).thenReturn("#.##");
|
when(config.get(FormatSettings.DECIMALS)).thenReturn("#.##");
|
||||||
|
|
||||||
@ -44,7 +47,7 @@ public class DecimalFormatterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCutDecimalsWhichIsRoundedDown() {
|
void cutDecimalsWhichIsRoundedDown() {
|
||||||
double d = 0.05234;
|
double d = 0.05234;
|
||||||
|
|
||||||
String result = underTest.apply(d);
|
String result = underTest.apply(d);
|
||||||
@ -53,7 +56,7 @@ public class DecimalFormatterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCutDecimalsWhichIsRoundedUp() {
|
void cutDecimalsWhichIsRoundedUp() {
|
||||||
double d = 0.05634;
|
double d = 0.05634;
|
||||||
|
|
||||||
String result = underTest.apply(d);
|
String result = underTest.apply(d);
|
||||||
|
@ -19,13 +19,15 @@ package com.djrapitops.plan.data.store.mutators.formatting;
|
|||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.system.settings.paths.FormatSettings;
|
import com.djrapitops.plan.system.settings.paths.FormatSettings;
|
||||||
import com.djrapitops.plan.utilities.formatting.time.TimeAmountFormatter;
|
import com.djrapitops.plan.utilities.formatting.time.TimeAmountFormatter;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,12 +35,13 @@ import static org.mockito.Mockito.when;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class TimeAmountFormatterDefaultTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class TimeAmountFormatterDefaultTest {
|
||||||
|
|
||||||
private static TimeAmountFormatter underTest;
|
private static TimeAmountFormatter underTest;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpClass() {
|
static void setUpFormatter() {
|
||||||
PlanConfig config = Mockito.mock(PlanConfig.class);
|
PlanConfig config = Mockito.mock(PlanConfig.class);
|
||||||
when(config.get(FormatSettings.YEAR)).thenReturn("1 year, ");
|
when(config.get(FormatSettings.YEAR)).thenReturn("1 year, ");
|
||||||
when(config.get(FormatSettings.YEARS)).thenReturn("%years% years, ");
|
when(config.get(FormatSettings.YEARS)).thenReturn("%years% years, ");
|
||||||
@ -56,7 +59,7 @@ public class TimeAmountFormatterDefaultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleOne() {
|
void exampleOne() {
|
||||||
String expected = "1 year, 1 month, 5d 12h 30m 20s";
|
String expected = "1 year, 1 month, 5d 12h 30m 20s";
|
||||||
|
|
||||||
long ms = TimeUnit.DAYS.toMillis(400L) +
|
long ms = TimeUnit.DAYS.toMillis(400L) +
|
||||||
@ -69,7 +72,7 @@ public class TimeAmountFormatterDefaultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleTwo() {
|
void exampleTwo() {
|
||||||
String expected = "1 year, 1 month, 5d ";
|
String expected = "1 year, 1 month, 5d ";
|
||||||
|
|
||||||
long ms = TimeUnit.DAYS.toMillis(400L);
|
long ms = TimeUnit.DAYS.toMillis(400L);
|
||||||
@ -79,7 +82,7 @@ public class TimeAmountFormatterDefaultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleThree() {
|
void exampleThree() {
|
||||||
String expected = "12h 20s";
|
String expected = "12h 20s";
|
||||||
|
|
||||||
long ms = TimeUnit.HOURS.toMillis(12L) +
|
long ms = TimeUnit.HOURS.toMillis(12L) +
|
||||||
@ -90,7 +93,7 @@ public class TimeAmountFormatterDefaultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleFour() {
|
void exampleFour() {
|
||||||
String expected = "30m ";
|
String expected = "30m ";
|
||||||
|
|
||||||
long ms = TimeUnit.MINUTES.toMillis(30L);
|
long ms = TimeUnit.MINUTES.toMillis(30L);
|
||||||
@ -100,7 +103,7 @@ public class TimeAmountFormatterDefaultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleFive() {
|
void exampleFive() {
|
||||||
String expected = "20s";
|
String expected = "20s";
|
||||||
|
|
||||||
long ms = TimeUnit.SECONDS.toMillis(20L);
|
long ms = TimeUnit.SECONDS.toMillis(20L);
|
||||||
@ -110,7 +113,7 @@ public class TimeAmountFormatterDefaultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleZero() {
|
void exampleZero() {
|
||||||
String expected = "-";
|
String expected = "-";
|
||||||
|
|
||||||
long ms = 0L;
|
long ms = 0L;
|
||||||
@ -120,7 +123,7 @@ public class TimeAmountFormatterDefaultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleOneSecond() {
|
void exampleOneSecond() {
|
||||||
String expected = "1s";
|
String expected = "1s";
|
||||||
|
|
||||||
long ms = TimeUnit.SECONDS.toMillis(1L);
|
long ms = TimeUnit.SECONDS.toMillis(1L);
|
||||||
@ -130,7 +133,7 @@ public class TimeAmountFormatterDefaultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleOneMinute() {
|
void exampleOneMinute() {
|
||||||
String expected = "1m ";
|
String expected = "1m ";
|
||||||
|
|
||||||
long ms = TimeUnit.MINUTES.toMillis(1L);
|
long ms = TimeUnit.MINUTES.toMillis(1L);
|
||||||
|
@ -19,13 +19,15 @@ package com.djrapitops.plan.data.store.mutators.formatting;
|
|||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.system.settings.paths.FormatSettings;
|
import com.djrapitops.plan.system.settings.paths.FormatSettings;
|
||||||
import com.djrapitops.plan.utilities.formatting.time.TimeAmountFormatter;
|
import com.djrapitops.plan.utilities.formatting.time.TimeAmountFormatter;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,12 +35,13 @@ import static org.mockito.Mockito.when;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class TimeAmountFormatterExtraZerosTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class TimeAmountFormatterExtraZerosTest {
|
||||||
|
|
||||||
private static TimeAmountFormatter underTest;
|
private static TimeAmountFormatter underTest;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpClass() {
|
static void setUpFormatter() {
|
||||||
PlanConfig config = Mockito.mock(PlanConfig.class);
|
PlanConfig config = Mockito.mock(PlanConfig.class);
|
||||||
when(config.get(FormatSettings.YEAR)).thenReturn("1 year, ");
|
when(config.get(FormatSettings.YEAR)).thenReturn("1 year, ");
|
||||||
when(config.get(FormatSettings.YEARS)).thenReturn("%years% years, ");
|
when(config.get(FormatSettings.YEARS)).thenReturn("%years% years, ");
|
||||||
@ -54,7 +57,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleOne() {
|
void exampleOne() {
|
||||||
String expected = "1 year, 1 month, 5d 12:30:20";
|
String expected = "1 year, 1 month, 5d 12:30:20";
|
||||||
|
|
||||||
long ms = TimeUnit.DAYS.toMillis(400L) +
|
long ms = TimeUnit.DAYS.toMillis(400L) +
|
||||||
@ -67,7 +70,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleTwo() {
|
void exampleTwo() {
|
||||||
String expected = "1 year, 1 month, 5d 00:00:00";
|
String expected = "1 year, 1 month, 5d 00:00:00";
|
||||||
|
|
||||||
long ms = TimeUnit.DAYS.toMillis(400L);
|
long ms = TimeUnit.DAYS.toMillis(400L);
|
||||||
@ -77,7 +80,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleThree() {
|
void exampleThree() {
|
||||||
String expected = "12:00:20";
|
String expected = "12:00:20";
|
||||||
|
|
||||||
long ms = TimeUnit.HOURS.toMillis(12L) +
|
long ms = TimeUnit.HOURS.toMillis(12L) +
|
||||||
@ -88,7 +91,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleFour() {
|
void exampleFour() {
|
||||||
String expected = "00:30:00";
|
String expected = "00:30:00";
|
||||||
|
|
||||||
long ms = TimeUnit.MINUTES.toMillis(30L);
|
long ms = TimeUnit.MINUTES.toMillis(30L);
|
||||||
@ -98,7 +101,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleFive() {
|
void exampleFive() {
|
||||||
String expected = "00:00:20";
|
String expected = "00:00:20";
|
||||||
|
|
||||||
long ms = TimeUnit.SECONDS.toMillis(20L);
|
long ms = TimeUnit.SECONDS.toMillis(20L);
|
||||||
@ -108,7 +111,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleZero() {
|
void exampleZero() {
|
||||||
String expected = "-";
|
String expected = "-";
|
||||||
|
|
||||||
long ms = 0L;
|
long ms = 0L;
|
||||||
@ -118,7 +121,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleOneSecond() {
|
void exampleOneSecond() {
|
||||||
String expected = "00:00:01";
|
String expected = "00:00:01";
|
||||||
|
|
||||||
long ms = TimeUnit.SECONDS.toMillis(1L);
|
long ms = TimeUnit.SECONDS.toMillis(1L);
|
||||||
@ -128,7 +131,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exampleOneMinute() {
|
void exampleOneMinute() {
|
||||||
String expected = "00:01:00";
|
String expected = "00:01:00";
|
||||||
|
|
||||||
long ms = TimeUnit.MINUTES.toMillis(1L);
|
long ms = TimeUnit.MINUTES.toMillis(1L);
|
||||||
|
@ -16,20 +16,24 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.data.time;
|
package com.djrapitops.plan.data.time;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link GMTimes}.
|
* Tests for {@link GMTimes}.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class GMTimesTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class GMTimesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allGMTimesAreSet() {
|
void allGMTimesAreSet() {
|
||||||
GMTimes times = new GMTimes();
|
GMTimes times = new GMTimes();
|
||||||
times.setAllGMTimes(1L, 2L, 3L, 4L);
|
times.setAllGMTimes(1L, 2L, 3L, 4L);
|
||||||
|
|
||||||
@ -40,7 +44,7 @@ public class GMTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allGMTimesAreSetWithTooFewArguments() {
|
void allGMTimesAreSetWithTooFewArguments() {
|
||||||
GMTimes times = new GMTimes();
|
GMTimes times = new GMTimes();
|
||||||
times.setAllGMTimes(1L, 2L);
|
times.setAllGMTimes(1L, 2L);
|
||||||
|
|
||||||
@ -51,7 +55,7 @@ public class GMTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allGMTimesAreSetWithTooManyArguments() {
|
void allGMTimesAreSetWithTooManyArguments() {
|
||||||
GMTimes times = new GMTimes();
|
GMTimes times = new GMTimes();
|
||||||
times.setAllGMTimes(1L, 2L, 3L, 4L, 5L, 6L);
|
times.setAllGMTimes(1L, 2L, 3L, 4L, 5L, 6L);
|
||||||
|
|
||||||
@ -62,7 +66,7 @@ public class GMTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void timesAreReset() {
|
void timesAreReset() {
|
||||||
GMTimes gmTimes = new GMTimes();
|
GMTimes gmTimes = new GMTimes();
|
||||||
gmTimes.setAllGMTimes(4, 3, 2, 1);
|
gmTimes.setAllGMTimes(4, 3, 2, 1);
|
||||||
gmTimes.resetTimes(10L);
|
gmTimes.resetTimes(10L);
|
||||||
@ -73,7 +77,7 @@ public class GMTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void timeIsSet() {
|
void timeIsSet() {
|
||||||
GMTimes gmTimes = new GMTimes();
|
GMTimes gmTimes = new GMTimes();
|
||||||
gmTimes.setTime("SURVIVAL", 5L);
|
gmTimes.setTime("SURVIVAL", 5L);
|
||||||
|
|
||||||
@ -81,7 +85,7 @@ public class GMTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stateIsRenamed() {
|
void stateIsRenamed() {
|
||||||
GMTimes gmTimes = new GMTimes();
|
GMTimes gmTimes = new GMTimes();
|
||||||
gmTimes.setAllGMTimes(5L);
|
gmTimes.setAllGMTimes(5L);
|
||||||
gmTimes.renameState("SURVIVAL", "Survival");
|
gmTimes.renameState("SURVIVAL", "Survival");
|
||||||
@ -91,7 +95,7 @@ public class GMTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stateIsChangedAppropriately() {
|
void stateIsChangedAppropriately() {
|
||||||
GMTimes gmTimes = new GMTimes(new HashMap<>(), "SURVIVAL", 0);
|
GMTimes gmTimes = new GMTimes(new HashMap<>(), "SURVIVAL", 0);
|
||||||
gmTimes.changeState("CREATIVE", 5L);
|
gmTimes.changeState("CREATIVE", 5L);
|
||||||
|
|
||||||
@ -106,7 +110,7 @@ public class GMTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stateIsChangedWhenStartTimeIsDefault() {
|
void stateIsChangedWhenStartTimeIsDefault() {
|
||||||
GMTimes gmTimes = new GMTimes("SURVIVAL");
|
GMTimes gmTimes = new GMTimes("SURVIVAL");
|
||||||
gmTimes.changeState("CREATIVE", 5L);
|
gmTimes.changeState("CREATIVE", 5L);
|
||||||
|
|
||||||
@ -121,7 +125,7 @@ public class GMTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stateIsChangedWhenBeginStateIsDefault() {
|
void stateIsChangedWhenBeginStateIsDefault() {
|
||||||
GMTimes test = new GMTimes();
|
GMTimes test = new GMTimes();
|
||||||
test.changeState("CREATIVE", 5L);
|
test.changeState("CREATIVE", 5L);
|
||||||
|
|
||||||
|
@ -17,19 +17,22 @@
|
|||||||
package com.djrapitops.plan.data.time;
|
package com.djrapitops.plan.data.time;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class WorldTimesTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class WorldTimesTest {
|
||||||
|
|
||||||
private final String worldOne = "ONE";
|
private final String worldOne = "ONE";
|
||||||
private final String worldTwo = "TWO";
|
private final String worldTwo = "TWO";
|
||||||
@ -38,7 +41,7 @@ public class WorldTimesTest {
|
|||||||
private WorldTimes worldTimes = new WorldTimes(worldOne, gms[0], time);
|
private WorldTimes worldTimes = new WorldTimes(worldOne, gms[0], time);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stateAffectedByWorldChange() {
|
void stateAffectedByWorldChange() {
|
||||||
long changeTime = time + 1000L;
|
long changeTime = time + 1000L;
|
||||||
worldTimes.updateState(worldTwo, gms[0], changeTime);
|
worldTimes.updateState(worldTwo, gms[0], changeTime);
|
||||||
|
|
||||||
@ -47,7 +50,7 @@ public class WorldTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stateAffectedByGamemodeChange() {
|
void stateAffectedByGamemodeChange() {
|
||||||
long changeTime = time + 1000L;
|
long changeTime = time + 1000L;
|
||||||
worldTimes.updateState(worldOne, gms[0], changeTime);
|
worldTimes.updateState(worldOne, gms[0], changeTime);
|
||||||
|
|
||||||
@ -56,7 +59,7 @@ public class WorldTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stateAffectedByTwoChangesAtOnce() {
|
void stateAffectedByTwoChangesAtOnce() {
|
||||||
long changeTime = time + 1000L;
|
long changeTime = time + 1000L;
|
||||||
long changeTime2 = changeTime + 1000L;
|
long changeTime2 = changeTime + 1000L;
|
||||||
|
|
||||||
@ -73,7 +76,7 @@ public class WorldTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stateAffectedByManyWorldChanges() {
|
void stateAffectedByManyWorldChanges() {
|
||||||
long amount = 1000L;
|
long amount = 1000L;
|
||||||
String[] worlds = new String[]{worldOne, worldTwo};
|
String[] worlds = new String[]{worldOne, worldTwo};
|
||||||
|
|
||||||
@ -111,7 +114,7 @@ public class WorldTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void gamemodeTrackingWorksForASingleWorld() {
|
void gamemodeTrackingWorksForASingleWorld() {
|
||||||
long changeTime = time + 1000L;
|
long changeTime = time + 1000L;
|
||||||
long changeTime2 = changeTime + 1000L;
|
long changeTime2 = changeTime + 1000L;
|
||||||
|
|
||||||
@ -130,7 +133,7 @@ public class WorldTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void gamemodeTrackingWorksForTwoWorlds() {
|
void gamemodeTrackingWorksForTwoWorlds() {
|
||||||
long changeTime = time + 1000L;
|
long changeTime = time + 1000L;
|
||||||
long changeTime2 = time + 2000L;
|
long changeTime2 = time + 2000L;
|
||||||
|
|
||||||
|
@ -26,46 +26,55 @@ import com.djrapitops.plan.db.patches.Patch;
|
|||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.system.settings.paths.DatabaseSettings;
|
import com.djrapitops.plan.system.settings.paths.DatabaseSettings;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.*;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.Rule;
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
import org.junit.Test;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
import rules.PluginComponentMocker;
|
|
||||||
import utilities.OptionalAssert;
|
import utilities.OptionalAssert;
|
||||||
import utilities.TestConstants;
|
import utilities.TestConstants;
|
||||||
|
import utilities.mocks.PluginMockComponent;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for the patching of Plan 4.5.2 H2 DB into the newest schema.
|
* Test for the patching of Plan 4.5.2 H2 DB into the newest schema.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class DBPatchH2RegressionTest extends DBPatchRegressionTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class DBPatchH2RegressionTest extends DBPatchRegressionTest {
|
||||||
|
|
||||||
@Rule
|
private static PluginMockComponent component;
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
||||||
@Rule
|
|
||||||
public PluginComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
|
||||||
|
|
||||||
String serverTable = "CREATE TABLE IF NOT EXISTS plan_servers (id integer NOT NULL AUTO_INCREMENT, uuid varchar(36) NOT NULL UNIQUE, name varchar(100), web_address varchar(100), is_installed boolean NOT NULL DEFAULT 1, max_players integer NOT NULL DEFAULT -1, PRIMARY KEY (id))";
|
private String serverTable = "CREATE TABLE IF NOT EXISTS plan_servers (id integer NOT NULL AUTO_INCREMENT, uuid varchar(36) NOT NULL UNIQUE, name varchar(100), web_address varchar(100), is_installed boolean NOT NULL DEFAULT 1, max_players integer NOT NULL DEFAULT -1, PRIMARY KEY (id))";
|
||||||
String usersTable = "CREATE TABLE IF NOT EXISTS plan_users (id integer NOT NULL AUTO_INCREMENT, uuid varchar(36) NOT NULL UNIQUE, registered bigint NOT NULL, name varchar(16) NOT NULL, times_kicked integer NOT NULL DEFAULT 0, PRIMARY KEY (id))";
|
private String usersTable = "CREATE TABLE IF NOT EXISTS plan_users (id integer NOT NULL AUTO_INCREMENT, uuid varchar(36) NOT NULL UNIQUE, registered bigint NOT NULL, name varchar(16) NOT NULL, times_kicked integer NOT NULL DEFAULT 0, PRIMARY KEY (id))";
|
||||||
String userInfoTable = "CREATE TABLE IF NOT EXISTS plan_user_info (user_id integer NOT NULL, registered bigint NOT NULL, opped boolean NOT NULL DEFAULT 0, banned boolean NOT NULL DEFAULT 0, server_id integer NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String userInfoTable = "CREATE TABLE IF NOT EXISTS plan_user_info (user_id integer NOT NULL, registered bigint NOT NULL, opped boolean NOT NULL DEFAULT 0, banned boolean NOT NULL DEFAULT 0, server_id integer NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String geoInfoTable = "CREATE TABLE IF NOT EXISTS plan_ips (user_id integer NOT NULL, ip varchar(39) NOT NULL, geolocation varchar(50) NOT NULL, ip_hash varchar(200), last_used bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id))";
|
private String geoInfoTable = "CREATE TABLE IF NOT EXISTS plan_ips (user_id integer NOT NULL, ip varchar(39) NOT NULL, geolocation varchar(50) NOT NULL, ip_hash varchar(200), last_used bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id))";
|
||||||
String nicknameTable = "CREATE TABLE IF NOT EXISTS plan_nicknames (user_id integer NOT NULL, nickname varchar(75) NOT NULL, server_id integer NOT NULL, last_used bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String nicknameTable = "CREATE TABLE IF NOT EXISTS plan_nicknames (user_id integer NOT NULL, nickname varchar(75) NOT NULL, server_id integer NOT NULL, last_used bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String sessionsTable = "CREATE TABLE IF NOT EXISTS plan_sessions (id integer NOT NULL AUTO_INCREMENT, user_id integer NOT NULL, server_id integer NOT NULL, session_start bigint NOT NULL, session_end bigint NOT NULL, mob_kills integer NOT NULL, deaths integer NOT NULL, afk_time bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id), PRIMARY KEY (id))";
|
private String sessionsTable = "CREATE TABLE IF NOT EXISTS plan_sessions (id integer NOT NULL AUTO_INCREMENT, user_id integer NOT NULL, server_id integer NOT NULL, session_start bigint NOT NULL, session_end bigint NOT NULL, mob_kills integer NOT NULL, deaths integer NOT NULL, afk_time bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id), PRIMARY KEY (id))";
|
||||||
String killsTable = "CREATE TABLE IF NOT EXISTS plan_kills (killer_id integer NOT NULL, victim_id integer NOT NULL, server_id integer NOT NULL, weapon varchar(30) NOT NULL, date bigint NOT NULL, session_id integer NOT NULL, FOREIGN KEY(killer_id) REFERENCES plan_users(id), FOREIGN KEY(victim_id) REFERENCES plan_users(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String killsTable = "CREATE TABLE IF NOT EXISTS plan_kills (killer_id integer NOT NULL, victim_id integer NOT NULL, server_id integer NOT NULL, weapon varchar(30) NOT NULL, date bigint NOT NULL, session_id integer NOT NULL, FOREIGN KEY(killer_id) REFERENCES plan_users(id), FOREIGN KEY(victim_id) REFERENCES plan_users(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String pingTable = "CREATE TABLE IF NOT EXISTS plan_ping (id integer NOT NULL AUTO_INCREMENT, user_id integer NOT NULL, server_id integer NOT NULL, date bigint NOT NULL, max_ping integer NOT NULL, min_ping integer NOT NULL, avg_ping double NOT NULL, PRIMARY KEY (id), FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String pingTable = "CREATE TABLE IF NOT EXISTS plan_ping (id integer NOT NULL AUTO_INCREMENT, user_id integer NOT NULL, server_id integer NOT NULL, date bigint NOT NULL, max_ping integer NOT NULL, min_ping integer NOT NULL, avg_ping double NOT NULL, PRIMARY KEY (id), FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String commandUseTable = "CREATE TABLE IF NOT EXISTS plan_commandusages (id integer NOT NULL AUTO_INCREMENT, command varchar(20) NOT NULL, times_used integer NOT NULL, server_id integer NOT NULL, PRIMARY KEY (id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String commandUseTable = "CREATE TABLE IF NOT EXISTS plan_commandusages (id integer NOT NULL AUTO_INCREMENT, command varchar(20) NOT NULL, times_used integer NOT NULL, server_id integer NOT NULL, PRIMARY KEY (id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String tpsTable = "CREATE TABLE IF NOT EXISTS plan_tps (server_id integer NOT NULL, date bigint NOT NULL, tps double NOT NULL, players_online integer NOT NULL, cpu_usage double NOT NULL, ram_usage bigint NOT NULL, entities integer NOT NULL, chunks_loaded integer NOT NULL, free_disk_space bigint NOT NULL, FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String tpsTable = "CREATE TABLE IF NOT EXISTS plan_tps (server_id integer NOT NULL, date bigint NOT NULL, tps double NOT NULL, players_online integer NOT NULL, cpu_usage double NOT NULL, ram_usage bigint NOT NULL, entities integer NOT NULL, chunks_loaded integer NOT NULL, free_disk_space bigint NOT NULL, FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String worldsTable = "CREATE TABLE IF NOT EXISTS plan_worlds (id integer NOT NULL AUTO_INCREMENT, world_name varchar(100) NOT NULL, server_id integer NOT NULL, PRIMARY KEY (id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String worldsTable = "CREATE TABLE IF NOT EXISTS plan_worlds (id integer NOT NULL AUTO_INCREMENT, world_name varchar(100) NOT NULL, server_id integer NOT NULL, PRIMARY KEY (id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String worldTimesTable = "CREATE TABLE IF NOT EXISTS plan_world_times (user_id integer NOT NULL, world_id integer NOT NULL, server_id integer NOT NULL, session_id integer NOT NULL, survival_time bigint NOT NULL DEFAULT 0, creative_time bigint NOT NULL DEFAULT 0, adventure_time bigint NOT NULL DEFAULT 0, spectator_time bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(world_id) REFERENCES plan_worlds(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id))";
|
private String worldTimesTable = "CREATE TABLE IF NOT EXISTS plan_world_times (user_id integer NOT NULL, world_id integer NOT NULL, server_id integer NOT NULL, session_id integer NOT NULL, survival_time bigint NOT NULL DEFAULT 0, creative_time bigint NOT NULL DEFAULT 0, adventure_time bigint NOT NULL DEFAULT 0, spectator_time bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(world_id) REFERENCES plan_worlds(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id))";
|
||||||
String securityTable = "CREATE TABLE IF NOT EXISTS plan_security (username varchar(100) NOT NULL UNIQUE, salted_pass_hash varchar(100) NOT NULL UNIQUE, permission_level integer NOT NULL)";
|
private String securityTable = "CREATE TABLE IF NOT EXISTS plan_security (username varchar(100) NOT NULL UNIQUE, salted_pass_hash varchar(100) NOT NULL UNIQUE, permission_level integer NOT NULL)";
|
||||||
String transferTable = "CREATE TABLE IF NOT EXISTS plan_transfer (sender_server_id integer NOT NULL, expiry_date bigint NOT NULL DEFAULT 0, type varchar(100) NOT NULL, extra_variables varchar(255) DEFAULT '', content_64 MEDIUMTEXT, part bigint NOT NULL DEFAULT 0, FOREIGN KEY(sender_server_id) REFERENCES plan_servers(id))";
|
private String transferTable = "CREATE TABLE IF NOT EXISTS plan_transfer (sender_server_id integer NOT NULL, expiry_date bigint NOT NULL DEFAULT 0, type varchar(100) NOT NULL, extra_variables varchar(255) DEFAULT '', content_64 MEDIUMTEXT, part bigint NOT NULL DEFAULT 0, FOREIGN KEY(sender_server_id) REFERENCES plan_servers(id))";
|
||||||
|
|
||||||
private H2DB underTest;
|
private H2DB underTest;
|
||||||
|
|
||||||
@Before
|
@BeforeAll
|
||||||
public void setUpDBWithOldSchema() {
|
static void setUpComponentMock(@TempDir Path tempDir) {
|
||||||
|
component = new PluginMockComponent(tempDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
static void closeSystem() throws Exception {
|
||||||
|
component.getPlanSystem().disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUpDBWithOldSchema() throws Exception {
|
||||||
PlanConfig config = component.getPlanSystem().getConfigSystem().getConfig();
|
PlanConfig config = component.getPlanSystem().getConfigSystem().getConfig();
|
||||||
|
|
||||||
config.set(DatabaseSettings.MYSQL_USER, "user");
|
config.set(DatabaseSettings.MYSQL_USER, "user");
|
||||||
@ -103,13 +112,13 @@ public class DBPatchH2RegressionTest extends DBPatchRegressionTest {
|
|||||||
insertData(underTest);
|
insertData(underTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void closeDatabase() {
|
void closeDatabase() {
|
||||||
underTest.close();
|
underTest.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void h2PatchesAreApplied() {
|
void h2PatchesAreApplied() {
|
||||||
Patch[] patches = underTest.patches();
|
Patch[] patches = underTest.patches();
|
||||||
for (Patch patch : patches) {
|
for (Patch patch : patches) {
|
||||||
underTest.executeTransaction(patch);
|
underTest.executeTransaction(patch);
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.db;
|
package com.djrapitops.plan.db;
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
|
||||||
import com.djrapitops.plan.data.store.containers.ServerContainer;
|
import com.djrapitops.plan.data.store.containers.ServerContainer;
|
||||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||||
import com.djrapitops.plan.db.access.queries.containers.ContainerFetchQueries;
|
import com.djrapitops.plan.db.access.queries.containers.ContainerFetchQueries;
|
||||||
@ -30,56 +29,76 @@ import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|||||||
import com.djrapitops.plan.system.settings.paths.DatabaseSettings;
|
import com.djrapitops.plan.system.settings.paths.DatabaseSettings;
|
||||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import org.junit.*;
|
import org.junit.jupiter.api.*;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import rules.PluginComponentMocker;
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.CIProperties;
|
import utilities.CIProperties;
|
||||||
import utilities.OptionalAssert;
|
import utilities.OptionalAssert;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
import utilities.TestConstants;
|
import utilities.TestConstants;
|
||||||
|
import utilities.mocks.PluginMockComponent;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import java.nio.file.Path;
|
||||||
import static org.junit.Assume.assumeTrue;
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for the patching of Plan 4.5.2 MySQL DB into the newest schema.
|
* Test for the patching of Plan 4.5.2 MySQL DB into the newest schema.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class DBPatchMySQLRegressionTest extends DBPatchRegressionTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class DBPatchMySQLRegressionTest extends DBPatchRegressionTest {
|
||||||
|
|
||||||
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
||||||
|
|
||||||
@Rule
|
public static PluginMockComponent component;
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
||||||
@Rule
|
|
||||||
public PluginComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
|
||||||
|
|
||||||
String serverTable = "CREATE TABLE IF NOT EXISTS plan_servers (id integer NOT NULL AUTO_INCREMENT, uuid varchar(36) NOT NULL UNIQUE, name varchar(100), web_address varchar(100), is_installed boolean NOT NULL DEFAULT 1, max_players integer NOT NULL DEFAULT -1, PRIMARY KEY (id))";
|
private String serverTable = "CREATE TABLE IF NOT EXISTS plan_servers (id integer NOT NULL AUTO_INCREMENT, uuid varchar(36) NOT NULL UNIQUE, name varchar(100), web_address varchar(100), is_installed boolean NOT NULL DEFAULT 1, max_players integer NOT NULL DEFAULT -1, PRIMARY KEY (id))";
|
||||||
String usersTable = "CREATE TABLE IF NOT EXISTS plan_users (id integer NOT NULL AUTO_INCREMENT, uuid varchar(36) NOT NULL UNIQUE, registered bigint NOT NULL, name varchar(16) NOT NULL, times_kicked integer NOT NULL DEFAULT 0, PRIMARY KEY (id))";
|
private String usersTable = "CREATE TABLE IF NOT EXISTS plan_users (id integer NOT NULL AUTO_INCREMENT, uuid varchar(36) NOT NULL UNIQUE, registered bigint NOT NULL, name varchar(16) NOT NULL, times_kicked integer NOT NULL DEFAULT 0, PRIMARY KEY (id))";
|
||||||
String userInfoTable = "CREATE TABLE IF NOT EXISTS plan_user_info (user_id integer NOT NULL, registered bigint NOT NULL, opped boolean NOT NULL DEFAULT 0, banned boolean NOT NULL DEFAULT 0, server_id integer NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String userInfoTable = "CREATE TABLE IF NOT EXISTS plan_user_info (user_id integer NOT NULL, registered bigint NOT NULL, opped boolean NOT NULL DEFAULT 0, banned boolean NOT NULL DEFAULT 0, server_id integer NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String geoInfoTable = "CREATE TABLE IF NOT EXISTS plan_ips (user_id integer NOT NULL, ip varchar(39) NOT NULL, geolocation varchar(50) NOT NULL, ip_hash varchar(200), last_used bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id))";
|
private String geoInfoTable = "CREATE TABLE IF NOT EXISTS plan_ips (user_id integer NOT NULL, ip varchar(39) NOT NULL, geolocation varchar(50) NOT NULL, ip_hash varchar(200), last_used bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id))";
|
||||||
String nicknameTable = "CREATE TABLE IF NOT EXISTS plan_nicknames (user_id integer NOT NULL, nickname varchar(75) NOT NULL, server_id integer NOT NULL, last_used bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String nicknameTable = "CREATE TABLE IF NOT EXISTS plan_nicknames (user_id integer NOT NULL, nickname varchar(75) NOT NULL, server_id integer NOT NULL, last_used bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String sessionsTable = "CREATE TABLE IF NOT EXISTS plan_sessions (id integer NOT NULL AUTO_INCREMENT, user_id integer NOT NULL, server_id integer NOT NULL, session_start bigint NOT NULL, session_end bigint NOT NULL, mob_kills integer NOT NULL, deaths integer NOT NULL, afk_time bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id), PRIMARY KEY (id))";
|
private String sessionsTable = "CREATE TABLE IF NOT EXISTS plan_sessions (id integer NOT NULL AUTO_INCREMENT, user_id integer NOT NULL, server_id integer NOT NULL, session_start bigint NOT NULL, session_end bigint NOT NULL, mob_kills integer NOT NULL, deaths integer NOT NULL, afk_time bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id), PRIMARY KEY (id))";
|
||||||
String killsTable = "CREATE TABLE IF NOT EXISTS plan_kills (killer_id integer NOT NULL, victim_id integer NOT NULL, server_id integer NOT NULL, weapon varchar(30) NOT NULL, date bigint NOT NULL, session_id integer NOT NULL, FOREIGN KEY(killer_id) REFERENCES plan_users(id), FOREIGN KEY(victim_id) REFERENCES plan_users(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String killsTable = "CREATE TABLE IF NOT EXISTS plan_kills (killer_id integer NOT NULL, victim_id integer NOT NULL, server_id integer NOT NULL, weapon varchar(30) NOT NULL, date bigint NOT NULL, session_id integer NOT NULL, FOREIGN KEY(killer_id) REFERENCES plan_users(id), FOREIGN KEY(victim_id) REFERENCES plan_users(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String pingTable = "CREATE TABLE IF NOT EXISTS plan_ping (id integer NOT NULL AUTO_INCREMENT, user_id integer NOT NULL, server_id integer NOT NULL, date bigint NOT NULL, max_ping integer NOT NULL, min_ping integer NOT NULL, avg_ping double NOT NULL, PRIMARY KEY (id), FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String pingTable = "CREATE TABLE IF NOT EXISTS plan_ping (id integer NOT NULL AUTO_INCREMENT, user_id integer NOT NULL, server_id integer NOT NULL, date bigint NOT NULL, max_ping integer NOT NULL, min_ping integer NOT NULL, avg_ping double NOT NULL, PRIMARY KEY (id), FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String commandUseTable = "CREATE TABLE IF NOT EXISTS plan_commandusages (id integer NOT NULL AUTO_INCREMENT, command varchar(20) NOT NULL, times_used integer NOT NULL, server_id integer NOT NULL, PRIMARY KEY (id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String commandUseTable = "CREATE TABLE IF NOT EXISTS plan_commandusages (id integer NOT NULL AUTO_INCREMENT, command varchar(20) NOT NULL, times_used integer NOT NULL, server_id integer NOT NULL, PRIMARY KEY (id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String tpsTable = "CREATE TABLE IF NOT EXISTS plan_tps (server_id integer NOT NULL, date bigint NOT NULL, tps double NOT NULL, players_online integer NOT NULL, cpu_usage double NOT NULL, ram_usage bigint NOT NULL, entities integer NOT NULL, chunks_loaded integer NOT NULL, free_disk_space bigint NOT NULL, FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String tpsTable = "CREATE TABLE IF NOT EXISTS plan_tps (server_id integer NOT NULL, date bigint NOT NULL, tps double NOT NULL, players_online integer NOT NULL, cpu_usage double NOT NULL, ram_usage bigint NOT NULL, entities integer NOT NULL, chunks_loaded integer NOT NULL, free_disk_space bigint NOT NULL, FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String worldsTable = "CREATE TABLE IF NOT EXISTS plan_worlds (id integer NOT NULL AUTO_INCREMENT, world_name varchar(100) NOT NULL, server_id integer NOT NULL, PRIMARY KEY (id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String worldsTable = "CREATE TABLE IF NOT EXISTS plan_worlds (id integer NOT NULL AUTO_INCREMENT, world_name varchar(100) NOT NULL, server_id integer NOT NULL, PRIMARY KEY (id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String worldTimesTable = "CREATE TABLE IF NOT EXISTS plan_world_times (user_id integer NOT NULL, world_id integer NOT NULL, server_id integer NOT NULL, session_id integer NOT NULL, survival_time bigint NOT NULL DEFAULT 0, creative_time bigint NOT NULL DEFAULT 0, adventure_time bigint NOT NULL DEFAULT 0, spectator_time bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(world_id) REFERENCES plan_worlds(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id))";
|
private String worldTimesTable = "CREATE TABLE IF NOT EXISTS plan_world_times (user_id integer NOT NULL, world_id integer NOT NULL, server_id integer NOT NULL, session_id integer NOT NULL, survival_time bigint NOT NULL DEFAULT 0, creative_time bigint NOT NULL DEFAULT 0, adventure_time bigint NOT NULL DEFAULT 0, spectator_time bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(world_id) REFERENCES plan_worlds(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id))";
|
||||||
String securityTable = "CREATE TABLE IF NOT EXISTS plan_security (username varchar(100) NOT NULL UNIQUE, salted_pass_hash varchar(100) NOT NULL UNIQUE, permission_level integer NOT NULL)";
|
private String securityTable = "CREATE TABLE IF NOT EXISTS plan_security (username varchar(100) NOT NULL UNIQUE, salted_pass_hash varchar(100) NOT NULL UNIQUE, permission_level integer NOT NULL)";
|
||||||
String transferTable = "CREATE TABLE IF NOT EXISTS plan_transfer (sender_server_id integer NOT NULL, expiry_date bigint NOT NULL DEFAULT 0, type varchar(100) NOT NULL, extra_variables varchar(255) DEFAULT '', content_64 MEDIUMTEXT, part bigint NOT NULL DEFAULT 0, FOREIGN KEY(sender_server_id) REFERENCES plan_servers(id))";
|
private String transferTable = "CREATE TABLE IF NOT EXISTS plan_transfer (sender_server_id integer NOT NULL, expiry_date bigint NOT NULL DEFAULT 0, type varchar(100) NOT NULL, extra_variables varchar(255) DEFAULT '', content_64 MEDIUMTEXT, part bigint NOT NULL DEFAULT 0, FOREIGN KEY(sender_server_id) REFERENCES plan_servers(id))";
|
||||||
|
|
||||||
private MySQLDB underTest;
|
private MySQLDB underTest;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void ensureTravisInUse() {
|
static void ensureCIServiceInUse(@TempDir Path tempDir) {
|
||||||
boolean isTravis = Boolean.parseBoolean(System.getenv(CIProperties.IS_TRAVIS));
|
boolean isCI = Boolean.parseBoolean(System.getenv(CIProperties.IS_CI_SERVICE));
|
||||||
assumeTrue(isTravis);
|
assumeTrue(isCI);
|
||||||
|
|
||||||
|
component = new PluginMockComponent(tempDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@AfterAll
|
||||||
public void setUpDBWithOldSchema() throws EnableException {
|
static void closeSystem() throws Exception {
|
||||||
|
if (component != null) component.getPlanSystem().disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dropAllTables() {
|
||||||
|
underTest.executeTransaction(new Transaction() {
|
||||||
|
@Override
|
||||||
|
protected void performOperations() {
|
||||||
|
execute("DROP DATABASE Plan");
|
||||||
|
execute("CREATE DATABASE Plan");
|
||||||
|
execute("USE Plan");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUpDBWithOldSchema() throws Exception {
|
||||||
PlanSystem system = component.getPlanSystem();
|
PlanSystem system = component.getPlanSystem();
|
||||||
PlanConfig config = system.getConfigSystem().getConfig();
|
PlanConfig config = system.getConfigSystem().getConfig();
|
||||||
config.set(DatabaseSettings.MYSQL_DATABASE, "Plan");
|
config.set(DatabaseSettings.MYSQL_DATABASE, "Plan");
|
||||||
@ -123,24 +142,13 @@ public class DBPatchMySQLRegressionTest extends DBPatchRegressionTest {
|
|||||||
insertData(underTest);
|
insertData(underTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dropAllTables() {
|
@AfterEach
|
||||||
underTest.executeTransaction(new Transaction() {
|
void closeDatabase() {
|
||||||
@Override
|
|
||||||
protected void performOperations() {
|
|
||||||
execute("DROP DATABASE Plan");
|
|
||||||
execute("CREATE DATABASE Plan");
|
|
||||||
execute("USE Plan");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void closeDatabase() {
|
|
||||||
underTest.close();
|
underTest.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mysqlPatchesAreApplied() {
|
void mysqlPatchesAreApplied() {
|
||||||
Patch[] patches = underTest.patches();
|
Patch[] patches = underTest.patches();
|
||||||
for (Patch patch : patches) {
|
for (Patch patch : patches) {
|
||||||
underTest.executeTransaction(patch);
|
underTest.executeTransaction(patch);
|
||||||
@ -157,7 +165,7 @@ public class DBPatchMySQLRegressionTest extends DBPatchRegressionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mysqlDoesNotApplyKillsOptimizationPatchAgain() {
|
void mysqlDoesNotApplyKillsOptimizationPatchAgain() {
|
||||||
mysqlPatchesAreApplied();
|
mysqlPatchesAreApplied();
|
||||||
|
|
||||||
KillsOptimizationPatch patch = new KillsOptimizationPatch();
|
KillsOptimizationPatch patch = new KillsOptimizationPatch();
|
||||||
|
@ -26,20 +26,20 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public abstract class DBPatchRegressionTest {
|
abstract class DBPatchRegressionTest {
|
||||||
|
|
||||||
String insertServer = "INSERT INTO plan_servers (uuid) VALUES ('" + TestConstants.SERVER_UUID + "')";
|
private String insertServer = "INSERT INTO plan_servers (uuid) VALUES ('" + TestConstants.SERVER_UUID + "')";
|
||||||
String insertUser = "INSERT INTO plan_users (uuid, name, registered) VALUES ('" + TestConstants.PLAYER_ONE_UUID + "', 'TestName', 1234)";
|
private String insertUser = "INSERT INTO plan_users (uuid, name, registered) VALUES ('" + TestConstants.PLAYER_ONE_UUID + "', 'TestName', 1234)";
|
||||||
String insertUser2 = "INSERT INTO plan_users (uuid, name, registered) VALUES ('" + TestConstants.PLAYER_TWO_UUID + "', 'TestName2', 1234)";
|
private String insertUser2 = "INSERT INTO plan_users (uuid, name, registered) VALUES ('" + TestConstants.PLAYER_TWO_UUID + "', 'TestName2', 1234)";
|
||||||
String insertUserInfo = "INSERT INTO plan_user_info (user_id, registered, server_id) VALUES (1, 1234, 1)";
|
private String insertUserInfo = "INSERT INTO plan_user_info (user_id, registered, server_id) VALUES (1, 1234, 1)";
|
||||||
String insertIP = "INSERT INTO plan_ips (user_id, ip, geolocation, ip_hash, last_used) VALUES (1, '1.1.1.1', 'Finland', 'hash', 1234)";
|
private String insertIP = "INSERT INTO plan_ips (user_id, ip, geolocation, ip_hash, last_used) VALUES (1, '1.1.1.1', 'Finland', 'hash', 1234)";
|
||||||
String insertNickname = "INSERT INTO plan_nicknames (user_id, nickname, server_id, last_used) VALUES (1, 'Nickname', 1, 1234)";
|
private String insertNickname = "INSERT INTO plan_nicknames (user_id, nickname, server_id, last_used) VALUES (1, 'Nickname', 1, 1234)";
|
||||||
String insertSession = "INSERT INTO plan_sessions (user_id, server_id, session_start, session_end, mob_kills, deaths, afk_time) VALUES (1,1,1234,5678,2,2,2)";
|
private String insertSession = "INSERT INTO plan_sessions (user_id, server_id, session_start, session_end, mob_kills, deaths, afk_time) VALUES (1,1,1234,5678,2,2,2)";
|
||||||
String insertKill = "INSERT INTO plan_kills (killer_id, session_id, server_id, victim_id, weapon, date) VALUES (1,1,1, 2, 'Sword', 3456)";
|
private String insertKill = "INSERT INTO plan_kills (killer_id, session_id, server_id, victim_id, weapon, date) VALUES (1,1,1, 2, 'Sword', 3456)";
|
||||||
String insertWorld = "INSERT INTO plan_worlds (server_id, world_name) VALUES (1, 'World')";
|
private String insertWorld = "INSERT INTO plan_worlds (server_id, world_name) VALUES (1, 'World')";
|
||||||
String insertWorldTimes = "INSERT INTO plan_world_times (user_id, server_id, world_id, session_id, survival_time) VALUES (1,1,1,1,1234)";
|
private String insertWorldTimes = "INSERT INTO plan_world_times (user_id, server_id, world_id, session_id, survival_time) VALUES (1,1,1,1,1234)";
|
||||||
|
|
||||||
protected void dropAllTables(SQLDB underTest) {
|
void dropAllTables(SQLDB underTest) {
|
||||||
underTest.executeTransaction(new Transaction() {
|
underTest.executeTransaction(new Transaction() {
|
||||||
@Override
|
@Override
|
||||||
protected void performOperations() {
|
protected void performOperations() {
|
||||||
@ -57,11 +57,16 @@ public abstract class DBPatchRegressionTest {
|
|||||||
execute("DROP TABLE " + UsersTable.TABLE_NAME);
|
execute("DROP TABLE " + UsersTable.TABLE_NAME);
|
||||||
execute("DROP TABLE " + WorldTable.TABLE_NAME);
|
execute("DROP TABLE " + WorldTable.TABLE_NAME);
|
||||||
execute("DROP TABLE " + WorldTimesTable.TABLE_NAME);
|
execute("DROP TABLE " + WorldTimesTable.TABLE_NAME);
|
||||||
|
execute("DROP TABLE " + ExtensionServerValueTable.TABLE_NAME);
|
||||||
|
execute("DROP TABLE " + ExtensionPlayerValueTable.TABLE_NAME);
|
||||||
|
execute("DROP TABLE " + ExtensionProviderTable.TABLE_NAME);
|
||||||
|
execute("DROP TABLE " + ExtensionPluginTable.TABLE_NAME);
|
||||||
|
execute("DROP TABLE " + ExtensionIconTable.TABLE_NAME);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void insertData(SQLDB underTest) {
|
void insertData(SQLDB underTest) {
|
||||||
underTest.executeTransaction(new Transaction() {
|
underTest.executeTransaction(new Transaction() {
|
||||||
@Override
|
@Override
|
||||||
protected void performOperations() {
|
protected void performOperations() {
|
||||||
@ -79,7 +84,7 @@ public abstract class DBPatchRegressionTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertPatchesHaveBeenApplied(Patch[] patches) {
|
void assertPatchesHaveBeenApplied(Patch[] patches) {
|
||||||
List<String> failed = new ArrayList<>();
|
List<String> failed = new ArrayList<>();
|
||||||
for (Patch patch : patches) {
|
for (Patch patch : patches) {
|
||||||
if (!patch.hasBeenApplied()) {
|
if (!patch.hasBeenApplied()) {
|
||||||
|
@ -24,47 +24,49 @@ import com.djrapitops.plan.db.access.transactions.commands.RemoveEverythingTrans
|
|||||||
import com.djrapitops.plan.db.access.transactions.init.CreateTablesTransaction;
|
import com.djrapitops.plan.db.access.transactions.init.CreateTablesTransaction;
|
||||||
import com.djrapitops.plan.db.patches.Patch;
|
import com.djrapitops.plan.db.patches.Patch;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
import rules.PluginComponentMocker;
|
import org.junit.runner.RunWith;
|
||||||
import utilities.OptionalAssert;
|
import utilities.OptionalAssert;
|
||||||
import utilities.TestConstants;
|
import utilities.TestConstants;
|
||||||
|
import utilities.mocks.PluginMockComponent;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for the patching of Plan 4.5.2 SQLite DB into the newest schema.
|
* Test for the patching of Plan 4.5.2 SQLite DB into the newest schema.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class DBPatchSQLiteRegressionTest extends DBPatchRegressionTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class DBPatchSQLiteRegressionTest extends DBPatchRegressionTest {
|
||||||
|
|
||||||
@Rule
|
private PluginMockComponent component;
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
||||||
@Rule
|
|
||||||
public PluginComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
|
||||||
|
|
||||||
String serverTable = "CREATE TABLE IF NOT EXISTS plan_servers (id integer PRIMARY KEY, uuid varchar(36) NOT NULL UNIQUE, name varchar(100), web_address varchar(100), is_installed boolean NOT NULL DEFAULT 1, max_players integer NOT NULL DEFAULT -1)";
|
private String serverTable = "CREATE TABLE IF NOT EXISTS plan_servers (id integer PRIMARY KEY, uuid varchar(36) NOT NULL UNIQUE, name varchar(100), web_address varchar(100), is_installed boolean NOT NULL DEFAULT 1, max_players integer NOT NULL DEFAULT -1)";
|
||||||
String usersTable = "CREATE TABLE IF NOT EXISTS plan_users (id integer PRIMARY KEY, uuid varchar(36) NOT NULL UNIQUE, registered bigint NOT NULL, name varchar(16) NOT NULL, times_kicked integer NOT NULL DEFAULT 0)";
|
private String usersTable = "CREATE TABLE IF NOT EXISTS plan_users (id integer PRIMARY KEY, uuid varchar(36) NOT NULL UNIQUE, registered bigint NOT NULL, name varchar(16) NOT NULL, times_kicked integer NOT NULL DEFAULT 0)";
|
||||||
String userInfoTable = "CREATE TABLE IF NOT EXISTS plan_user_info (user_id integer NOT NULL, registered bigint NOT NULL, opped boolean NOT NULL DEFAULT 0, banned boolean NOT NULL DEFAULT 0, server_id integer NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String userInfoTable = "CREATE TABLE IF NOT EXISTS plan_user_info (user_id integer NOT NULL, registered bigint NOT NULL, opped boolean NOT NULL DEFAULT 0, banned boolean NOT NULL DEFAULT 0, server_id integer NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String geoInfoTable = "CREATE TABLE IF NOT EXISTS plan_ips (user_id integer NOT NULL, ip varchar(39) NOT NULL, geolocation varchar(50) NOT NULL, ip_hash varchar(200), last_used bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id))";
|
private String geoInfoTable = "CREATE TABLE IF NOT EXISTS plan_ips (user_id integer NOT NULL, ip varchar(39) NOT NULL, geolocation varchar(50) NOT NULL, ip_hash varchar(200), last_used bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id))";
|
||||||
String nicknameTable = "CREATE TABLE IF NOT EXISTS plan_nicknames (user_id integer NOT NULL, nickname varchar(75) NOT NULL, server_id integer NOT NULL, last_used bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String nicknameTable = "CREATE TABLE IF NOT EXISTS plan_nicknames (user_id integer NOT NULL, nickname varchar(75) NOT NULL, server_id integer NOT NULL, last_used bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String sessionsTable = "CREATE TABLE IF NOT EXISTS plan_sessions (id integer PRIMARY KEY, user_id integer NOT NULL, server_id integer NOT NULL, session_start bigint NOT NULL, session_end bigint NOT NULL, mob_kills integer NOT NULL, deaths integer NOT NULL, afk_time bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String sessionsTable = "CREATE TABLE IF NOT EXISTS plan_sessions (id integer PRIMARY KEY, user_id integer NOT NULL, server_id integer NOT NULL, session_start bigint NOT NULL, session_end bigint NOT NULL, mob_kills integer NOT NULL, deaths integer NOT NULL, afk_time bigint NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String killsTable = "CREATE TABLE IF NOT EXISTS plan_kills (killer_id integer NOT NULL, victim_id integer NOT NULL, server_id integer NOT NULL, weapon varchar(30) NOT NULL, date bigint NOT NULL, session_id integer NOT NULL, FOREIGN KEY(killer_id) REFERENCES plan_users(id), FOREIGN KEY(victim_id) REFERENCES plan_users(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String killsTable = "CREATE TABLE IF NOT EXISTS plan_kills (killer_id integer NOT NULL, victim_id integer NOT NULL, server_id integer NOT NULL, weapon varchar(30) NOT NULL, date bigint NOT NULL, session_id integer NOT NULL, FOREIGN KEY(killer_id) REFERENCES plan_users(id), FOREIGN KEY(victim_id) REFERENCES plan_users(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String pingTable = "CREATE TABLE IF NOT EXISTS plan_ping (id integer PRIMARY KEY, user_id integer NOT NULL, server_id integer NOT NULL, date bigint NOT NULL, max_ping integer NOT NULL, min_ping integer NOT NULL, avg_ping double NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String pingTable = "CREATE TABLE IF NOT EXISTS plan_ping (id integer PRIMARY KEY, user_id integer NOT NULL, server_id integer NOT NULL, date bigint NOT NULL, max_ping integer NOT NULL, min_ping integer NOT NULL, avg_ping double NOT NULL, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String commandUseTable = "CREATE TABLE IF NOT EXISTS plan_commandusages (id integer PRIMARY KEY, command varchar(20) NOT NULL, times_used integer NOT NULL, server_id integer NOT NULL, FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String commandUseTable = "CREATE TABLE IF NOT EXISTS plan_commandusages (id integer PRIMARY KEY, command varchar(20) NOT NULL, times_used integer NOT NULL, server_id integer NOT NULL, FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String tpsTable = "CREATE TABLE IF NOT EXISTS plan_tps (server_id integer NOT NULL, date bigint NOT NULL, tps double NOT NULL, players_online integer NOT NULL, cpu_usage double NOT NULL, ram_usage bigint NOT NULL, entities integer NOT NULL, chunks_loaded integer NOT NULL, free_disk_space bigint NOT NULL, FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String tpsTable = "CREATE TABLE IF NOT EXISTS plan_tps (server_id integer NOT NULL, date bigint NOT NULL, tps double NOT NULL, players_online integer NOT NULL, cpu_usage double NOT NULL, ram_usage bigint NOT NULL, entities integer NOT NULL, chunks_loaded integer NOT NULL, free_disk_space bigint NOT NULL, FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String worldsTable = "CREATE TABLE IF NOT EXISTS plan_worlds (id integer PRIMARY KEY, world_name varchar(100) NOT NULL, server_id integer NOT NULL, FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
private String worldsTable = "CREATE TABLE IF NOT EXISTS plan_worlds (id integer PRIMARY KEY, world_name varchar(100) NOT NULL, server_id integer NOT NULL, FOREIGN KEY(server_id) REFERENCES plan_servers(id))";
|
||||||
String worldTimesTable = "CREATE TABLE IF NOT EXISTS plan_world_times (user_id integer NOT NULL, world_id integer NOT NULL, server_id integer NOT NULL, session_id integer NOT NULL, survival_time bigint NOT NULL DEFAULT 0, creative_time bigint NOT NULL DEFAULT 0, adventure_time bigint NOT NULL DEFAULT 0, spectator_time bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(world_id) REFERENCES plan_worlds(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id))";
|
private String worldTimesTable = "CREATE TABLE IF NOT EXISTS plan_world_times (user_id integer NOT NULL, world_id integer NOT NULL, server_id integer NOT NULL, session_id integer NOT NULL, survival_time bigint NOT NULL DEFAULT 0, creative_time bigint NOT NULL DEFAULT 0, adventure_time bigint NOT NULL DEFAULT 0, spectator_time bigint NOT NULL DEFAULT 0, FOREIGN KEY(user_id) REFERENCES plan_users(id), FOREIGN KEY(world_id) REFERENCES plan_worlds(id), FOREIGN KEY(server_id) REFERENCES plan_servers(id), FOREIGN KEY(session_id) REFERENCES plan_sessions(id))";
|
||||||
String securityTable = "CREATE TABLE IF NOT EXISTS plan_security (username varchar(100) NOT NULL UNIQUE, salted_pass_hash varchar(100) NOT NULL UNIQUE, permission_level integer NOT NULL)";
|
private String securityTable = "CREATE TABLE IF NOT EXISTS plan_security (username varchar(100) NOT NULL UNIQUE, salted_pass_hash varchar(100) NOT NULL UNIQUE, permission_level integer NOT NULL)";
|
||||||
String transferTable = "CREATE TABLE IF NOT EXISTS plan_transfer (sender_server_id integer NOT NULL, expiry_date bigint NOT NULL DEFAULT 0, type varchar(100) NOT NULL, extra_variables varchar(255) DEFAULT '', content_64 varchar(1), part bigint NOT NULL DEFAULT 0, FOREIGN KEY(sender_server_id) REFERENCES plan_servers(id))";
|
private String transferTable = "CREATE TABLE IF NOT EXISTS plan_transfer (sender_server_id integer NOT NULL, expiry_date bigint NOT NULL DEFAULT 0, type varchar(100) NOT NULL, extra_variables varchar(255) DEFAULT '', content_64 varchar(1), part bigint NOT NULL DEFAULT 0, FOREIGN KEY(sender_server_id) REFERENCES plan_servers(id))";
|
||||||
|
|
||||||
private SQLiteDB underTest;
|
private SQLiteDB underTest;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUpDBWithOldSchema() {
|
void setUpDBWithOldSchema(@TempDir Path tempDir) throws Exception {
|
||||||
underTest = component.getPlanSystem().getDatabaseSystem().getSqLiteFactory()
|
component = new PluginMockComponent(tempDir);
|
||||||
|
underTest = this.component.getPlanSystem().getDatabaseSystem().getSqLiteFactory()
|
||||||
.usingFileCalled("test");
|
.usingFileCalled("test");
|
||||||
underTest.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
|
underTest.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
|
||||||
underTest.init();
|
underTest.init();
|
||||||
@ -96,13 +98,14 @@ public class DBPatchSQLiteRegressionTest extends DBPatchRegressionTest {
|
|||||||
insertData(underTest);
|
insertData(underTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void closeDatabase() {
|
void closeDatabase() throws Exception {
|
||||||
underTest.close();
|
underTest.close();
|
||||||
|
component.getPlanSystem().disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sqlitePatchesAreApplied() {
|
void sqlitePatchesAreApplied() {
|
||||||
Patch[] patches = underTest.patches();
|
Patch[] patches = underTest.patches();
|
||||||
for (Patch patch : patches) {
|
for (Patch patch : patches) {
|
||||||
underTest.executeTransaction(patch);
|
underTest.executeTransaction(patch);
|
||||||
|
@ -45,8 +45,8 @@ public class MySQLTest extends CommonDBTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpDatabase() throws Exception {
|
public static void setUpDatabase() throws Exception {
|
||||||
boolean isTravis = Boolean.parseBoolean(System.getenv(CIProperties.IS_TRAVIS));
|
boolean isCI = Boolean.parseBoolean(System.getenv(CIProperties.IS_CI_SERVICE));
|
||||||
assumeTrue(isTravis);
|
assumeTrue(isCI);
|
||||||
|
|
||||||
PlanConfig config = component.getPlanSystem().getConfigSystem().getConfig();
|
PlanConfig config = component.getPlanSystem().getConfigSystem().getConfig();
|
||||||
config.set(DatabaseSettings.MYSQL_DATABASE, "Plan");
|
config.set(DatabaseSettings.MYSQL_DATABASE, "Plan");
|
||||||
|
@ -18,8 +18,10 @@ package com.djrapitops.plan.db.access.transactions.events;
|
|||||||
|
|
||||||
import com.djrapitops.plan.data.store.objects.DateObj;
|
import com.djrapitops.plan.data.store.objects.DateObj;
|
||||||
import com.djrapitops.plan.utilities.analysis.Median;
|
import com.djrapitops.plan.utilities.analysis.Median;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
import utilities.TestConstants;
|
import utilities.TestConstants;
|
||||||
|
|
||||||
@ -36,12 +38,13 @@ import static org.junit.Assert.assertEquals;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class PingMedianTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class PingMedianTest {
|
||||||
|
|
||||||
private List<DateObj<Integer>> testPing;
|
private static List<DateObj<Integer>> testPing;
|
||||||
|
|
||||||
@Before
|
@BeforeAll
|
||||||
public void setUp() {
|
static void setUpTestData() {
|
||||||
testPing = new ArrayList<>();
|
testPing = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < TimeUnit.MINUTES.toMillis(1L); i += TimeUnit.SECONDS.toMillis(2L)) {
|
for (int i = 0; i < TimeUnit.MINUTES.toMillis(1L); i += TimeUnit.SECONDS.toMillis(2L)) {
|
||||||
@ -50,7 +53,7 @@ public class PingMedianTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void medianCalculation() {
|
void medianCalculationIsCorrect() {
|
||||||
List<Integer> collect = testPing.stream().map(DateObj::getValue).sorted().collect(Collectors.toList());
|
List<Integer> collect = testPing.stream().map(DateObj::getValue).sorted().collect(Collectors.toList());
|
||||||
|
|
||||||
int expected = (int) Median.forList(collect).calculate();
|
int expected = (int) Median.forList(collect).calculate();
|
||||||
@ -61,7 +64,7 @@ public class PingMedianTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void medianCalculationForSingleEntry() {
|
void medianCalculationForSingleEntryIsEntry() {
|
||||||
int expected = 50;
|
int expected = 50;
|
||||||
int result = new PingStoreTransaction(TestConstants.PLAYER_ONE_UUID, TestConstants.SERVER_UUID,
|
int result = new PingStoreTransaction(TestConstants.PLAYER_ONE_UUID, TestConstants.SERVER_UUID,
|
||||||
Collections.singletonList(new DateObj<>(0, expected)))
|
Collections.singletonList(new DateObj<>(0, expected)))
|
||||||
@ -71,7 +74,7 @@ public class PingMedianTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void medianCalculationForNoEntries() {
|
void medianCalculationForNoEntriesIsMinusOne() {
|
||||||
int expected = -1;
|
int expected = -1;
|
||||||
int result = new PingStoreTransaction(TestConstants.PLAYER_ONE_UUID, TestConstants.SERVER_UUID, new ArrayList<>())
|
int result = new PingStoreTransaction(TestConstants.PLAYER_ONE_UUID, TestConstants.SERVER_UUID, new ArrayList<>())
|
||||||
.getMeanValue();
|
.getMeanValue();
|
||||||
|
@ -22,22 +22,25 @@ import com.djrapitops.plan.system.locale.Locale;
|
|||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.system.settings.paths.DataGatheringSettings;
|
import com.djrapitops.plan.system.settings.paths.DataGatheringSettings;
|
||||||
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.ClassRule;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,26 +48,25 @@ import static org.mockito.Mockito.when;
|
|||||||
*
|
*
|
||||||
* @author Fuzzlemann
|
* @author Fuzzlemann
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
@RunWith(JUnitPlatform.class)
|
||||||
public class GeolocationCacheTest {
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class GeolocationCacheTest {
|
||||||
|
|
||||||
private static final Map<String, String> TEST_DATA = new HashMap<>();
|
private static final Map<String, String> TEST_DATA = new HashMap<>();
|
||||||
private static File IP_STORE;
|
private static File IP_STORE;
|
||||||
|
private static Path tempDir;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
public PlanFiles files;
|
public PlanFiles files;
|
||||||
@Mock
|
@Mock
|
||||||
public PlanConfig config;
|
public PlanConfig config;
|
||||||
|
|
||||||
@ClassRule
|
|
||||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
||||||
private GeolocationCache underTest;
|
private GeolocationCache underTest;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpClass() throws IOException {
|
static void setUpTestData(@TempDir Path tempDir) throws IOException {
|
||||||
IP_STORE = temporaryFolder.newFile("GeoIP.dat");
|
GeolocationCacheTest.tempDir = tempDir;
|
||||||
// TemporaryFolder creates the file, which prevents cache from downloading the GeoIP database from the internet.
|
IP_STORE = GeolocationCacheTest.tempDir.resolve("GeoIP.dat").toFile();
|
||||||
// This is why the file needs to be removed first.
|
|
||||||
Files.delete(IP_STORE.toPath());
|
|
||||||
|
|
||||||
TEST_DATA.put("8.8.8.8", "United States");
|
TEST_DATA.put("8.8.8.8", "United States");
|
||||||
TEST_DATA.put("8.8.4.4", "United States");
|
TEST_DATA.put("8.8.4.4", "United States");
|
||||||
@ -77,8 +79,8 @@ public class GeolocationCacheTest {
|
|||||||
TEST_DATA.put("127.0.0.1", "Local Machine");
|
TEST_DATA.put("127.0.0.1", "Local Machine");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws EnableException {
|
void setUpCache() throws EnableException {
|
||||||
when(config.isTrue(DataGatheringSettings.GEOLOCATIONS)).thenReturn(true);
|
when(config.isTrue(DataGatheringSettings.GEOLOCATIONS)).thenReturn(true);
|
||||||
when(files.getFileFromPluginFolder("GeoIP.dat")).thenReturn(IP_STORE);
|
when(files.getFileFromPluginFolder("GeoIP.dat")).thenReturn(IP_STORE);
|
||||||
|
|
||||||
@ -88,8 +90,14 @@ public class GeolocationCacheTest {
|
|||||||
underTest.enable();
|
underTest.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDownCache() throws IOException {
|
||||||
|
underTest.disable();
|
||||||
|
Files.deleteIfExists(IP_STORE.toPath());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void countryIsFetched() {
|
void countryIsFetched() {
|
||||||
for (Map.Entry<String, String> entry : TEST_DATA.entrySet()) {
|
for (Map.Entry<String, String> entry : TEST_DATA.entrySet()) {
|
||||||
String ip = entry.getKey();
|
String ip = entry.getKey();
|
||||||
String expCountry = entry.getValue();
|
String expCountry = entry.getValue();
|
||||||
@ -101,7 +109,7 @@ public class GeolocationCacheTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void callsToCachedIPsReturnCachedEntries() {
|
void callsToCachedIPsReturnCachedEntries() {
|
||||||
for (Map.Entry<String, String> entry : TEST_DATA.entrySet()) {
|
for (Map.Entry<String, String> entry : TEST_DATA.entrySet()) {
|
||||||
String ip = entry.getKey();
|
String ip = entry.getKey();
|
||||||
String expIp = entry.getValue();
|
String expIp = entry.getValue();
|
||||||
|
@ -17,38 +17,41 @@
|
|||||||
package com.djrapitops.plan.system.cache;
|
package com.djrapitops.plan.system.cache;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.container.Session;
|
import com.djrapitops.plan.data.container.Session;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.TestConstants;
|
import utilities.TestConstants;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class SessionCacheTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class SessionCacheTest {
|
||||||
|
|
||||||
private Session session;
|
private Session session;
|
||||||
private final UUID uuid = TestConstants.PLAYER_ONE_UUID;
|
private final UUID uuid = TestConstants.PLAYER_ONE_UUID;
|
||||||
private final UUID serverUUID = TestConstants.SERVER_UUID;
|
private final UUID serverUUID = TestConstants.SERVER_UUID;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
session = new Session(uuid, serverUUID, 12345L, "World1", "SURVIVAL");
|
session = new Session(uuid, serverUUID, 12345L, "World1", "SURVIVAL");
|
||||||
|
|
||||||
SessionCache sessionCache = new SessionCache();
|
SessionCache sessionCache = new SessionCache();
|
||||||
sessionCache.cacheSession(uuid, session);
|
sessionCache.cacheSession(uuid, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() {
|
void tearDown() {
|
||||||
SessionCache.clear();
|
SessionCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAtomity() {
|
void testAtomity() {
|
||||||
Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
||||||
assertTrue(cachedSession.isPresent());
|
assertTrue(cachedSession.isPresent());
|
||||||
assertEquals(session, cachedSession.get());
|
assertEquals(session, cachedSession.get());
|
||||||
|
@ -21,7 +21,9 @@ import com.djrapitops.plan.data.container.TPS;
|
|||||||
import com.djrapitops.plan.data.store.objects.Nickname;
|
import com.djrapitops.plan.data.store.objects.Nickname;
|
||||||
import com.djrapitops.plan.data.time.GMTimes;
|
import com.djrapitops.plan.data.time.GMTimes;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
import utilities.TestConstants;
|
import utilities.TestConstants;
|
||||||
|
|
||||||
@ -30,22 +32,21 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertNull;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static junit.framework.TestCase.assertTrue;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for various {@link com.djrapitops.plan.system.importing.importers.Importer}s.
|
* Tests for various {@link com.djrapitops.plan.system.importing.importers.Importer}s.
|
||||||
*
|
*
|
||||||
* @author Fuzzlemann
|
* @author Fuzzlemann
|
||||||
*/
|
*/
|
||||||
public class ImportBuilderTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class ImportBuilderTest {
|
||||||
|
|
||||||
private int randomInt = RandomData.randomInt(0, 10);
|
private int randomInt = RandomData.randomInt(0, 10);
|
||||||
private String randomString = RandomData.randomString(randomInt);
|
private String randomString = RandomData.randomString(randomInt);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyServerBuilderInitializesCollections() {
|
void emptyServerBuilderInitializesCollections() {
|
||||||
ServerImportData data = ServerImportData.builder().build();
|
ServerImportData data = ServerImportData.builder().build();
|
||||||
|
|
||||||
assertNotNull(data.getCommandUsages());
|
assertNotNull(data.getCommandUsages());
|
||||||
@ -53,7 +54,7 @@ public class ImportBuilderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyUserBuilderInitializesSomeVariables() {
|
void emptyUserBuilderInitializesSomeVariables() {
|
||||||
UserImportData data = UserImportData.builder(TestConstants.SERVER_UUID).build();
|
UserImportData data = UserImportData.builder(TestConstants.SERVER_UUID).build();
|
||||||
|
|
||||||
assertEquals(0, data.getRegistered());
|
assertEquals(0, data.getRegistered());
|
||||||
@ -79,7 +80,7 @@ public class ImportBuilderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serverDataBuilderConstructsCorrectItem() {
|
void serverDataBuilderConstructsCorrectItem() {
|
||||||
ServerImportData.ServerImportDataBuilder builder = ServerImportData.builder();
|
ServerImportData.ServerImportDataBuilder builder = ServerImportData.builder();
|
||||||
|
|
||||||
TPS tps = new TPS(randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt);
|
TPS tps = new TPS(randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt);
|
||||||
@ -107,7 +108,7 @@ public class ImportBuilderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void userDataBuilderConstructsCorrectItem() {
|
void userDataBuilderConstructsCorrectItem() {
|
||||||
UserImportData.UserImportDataBuilder builder = UserImportData.builder(TestConstants.SERVER_UUID);
|
UserImportData.UserImportDataBuilder builder = UserImportData.builder(TestConstants.SERVER_UUID);
|
||||||
|
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
|
@ -25,18 +25,20 @@ import com.djrapitops.plan.db.access.transactions.events.WorldNameStoreTransacti
|
|||||||
import com.djrapitops.plan.system.PlanSystem;
|
import com.djrapitops.plan.system.PlanSystem;
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.system.settings.paths.ExportSettings;
|
import com.djrapitops.plan.system.settings.paths.ExportSettings;
|
||||||
|
import com.jayway.awaitility.Awaitility;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.TestConstants;
|
import utilities.TestConstants;
|
||||||
import utilities.dagger.DaggerPlanPluginComponent;
|
import utilities.mocks.PluginMockComponent;
|
||||||
import utilities.dagger.PlanPluginComponent;
|
|
||||||
import utilities.mocks.PlanPluginMocker;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
@ -46,19 +48,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@RunWith(JUnitPlatform.class)
|
||||||
class AnalysisExportTest {
|
class AnalysisExportTest {
|
||||||
|
|
||||||
private PlanSystem system;
|
private PlanSystem system;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setupPlanSystem(@TempDir Path dir) throws Exception {
|
void setupPlanSystem(@TempDir Path dir) throws Exception {
|
||||||
PlanPluginComponent component = DaggerPlanPluginComponent.builder().plan(PlanPluginMocker.setUp()
|
PluginMockComponent component = new PluginMockComponent(dir);
|
||||||
.withDataFolder(dir.toFile()).withLogging()
|
|
||||||
.withResourceFetchingFromJar()
|
|
||||||
.getPlanMock()
|
|
||||||
).build();
|
|
||||||
|
|
||||||
system = component.system();
|
system = component.getPlanSystem();
|
||||||
PlanConfig config = system.getConfigSystem().getConfig();
|
PlanConfig config = system.getConfigSystem().getConfig();
|
||||||
config.set(ExportSettings.JSON_EXPORT_PATH, "Test");
|
config.set(ExportSettings.JSON_EXPORT_PATH, "Test");
|
||||||
config.set(ExportSettings.SERVER_JSON, true);
|
config.set(ExportSettings.SERVER_JSON, true);
|
||||||
@ -84,9 +83,13 @@ class AnalysisExportTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void serverJSONIsExported() throws WebException {
|
void serverJSONIsExported() throws WebException {
|
||||||
system.getInfoSystem().generateAnalysisPage(TestConstants.SERVER_UUID);
|
system.getInfoSystem().generateAnalysisPage(system.getServerInfo().getServerUUID());
|
||||||
|
|
||||||
File exportFolder = system.getPlanFiles().getFileFromPluginFolder("Test");
|
File exportFolder = system.getPlanFiles().getFileFromPluginFolder("Test");
|
||||||
|
|
||||||
|
Awaitility.await().atMost(5, TimeUnit.SECONDS)
|
||||||
|
.until(() -> exportFolder.listFiles() != null);
|
||||||
|
|
||||||
File[] folders = exportFolder.listFiles();
|
File[] folders = exportFolder.listFiles();
|
||||||
assertNotNull(folders);
|
assertNotNull(folders);
|
||||||
|
|
||||||
@ -97,7 +100,7 @@ class AnalysisExportTest {
|
|||||||
}
|
}
|
||||||
if (folder.getName().equals("server")) {
|
if (folder.getName().equals("server")) {
|
||||||
for (File file : folder.listFiles()) {
|
for (File file : folder.listFiles()) {
|
||||||
if (file.getName().contains("Test.json")) {
|
if (file.getName().contains("Plan.json")) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,14 @@
|
|||||||
package com.djrapitops.plan.system.locale;
|
package com.djrapitops.plan.system.locale;
|
||||||
|
|
||||||
import com.djrapitops.plan.system.file.FileResource;
|
import com.djrapitops.plan.system.file.FileResource;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@ -31,14 +33,12 @@ import static org.junit.Assert.assertEquals;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class LocaleFileWriterTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class LocaleFileWriterTest {
|
||||||
@Rule
|
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void writesAllIdentifiers() throws IOException {
|
void writesAllIdentifiers(@TempDir Path tempDir) throws IOException {
|
||||||
File file = temporaryFolder.newFile();
|
File file = tempDir.resolve("localeFile.txt").toFile();
|
||||||
new LocaleFileWriter(new Locale()).writeToFile(file);
|
new LocaleFileWriter(new Locale()).writeToFile(file);
|
||||||
|
|
||||||
long expected = LocaleSystem.getIdentifiers().size();
|
long expected = LocaleSystem.getIdentifiers().size();
|
||||||
|
@ -16,12 +16,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.system.locale;
|
package com.djrapitops.plan.system.locale;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
public class LocaleSystemTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class LocaleSystemTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noIdentifierCollisions() {
|
void noIdentifierCollisions() {
|
||||||
// No Exception wanted
|
// No Exception wanted
|
||||||
LocaleSystem.getIdentifiers();
|
LocaleSystem.getIdentifiers();
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,19 @@ import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|||||||
import com.djrapitops.plan.system.settings.paths.*;
|
import com.djrapitops.plan.system.settings.paths.*;
|
||||||
import com.djrapitops.plan.system.settings.paths.key.Setting;
|
import com.djrapitops.plan.system.settings.paths.key.Setting;
|
||||||
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
||||||
import org.junit.ClassRule;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.FieldFetcher;
|
import utilities.FieldFetcher;
|
||||||
import utilities.TestResources;
|
import utilities.TestResources;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -40,10 +45,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@RunWith(JUnitPlatform.class)
|
||||||
public class ConfigSettingKeyTest {
|
public class ConfigSettingKeyTest {
|
||||||
|
|
||||||
@ClassRule
|
public static Path temporaryFolder;
|
||||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
||||||
|
@BeforeAll
|
||||||
|
static void prepareTempDir(@TempDir Path tempDir) {
|
||||||
|
temporaryFolder = tempDir;
|
||||||
|
}
|
||||||
|
|
||||||
public static void assertValidDefaultValuesForAllSettings(PlanConfig config, Iterable<Setting> settings) {
|
public static void assertValidDefaultValuesForAllSettings(PlanConfig config, Iterable<Setting> settings) {
|
||||||
List<String> fails = new ArrayList<>();
|
List<String> fails = new ArrayList<>();
|
||||||
@ -115,21 +125,23 @@ public class ConfigSettingKeyTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serverConfigHasValidDefaultValues() throws IOException, IllegalAccessException {
|
@DisplayName("config.yml has valid default values")
|
||||||
|
void serverConfigHasValidDefaultValues() throws IOException, IllegalAccessException {
|
||||||
PlanConfig planConfig = createConfig("config.yml");
|
PlanConfig planConfig = createConfig("config.yml");
|
||||||
Collection<Setting> settings = getServerSettings();
|
Collection<Setting> settings = getServerSettings();
|
||||||
assertValidDefaultValuesForAllSettings(planConfig, settings);
|
assertValidDefaultValuesForAllSettings(planConfig, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void proxyConfigHasValidDefaultValues() throws IOException, IllegalAccessException {
|
@DisplayName("bungeeconfig.yml has valid default values")
|
||||||
|
void proxyConfigHasValidDefaultValues() throws IOException, IllegalAccessException {
|
||||||
PlanConfig planConfig = createConfig("bungeeconfig.yml");
|
PlanConfig planConfig = createConfig("bungeeconfig.yml");
|
||||||
Collection<Setting> settings = getProxySettings();
|
Collection<Setting> settings = getProxySettings();
|
||||||
assertValidDefaultValuesForAllSettings(planConfig, settings);
|
assertValidDefaultValuesForAllSettings(planConfig, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlanConfig createConfig(String copyDefaultSettingsFrom) throws IOException {
|
private PlanConfig createConfig(String copyDefaultSettingsFrom) throws IOException {
|
||||||
File configFile = temporaryFolder.newFile();
|
File configFile = Files.createTempFile(temporaryFolder, "config", ".yml").toFile();
|
||||||
TestResources.copyResourceIntoFile(configFile, "/assets/plan/" + copyDefaultSettingsFrom);
|
TestResources.copyResourceIntoFile(configFile, "/assets/plan/" + copyDefaultSettingsFrom);
|
||||||
return createConfig(configFile);
|
return createConfig(configFile);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
package com.djrapitops.plan.system.update;
|
package com.djrapitops.plan.system.update;
|
||||||
|
|
||||||
import com.djrapitops.plugin.api.utility.Version;
|
import com.djrapitops.plugin.api.utility.Version;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -25,10 +27,11 @@ import java.util.List;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class VersionInfoLoaderTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class VersionInfoLoaderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void versionLoaderTest() throws IOException {
|
void versionLoaderTest() throws IOException {
|
||||||
List<VersionInfo> versions = VersionInfoLoader.load();
|
List<VersionInfo> versions = VersionInfoLoader.load();
|
||||||
|
|
||||||
VersionInfo oldest = versions.get(versions.size() - 1);
|
VersionInfo oldest = versions.get(versions.size() - 1);
|
||||||
|
@ -24,48 +24,45 @@ import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|||||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||||
import com.djrapitops.plan.utilities.Base64Util;
|
import com.djrapitops.plan.utilities.Base64Util;
|
||||||
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||||
import org.junit.AfterClass;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.ClassRule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
|
||||||
import rules.ComponentMocker;
|
|
||||||
import rules.PluginComponentMocker;
|
|
||||||
import utilities.HTTPConnector;
|
import utilities.HTTPConnector;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
import utilities.TestResources;
|
import utilities.TestResources;
|
||||||
|
import utilities.mocks.PluginMockComponent;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
@RunWith(JUnitPlatform.class)
|
||||||
public class HTTPSWebServerAuthTest {
|
class HTTPSWebServerAuthTest {
|
||||||
|
|
||||||
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
||||||
|
|
||||||
@ClassRule
|
public static PluginMockComponent component;
|
||||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
||||||
@ClassRule
|
|
||||||
public static ComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
|
||||||
|
|
||||||
private static PlanSystem system;
|
private static PlanSystem system;
|
||||||
|
|
||||||
private HTTPConnector connector = new HTTPConnector();
|
private HTTPConnector connector = new HTTPConnector();
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpClass() throws Exception {
|
static void setUpClass(@TempDir Path tempDir) throws Exception {
|
||||||
File file = temporaryFolder.newFile();
|
File file = tempDir.resolve("Cert.keystore").toFile();
|
||||||
TestResources.copyResourceIntoFile(file, "/Cert.keystore");
|
TestResources.copyResourceIntoFile(file, "/Cert.keystore");
|
||||||
String absolutePath = file.getAbsolutePath();
|
String absolutePath = file.getAbsolutePath();
|
||||||
|
|
||||||
|
component = new PluginMockComponent(tempDir);
|
||||||
system = component.getPlanSystem();
|
system = component.getPlanSystem();
|
||||||
|
|
||||||
PlanConfig config = system.getConfigSystem().getConfig();
|
PlanConfig config = system.getConfigSystem().getConfig();
|
||||||
@ -83,8 +80,8 @@ public class HTTPSWebServerAuthTest {
|
|||||||
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(webUser));
|
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(webUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterAll
|
||||||
public static void tearDownClass() {
|
static void tearDownClass() {
|
||||||
if (system != null) {
|
if (system != null) {
|
||||||
system.disable();
|
system.disable();
|
||||||
}
|
}
|
||||||
@ -93,9 +90,8 @@ public class HTTPSWebServerAuthTest {
|
|||||||
/**
|
/**
|
||||||
* Test case against "Perm level 0 required, got 0".
|
* Test case against "Perm level 0 required, got 0".
|
||||||
*/
|
*/
|
||||||
@Test(timeout = 5000)
|
@Test
|
||||||
// @Ignore("HTTPS Start fails due to paths being bad for some reason")
|
void testHTTPSAuthForPages() throws IOException, WebException, KeyManagementException, NoSuchAlgorithmException {
|
||||||
public void testHTTPSAuthForPages() throws IOException, WebException, KeyManagementException, NoSuchAlgorithmException {
|
|
||||||
assertTrue("WebServer is not using https", system.getWebServerSystem().getWebServer().isUsingHTTPS());
|
assertTrue("WebServer is not using https", system.getWebServerSystem().getWebServer().isUsingHTTPS());
|
||||||
|
|
||||||
String address = "https://localhost:" + TEST_PORT_NUMBER;
|
String address = "https://localhost:" + TEST_PORT_NUMBER;
|
||||||
|
@ -26,22 +26,22 @@ import com.djrapitops.plan.system.database.DBSystem;
|
|||||||
import com.djrapitops.plan.system.locale.lang.ErrorPageLang;
|
import com.djrapitops.plan.system.locale.lang.ErrorPageLang;
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||||
import com.djrapitops.plan.system.webserver.cache.PageId;
|
import extension.SeleniumExtension;
|
||||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import com.jayway.awaitility.Awaitility;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.*;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import rules.ComponentMocker;
|
|
||||||
import rules.PluginComponentMocker;
|
|
||||||
import rules.SeleniumDriver;
|
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
import utilities.TestConstants;
|
import utilities.TestConstants;
|
||||||
|
import utilities.mocks.PluginMockComponent;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
@ -53,22 +53,19 @@ import static org.junit.Assert.assertFalse;
|
|||||||
* - Automatic formatting of plugin javascript (See https://github.com/Rsl1122/Plan-PlayerAnalytics/issues/820)
|
* - Automatic formatting of plugin javascript (See https://github.com/Rsl1122/Plan-PlayerAnalytics/issues/820)
|
||||||
* - Missing file definition in Mocker
|
* - Missing file definition in Mocker
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
@RunWith(JUnitPlatform.class)
|
||||||
public class JSErrorRegressionTest {
|
@ExtendWith(SeleniumExtension.class)
|
||||||
|
class JSErrorRegressionTest {
|
||||||
|
|
||||||
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
||||||
|
|
||||||
@ClassRule
|
public static PluginMockComponent component;
|
||||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
||||||
@ClassRule
|
|
||||||
public static ComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
|
||||||
@ClassRule
|
|
||||||
public static SeleniumDriver seleniumDriver = new SeleniumDriver();
|
|
||||||
|
|
||||||
private static PlanSystem bukkitSystem;
|
private static PlanSystem bukkitSystem;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpClass() throws Exception {
|
static void setUpClass(@TempDir Path tempDir) throws Exception {
|
||||||
|
component = new PluginMockComponent(tempDir);
|
||||||
bukkitSystem = component.getPlanSystem();
|
bukkitSystem = component.getPlanSystem();
|
||||||
|
|
||||||
PlanConfig config = bukkitSystem.getConfigSystem().getConfig();
|
PlanConfig config = bukkitSystem.getConfigSystem().getConfig();
|
||||||
@ -89,67 +86,60 @@ public class JSErrorRegressionTest {
|
|||||||
database.executeTransaction(new SessionEndTransaction(session));
|
database.executeTransaction(new SessionEndTransaction(session));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterAll
|
||||||
public void tearDownTest() {
|
static void tearDownClass() {
|
||||||
seleniumDriver.newTab();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownClass() {
|
|
||||||
if (bukkitSystem != null) {
|
if (bukkitSystem != null) {
|
||||||
bukkitSystem.disable();
|
bukkitSystem.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDownTest(WebDriver driver) {
|
||||||
|
SeleniumExtension.newTab(driver);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void playerPageDoesNotHaveJavascriptErrors() {
|
void playerPageDoesNotHaveJavascriptErrors(WebDriver driver) {
|
||||||
System.out.println("Testing Player Page");
|
System.out.println("Testing Player Page");
|
||||||
WebDriver driver = seleniumDriver.getDriver();
|
|
||||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/player/TestPlayer");
|
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/player/TestPlayer");
|
||||||
assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void playerPageAccessibleViaUUID() {
|
void playerPageAccessibleViaUUID(WebDriver driver) {
|
||||||
System.out.println("Testing Player Page via UUID");
|
System.out.println("Testing Player Page via UUID");
|
||||||
WebDriver driver = seleniumDriver.getDriver();
|
|
||||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/player/" + TestConstants.PLAYER_ONE_UUID);
|
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/player/" + TestConstants.PLAYER_ONE_UUID);
|
||||||
assertFalse(driver.getPageSource(), driver.getPageSource().contains(ErrorPageLang.NOT_PLAYED_404.getDefault()));
|
assertFalse(driver.getPageSource(), driver.getPageSource().contains(ErrorPageLang.NOT_PLAYED_404.getDefault()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test TODO Figure out why /network page is shown
|
||||||
@Ignore("PlanPluginMocker displays network page for some reason. Investigate")
|
// void serverPageDoesNotHaveJavascriptErrors(WebDriver driver) {
|
||||||
public void serverPageDoesNotHaveJavascriptErrors() {
|
// System.out.println("Testing Server Page");
|
||||||
System.out.println("Testing Server Page");
|
// // Open the page that has refreshing info
|
||||||
WebDriver driver = seleniumDriver.getDriver();
|
// driver.get("http://localhost:" + TEST_PORT_NUMBER + "/server");
|
||||||
// Open the page that has refreshing info
|
// assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
||||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/server");
|
//
|
||||||
assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
// // Wait until Plan caches analysis results
|
||||||
|
// Awaitility.await()
|
||||||
|
// .atMost(10, TimeUnit.SECONDS)
|
||||||
|
// .until(() -> ResponseCache.isCached(PageId.SERVER.of(TestConstants.SERVER_UUID)));
|
||||||
|
//
|
||||||
|
// // Open the page with analysis stuff
|
||||||
|
// SeleniumExtension.newTab(driver);
|
||||||
|
// driver.get("http://localhost:" + TEST_PORT_NUMBER + "/server");
|
||||||
|
// assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
||||||
|
// }
|
||||||
|
|
||||||
// Wait until Plan caches analysis results
|
// @Test TODO Figure out why /network players page is shown
|
||||||
Awaitility.await()
|
// void playersPageDoesNotHaveJavascriptErrors(WebDriver driver) {
|
||||||
.atMost(10, TimeUnit.SECONDS)
|
// System.out.println("Testing Players Page");
|
||||||
.until(() -> ResponseCache.isCached(PageId.SERVER.of(TestConstants.SERVER_UUID)));
|
// driver.get("http://localhost:" + TEST_PORT_NUMBER + "/players");
|
||||||
|
// assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
||||||
// Open the page with analysis stuff
|
// }
|
||||||
seleniumDriver.newTab();
|
|
||||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/server");
|
|
||||||
assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("PlanPluginMocker displays network page for some reason. Investigate")
|
void debugPageDoesNotHaveJavascriptErrors(WebDriver driver) {
|
||||||
public void playersPageDoesNotHaveJavascriptErrors() {
|
|
||||||
System.out.println("Testing Players Page");
|
|
||||||
WebDriver driver = seleniumDriver.getDriver();
|
|
||||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/players");
|
|
||||||
assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void debugPageDoesNotHaveJavascriptErrors() {
|
|
||||||
System.out.println("Testing Debug Page");
|
System.out.println("Testing Debug Page");
|
||||||
WebDriver driver = seleniumDriver.getDriver();
|
|
||||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/debug");
|
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/debug");
|
||||||
assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,13 @@ package com.djrapitops.plan.utilities;
|
|||||||
import com.djrapitops.plan.system.settings.Permissions;
|
import com.djrapitops.plan.system.settings.Permissions;
|
||||||
import com.djrapitops.plugin.command.Sender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.command.SenderType;
|
import com.djrapitops.plugin.command.SenderType;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,7 +33,8 @@ import static org.mockito.Mockito.when;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class MiscUtilsTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class MiscUtilsTest {
|
||||||
|
|
||||||
private Sender mockAPlayerSender(String name, boolean hasPermission) {
|
private Sender mockAPlayerSender(String name, boolean hasPermission) {
|
||||||
Sender sender = Mockito.mock(Sender.class);
|
Sender sender = Mockito.mock(Sender.class);
|
||||||
@ -42,7 +45,7 @@ public class MiscUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNameShouldReturnNameWithPermission() {
|
void getNameShouldReturnNameWithPermission() {
|
||||||
String[] args = new String[]{"Rsl1122", "Test"};
|
String[] args = new String[]{"Rsl1122", "Test"};
|
||||||
Sender sender = mockAPlayerSender("TestName", true);
|
Sender sender = mockAPlayerSender("TestName", true);
|
||||||
|
|
||||||
@ -53,7 +56,7 @@ public class MiscUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNameShouldReturnNullWithoutPermission() {
|
void getNameShouldReturnNullWithoutPermission() {
|
||||||
String[] args = new String[]{"Rsl1122", "Test"};
|
String[] args = new String[]{"Rsl1122", "Test"};
|
||||||
Sender sender = mockAPlayerSender("TestName", false);
|
Sender sender = mockAPlayerSender("TestName", false);
|
||||||
|
|
||||||
@ -63,7 +66,7 @@ public class MiscUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNameShouldReturnPlayerNameWithoutArgs() {
|
void getNameShouldReturnPlayerNameWithoutArgs() {
|
||||||
String[] args = new String[]{};
|
String[] args = new String[]{};
|
||||||
String expected = "TestName";
|
String expected = "TestName";
|
||||||
Sender sender = mockAPlayerSender(expected, true);
|
Sender sender = mockAPlayerSender(expected, true);
|
||||||
@ -74,7 +77,7 @@ public class MiscUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNameShouldReturnPlayerNameWithoutArgsOrPermission() {
|
void getNameShouldReturnPlayerNameWithoutArgsOrPermission() {
|
||||||
String[] args = new String[]{};
|
String[] args = new String[]{};
|
||||||
String expected = "TestName2";
|
String expected = "TestName2";
|
||||||
Sender sender = mockAPlayerSender(expected, false);
|
Sender sender = mockAPlayerSender(expected, false);
|
||||||
@ -85,7 +88,7 @@ public class MiscUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNameShouldReturnPlayerNameWithoutPermissionForOwnName() {
|
void getNameShouldReturnPlayerNameWithoutPermissionForOwnName() {
|
||||||
String[] args = new String[]{"testname2"};
|
String[] args = new String[]{"testname2"};
|
||||||
String expected = "TestName2";
|
String expected = "TestName2";
|
||||||
Sender sender = mockAPlayerSender(expected, false);
|
Sender sender = mockAPlayerSender(expected, false);
|
||||||
@ -96,7 +99,7 @@ public class MiscUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNameShouldReturnArgumentForConsole() {
|
void getNameShouldReturnArgumentForConsole() {
|
||||||
String[] args = new String[]{"TestConsoleSender"};
|
String[] args = new String[]{"TestConsoleSender"};
|
||||||
String expected = "TestConsoleSender";
|
String expected = "TestConsoleSender";
|
||||||
|
|
||||||
|
@ -16,25 +16,28 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.utilities;
|
package com.djrapitops.plan.utilities;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fuzzlemann
|
* @author Fuzzlemann
|
||||||
*/
|
*/
|
||||||
public class PassEncryptTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class PassEncryptTest {
|
||||||
|
|
||||||
private final Map<String, String> PASSWORD_MAP = new HashMap<>();
|
private static final Map<String, String> PASSWORD_MAP = new HashMap<>();
|
||||||
|
|
||||||
@Before
|
@BeforeAll
|
||||||
public void setUp() throws Exception {
|
static void setUpPasswords() throws Exception {
|
||||||
for (int i = 0; i < RandomData.randomInt(1, 10); i++) {
|
for (int i = 0; i < RandomData.randomInt(1, 10); i++) {
|
||||||
String password = RandomData.randomString(RandomData.randomInt(5, 16));
|
String password = RandomData.randomString(RandomData.randomInt(5, 16));
|
||||||
PASSWORD_MAP.put(password, PassEncryptUtil.createHash(password));
|
PASSWORD_MAP.put(password, PassEncryptUtil.createHash(password));
|
||||||
@ -42,7 +45,7 @@ public class PassEncryptTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVerification() throws Exception {
|
void testVerification() throws Exception {
|
||||||
for (Map.Entry<String, String> entry : PASSWORD_MAP.entrySet()) {
|
for (Map.Entry<String, String> entry : PASSWORD_MAP.entrySet()) {
|
||||||
String password = entry.getKey();
|
String password = entry.getKey();
|
||||||
String hash = entry.getValue();
|
String hash = entry.getValue();
|
||||||
|
@ -16,16 +16,19 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.utilities;
|
package com.djrapitops.plan.utilities;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class SHA256HashTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class SHA256HashTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sameStringReturnsSameHash() throws NoSuchAlgorithmException {
|
void sameStringReturnsSameHash() throws NoSuchAlgorithmException {
|
||||||
String expected = new SHA256Hash("1.3.4.5").create();
|
String expected = new SHA256Hash("1.3.4.5").create();
|
||||||
String result = new SHA256Hash("1.3.4.5").create();
|
String result = new SHA256Hash("1.3.4.5").create();
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
@ -16,24 +16,27 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.utilities.analysis;
|
package com.djrapitops.plan.utilities.analysis;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link Median}.
|
* Tests for {@link Median}.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class MedianTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class MedianTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleOdd() {
|
void simpleOdd() {
|
||||||
List<Integer> testValues = Arrays.asList(1, 3, 3, 6, 7, 8, 9);
|
List<Integer> testValues = Arrays.asList(1, 3, 3, 6, 7, 8, 9);
|
||||||
Collections.shuffle(testValues);
|
Collections.shuffle(testValues);
|
||||||
double expected = 6;
|
double expected = 6;
|
||||||
@ -43,7 +46,7 @@ public class MedianTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleEven() {
|
void simpleEven() {
|
||||||
List<Integer> testValues = Arrays.asList(1, 2, 3, 4, 5, 6, 8, 9);
|
List<Integer> testValues = Arrays.asList(1, 2, 3, 4, 5, 6, 8, 9);
|
||||||
Collections.shuffle(testValues);
|
Collections.shuffle(testValues);
|
||||||
double expected = 4.5;
|
double expected = 4.5;
|
||||||
@ -53,7 +56,7 @@ public class MedianTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void empty() {
|
void empty() {
|
||||||
double expected = -1;
|
double expected = -1;
|
||||||
double result = Median.forList(new ArrayList<Integer>()).calculate();
|
double result = Median.forList(new ArrayList<Integer>()).calculate();
|
||||||
|
|
||||||
@ -61,7 +64,7 @@ public class MedianTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValue() {
|
void singleValue() {
|
||||||
double expected = 50;
|
double expected = 50;
|
||||||
double result = Median.forList(Collections.singletonList((int) expected)).calculate();
|
double result = Median.forList(Collections.singletonList((int) expected)).calculate();
|
||||||
|
|
||||||
@ -69,7 +72,7 @@ public class MedianTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void twoValues() {
|
void twoValues() {
|
||||||
List<Integer> testValues = Arrays.asList(1, 2);
|
List<Integer> testValues = Arrays.asList(1, 2);
|
||||||
double expected = 1.5;
|
double expected = 1.5;
|
||||||
double result = Median.forList(testValues).calculate();
|
double result = Median.forList(testValues).calculate();
|
||||||
@ -78,7 +81,7 @@ public class MedianTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void overflowOdd() {
|
void overflowOdd() {
|
||||||
List<Integer> testValues = Arrays.asList(Integer.MIN_VALUE, 2, Integer.MAX_VALUE);
|
List<Integer> testValues = Arrays.asList(Integer.MIN_VALUE, 2, Integer.MAX_VALUE);
|
||||||
double expected = 2;
|
double expected = 2;
|
||||||
double result = Median.forList(testValues).calculate();
|
double result = Median.forList(testValues).calculate();
|
||||||
@ -87,7 +90,7 @@ public class MedianTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void overflowEven() {
|
void overflowEven() {
|
||||||
List<Integer> testValues = Arrays.asList(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
List<Integer> testValues = Arrays.asList(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||||
double expected = -0.5;
|
double expected = -0.5;
|
||||||
double result = Median.forList(testValues).calculate();
|
double result = Median.forList(testValues).calculate();
|
||||||
@ -96,7 +99,7 @@ public class MedianTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void overflowEven2() {
|
void overflowEven2() {
|
||||||
List<Integer> testValues = Arrays.asList(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
List<Integer> testValues = Arrays.asList(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||||
double expected = Integer.MAX_VALUE;
|
double expected = Integer.MAX_VALUE;
|
||||||
double result = Median.forList(testValues).calculate();
|
double result = Median.forList(testValues).calculate();
|
||||||
|
@ -26,19 +26,22 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
|||||||
import com.djrapitops.plan.system.locale.lang.Lang;
|
import com.djrapitops.plan.system.locale.lang.Lang;
|
||||||
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.line.Point;
|
import com.djrapitops.plan.utilities.html.graphs.line.Point;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class ComparatorTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class ComparatorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pointComparator() {
|
void pointComparator() {
|
||||||
List<Point> points = RandomData.randomPoints();
|
List<Point> points = RandomData.randomPoints();
|
||||||
|
|
||||||
List<Long> expected = points.stream().map(Point::getX).map(i -> (long) (double) i)
|
List<Long> expected = points.stream().map(Point::getX).map(i -> (long) (double) i)
|
||||||
@ -51,7 +54,7 @@ public class ComparatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sessionDataComparator() {
|
void sessionDataComparator() {
|
||||||
List<Session> sessions = RandomData.randomSessions();
|
List<Session> sessions = RandomData.randomSessions();
|
||||||
|
|
||||||
List<Long> expected = sessions.stream().map(s -> s.getUnsafe(SessionKeys.START))
|
List<Long> expected = sessions.stream().map(s -> s.getUnsafe(SessionKeys.START))
|
||||||
@ -65,7 +68,7 @@ public class ComparatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tpsComparator() {
|
void tpsComparator() {
|
||||||
List<TPS> tpsList = RandomData.randomTPS();
|
List<TPS> tpsList = RandomData.randomTPS();
|
||||||
|
|
||||||
List<Long> expected = tpsList.stream().map(TPS::getDate)
|
List<Long> expected = tpsList.stream().map(TPS::getDate)
|
||||||
@ -78,7 +81,7 @@ public class ComparatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void webUserComparator() throws PassEncryptUtil.CannotPerformOperationException {
|
void webUserComparator() throws PassEncryptUtil.CannotPerformOperationException {
|
||||||
List<WebUser> webUsers = RandomData.randomWebUsers();
|
List<WebUser> webUsers = RandomData.randomWebUsers();
|
||||||
|
|
||||||
List<Integer> expected = webUsers.stream().map(WebUser::getPermLevel)
|
List<Integer> expected = webUsers.stream().map(WebUser::getPermLevel)
|
||||||
@ -92,7 +95,7 @@ public class ComparatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stringLengthComparator() {
|
void stringLengthComparator() {
|
||||||
List<Integer> result = Stream.of(
|
List<Integer> result = Stream.of(
|
||||||
RandomData.randomString(10),
|
RandomData.randomString(10),
|
||||||
RandomData.randomString(3),
|
RandomData.randomString(3),
|
||||||
@ -112,7 +115,7 @@ public class ComparatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void localeEntryComparator() {
|
void localeEntryComparator() {
|
||||||
Map<Lang, Message> messageMap = new HashMap<>();
|
Map<Lang, Message> messageMap = new HashMap<>();
|
||||||
messageMap.put(CmdHelpLang.SERVERS, new Message(RandomData.randomString(10)));
|
messageMap.put(CmdHelpLang.SERVERS, new Message(RandomData.randomString(10)));
|
||||||
messageMap.put(CmdHelpLang.ANALYZE, new Message(RandomData.randomString(10)));
|
messageMap.put(CmdHelpLang.ANALYZE, new Message(RandomData.randomString(10)));
|
||||||
@ -132,7 +135,7 @@ public class ComparatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void geoInfoComparator() {
|
void geoInfoComparator() {
|
||||||
List<GeoInfo> geoInfos = RandomData.randomGeoInfo();
|
List<GeoInfo> geoInfos = RandomData.randomGeoInfo();
|
||||||
|
|
||||||
List<Long> expected = geoInfos.stream().map(GeoInfo::getDate)
|
List<Long> expected = geoInfos.stream().map(GeoInfo::getDate)
|
||||||
|
@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
@RunWith(JUnitPlatform.class)
|
@RunWith(JUnitPlatform.class)
|
||||||
public class HtmlTest {
|
class HtmlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void parsingWithNoArgsDoesNotReplacePlaceholder() {
|
void parsingWithNoArgsDoesNotReplacePlaceholder() {
|
||||||
|
@ -16,18 +16,21 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.utilities.html;
|
package com.djrapitops.plan.utilities.html;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class HtmlUtilsTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class HtmlUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveXSS() {
|
void testRemoveXSS() {
|
||||||
String randomString = RandomData.randomString(10);
|
String randomString = RandomData.randomString(10);
|
||||||
|
|
||||||
String xss = "<script>" + randomString + "</script><!---->";
|
String xss = "<script>" + randomString + "</script><!---->";
|
||||||
|
@ -18,34 +18,38 @@ package com.djrapitops.plan.utilities.html.graphs.line;
|
|||||||
|
|
||||||
import com.djrapitops.plan.data.container.TPS;
|
import com.djrapitops.plan.data.container.TPS;
|
||||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for {@link LineGraph}.
|
* Test class for {@link LineGraph}.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class LineGraphTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class LineGraphTest {
|
||||||
|
|
||||||
private final List<TPS> tpsList = new ArrayList<>();
|
private static List<TPS> DATA;
|
||||||
|
|
||||||
@Before
|
@BeforeAll
|
||||||
public void setUp() {
|
static void setUp() {
|
||||||
|
DATA = new ArrayList<>();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
tpsList.add(new TPS(i, i, i, i, i, i, i, i));
|
DATA.add(new TPS(i, i, i, i, i, i, i, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLineGraphsForBracketErrors() {
|
void testLineGraphsForBracketErrors() {
|
||||||
TPSMutator mutator = new TPSMutator(tpsList);
|
TPSMutator mutator = new TPSMutator(DATA);
|
||||||
LineGraph[] graphs = new LineGraph[]{
|
LineGraph[] graphs = new LineGraph[]{
|
||||||
new CPUGraph(mutator, true),
|
new CPUGraph(mutator, true),
|
||||||
new PlayersOnlineGraph(mutator, false),
|
new PlayersOnlineGraph(mutator, false),
|
||||||
@ -79,15 +83,15 @@ public class LineGraphTest {
|
|||||||
break;
|
break;
|
||||||
case ')':
|
case ')':
|
||||||
Character pop = bracketStack.pop();
|
Character pop = bracketStack.pop();
|
||||||
assertEquals("Bracket mismatch at char: " + i + " Expected (, got " + pop, '(', (char) pop);
|
assertEquals('(', (char) pop, "Bracket mismatch at char: " + i + " Expected (, got " + pop);
|
||||||
break;
|
break;
|
||||||
case ']':
|
case ']':
|
||||||
Character pop1 = bracketStack.pop();
|
Character pop1 = bracketStack.pop();
|
||||||
assertEquals("Bracket mismatch at char: " + i + " Expected [, got " + pop1, '[', (char) pop1);
|
assertEquals('[', (char) pop1, "Bracket mismatch at char: " + i + " Expected [, got " + pop1);
|
||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
Character pop2 = bracketStack.pop();
|
Character pop2 = bracketStack.pop();
|
||||||
assertEquals("Bracket mismatch at char: " + i + " Expected {, got " + pop2, '{', (char) pop2);
|
assertEquals('{', (char) pop2, "Bracket mismatch at char: " + i + " Expected {, got " + pop2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -24,8 +24,10 @@ import com.djrapitops.plan.system.database.DBSystem;
|
|||||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||||
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
||||||
import com.djrapitops.plugin.logging.error.ConsoleErrorLogger;
|
import com.djrapitops.plugin.logging.error.ConsoleErrorLogger;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -34,17 +36,18 @@ import java.util.List;
|
|||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link PlayersTable}
|
* Tests for {@link PlayersTable}
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class PlayersTableTest {
|
@RunWith(JUnitPlatform.class)
|
||||||
|
class PlayersTableTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpClass() {
|
static void setUpClass() {
|
||||||
new CommonAPI(
|
new CommonAPI(
|
||||||
Mockito.mock(DBSystem.class),
|
Mockito.mock(DBSystem.class),
|
||||||
Mockito.mock(UUIDUtility.class),
|
Mockito.mock(UUIDUtility.class),
|
||||||
@ -55,7 +58,7 @@ public class PlayersTableTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noClassCastExceptionsFromFormatting() {
|
void noClassCastExceptionsFromFormatting() {
|
||||||
PlayerContainer container = new PlayerContainer();
|
PlayerContainer container = new PlayerContainer();
|
||||||
container.putRawData(PlayerKeys.SESSIONS, new ArrayList<>());
|
container.putRawData(PlayerKeys.SESSIONS, new ArrayList<>());
|
||||||
List<PlayerContainer> players = Collections.singletonList(container);
|
List<PlayerContainer> players = Collections.singletonList(container);
|
||||||
@ -79,12 +82,12 @@ public class PlayersTableTest {
|
|||||||
for (String s : split) {
|
for (String s : split) {
|
||||||
if (s.startsWith("/")) {
|
if (s.startsWith("/")) {
|
||||||
String expectedElement = stack.pop();
|
String expectedElement = stack.pop();
|
||||||
assertTrue("Element not properly closed: " + expectedElement, s.startsWith("/" + expectedElement));
|
assertTrue(s.startsWith("/" + expectedElement), () -> "Element not properly closed: " + expectedElement);
|
||||||
} else {
|
} else {
|
||||||
stack.push(s.split(" ", 2)[0].split(">", 2)[0]);
|
stack.push(s.split(" ", 2)[0].split(">", 2)[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stack.pop(); // Pop the empty string since the html string starts with <
|
stack.pop(); // Pop the empty string since the html string starts with <
|
||||||
assertTrue("Stack was not empty: " + stack.toString(), stack.empty());
|
assertTrue(stack.empty(), () -> "Stack was not empty: " + stack.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -68,7 +68,7 @@ public class SeleniumExtension implements ParameterResolver, BeforeAllCallback,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private WebDriver getChromeWebDriver() {
|
private WebDriver getChromeWebDriver() {
|
||||||
if (Boolean.parseBoolean(System.getenv(CIProperties.IS_TRAVIS))) {
|
if (Boolean.parseBoolean(System.getenv(CIProperties.IS_CI_SERVICE))) {
|
||||||
ChromeOptions chromeOptions = new ChromeOptions();
|
ChromeOptions chromeOptions = new ChromeOptions();
|
||||||
chromeOptions.setBinary("/usr/bin/google-chrome-stable");
|
chromeOptions.setBinary("/usr/bin/google-chrome-stable");
|
||||||
chromeOptions.setHeadless(true);
|
chromeOptions.setHeadless(true);
|
||||||
|
@ -47,7 +47,7 @@ public class SeleniumDriver extends ExternalResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private WebDriver getChromeWebDriver() {
|
private WebDriver getChromeWebDriver() {
|
||||||
if (Boolean.parseBoolean(System.getenv(CIProperties.IS_TRAVIS))) {
|
if (Boolean.parseBoolean(System.getenv(CIProperties.IS_CI_SERVICE))) {
|
||||||
ChromeOptions chromeOptions = new ChromeOptions();
|
ChromeOptions chromeOptions = new ChromeOptions();
|
||||||
chromeOptions.setBinary("/usr/bin/google-chrome-stable");
|
chromeOptions.setBinary("/usr/bin/google-chrome-stable");
|
||||||
chromeOptions.setHeadless(true);
|
chromeOptions.setHeadless(true);
|
||||||
|
@ -23,7 +23,7 @@ package utilities;
|
|||||||
*/
|
*/
|
||||||
public class CIProperties {
|
public class CIProperties {
|
||||||
|
|
||||||
public static final String IS_TRAVIS = "TRAVIS";
|
public static final String IS_CI_SERVICE = "TRAVIS";
|
||||||
public static final String CHROME_DRIVER = "CHROMEDRIVER";
|
public static final String CHROME_DRIVER = "CHROMEDRIVER";
|
||||||
|
|
||||||
private CIProperties() {
|
private CIProperties() {
|
||||||
|
@ -18,8 +18,8 @@ package utilities;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility for asserts containing Optionals.
|
* Utility for asserts containing Optionals.
|
||||||
@ -29,8 +29,8 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class OptionalAssert {
|
public class OptionalAssert {
|
||||||
|
|
||||||
public static <T> void equals(T expected, Optional<T> result) {
|
public static <T> void equals(T expected, Optional<T> result) {
|
||||||
assertTrue("No result present, expected: " + expected, result.isPresent());
|
assertTrue(result.isPresent(), () -> "No result present, expected: " + expected);
|
||||||
assertEquals("Wrong result, expected: " + expected + ", got: " + result.get(), expected, result.get());
|
assertEquals(expected, result.get(), () -> "Wrong result, expected: " + expected + ", got: " + result.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -23,7 +23,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract Mocker for methods that can be used for both Bungee and Bukkit.
|
* Abstract Mocker for methods that can be used for both Bungee and Bukkit.
|
||||||
@ -47,7 +47,7 @@ abstract class Mocker {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
File file = getFile("/assets/plan/" + fileName);
|
File file = getFile("/assets/plan/" + fileName);
|
||||||
doReturn(Files.newInputStream(file.toPath())).when(planMock).getResource("assets/plan/" + fileName);
|
when(planMock.getResource("assets/plan/" + fileName)).thenAnswer(invocationOnMock -> Files.newInputStream(file.toPath()));
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
System.out.println("File is missing! " + fileName);
|
System.out.println("File is missing! " + fileName);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.mocks;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.PlanPlugin;
|
||||||
|
import com.djrapitops.plan.system.PlanSystem;
|
||||||
|
import utilities.dagger.DaggerPlanPluginComponent;
|
||||||
|
import utilities.dagger.PlanPluginComponent;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test utility for creating a dagger PlanComponent using a mocked Plan.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class PluginMockComponent {
|
||||||
|
|
||||||
|
private final Path tempDir;
|
||||||
|
|
||||||
|
private PlanPlugin planMock;
|
||||||
|
private PlanPluginComponent component;
|
||||||
|
|
||||||
|
public PluginMockComponent(Path tempDir) {
|
||||||
|
this.tempDir = tempDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlanPlugin getPlanMock() throws Exception {
|
||||||
|
if (planMock == null) {
|
||||||
|
planMock = PlanPluginMocker.setUp()
|
||||||
|
.withDataFolder(tempDir.toFile())
|
||||||
|
.withResourceFetchingFromJar()
|
||||||
|
.withLogging().getPlanMock();
|
||||||
|
}
|
||||||
|
return planMock;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlanSystem getPlanSystem() throws Exception {
|
||||||
|
if (component == null) {
|
||||||
|
component = DaggerPlanPluginComponent.builder().plan(getPlanMock()).build();
|
||||||
|
}
|
||||||
|
return component.system();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user