mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 02:57:52 +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.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* DataContainer implementation that stores everything in {@link Supplier} objects.
|
||||
@ -129,6 +128,11 @@ public class SupplierDataContainer implements DataContainer {
|
||||
|
||||
@Override
|
||||
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.UnknownHostException;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
@ -150,7 +152,12 @@ public class GeolocationCache implements SubSystem {
|
||||
try {
|
||||
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);
|
||||
|
||||
CountryResponse response = reader.country(inetAddress);
|
||||
@ -178,9 +185,10 @@ public class GeolocationCache implements SubSystem {
|
||||
InputStream in = downloadSite.openStream();
|
||||
GZIPInputStream gzipIn = new GZIPInputStream(in);
|
||||
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)
|
||||
@ExtendWith(PrintExtension.class)
|
||||
public class ShutdownSaveTest {
|
||||
class ShutdownSaveTest {
|
||||
|
||||
private boolean shutdownStatus;
|
||||
private ServerShutdownSave underTest;
|
||||
|
@ -17,47 +17,50 @@
|
||||
package com.djrapitops.plan.data;
|
||||
|
||||
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 java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
/**
|
||||
* Tests for {@link PlayerKill}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlayerKillTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class PlayerKillTest {
|
||||
|
||||
private String weapon = RandomData.randomString(10);
|
||||
private UUID testUUID = UUID.randomUUID();
|
||||
private PlayerKill underTest = new PlayerKill(testUUID, weapon, 100L);
|
||||
|
||||
@Test
|
||||
public void victimUUIDIsReturned() {
|
||||
void victimUUIDIsReturned() {
|
||||
assertEquals(testUUID, underTest.getVictim());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateIsReturned() {
|
||||
void dateIsReturned() {
|
||||
assertEquals(100L, underTest.getDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void weaponIsReturned() {
|
||||
void weaponIsReturned() {
|
||||
assertEquals(weapon, underTest.getWeapon());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noVictimFound() {
|
||||
void noVictimFound() {
|
||||
assertFalse(underTest.getVictimName().isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void victimFound() {
|
||||
void victimFound() {
|
||||
String expectedName = "Test Victim";
|
||||
PlayerKill underTest = new PlayerKill(testUUID, weapon, 100L, expectedName);
|
||||
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.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 static junit.framework.TestCase.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
public class ResponseCacheTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class ResponseCacheTest {
|
||||
private final String IDENTIFIER = RandomData.randomString(10);
|
||||
private final String RESPONSE_STRING = RandomData.randomString(10);
|
||||
private final Response RESPONSE = new Response() {
|
||||
@ -37,7 +40,7 @@ public class ResponseCacheTest {
|
||||
};
|
||||
|
||||
@Test
|
||||
public void testCache() {
|
||||
void responseIsCachedIfNotFoundDuringLoad() {
|
||||
assertFalse(ResponseCache.isCached(IDENTIFIER));
|
||||
|
||||
Response response = ResponseCache.loadResponse(IDENTIFIER, () -> RESPONSE);
|
||||
@ -47,7 +50,7 @@ public class ResponseCacheTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearCache() {
|
||||
void responseIsClearedWhenCacheIsCleared() {
|
||||
ResponseCache.cacheResponse(IDENTIFIER, () -> RESPONSE);
|
||||
assertTrue(ResponseCache.isCached(IDENTIFIER));
|
||||
|
||||
|
@ -16,23 +16,26 @@
|
||||
*/
|
||||
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.UnknownHostException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test for functionality of GeoInfo object.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class GeoInfoTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class GeoInfoTest {
|
||||
|
||||
@Test
|
||||
public void automaticallyHidesLast16Bits() throws NoSuchAlgorithmException, UnknownHostException {
|
||||
void automaticallyHidesLast16Bits() throws NoSuchAlgorithmException, UnknownHostException {
|
||||
InetAddress test = InetAddress.getByName("1.2.3.4");
|
||||
String expected = "1.2.xx.xx";
|
||||
String result = new GeoInfo(test, "Irrelevant", 3).getIp();
|
||||
@ -41,7 +44,7 @@ public class GeoInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatIP() throws UnknownHostException {
|
||||
void testFormatIP() throws UnknownHostException {
|
||||
InetAddress ip = InetAddress.getByName("1.2.3.4");
|
||||
InetAddress ip2 = InetAddress.getByName("1.2.3.26");
|
||||
InetAddress ip3 = InetAddress.getByName("1.2.3.235");
|
||||
@ -53,7 +56,7 @@ public class GeoInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatIPv6() throws UnknownHostException {
|
||||
void testFormatIPv6() throws UnknownHostException {
|
||||
InetAddress ip = InetAddress.getByName("1234:1234:1234:1234:1234:1234:1234:1234%0");
|
||||
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.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 java.util.List;
|
||||
import java.util.Optional;
|
||||
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}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SessionTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class SessionTest {
|
||||
|
||||
private final UUID serverUUID = TestConstants.SERVER_UUID;
|
||||
|
||||
@Test
|
||||
public void safeStartKeyConstructor() {
|
||||
void safeStartKeyConstructor() {
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
Session session = new Session(null, serverUUID, System.currentTimeMillis(), null, null);
|
||||
|
||||
@ -47,7 +50,7 @@ public class SessionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeStartKeyDBConstructor() {
|
||||
void safeStartKeyDBConstructor() {
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
long time = System.currentTimeMillis();
|
||||
Session session = new Session(-1, null, null, time, time + 1, 0, 0, 0);
|
||||
@ -58,7 +61,7 @@ public class SessionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void killsAreAdded() {
|
||||
void killsAreAdded() {
|
||||
Session session = new Session(null, serverUUID, System.currentTimeMillis(), "", "");
|
||||
|
||||
Optional<List<PlayerKill>> beforeOptional = session.getValue(SessionKeys.PLAYER_KILLS);
|
||||
@ -77,7 +80,7 @@ public class SessionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void killsAreAdded2() {
|
||||
void killsAreAdded2() {
|
||||
Session session = new Session(null, serverUUID, System.currentTimeMillis(), "", "");
|
||||
|
||||
session.playerKilled(new PlayerKill(TestConstants.PLAYER_TWO_UUID, "Weapon", System.currentTimeMillis()));
|
||||
@ -90,7 +93,7 @@ public class SessionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void worldTimesWorks() {
|
||||
void worldTimesWorks() {
|
||||
long time = System.currentTimeMillis();
|
||||
Session session = new Session(null, serverUUID, time, "One", "Survival");
|
||||
session.changeState("Two", "Three", time + 5L);
|
||||
|
@ -16,51 +16,54 @@
|
||||
*/
|
||||
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.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
/**
|
||||
* Equals test for Key objects.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class KeyTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class KeyTest {
|
||||
|
||||
@Test
|
||||
public void twoInstancesAreEqual() {
|
||||
void twoInstancesAreEqual() {
|
||||
Key<Integer> testKey = new Key<>(Integer.class, "test");
|
||||
Key<Integer> testKey2 = new Key<>(Integer.class, "test");
|
||||
assertEquals(testKey, testKey2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoComplexInstancesAreEqual() {
|
||||
void twoComplexInstancesAreEqual() {
|
||||
Key<List<Integer>> testKey = new Key<>(new Type<List<Integer>>() {}, "test");
|
||||
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
||||
assertEquals(testKey, testKey2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoComplexInstancesAreNotEqual() {
|
||||
void twoComplexInstancesAreNotEqual() {
|
||||
Key<List<Long>> testKey = new Key<>(new Type<List<Long>>() {}, "test");
|
||||
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
||||
assertNotEquals(testKey, testKey2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoComplexInstancesAreNotEqual2() {
|
||||
void twoComplexInstancesAreNotEqual2() {
|
||||
Key<ArrayList<Integer>> testKey = new Key<>(new Type<ArrayList<Integer>>() {}, "test");
|
||||
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
||||
assertNotEquals(testKey, testKey2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoInstancesAreNotEqual() {
|
||||
void twoInstancesAreNotEqual() {
|
||||
Key<Integer> testKey = new Key<>(Integer.class, "test");
|
||||
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
|
||||
assertNotEquals(testKey, testKey2);
|
||||
|
@ -17,22 +17,25 @@
|
||||
package com.djrapitops.plan.data.store.containers;
|
||||
|
||||
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.
|
||||
*
|
||||
* @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_COPY = new Key<>(String.class, "TEST_KEY");
|
||||
|
||||
@Test
|
||||
public void safeUnsafeKeySupplierSameObject() {
|
||||
void safeUnsafeKeySupplierSameObject() {
|
||||
DataContainer container = new SupplierDataContainer();
|
||||
container.putSupplier(TEST_KEY, () -> "Success");
|
||||
|
||||
@ -40,7 +43,7 @@ public class SupplierDataContainerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeUnsafeKeySupplierDifferentObject() {
|
||||
void safeUnsafeKeySupplierDifferentObject() {
|
||||
DataContainer container = new SupplierDataContainer();
|
||||
container.putSupplier(TEST_KEY, () -> "Success");
|
||||
|
||||
@ -48,7 +51,7 @@ public class SupplierDataContainerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeUnsafeKeyRawSameObject() {
|
||||
void safeUnsafeKeyRawSameObject() {
|
||||
DataContainer container = new SupplierDataContainer();
|
||||
container.putRawData(TEST_KEY, "Success");
|
||||
|
||||
@ -56,7 +59,7 @@ public class SupplierDataContainerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeUnsafeKeyRawDifferentObject() {
|
||||
void safeUnsafeKeyRawDifferentObject() {
|
||||
DataContainer container = new SupplierDataContainer();
|
||||
container.putRawData(TEST_KEY, "Success");
|
||||
|
||||
@ -64,7 +67,7 @@ public class SupplierDataContainerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeUnsafeKeyRawNull() {
|
||||
void safeUnsafeKeyRawNull() {
|
||||
DataContainer container = new SupplierDataContainer();
|
||||
container.putRawData(TEST_KEY, null);
|
||||
|
||||
@ -73,7 +76,7 @@ public class SupplierDataContainerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeUnsafeKeyNullSupplier() {
|
||||
void safeUnsafeKeyNullSupplier() {
|
||||
DataContainer container = new SupplierDataContainer();
|
||||
container.putSupplier(TEST_KEY, null);
|
||||
|
||||
@ -81,7 +84,7 @@ public class SupplierDataContainerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeUnsafeKeySupplierNull() {
|
||||
void safeUnsafeKeySupplierNull() {
|
||||
DataContainer container = new SupplierDataContainer();
|
||||
container.putSupplier(TEST_KEY, () -> null);
|
||||
|
||||
@ -90,7 +93,7 @@ public class SupplierDataContainerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cachingSupplier() {
|
||||
void cachingSupplier() {
|
||||
DataContainer container = new SupplierDataContainer();
|
||||
String firstObj = "First";
|
||||
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.builders.TPSBuilder;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -28,20 +30,21 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link TPSMutator}
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TPSMutatorTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class TPSMutatorTest {
|
||||
|
||||
private List<TPS> testData;
|
||||
private long time;
|
||||
private static List<TPS> testData;
|
||||
private static long time;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeAll
|
||||
static void setUpTestData() {
|
||||
testData = new ArrayList<>();
|
||||
|
||||
time = System.currentTimeMillis();
|
||||
@ -63,14 +66,14 @@ public class TPSMutatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noDownTimeIsCorrect() {
|
||||
void noDowntimeIsCorrect() {
|
||||
long expected = 0;
|
||||
long result = new TPSMutator(testData).serverDownTime();
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noDownTimeOnSingleEntry() {
|
||||
void noDowntimeOnSingleEntry() {
|
||||
long expected = 0;
|
||||
long result = new TPSMutator(Collections.singletonList(
|
||||
TPSBuilder.get().date(time - TimeUnit.DAYS.toMillis(1L))
|
||||
@ -87,7 +90,7 @@ public class TPSMutatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fullDownTime() {
|
||||
void fullDowntime() {
|
||||
long periodLength = TimeUnit.MINUTES.toMillis(5L);
|
||||
long expected = TimeAmount.MONTH.toMillis(2L) - periodLength;
|
||||
|
||||
@ -102,7 +105,7 @@ public class TPSMutatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filteredFullMonthDownTime() {
|
||||
void filteredFullMonthDowntime() {
|
||||
long periodLength = TimeUnit.MINUTES.toMillis(5L);
|
||||
long expected = TimeAmount.MONTH.toMillis(1L) - periodLength;
|
||||
|
||||
@ -120,7 +123,7 @@ public class TPSMutatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filteredFullMonthDownTimeWhenRandomOrder() {
|
||||
void filteredFullMonthDowntimeWhenRandomOrder() {
|
||||
long periodLength = TimeUnit.MINUTES.toMillis(5L);
|
||||
long expected = TimeAmount.MONTH.toMillis(1L) - periodLength;
|
||||
|
||||
@ -140,7 +143,7 @@ public class TPSMutatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterWorksCorrectly() {
|
||||
void filterWorksCorrectly() {
|
||||
long monthAgo = time - TimeAmount.MONTH.toMillis(1L);
|
||||
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.paths.FormatSettings;
|
||||
import com.djrapitops.plan.utilities.formatting.DecimalFormatter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
@ -31,12 +33,13 @@ import static org.mockito.Mockito.when;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DecimalFormatterTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class DecimalFormatterTest {
|
||||
|
||||
private DecimalFormatter underTest;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUpFormatter() {
|
||||
PlanConfig config = Mockito.mock(PlanConfig.class);
|
||||
when(config.get(FormatSettings.DECIMALS)).thenReturn("#.##");
|
||||
|
||||
@ -44,7 +47,7 @@ public class DecimalFormatterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCutDecimalsWhichIsRoundedDown() {
|
||||
void cutDecimalsWhichIsRoundedDown() {
|
||||
double d = 0.05234;
|
||||
|
||||
String result = underTest.apply(d);
|
||||
@ -53,7 +56,7 @@ public class DecimalFormatterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCutDecimalsWhichIsRoundedUp() {
|
||||
void cutDecimalsWhichIsRoundedUp() {
|
||||
double d = 0.05634;
|
||||
|
||||
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.paths.FormatSettings;
|
||||
import com.djrapitops.plan.utilities.formatting.time.TimeAmountFormatter;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -33,12 +35,13 @@ import static org.mockito.Mockito.when;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TimeAmountFormatterDefaultTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class TimeAmountFormatterDefaultTest {
|
||||
|
||||
private static TimeAmountFormatter underTest;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
@BeforeAll
|
||||
static void setUpFormatter() {
|
||||
PlanConfig config = Mockito.mock(PlanConfig.class);
|
||||
when(config.get(FormatSettings.YEAR)).thenReturn("1 year, ");
|
||||
when(config.get(FormatSettings.YEARS)).thenReturn("%years% years, ");
|
||||
@ -56,7 +59,7 @@ public class TimeAmountFormatterDefaultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleOne() {
|
||||
void exampleOne() {
|
||||
String expected = "1 year, 1 month, 5d 12h 30m 20s";
|
||||
|
||||
long ms = TimeUnit.DAYS.toMillis(400L) +
|
||||
@ -69,7 +72,7 @@ public class TimeAmountFormatterDefaultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleTwo() {
|
||||
void exampleTwo() {
|
||||
String expected = "1 year, 1 month, 5d ";
|
||||
|
||||
long ms = TimeUnit.DAYS.toMillis(400L);
|
||||
@ -79,7 +82,7 @@ public class TimeAmountFormatterDefaultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleThree() {
|
||||
void exampleThree() {
|
||||
String expected = "12h 20s";
|
||||
|
||||
long ms = TimeUnit.HOURS.toMillis(12L) +
|
||||
@ -90,7 +93,7 @@ public class TimeAmountFormatterDefaultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleFour() {
|
||||
void exampleFour() {
|
||||
String expected = "30m ";
|
||||
|
||||
long ms = TimeUnit.MINUTES.toMillis(30L);
|
||||
@ -100,7 +103,7 @@ public class TimeAmountFormatterDefaultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleFive() {
|
||||
void exampleFive() {
|
||||
String expected = "20s";
|
||||
|
||||
long ms = TimeUnit.SECONDS.toMillis(20L);
|
||||
@ -110,7 +113,7 @@ public class TimeAmountFormatterDefaultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleZero() {
|
||||
void exampleZero() {
|
||||
String expected = "-";
|
||||
|
||||
long ms = 0L;
|
||||
@ -120,7 +123,7 @@ public class TimeAmountFormatterDefaultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleOneSecond() {
|
||||
void exampleOneSecond() {
|
||||
String expected = "1s";
|
||||
|
||||
long ms = TimeUnit.SECONDS.toMillis(1L);
|
||||
@ -130,7 +133,7 @@ public class TimeAmountFormatterDefaultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleOneMinute() {
|
||||
void exampleOneMinute() {
|
||||
String expected = "1m ";
|
||||
|
||||
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.paths.FormatSettings;
|
||||
import com.djrapitops.plan.utilities.formatting.time.TimeAmountFormatter;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -33,12 +35,13 @@ import static org.mockito.Mockito.when;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TimeAmountFormatterExtraZerosTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class TimeAmountFormatterExtraZerosTest {
|
||||
|
||||
private static TimeAmountFormatter underTest;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
@BeforeAll
|
||||
static void setUpFormatter() {
|
||||
PlanConfig config = Mockito.mock(PlanConfig.class);
|
||||
when(config.get(FormatSettings.YEAR)).thenReturn("1 year, ");
|
||||
when(config.get(FormatSettings.YEARS)).thenReturn("%years% years, ");
|
||||
@ -54,7 +57,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleOne() {
|
||||
void exampleOne() {
|
||||
String expected = "1 year, 1 month, 5d 12:30:20";
|
||||
|
||||
long ms = TimeUnit.DAYS.toMillis(400L) +
|
||||
@ -67,7 +70,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleTwo() {
|
||||
void exampleTwo() {
|
||||
String expected = "1 year, 1 month, 5d 00:00:00";
|
||||
|
||||
long ms = TimeUnit.DAYS.toMillis(400L);
|
||||
@ -77,7 +80,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleThree() {
|
||||
void exampleThree() {
|
||||
String expected = "12:00:20";
|
||||
|
||||
long ms = TimeUnit.HOURS.toMillis(12L) +
|
||||
@ -88,7 +91,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleFour() {
|
||||
void exampleFour() {
|
||||
String expected = "00:30:00";
|
||||
|
||||
long ms = TimeUnit.MINUTES.toMillis(30L);
|
||||
@ -98,7 +101,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleFive() {
|
||||
void exampleFive() {
|
||||
String expected = "00:00:20";
|
||||
|
||||
long ms = TimeUnit.SECONDS.toMillis(20L);
|
||||
@ -108,7 +111,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleZero() {
|
||||
void exampleZero() {
|
||||
String expected = "-";
|
||||
|
||||
long ms = 0L;
|
||||
@ -118,7 +121,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleOneSecond() {
|
||||
void exampleOneSecond() {
|
||||
String expected = "00:00:01";
|
||||
|
||||
long ms = TimeUnit.SECONDS.toMillis(1L);
|
||||
@ -128,7 +131,7 @@ public class TimeAmountFormatterExtraZerosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleOneMinute() {
|
||||
void exampleOneMinute() {
|
||||
String expected = "00:01:00";
|
||||
|
||||
long ms = TimeUnit.MINUTES.toMillis(1L);
|
||||
|
@ -16,20 +16,24 @@
|
||||
*/
|
||||
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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link GMTimes}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class GMTimesTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class GMTimesTest {
|
||||
|
||||
@Test
|
||||
public void allGMTimesAreSet() {
|
||||
void allGMTimesAreSet() {
|
||||
GMTimes times = new GMTimes();
|
||||
times.setAllGMTimes(1L, 2L, 3L, 4L);
|
||||
|
||||
@ -40,7 +44,7 @@ public class GMTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allGMTimesAreSetWithTooFewArguments() {
|
||||
void allGMTimesAreSetWithTooFewArguments() {
|
||||
GMTimes times = new GMTimes();
|
||||
times.setAllGMTimes(1L, 2L);
|
||||
|
||||
@ -51,7 +55,7 @@ public class GMTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allGMTimesAreSetWithTooManyArguments() {
|
||||
void allGMTimesAreSetWithTooManyArguments() {
|
||||
GMTimes times = new GMTimes();
|
||||
times.setAllGMTimes(1L, 2L, 3L, 4L, 5L, 6L);
|
||||
|
||||
@ -62,7 +66,7 @@ public class GMTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timesAreReset() {
|
||||
void timesAreReset() {
|
||||
GMTimes gmTimes = new GMTimes();
|
||||
gmTimes.setAllGMTimes(4, 3, 2, 1);
|
||||
gmTimes.resetTimes(10L);
|
||||
@ -73,7 +77,7 @@ public class GMTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeIsSet() {
|
||||
void timeIsSet() {
|
||||
GMTimes gmTimes = new GMTimes();
|
||||
gmTimes.setTime("SURVIVAL", 5L);
|
||||
|
||||
@ -81,7 +85,7 @@ public class GMTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateIsRenamed() {
|
||||
void stateIsRenamed() {
|
||||
GMTimes gmTimes = new GMTimes();
|
||||
gmTimes.setAllGMTimes(5L);
|
||||
gmTimes.renameState("SURVIVAL", "Survival");
|
||||
@ -91,7 +95,7 @@ public class GMTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateIsChangedAppropriately() {
|
||||
void stateIsChangedAppropriately() {
|
||||
GMTimes gmTimes = new GMTimes(new HashMap<>(), "SURVIVAL", 0);
|
||||
gmTimes.changeState("CREATIVE", 5L);
|
||||
|
||||
@ -106,7 +110,7 @@ public class GMTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateIsChangedWhenStartTimeIsDefault() {
|
||||
void stateIsChangedWhenStartTimeIsDefault() {
|
||||
GMTimes gmTimes = new GMTimes("SURVIVAL");
|
||||
gmTimes.changeState("CREATIVE", 5L);
|
||||
|
||||
@ -121,7 +125,7 @@ public class GMTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateIsChangedWhenBeginStateIsDefault() {
|
||||
void stateIsChangedWhenBeginStateIsDefault() {
|
||||
GMTimes test = new GMTimes();
|
||||
test.changeState("CREATIVE", 5L);
|
||||
|
||||
|
@ -17,19 +17,22 @@
|
||||
package com.djrapitops.plan.data.time;
|
||||
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class WorldTimesTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class WorldTimesTest {
|
||||
|
||||
private final String worldOne = "ONE";
|
||||
private final String worldTwo = "TWO";
|
||||
@ -38,7 +41,7 @@ public class WorldTimesTest {
|
||||
private WorldTimes worldTimes = new WorldTimes(worldOne, gms[0], time);
|
||||
|
||||
@Test
|
||||
public void stateAffectedByWorldChange() {
|
||||
void stateAffectedByWorldChange() {
|
||||
long changeTime = time + 1000L;
|
||||
worldTimes.updateState(worldTwo, gms[0], changeTime);
|
||||
|
||||
@ -47,7 +50,7 @@ public class WorldTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateAffectedByGamemodeChange() {
|
||||
void stateAffectedByGamemodeChange() {
|
||||
long changeTime = time + 1000L;
|
||||
worldTimes.updateState(worldOne, gms[0], changeTime);
|
||||
|
||||
@ -56,7 +59,7 @@ public class WorldTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateAffectedByTwoChangesAtOnce() {
|
||||
void stateAffectedByTwoChangesAtOnce() {
|
||||
long changeTime = time + 1000L;
|
||||
long changeTime2 = changeTime + 1000L;
|
||||
|
||||
@ -73,7 +76,7 @@ public class WorldTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateAffectedByManyWorldChanges() {
|
||||
void stateAffectedByManyWorldChanges() {
|
||||
long amount = 1000L;
|
||||
String[] worlds = new String[]{worldOne, worldTwo};
|
||||
|
||||
@ -111,7 +114,7 @@ public class WorldTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gamemodeTrackingWorksForASingleWorld() {
|
||||
void gamemodeTrackingWorksForASingleWorld() {
|
||||
long changeTime = time + 1000L;
|
||||
long changeTime2 = changeTime + 1000L;
|
||||
|
||||
@ -130,7 +133,7 @@ public class WorldTimesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gamemodeTrackingWorksForTwoWorlds() {
|
||||
void gamemodeTrackingWorksForTwoWorlds() {
|
||||
long changeTime = time + 1000L;
|
||||
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.paths.DatabaseSettings;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import rules.PluginComponentMocker;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import utilities.OptionalAssert;
|
||||
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.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DBPatchH2RegressionTest extends DBPatchRegressionTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class DBPatchH2RegressionTest extends DBPatchRegressionTest {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@Rule
|
||||
public PluginComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
||||
private static PluginMockComponent component;
|
||||
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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;
|
||||
|
||||
@Before
|
||||
public void setUpDBWithOldSchema() {
|
||||
@BeforeAll
|
||||
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();
|
||||
|
||||
config.set(DatabaseSettings.MYSQL_USER, "user");
|
||||
@ -103,13 +112,13 @@ public class DBPatchH2RegressionTest extends DBPatchRegressionTest {
|
||||
insertData(underTest);
|
||||
}
|
||||
|
||||
@After
|
||||
public void closeDatabase() {
|
||||
@AfterEach
|
||||
void closeDatabase() {
|
||||
underTest.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void h2PatchesAreApplied() {
|
||||
void h2PatchesAreApplied() {
|
||||
Patch[] patches = underTest.patches();
|
||||
for (Patch patch : patches) {
|
||||
underTest.executeTransaction(patch);
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
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.keys.ServerKeys;
|
||||
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.WebserverSettings;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import org.junit.*;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import rules.PluginComponentMocker;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import utilities.CIProperties;
|
||||
import utilities.OptionalAssert;
|
||||
import utilities.RandomData;
|
||||
import utilities.TestConstants;
|
||||
import utilities.mocks.PluginMockComponent;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import java.nio.file.Path;
|
||||
|
||||
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.
|
||||
*
|
||||
* @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);
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@Rule
|
||||
public PluginComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
||||
public static PluginMockComponent component;
|
||||
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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;
|
||||
|
||||
@BeforeClass
|
||||
public static void ensureTravisInUse() {
|
||||
boolean isTravis = Boolean.parseBoolean(System.getenv(CIProperties.IS_TRAVIS));
|
||||
assumeTrue(isTravis);
|
||||
@BeforeAll
|
||||
static void ensureCIServiceInUse(@TempDir Path tempDir) {
|
||||
boolean isCI = Boolean.parseBoolean(System.getenv(CIProperties.IS_CI_SERVICE));
|
||||
assumeTrue(isCI);
|
||||
|
||||
component = new PluginMockComponent(tempDir);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUpDBWithOldSchema() throws EnableException {
|
||||
@AfterAll
|
||||
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();
|
||||
PlanConfig config = system.getConfigSystem().getConfig();
|
||||
config.set(DatabaseSettings.MYSQL_DATABASE, "Plan");
|
||||
@ -123,24 +142,13 @@ public class DBPatchMySQLRegressionTest extends DBPatchRegressionTest {
|
||||
insertData(underTest);
|
||||
}
|
||||
|
||||
private void dropAllTables() {
|
||||
underTest.executeTransaction(new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute("DROP DATABASE Plan");
|
||||
execute("CREATE DATABASE Plan");
|
||||
execute("USE Plan");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@After
|
||||
public void closeDatabase() {
|
||||
@AfterEach
|
||||
void closeDatabase() {
|
||||
underTest.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mysqlPatchesAreApplied() {
|
||||
void mysqlPatchesAreApplied() {
|
||||
Patch[] patches = underTest.patches();
|
||||
for (Patch patch : patches) {
|
||||
underTest.executeTransaction(patch);
|
||||
@ -157,7 +165,7 @@ public class DBPatchMySQLRegressionTest extends DBPatchRegressionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mysqlDoesNotApplyKillsOptimizationPatchAgain() {
|
||||
void mysqlDoesNotApplyKillsOptimizationPatchAgain() {
|
||||
mysqlPatchesAreApplied();
|
||||
|
||||
KillsOptimizationPatch patch = new KillsOptimizationPatch();
|
||||
|
@ -26,20 +26,20 @@ import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class DBPatchRegressionTest {
|
||||
abstract class DBPatchRegressionTest {
|
||||
|
||||
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)";
|
||||
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)";
|
||||
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)";
|
||||
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)";
|
||||
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 insertServer = "INSERT INTO plan_servers (uuid) VALUES ('" + TestConstants.SERVER_UUID + "')";
|
||||
private String insertUser = "INSERT INTO plan_users (uuid, name, registered) VALUES ('" + TestConstants.PLAYER_ONE_UUID + "', 'TestName', 1234)";
|
||||
private String insertUser2 = "INSERT INTO plan_users (uuid, name, registered) VALUES ('" + TestConstants.PLAYER_TWO_UUID + "', 'TestName2', 1234)";
|
||||
private String insertUserInfo = "INSERT INTO plan_user_info (user_id, registered, server_id) VALUES (1, 1234, 1)";
|
||||
private 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 insertNickname = "INSERT INTO plan_nicknames (user_id, nickname, server_id, last_used) VALUES (1, 'Nickname', 1, 1234)";
|
||||
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)";
|
||||
private 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 insertWorld = "INSERT INTO plan_worlds (server_id, world_name) VALUES (1, 'World')";
|
||||
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() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
@ -57,11 +57,16 @@ public abstract class DBPatchRegressionTest {
|
||||
execute("DROP TABLE " + UsersTable.TABLE_NAME);
|
||||
execute("DROP TABLE " + WorldTable.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() {
|
||||
@Override
|
||||
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<>();
|
||||
for (Patch patch : patches) {
|
||||
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.patches.Patch;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import rules.PluginComponentMocker;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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.OptionalAssert;
|
||||
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.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DBPatchSQLiteRegressionTest extends DBPatchRegressionTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class DBPatchSQLiteRegressionTest extends DBPatchRegressionTest {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@Rule
|
||||
public PluginComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
||||
private PluginMockComponent component;
|
||||
|
||||
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)";
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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))";
|
||||
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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;
|
||||
|
||||
@Before
|
||||
public void setUpDBWithOldSchema() {
|
||||
underTest = component.getPlanSystem().getDatabaseSystem().getSqLiteFactory()
|
||||
@BeforeEach
|
||||
void setUpDBWithOldSchema(@TempDir Path tempDir) throws Exception {
|
||||
component = new PluginMockComponent(tempDir);
|
||||
underTest = this.component.getPlanSystem().getDatabaseSystem().getSqLiteFactory()
|
||||
.usingFileCalled("test");
|
||||
underTest.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
|
||||
underTest.init();
|
||||
@ -96,13 +98,14 @@ public class DBPatchSQLiteRegressionTest extends DBPatchRegressionTest {
|
||||
insertData(underTest);
|
||||
}
|
||||
|
||||
@After
|
||||
public void closeDatabase() {
|
||||
@AfterEach
|
||||
void closeDatabase() throws Exception {
|
||||
underTest.close();
|
||||
component.getPlanSystem().disable();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sqlitePatchesAreApplied() {
|
||||
void sqlitePatchesAreApplied() {
|
||||
Patch[] patches = underTest.patches();
|
||||
for (Patch patch : patches) {
|
||||
underTest.executeTransaction(patch);
|
||||
|
@ -45,8 +45,8 @@ public class MySQLTest extends CommonDBTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpDatabase() throws Exception {
|
||||
boolean isTravis = Boolean.parseBoolean(System.getenv(CIProperties.IS_TRAVIS));
|
||||
assumeTrue(isTravis);
|
||||
boolean isCI = Boolean.parseBoolean(System.getenv(CIProperties.IS_CI_SERVICE));
|
||||
assumeTrue(isCI);
|
||||
|
||||
PlanConfig config = component.getPlanSystem().getConfigSystem().getConfig();
|
||||
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.utilities.analysis.Median;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import utilities.RandomData;
|
||||
import utilities.TestConstants;
|
||||
|
||||
@ -36,12 +38,13 @@ import static org.junit.Assert.assertEquals;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PingMedianTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class PingMedianTest {
|
||||
|
||||
private List<DateObj<Integer>> testPing;
|
||||
private static List<DateObj<Integer>> testPing;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeAll
|
||||
static void setUpTestData() {
|
||||
testPing = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < TimeUnit.MINUTES.toMillis(1L); i += TimeUnit.SECONDS.toMillis(2L)) {
|
||||
@ -50,7 +53,7 @@ public class PingMedianTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void medianCalculation() {
|
||||
void medianCalculationIsCorrect() {
|
||||
List<Integer> collect = testPing.stream().map(DateObj::getValue).sorted().collect(Collectors.toList());
|
||||
|
||||
int expected = (int) Median.forList(collect).calculate();
|
||||
@ -61,7 +64,7 @@ public class PingMedianTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void medianCalculationForSingleEntry() {
|
||||
void medianCalculationForSingleEntryIsEntry() {
|
||||
int expected = 50;
|
||||
int result = new PingStoreTransaction(TestConstants.PLAYER_ONE_UUID, TestConstants.SERVER_UUID,
|
||||
Collections.singletonList(new DateObj<>(0, expected)))
|
||||
@ -71,7 +74,7 @@ public class PingMedianTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void medianCalculationForNoEntries() {
|
||||
void medianCalculationForNoEntriesIsMinusOne() {
|
||||
int expected = -1;
|
||||
int result = new PingStoreTransaction(TestConstants.PLAYER_ONE_UUID, TestConstants.SERVER_UUID, new ArrayList<>())
|
||||
.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.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
@ -45,26 +48,25 @@ import static org.mockito.Mockito.when;
|
||||
*
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class GeolocationCacheTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class GeolocationCacheTest {
|
||||
|
||||
private static final Map<String, String> TEST_DATA = new HashMap<>();
|
||||
private static File IP_STORE;
|
||||
private static Path tempDir;
|
||||
|
||||
@Mock
|
||||
public PlanFiles files;
|
||||
@Mock
|
||||
public PlanConfig config;
|
||||
|
||||
@ClassRule
|
||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
private GeolocationCache underTest;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws IOException {
|
||||
IP_STORE = temporaryFolder.newFile("GeoIP.dat");
|
||||
// TemporaryFolder creates the file, which prevents cache from downloading the GeoIP database from the internet.
|
||||
// This is why the file needs to be removed first.
|
||||
Files.delete(IP_STORE.toPath());
|
||||
@BeforeAll
|
||||
static void setUpTestData(@TempDir Path tempDir) throws IOException {
|
||||
GeolocationCacheTest.tempDir = tempDir;
|
||||
IP_STORE = GeolocationCacheTest.tempDir.resolve("GeoIP.dat").toFile();
|
||||
|
||||
TEST_DATA.put("8.8.8.8", "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");
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws EnableException {
|
||||
@BeforeEach
|
||||
void setUpCache() throws EnableException {
|
||||
when(config.isTrue(DataGatheringSettings.GEOLOCATIONS)).thenReturn(true);
|
||||
when(files.getFileFromPluginFolder("GeoIP.dat")).thenReturn(IP_STORE);
|
||||
|
||||
@ -88,8 +90,14 @@ public class GeolocationCacheTest {
|
||||
underTest.enable();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDownCache() throws IOException {
|
||||
underTest.disable();
|
||||
Files.deleteIfExists(IP_STORE.toPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void countryIsFetched() {
|
||||
void countryIsFetched() {
|
||||
for (Map.Entry<String, String> entry : TEST_DATA.entrySet()) {
|
||||
String ip = entry.getKey();
|
||||
String expCountry = entry.getValue();
|
||||
@ -101,7 +109,7 @@ public class GeolocationCacheTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void callsToCachedIPsReturnCachedEntries() {
|
||||
void callsToCachedIPsReturnCachedEntries() {
|
||||
for (Map.Entry<String, String> entry : TEST_DATA.entrySet()) {
|
||||
String ip = entry.getKey();
|
||||
String expIp = entry.getValue();
|
||||
|
@ -17,38 +17,41 @@
|
||||
package com.djrapitops.plan.system.cache;
|
||||
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import utilities.TestConstants;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class SessionCacheTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class SessionCacheTest {
|
||||
|
||||
private Session session;
|
||||
private final UUID uuid = TestConstants.PLAYER_ONE_UUID;
|
||||
private final UUID serverUUID = TestConstants.SERVER_UUID;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
session = new Session(uuid, serverUUID, 12345L, "World1", "SURVIVAL");
|
||||
|
||||
SessionCache sessionCache = new SessionCache();
|
||||
sessionCache.cacheSession(uuid, session);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
SessionCache.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtomity() {
|
||||
void testAtomity() {
|
||||
Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
||||
assertTrue(cachedSession.isPresent());
|
||||
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.time.GMTimes;
|
||||
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.TestConstants;
|
||||
|
||||
@ -30,22 +32,21 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Tests for various {@link com.djrapitops.plan.system.importing.importers.Importer}s.
|
||||
*
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
public class ImportBuilderTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class ImportBuilderTest {
|
||||
|
||||
private int randomInt = RandomData.randomInt(0, 10);
|
||||
private String randomString = RandomData.randomString(randomInt);
|
||||
|
||||
@Test
|
||||
public void emptyServerBuilderInitializesCollections() {
|
||||
void emptyServerBuilderInitializesCollections() {
|
||||
ServerImportData data = ServerImportData.builder().build();
|
||||
|
||||
assertNotNull(data.getCommandUsages());
|
||||
@ -53,7 +54,7 @@ public class ImportBuilderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyUserBuilderInitializesSomeVariables() {
|
||||
void emptyUserBuilderInitializesSomeVariables() {
|
||||
UserImportData data = UserImportData.builder(TestConstants.SERVER_UUID).build();
|
||||
|
||||
assertEquals(0, data.getRegistered());
|
||||
@ -79,7 +80,7 @@ public class ImportBuilderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverDataBuilderConstructsCorrectItem() {
|
||||
void serverDataBuilderConstructsCorrectItem() {
|
||||
ServerImportData.ServerImportDataBuilder builder = ServerImportData.builder();
|
||||
|
||||
TPS tps = new TPS(randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt);
|
||||
@ -107,7 +108,7 @@ public class ImportBuilderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userDataBuilderConstructsCorrectItem() {
|
||||
void userDataBuilderConstructsCorrectItem() {
|
||||
UserImportData.UserImportDataBuilder builder = UserImportData.builder(TestConstants.SERVER_UUID);
|
||||
|
||||
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.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.ExportSettings;
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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.TestConstants;
|
||||
import utilities.dagger.DaggerPlanPluginComponent;
|
||||
import utilities.dagger.PlanPluginComponent;
|
||||
import utilities.mocks.PlanPluginMocker;
|
||||
import utilities.mocks.PluginMockComponent;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@ -46,19 +48,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class AnalysisExportTest {
|
||||
|
||||
private PlanSystem system;
|
||||
|
||||
@BeforeEach
|
||||
void setupPlanSystem(@TempDir Path dir) throws Exception {
|
||||
PlanPluginComponent component = DaggerPlanPluginComponent.builder().plan(PlanPluginMocker.setUp()
|
||||
.withDataFolder(dir.toFile()).withLogging()
|
||||
.withResourceFetchingFromJar()
|
||||
.getPlanMock()
|
||||
).build();
|
||||
PluginMockComponent component = new PluginMockComponent(dir);
|
||||
|
||||
system = component.system();
|
||||
system = component.getPlanSystem();
|
||||
PlanConfig config = system.getConfigSystem().getConfig();
|
||||
config.set(ExportSettings.JSON_EXPORT_PATH, "Test");
|
||||
config.set(ExportSettings.SERVER_JSON, true);
|
||||
@ -84,9 +83,13 @@ class AnalysisExportTest {
|
||||
|
||||
@Test
|
||||
void serverJSONIsExported() throws WebException {
|
||||
system.getInfoSystem().generateAnalysisPage(TestConstants.SERVER_UUID);
|
||||
system.getInfoSystem().generateAnalysisPage(system.getServerInfo().getServerUUID());
|
||||
|
||||
File exportFolder = system.getPlanFiles().getFileFromPluginFolder("Test");
|
||||
|
||||
Awaitility.await().atMost(5, TimeUnit.SECONDS)
|
||||
.until(() -> exportFolder.listFiles() != null);
|
||||
|
||||
File[] folders = exportFolder.listFiles();
|
||||
assertNotNull(folders);
|
||||
|
||||
@ -97,7 +100,7 @@ class AnalysisExportTest {
|
||||
}
|
||||
if (folder.getName().equals("server")) {
|
||||
for (File file : folder.listFiles()) {
|
||||
if (file.getName().contains("Test.json")) {
|
||||
if (file.getName().contains("Plan.json")) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,14 @@
|
||||
package com.djrapitops.plan.system.locale;
|
||||
|
||||
import com.djrapitops.plan.system.file.FileResource;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@ -31,14 +33,12 @@ import static org.junit.Assert.assertEquals;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class LocaleFileWriterTest {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class LocaleFileWriterTest {
|
||||
|
||||
@Test
|
||||
public void writesAllIdentifiers() throws IOException {
|
||||
File file = temporaryFolder.newFile();
|
||||
void writesAllIdentifiers(@TempDir Path tempDir) throws IOException {
|
||||
File file = tempDir.resolve("localeFile.txt").toFile();
|
||||
new LocaleFileWriter(new Locale()).writeToFile(file);
|
||||
|
||||
long expected = LocaleSystem.getIdentifiers().size();
|
||||
|
@ -16,12 +16,15 @@
|
||||
*/
|
||||
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
|
||||
public void noIdentifierCollisions() {
|
||||
void noIdentifierCollisions() {
|
||||
// No Exception wanted
|
||||
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.key.Setting;
|
||||
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
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.TestResources;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -40,10 +45,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(JUnitPlatform.class)
|
||||
public class ConfigSettingKeyTest {
|
||||
|
||||
@ClassRule
|
||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
public static Path temporaryFolder;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareTempDir(@TempDir Path tempDir) {
|
||||
temporaryFolder = tempDir;
|
||||
}
|
||||
|
||||
public static void assertValidDefaultValuesForAllSettings(PlanConfig config, Iterable<Setting> settings) {
|
||||
List<String> fails = new ArrayList<>();
|
||||
@ -115,21 +125,23 @@ public class ConfigSettingKeyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverConfigHasValidDefaultValues() throws IOException, IllegalAccessException {
|
||||
@DisplayName("config.yml has valid default values")
|
||||
void serverConfigHasValidDefaultValues() throws IOException, IllegalAccessException {
|
||||
PlanConfig planConfig = createConfig("config.yml");
|
||||
Collection<Setting> settings = getServerSettings();
|
||||
assertValidDefaultValuesForAllSettings(planConfig, settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void proxyConfigHasValidDefaultValues() throws IOException, IllegalAccessException {
|
||||
@DisplayName("bungeeconfig.yml has valid default values")
|
||||
void proxyConfigHasValidDefaultValues() throws IOException, IllegalAccessException {
|
||||
PlanConfig planConfig = createConfig("bungeeconfig.yml");
|
||||
Collection<Setting> settings = getProxySettings();
|
||||
assertValidDefaultValuesForAllSettings(planConfig, settings);
|
||||
}
|
||||
|
||||
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);
|
||||
return createConfig(configFile);
|
||||
}
|
||||
|
@ -17,7 +17,9 @@
|
||||
package com.djrapitops.plan.system.update;
|
||||
|
||||
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.util.List;
|
||||
@ -25,10 +27,11 @@ import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class VersionInfoLoaderTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class VersionInfoLoaderTest {
|
||||
|
||||
@Test
|
||||
public void versionLoaderTest() throws IOException {
|
||||
void versionLoaderTest() throws IOException {
|
||||
List<VersionInfo> versions = VersionInfoLoader.load();
|
||||
|
||||
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.utilities.Base64Util;
|
||||
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
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 org.mockito.junit.MockitoJUnitRunner;
|
||||
import rules.ComponentMocker;
|
||||
import rules.PluginComponentMocker;
|
||||
import utilities.HTTPConnector;
|
||||
import utilities.RandomData;
|
||||
import utilities.TestResources;
|
||||
import utilities.mocks.PluginMockComponent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class HTTPSWebServerAuthTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class HTTPSWebServerAuthTest {
|
||||
|
||||
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
||||
|
||||
@ClassRule
|
||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@ClassRule
|
||||
public static ComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
||||
public static PluginMockComponent component;
|
||||
|
||||
private static PlanSystem system;
|
||||
|
||||
private HTTPConnector connector = new HTTPConnector();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
File file = temporaryFolder.newFile();
|
||||
@BeforeAll
|
||||
static void setUpClass(@TempDir Path tempDir) throws Exception {
|
||||
File file = tempDir.resolve("Cert.keystore").toFile();
|
||||
TestResources.copyResourceIntoFile(file, "/Cert.keystore");
|
||||
String absolutePath = file.getAbsolutePath();
|
||||
|
||||
component = new PluginMockComponent(tempDir);
|
||||
system = component.getPlanSystem();
|
||||
|
||||
PlanConfig config = system.getConfigSystem().getConfig();
|
||||
@ -83,8 +80,8 @@ public class HTTPSWebServerAuthTest {
|
||||
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(webUser));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
@AfterAll
|
||||
static void tearDownClass() {
|
||||
if (system != null) {
|
||||
system.disable();
|
||||
}
|
||||
@ -93,9 +90,8 @@ public class HTTPSWebServerAuthTest {
|
||||
/**
|
||||
* Test case against "Perm level 0 required, got 0".
|
||||
*/
|
||||
@Test(timeout = 5000)
|
||||
// @Ignore("HTTPS Start fails due to paths being bad for some reason")
|
||||
public void testHTTPSAuthForPages() throws IOException, WebException, KeyManagementException, NoSuchAlgorithmException {
|
||||
@Test
|
||||
void testHTTPSAuthForPages() throws IOException, WebException, KeyManagementException, NoSuchAlgorithmException {
|
||||
assertTrue("WebServer is not using https", system.getWebServerSystem().getWebServer().isUsingHTTPS());
|
||||
|
||||
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.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.system.webserver.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import org.junit.*;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import extension.SeleniumExtension;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
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.mockito.junit.MockitoJUnitRunner;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import rules.ComponentMocker;
|
||||
import rules.PluginComponentMocker;
|
||||
import rules.SeleniumDriver;
|
||||
import utilities.RandomData;
|
||||
import utilities.TestConstants;
|
||||
import utilities.mocks.PluginMockComponent;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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)
|
||||
* - Missing file definition in Mocker
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class JSErrorRegressionTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
@ExtendWith(SeleniumExtension.class)
|
||||
class JSErrorRegressionTest {
|
||||
|
||||
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
||||
|
||||
@ClassRule
|
||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@ClassRule
|
||||
public static ComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
||||
@ClassRule
|
||||
public static SeleniumDriver seleniumDriver = new SeleniumDriver();
|
||||
public static PluginMockComponent component;
|
||||
|
||||
private static PlanSystem bukkitSystem;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUpClass(@TempDir Path tempDir) throws Exception {
|
||||
component = new PluginMockComponent(tempDir);
|
||||
bukkitSystem = component.getPlanSystem();
|
||||
|
||||
PlanConfig config = bukkitSystem.getConfigSystem().getConfig();
|
||||
@ -89,67 +86,60 @@ public class JSErrorRegressionTest {
|
||||
database.executeTransaction(new SessionEndTransaction(session));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDownTest() {
|
||||
seleniumDriver.newTab();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
@AfterAll
|
||||
static void tearDownClass() {
|
||||
if (bukkitSystem != null) {
|
||||
bukkitSystem.disable();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDownTest(WebDriver driver) {
|
||||
SeleniumExtension.newTab(driver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void playerPageDoesNotHaveJavascriptErrors() {
|
||||
void playerPageDoesNotHaveJavascriptErrors(WebDriver driver) {
|
||||
System.out.println("Testing Player Page");
|
||||
WebDriver driver = seleniumDriver.getDriver();
|
||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/player/TestPlayer");
|
||||
assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void playerPageAccessibleViaUUID() {
|
||||
void playerPageAccessibleViaUUID(WebDriver driver) {
|
||||
System.out.println("Testing Player Page via UUID");
|
||||
WebDriver driver = seleniumDriver.getDriver();
|
||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/player/" + TestConstants.PLAYER_ONE_UUID);
|
||||
assertFalse(driver.getPageSource(), driver.getPageSource().contains(ErrorPageLang.NOT_PLAYED_404.getDefault()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("PlanPluginMocker displays network page for some reason. Investigate")
|
||||
public void serverPageDoesNotHaveJavascriptErrors() {
|
||||
System.out.println("Testing Server Page");
|
||||
WebDriver driver = seleniumDriver.getDriver();
|
||||
// Open the page that has refreshing info
|
||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/server");
|
||||
assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
||||
// @Test TODO Figure out why /network page is shown
|
||||
// void serverPageDoesNotHaveJavascriptErrors(WebDriver driver) {
|
||||
// System.out.println("Testing Server Page");
|
||||
// // Open the page that has refreshing info
|
||||
// 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
|
||||
Awaitility.await()
|
||||
.atMost(10, TimeUnit.SECONDS)
|
||||
.until(() -> ResponseCache.isCached(PageId.SERVER.of(TestConstants.SERVER_UUID)));
|
||||
|
||||
// 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 TODO Figure out why /network players page is shown
|
||||
// void playersPageDoesNotHaveJavascriptErrors(WebDriver driver) {
|
||||
// System.out.println("Testing Players Page");
|
||||
// driver.get("http://localhost:" + TEST_PORT_NUMBER + "/players");
|
||||
// assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred"));
|
||||
// }
|
||||
|
||||
@Test
|
||||
@Ignore("PlanPluginMocker displays network page for some reason. Investigate")
|
||||
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() {
|
||||
void debugPageDoesNotHaveJavascriptErrors(WebDriver driver) {
|
||||
System.out.println("Testing Debug Page");
|
||||
WebDriver driver = seleniumDriver.getDriver();
|
||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/debug");
|
||||
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.plugin.command.Sender;
|
||||
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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
@ -31,7 +33,8 @@ import static org.mockito.Mockito.when;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class MiscUtilsTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class MiscUtilsTest {
|
||||
|
||||
private Sender mockAPlayerSender(String name, boolean hasPermission) {
|
||||
Sender sender = Mockito.mock(Sender.class);
|
||||
@ -42,7 +45,7 @@ public class MiscUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameShouldReturnNameWithPermission() {
|
||||
void getNameShouldReturnNameWithPermission() {
|
||||
String[] args = new String[]{"Rsl1122", "Test"};
|
||||
Sender sender = mockAPlayerSender("TestName", true);
|
||||
|
||||
@ -53,7 +56,7 @@ public class MiscUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameShouldReturnNullWithoutPermission() {
|
||||
void getNameShouldReturnNullWithoutPermission() {
|
||||
String[] args = new String[]{"Rsl1122", "Test"};
|
||||
Sender sender = mockAPlayerSender("TestName", false);
|
||||
|
||||
@ -63,7 +66,7 @@ public class MiscUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameShouldReturnPlayerNameWithoutArgs() {
|
||||
void getNameShouldReturnPlayerNameWithoutArgs() {
|
||||
String[] args = new String[]{};
|
||||
String expected = "TestName";
|
||||
Sender sender = mockAPlayerSender(expected, true);
|
||||
@ -74,7 +77,7 @@ public class MiscUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameShouldReturnPlayerNameWithoutArgsOrPermission() {
|
||||
void getNameShouldReturnPlayerNameWithoutArgsOrPermission() {
|
||||
String[] args = new String[]{};
|
||||
String expected = "TestName2";
|
||||
Sender sender = mockAPlayerSender(expected, false);
|
||||
@ -85,7 +88,7 @@ public class MiscUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameShouldReturnPlayerNameWithoutPermissionForOwnName() {
|
||||
void getNameShouldReturnPlayerNameWithoutPermissionForOwnName() {
|
||||
String[] args = new String[]{"testname2"};
|
||||
String expected = "TestName2";
|
||||
Sender sender = mockAPlayerSender(expected, false);
|
||||
@ -96,7 +99,7 @@ public class MiscUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameShouldReturnArgumentForConsole() {
|
||||
void getNameShouldReturnArgumentForConsole() {
|
||||
String[] args = new String[]{"TestConsoleSender"};
|
||||
String expected = "TestConsoleSender";
|
||||
|
||||
|
@ -16,25 +16,28 @@
|
||||
*/
|
||||
package com.djrapitops.plan.utilities;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import utilities.RandomData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @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
|
||||
public void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUpPasswords() throws Exception {
|
||||
for (int i = 0; i < RandomData.randomInt(1, 10); i++) {
|
||||
String password = RandomData.randomString(RandomData.randomInt(5, 16));
|
||||
PASSWORD_MAP.put(password, PassEncryptUtil.createHash(password));
|
||||
@ -42,7 +45,7 @@ public class PassEncryptTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerification() throws Exception {
|
||||
void testVerification() throws Exception {
|
||||
for (Map.Entry<String, String> entry : PASSWORD_MAP.entrySet()) {
|
||||
String password = entry.getKey();
|
||||
String hash = entry.getValue();
|
||||
|
@ -16,16 +16,19 @@
|
||||
*/
|
||||
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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class SHA256HashTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class SHA256HashTest {
|
||||
|
||||
@Test
|
||||
public void sameStringReturnsSameHash() throws NoSuchAlgorithmException {
|
||||
void sameStringReturnsSameHash() throws NoSuchAlgorithmException {
|
||||
String expected = new SHA256Hash("1.3.4.5").create();
|
||||
String result = new SHA256Hash("1.3.4.5").create();
|
||||
assertEquals(expected, result);
|
||||
|
@ -16,24 +16,27 @@
|
||||
*/
|
||||
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.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link Median}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class MedianTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class MedianTest {
|
||||
|
||||
@Test
|
||||
public void simpleOdd() {
|
||||
void simpleOdd() {
|
||||
List<Integer> testValues = Arrays.asList(1, 3, 3, 6, 7, 8, 9);
|
||||
Collections.shuffle(testValues);
|
||||
double expected = 6;
|
||||
@ -43,7 +46,7 @@ public class MedianTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleEven() {
|
||||
void simpleEven() {
|
||||
List<Integer> testValues = Arrays.asList(1, 2, 3, 4, 5, 6, 8, 9);
|
||||
Collections.shuffle(testValues);
|
||||
double expected = 4.5;
|
||||
@ -53,7 +56,7 @@ public class MedianTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void empty() {
|
||||
void empty() {
|
||||
double expected = -1;
|
||||
double result = Median.forList(new ArrayList<Integer>()).calculate();
|
||||
|
||||
@ -61,7 +64,7 @@ public class MedianTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleValue() {
|
||||
void singleValue() {
|
||||
double expected = 50;
|
||||
double result = Median.forList(Collections.singletonList((int) expected)).calculate();
|
||||
|
||||
@ -69,7 +72,7 @@ public class MedianTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoValues() {
|
||||
void twoValues() {
|
||||
List<Integer> testValues = Arrays.asList(1, 2);
|
||||
double expected = 1.5;
|
||||
double result = Median.forList(testValues).calculate();
|
||||
@ -78,7 +81,7 @@ public class MedianTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overflowOdd() {
|
||||
void overflowOdd() {
|
||||
List<Integer> testValues = Arrays.asList(Integer.MIN_VALUE, 2, Integer.MAX_VALUE);
|
||||
double expected = 2;
|
||||
double result = Median.forList(testValues).calculate();
|
||||
@ -87,7 +90,7 @@ public class MedianTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overflowEven() {
|
||||
void overflowEven() {
|
||||
List<Integer> testValues = Arrays.asList(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
double expected = -0.5;
|
||||
double result = Median.forList(testValues).calculate();
|
||||
@ -96,7 +99,7 @@ public class MedianTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overflowEven2() {
|
||||
void overflowEven2() {
|
||||
List<Integer> testValues = Arrays.asList(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
double expected = Integer.MAX_VALUE;
|
||||
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.utilities.PassEncryptUtil;
|
||||
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 java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
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
|
||||
public void pointComparator() {
|
||||
void pointComparator() {
|
||||
List<Point> points = RandomData.randomPoints();
|
||||
|
||||
List<Long> expected = points.stream().map(Point::getX).map(i -> (long) (double) i)
|
||||
@ -51,7 +54,7 @@ public class ComparatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sessionDataComparator() {
|
||||
void sessionDataComparator() {
|
||||
List<Session> sessions = RandomData.randomSessions();
|
||||
|
||||
List<Long> expected = sessions.stream().map(s -> s.getUnsafe(SessionKeys.START))
|
||||
@ -65,7 +68,7 @@ public class ComparatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tpsComparator() {
|
||||
void tpsComparator() {
|
||||
List<TPS> tpsList = RandomData.randomTPS();
|
||||
|
||||
List<Long> expected = tpsList.stream().map(TPS::getDate)
|
||||
@ -78,7 +81,7 @@ public class ComparatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webUserComparator() throws PassEncryptUtil.CannotPerformOperationException {
|
||||
void webUserComparator() throws PassEncryptUtil.CannotPerformOperationException {
|
||||
List<WebUser> webUsers = RandomData.randomWebUsers();
|
||||
|
||||
List<Integer> expected = webUsers.stream().map(WebUser::getPermLevel)
|
||||
@ -92,7 +95,7 @@ public class ComparatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringLengthComparator() {
|
||||
void stringLengthComparator() {
|
||||
List<Integer> result = Stream.of(
|
||||
RandomData.randomString(10),
|
||||
RandomData.randomString(3),
|
||||
@ -112,7 +115,7 @@ public class ComparatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localeEntryComparator() {
|
||||
void localeEntryComparator() {
|
||||
Map<Lang, Message> messageMap = new HashMap<>();
|
||||
messageMap.put(CmdHelpLang.SERVERS, new Message(RandomData.randomString(10)));
|
||||
messageMap.put(CmdHelpLang.ANALYZE, new Message(RandomData.randomString(10)));
|
||||
@ -132,7 +135,7 @@ public class ComparatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void geoInfoComparator() {
|
||||
void geoInfoComparator() {
|
||||
List<GeoInfo> geoInfos = RandomData.randomGeoInfo();
|
||||
|
||||
List<Long> expected = geoInfos.stream().map(GeoInfo::getDate)
|
||||
|
@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(JUnitPlatform.class)
|
||||
public class HtmlTest {
|
||||
class HtmlTest {
|
||||
|
||||
@Test
|
||||
void parsingWithNoArgsDoesNotReplacePlaceholder() {
|
||||
|
@ -16,18 +16,21 @@
|
||||
*/
|
||||
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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class HtmlUtilsTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class HtmlUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testRemoveXSS() {
|
||||
void testRemoveXSS() {
|
||||
String randomString = RandomData.randomString(10);
|
||||
|
||||
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.store.mutators.TPSMutator;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test class for {@link LineGraph}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class LineGraphTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class LineGraphTest {
|
||||
|
||||
private final List<TPS> tpsList = new ArrayList<>();
|
||||
private static List<TPS> DATA;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
DATA = new ArrayList<>();
|
||||
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
|
||||
public void testLineGraphsForBracketErrors() {
|
||||
TPSMutator mutator = new TPSMutator(tpsList);
|
||||
void testLineGraphsForBracketErrors() {
|
||||
TPSMutator mutator = new TPSMutator(DATA);
|
||||
LineGraph[] graphs = new LineGraph[]{
|
||||
new CPUGraph(mutator, true),
|
||||
new PlayersOnlineGraph(mutator, false),
|
||||
@ -79,15 +83,15 @@ public class LineGraphTest {
|
||||
break;
|
||||
case ')':
|
||||
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;
|
||||
case ']':
|
||||
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;
|
||||
case '}':
|
||||
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;
|
||||
default:
|
||||
break;
|
||||
|
@ -24,8 +24,10 @@ import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ConsoleErrorLogger;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -34,17 +36,18 @@ import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link PlayersTable}
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlayersTableTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class PlayersTableTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
@BeforeAll
|
||||
static void setUpClass() {
|
||||
new CommonAPI(
|
||||
Mockito.mock(DBSystem.class),
|
||||
Mockito.mock(UUIDUtility.class),
|
||||
@ -55,7 +58,7 @@ public class PlayersTableTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noClassCastExceptionsFromFormatting() {
|
||||
void noClassCastExceptionsFromFormatting() {
|
||||
PlayerContainer container = new PlayerContainer();
|
||||
container.putRawData(PlayerKeys.SESSIONS, new ArrayList<>());
|
||||
List<PlayerContainer> players = Collections.singletonList(container);
|
||||
@ -79,12 +82,12 @@ public class PlayersTableTest {
|
||||
for (String s : split) {
|
||||
if (s.startsWith("/")) {
|
||||
String expectedElement = stack.pop();
|
||||
assertTrue("Element not properly closed: " + expectedElement, s.startsWith("/" + expectedElement));
|
||||
assertTrue(s.startsWith("/" + expectedElement), () -> "Element not properly closed: " + expectedElement);
|
||||
} else {
|
||||
stack.push(s.split(" ", 2)[0].split(">", 2)[0]);
|
||||
}
|
||||
}
|
||||
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() {
|
||||
if (Boolean.parseBoolean(System.getenv(CIProperties.IS_TRAVIS))) {
|
||||
if (Boolean.parseBoolean(System.getenv(CIProperties.IS_CI_SERVICE))) {
|
||||
ChromeOptions chromeOptions = new ChromeOptions();
|
||||
chromeOptions.setBinary("/usr/bin/google-chrome-stable");
|
||||
chromeOptions.setHeadless(true);
|
||||
|
@ -47,7 +47,7 @@ public class SeleniumDriver extends ExternalResource {
|
||||
}
|
||||
|
||||
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.setBinary("/usr/bin/google-chrome-stable");
|
||||
chromeOptions.setHeadless(true);
|
||||
|
@ -23,7 +23,7 @@ package utilities;
|
||||
*/
|
||||
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";
|
||||
|
||||
private CIProperties() {
|
||||
|
@ -18,8 +18,8 @@ package utilities;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Utility for asserts containing Optionals.
|
||||
@ -29,8 +29,8 @@ import static org.junit.Assert.assertTrue;
|
||||
public class OptionalAssert {
|
||||
|
||||
public static <T> void equals(T expected, Optional<T> result) {
|
||||
assertTrue("No result present, expected: " + expected, result.isPresent());
|
||||
assertEquals("Wrong result, expected: " + expected + ", got: " + result.get(), expected, result.get());
|
||||
assertTrue(result.isPresent(), () -> "No result present, expected: " + expected);
|
||||
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.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.
|
||||
@ -47,7 +47,7 @@ abstract class Mocker {
|
||||
}
|
||||
try {
|
||||
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) {
|
||||
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