mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-16 21:13:05 +03:00
[FEATURE] Система тестов - начало.
This commit is contained in:
parent
8854fbfe16
commit
c788fd4d2c
6 changed files with 96 additions and 21 deletions
|
@ -309,7 +309,7 @@ public static void main(String... args) throws Throwable {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
LaunchServer launchserver = new LaunchServer(IOHelper.WORKING_DIR, args);
|
LaunchServer launchserver = new LaunchServer(IOHelper.WORKING_DIR, false, args);
|
||||||
if (args.length == 0) launchserver.run();
|
if (args.length == 0) launchserver.run();
|
||||||
else { //Обработка команды
|
else { //Обработка команды
|
||||||
launchserver.commandHandler.eval(args, false);
|
launchserver.commandHandler.eval(args, false);
|
||||||
|
@ -326,6 +326,8 @@ public static void main(String... args) throws Throwable {
|
||||||
|
|
||||||
public final Path dir;
|
public final Path dir;
|
||||||
|
|
||||||
|
public final boolean testEnv;
|
||||||
|
|
||||||
public final Path launcherLibraries;
|
public final Path launcherLibraries;
|
||||||
|
|
||||||
public final Path launcherLibrariesCompile;
|
public final Path launcherLibrariesCompile;
|
||||||
|
@ -355,7 +357,7 @@ public static void main(String... args) throws Throwable {
|
||||||
|
|
||||||
public final JARLauncherBinary launcherBinary;
|
public final JARLauncherBinary launcherBinary;
|
||||||
|
|
||||||
public Class<LauncherBinary> launcherEXEBinaryClass;
|
public Class<? extends LauncherBinary> launcherEXEBinaryClass;
|
||||||
|
|
||||||
public final LauncherBinary launcherEXEBinary;
|
public final LauncherBinary launcherEXEBinary;
|
||||||
// HWID ban + anti-brutforce
|
// HWID ban + anti-brutforce
|
||||||
|
@ -400,8 +402,11 @@ public static void main(String... args) throws Throwable {
|
||||||
public static Gson gson;
|
public static Gson gson;
|
||||||
public static GsonBuilder gsonBuilder;
|
public static GsonBuilder gsonBuilder;
|
||||||
|
|
||||||
public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecException {
|
public static Class<? extends LauncherBinary> defaultLauncherEXEBinaryClass = null;
|
||||||
|
|
||||||
|
public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException, InvalidKeySpecException {
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
|
this.testEnv = testEnv;
|
||||||
taskPool = new Timer("Timered task worker thread", true);
|
taskPool = new Timer("Timered task worker thread", true);
|
||||||
launcherLibraries = dir.resolve("launcher-libraries");
|
launcherLibraries = dir.resolve("launcher-libraries");
|
||||||
launcherLibrariesCompile = dir.resolve("launcher-libraries-compile");
|
launcherLibrariesCompile = dir.resolve("launcher-libraries-compile");
|
||||||
|
@ -425,16 +430,19 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
|
|
||||||
// Set command handler
|
// Set command handler
|
||||||
CommandHandler localCommandHandler;
|
CommandHandler localCommandHandler;
|
||||||
try {
|
if (testEnv)
|
||||||
Class.forName("jline.Terminal");
|
localCommandHandler = new StdCommandHandler(false);
|
||||||
|
else
|
||||||
|
try {
|
||||||
|
Class.forName("jline.Terminal");
|
||||||
|
|
||||||
// JLine2 available
|
// JLine2 available
|
||||||
localCommandHandler = new JLineCommandHandler();
|
localCommandHandler = new JLineCommandHandler();
|
||||||
LogHelper.info("JLine2 terminal enabled");
|
LogHelper.info("JLine2 terminal enabled");
|
||||||
} catch (ClassNotFoundException ignored) {
|
} catch (ClassNotFoundException ignored) {
|
||||||
localCommandHandler = new StdCommandHandler(true);
|
localCommandHandler = new StdCommandHandler(true);
|
||||||
LogHelper.warning("JLine2 isn't in classpath, using std");
|
LogHelper.warning("JLine2 isn't in classpath, using std");
|
||||||
}
|
}
|
||||||
ru.gravit.launchserver.command.handler.CommandHandler.registerCommands(localCommandHandler);
|
ru.gravit.launchserver.command.handler.CommandHandler.registerCommands(localCommandHandler);
|
||||||
commandHandler = localCommandHandler;
|
commandHandler = localCommandHandler;
|
||||||
|
|
||||||
|
@ -463,7 +471,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
LogHelper.subInfo("Modulus CRC32: 0x%08x", crc.getValue());
|
LogHelper.subInfo("Modulus CRC32: 0x%08x", crc.getValue());
|
||||||
|
|
||||||
// Load class bindings.
|
// Load class bindings.
|
||||||
launcherEXEBinaryClass = null;
|
launcherEXEBinaryClass = defaultLauncherEXEBinaryClass;
|
||||||
|
|
||||||
// pre init modules
|
// pre init modules
|
||||||
modulesManager = new ModulesManager(this);
|
modulesManager = new ModulesManager(this);
|
||||||
|
@ -472,7 +480,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
initGson();
|
initGson();
|
||||||
|
|
||||||
// Read LaunchServer config
|
// Read LaunchServer config
|
||||||
generateConfigIfNotExists();
|
generateConfigIfNotExists(testEnv);
|
||||||
LogHelper.info("Reading LaunchServer config file");
|
LogHelper.info("Reading LaunchServer config file");
|
||||||
try (BufferedReader reader = IOHelper.newReader(configFile)) {
|
try (BufferedReader reader = IOHelper.newReader(configFile)) {
|
||||||
config = Launcher.gson.fromJson(reader, Config.class);
|
config = Launcher.gson.fromJson(reader, Config.class);
|
||||||
|
@ -628,7 +636,7 @@ public void close() {
|
||||||
LogHelper.info("LaunchServer stopped");
|
LogHelper.info("LaunchServer stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateConfigIfNotExists() throws IOException {
|
private void generateConfigIfNotExists(boolean testEnv) throws IOException {
|
||||||
if (IOHelper.isFile(configFile))
|
if (IOHelper.isFile(configFile))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -688,10 +696,15 @@ private void generateConfigIfNotExists() throws IOException {
|
||||||
newConfig.components.put("authLimiter", authLimiterComponent);
|
newConfig.components.put("authLimiter", authLimiterComponent);
|
||||||
|
|
||||||
// Set server address
|
// Set server address
|
||||||
System.out.println("LaunchServer address: ");
|
if (testEnv) {
|
||||||
newConfig.setLegacyAddress(commandHandler.readLine());
|
newConfig.setLegacyAddress("localhost");
|
||||||
System.out.println("LaunchServer projectName: ");
|
newConfig.setProjectName("test");
|
||||||
newConfig.setProjectName(commandHandler.readLine());
|
} else {
|
||||||
|
System.out.println("LaunchServer address: ");
|
||||||
|
newConfig.setLegacyAddress(commandHandler.readLine());
|
||||||
|
System.out.println("LaunchServer projectName: ");
|
||||||
|
newConfig.setProjectName(commandHandler.readLine());
|
||||||
|
}
|
||||||
|
|
||||||
// Write LaunchServer config
|
// Write LaunchServer config
|
||||||
LogHelper.info("Writing LaunchServer config file");
|
LogHelper.info("Writing LaunchServer config file");
|
||||||
|
@ -734,8 +747,10 @@ public void run() {
|
||||||
throw new IllegalStateException("LaunchServer has been already started");
|
throw new IllegalStateException("LaunchServer has been already started");
|
||||||
|
|
||||||
// Add shutdown hook, then start LaunchServer
|
// Add shutdown hook, then start LaunchServer
|
||||||
JVMHelper.RUNTIME.addShutdownHook(CommonHelper.newThread(null, false, this::close));
|
if (!this.testEnv) {
|
||||||
CommonHelper.newThread("Command Thread", true, commandHandler).start();
|
JVMHelper.RUNTIME.addShutdownHook(CommonHelper.newThread(null, false, this::close));
|
||||||
|
CommonHelper.newThread("Command Thread", true, commandHandler).start();
|
||||||
|
}
|
||||||
rebindServerSocket();
|
rebindServerSocket();
|
||||||
if (config.netty != null)
|
if (config.netty != null)
|
||||||
rebindNettyServerSocket();
|
rebindNettyServerSocket();
|
||||||
|
|
1
LauncherTest/permissions.json
Normal file
1
LauncherTest/permissions.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package ru.gravit.launcher.test.utils;
|
||||||
|
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.binary.LauncherBinary;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
public class EXENonWarningLauncherBinary extends LauncherBinary {
|
||||||
|
|
||||||
|
public EXENonWarningLauncherBinary(LaunchServer server) {
|
||||||
|
super(server, server.dir.resolve(server.config.binaryName + ".exe"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void build() throws IOException {
|
||||||
|
if (IOHelper.isFile(syncBinaryFile)) {
|
||||||
|
Files.delete(syncBinaryFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
36
LauncherTest/src/test/java/ru/gravit/launcher/StartTest.java
Normal file
36
LauncherTest/src/test/java/ru/gravit/launcher/StartTest.java
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
package ru.gravit.launcher;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.test.utils.EXENonWarningLauncherBinary;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
public class StartTest {
|
||||||
|
@TempDir
|
||||||
|
public Path dir;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void prepare() {
|
||||||
|
LogHelper.removeStdOutput();
|
||||||
|
LaunchServer.defaultLauncherEXEBinaryClass = EXENonWarningLauncherBinary.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkLaunchServerStarts() {
|
||||||
|
try {
|
||||||
|
LaunchServer srv = new LaunchServer(dir, true, new String[] { "checkInstall" });
|
||||||
|
srv.run();
|
||||||
|
srv.commandHandler.eval(new String[] { "checkInstall" }, false);
|
||||||
|
srv.close();
|
||||||
|
} catch (InvalidKeySpecException | IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue