Fixes an error caused by the BuildTools directory not being created Creates functions for writing to files in CommonFunctions Adds some more error info to the log when BuildTools fails to download Fixes some typos Makes sure all visible text is logged
126 lines
4.4 KiB
Java
126 lines
4.4 KiB
Java
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.jupiter.api.AfterAll;
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import javax.naming.ConfigurationException;
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
|
public class JarDownloaderTest {
|
|
private static String targetDirectory;
|
|
|
|
@BeforeAll
|
|
public static void setUp() {
|
|
String filesDirectory = Main.getApplicationWorkDirectory() + File.separator + "files";
|
|
try {
|
|
CommonFunctions.createFolder(new File(filesDirectory + File.separator + "testjars"));
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
}
|
|
targetDirectory = filesDirectory + File.separator + "testjars" + File.separator;
|
|
removeDownloadedFiles();
|
|
}
|
|
|
|
@AfterAll
|
|
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 spongeForgeDownloadTest() throws IOException, ConfigurationException {
|
|
singleDownloadTest(ServerTypeHandler.getByName("SpongeForge"));
|
|
}*/
|
|
|
|
@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()) {
|
|
if ((serverType.getName().equals("Spigot") || serverType.getName().equals("Bukkit"))
|
|
&& serverVersion.equals("Latest")) {
|
|
continue;
|
|
}
|
|
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 target = new File(targetDirectory);
|
|
if (!target.exists() && !target.mkdirs()) {
|
|
throw new IllegalArgumentException("Unable to create the test files directory");
|
|
}
|
|
CommonFunctions.removeFilesRecursively(target);
|
|
}
|
|
}
|