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
Some checks failed
KnarCraft/Minecraft-Server-Launcher/pipeline/head There was a failure building this commit
This commit is contained in:
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user