Makes snapshot a vanilla version and loads all jars from the jars folder
Some checks failed
KnarCraft/Minecraft-Server-Launcher/pipeline/head There was a failure building this commit

This commit is contained in:
2020-08-13 03:04:02 +02:00
parent ab6453cdc3
commit 70d064e590
12 changed files with 210 additions and 67 deletions

View File

@ -1,18 +0,0 @@
package net.knarcraft.minecraftserverlauncher;
import net.knarcraft.minecraftserverlauncher.userinterface.FakeGUI;
import net.knarcraft.minecraftserverlauncher.utility.JarDownloader;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
public class DownloadTests {
@Test
public void downloadJarsTest() throws IOException {
String targetDirectory = Main.getApplicationWorkDirectory() + File.separator + "files" + File.separator + "testjars" + File.separator;
JarDownloader downloader = new JarDownloader(new FakeGUI(), targetDirectory);
downloader.downloadJars();
}
}

View File

@ -0,0 +1,38 @@
package net.knarcraft.minecraftserverlauncher.server;
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
import org.junit.Test;
import javax.naming.ConfigurationException;
import java.util.Arrays;
import static junit.framework.TestCase.assertEquals;
public class ServerTypeHandlerTest {
@Test
public void getTypeNamesTest() throws ConfigurationException {
String[] serverTypeNames = ServerTypeHandler.getTypeNames();
String[] typeNames = new String[serverTypeNames.length];
int index = 0;
for (ServerType serverType : ServerTypeHandler.getServerTypes()) {
typeNames[index++] = serverType.getName();
}
assertEquals(Arrays.asList(typeNames), Arrays.asList(serverTypeNames));
}
@Test
public void getTypeFromNameTest() throws ConfigurationException {
ServerType targetType = null;
for (ServerType serverType : ServerTypeHandler.getServerTypes()) {
if (serverType.getName().equals("Vanilla")) {
targetType = serverType;
}
}
ServerType typeFromName = ServerTypeHandler.getByName("Vanilla");
assertEquals(targetType, typeFromName);
}
}

View File

@ -1,4 +1,4 @@
package net.knarcraft.minecraftserverlauncher;
package net.knarcraft.minecraftserverlauncher.utility;
import net.knarcraft.minecraftserverlauncher.profile.Profile;
import org.junit.Test;
@ -8,16 +8,16 @@ import java.io.FileNotFoundException;
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.stringBetween;
import static org.junit.Assert.assertEquals;
public class Tests {
public class CommonFunctionsTest {
@Test
public void saveProfile() throws FileNotFoundException { //Make sure we can write profiles to disk
public void saveProfileTest() throws FileNotFoundException {
Profile.addProfile("Test");
Profile.getCurrent().save();
}
@Test
public void stringBetweenTest() { //Make sure stringBetween is not creating exceptions
public void stringBetweenTest() {
String substring = stringBetween("fish'nchips", "f", "'");
assertEquals("ish", substring);
substring = stringBetween("something", "whale", "fish");

View File

@ -0,0 +1,111 @@
package net.knarcraft.minecraftserverlauncher.utility;
import net.knarcraft.minecraftserverlauncher.Main;
import net.knarcraft.minecraftserverlauncher.server.ServerTypeHandler;
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
import net.knarcraft.minecraftserverlauncher.userinterface.FakeGUI;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import javax.naming.ConfigurationException;
import java.io.File;
import java.io.IOException;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;
public class JarDownloaderTest {
private static String targetDirectory;
@BeforeClass
public static void setUp() {
targetDirectory = Main.getApplicationWorkDirectory() + File.separator + "files" + File.separator +
"testjars" + File.separator;
removeDownloadedFiles();
}
@AfterClass
public static void cleanUp() {
removeDownloadedFiles();
}
@Test
public void downloadJarsTest() throws IOException {
JarDownloader downloader = new JarDownloader(new FakeGUI(), targetDirectory);
downloader.downloadJars();
}
@Test
public void spongeVanillaDownloadTest() throws IOException, ConfigurationException {
singleDownloadTest(ServerTypeHandler.getByName("SpongeVanilla"));
}
@Test
public void spigotDownloadTest() throws ConfigurationException, IOException {
singleDownloadTest(ServerTypeHandler.getByName("Spigot"));
}
@Test
public void mcpcPlusDownloadTest() throws ConfigurationException, IOException {
singleDownloadTest(ServerTypeHandler.getByName("MCPCplus"));
}
@Test
public void craftbukkitDownloadTest() throws ConfigurationException, IOException {
singleDownloadTest(ServerTypeHandler.getByName("Bukkit"));
}
@Test
public void paperDownloadTest() throws ConfigurationException, IOException {
singleDownloadTest(ServerTypeHandler.getByName("Paper"));
}
@Test
public void bungeeDownloadTest() throws ConfigurationException, IOException {
singleDownloadTest(ServerTypeHandler.getByName("Bungee"));
}
@Test
public void waterfallDownloadTest() throws ConfigurationException, IOException {
singleDownloadTest(ServerTypeHandler.getByName("Waterfall"));
}
@Test
public void travertineDownloadTest() throws ConfigurationException, IOException {
singleDownloadTest(ServerTypeHandler.getByName("Travertine"));
}
@Test
public void vanillaDownloadTest() throws ConfigurationException, IOException {
singleDownloadTest(ServerTypeHandler.getByName("Vanilla"));
}
/**
* Downloads all .jar files for a single server type and asserts it works
*
* @param serverType <p>The server type to test</p>
* @throws IOException <p>If unable to download any of the .jar files</p>
*/
private void singleDownloadTest(ServerType serverType) throws IOException {
assertNotNull(serverType);
for (String serverVersion : serverType.getVersions()) {
System.out.println("Downloading " + serverType.getName() + serverVersion + ".jar");
serverType.downloadJar(targetDirectory, serverVersion);
assertTrue(new File(targetDirectory + serverType.getName() + serverVersion + ".jar").exists());
}
}
/**
* Removes downloaded test jars
*/
private static void removeDownloadedFiles() {
File[] oldFiles = new File(targetDirectory).listFiles();
if (oldFiles == null) {
throw new IllegalArgumentException("Unable to list files in jar test directory");
}
for (File file : oldFiles) {
assertTrue(file.delete());
}
}
}