Add Main class for game engine initialization and remove BootstrapTest
This commit is contained in:
70
src/main/java/de/extio/game_engine/Main.java
Normal file
70
src/main/java/de/extio/game_engine/Main.java
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package de.extio.game_engine;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.logging.ConsoleHandler;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Condition;
|
||||||
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
|
import org.springframework.context.annotation.Conditional;
|
||||||
|
import org.springframework.context.event.ContextClosedEvent;
|
||||||
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@ComponentScan
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(final String[] args) {
|
||||||
|
System.setProperty("game-engine.env", "standalone");
|
||||||
|
|
||||||
|
// final Logger rootLogger = Logger.getLogger("");
|
||||||
|
// rootLogger.setLevel(Level.ALL);
|
||||||
|
// final ConsoleHandler consoleHandler = new ConsoleHandler();
|
||||||
|
// consoleHandler.setLevel(Level.ALL);
|
||||||
|
// final Logger logger = Logger.getLogger("java.awt.event.Component");
|
||||||
|
// logger.setLevel(Level.ALL);
|
||||||
|
// logger.setUseParentHandlers(false);
|
||||||
|
// logger.addHandler(consoleHandler);
|
||||||
|
|
||||||
|
// SpringApplication.run(Main.class, args);
|
||||||
|
final SpringApplicationBuilder builder = new SpringApplicationBuilder(Main.class);
|
||||||
|
builder.headless(false);
|
||||||
|
builder.properties("logging.level.de.extio=TRACE");
|
||||||
|
builder.run(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "gameEngineEventConsumer")
|
||||||
|
@Conditional(StandaloneEnvCondition.class)
|
||||||
|
public Consumer<Object> eventConsumer() {
|
||||||
|
return event -> {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Bean
|
||||||
|
// @Conditional(StandaloneEnvCondition.class)
|
||||||
|
// public ApplicationListener<ContextClosedEvent> shutdownListener() {
|
||||||
|
// return event -> {
|
||||||
|
// System.exit(0);
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
static class StandaloneEnvCondition implements Condition {
|
||||||
|
|
||||||
|
public StandaloneEnvCondition() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) {
|
||||||
|
final String env = System.getProperty("game-engine.env", "prod");
|
||||||
|
return "standalone".equalsIgnoreCase(env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package de.extio.game_engine;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.SpringBootConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@ContextConfiguration(classes = BootstrapTest.TestConfig.class)
|
|
||||||
public class BootstrapTest {
|
|
||||||
|
|
||||||
static {
|
|
||||||
System.setProperty("java.awt.headless", "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
@SpringBootConfiguration
|
|
||||||
@EnableAutoConfiguration
|
|
||||||
@ComponentScan(basePackages = "de.extio.game_engine")
|
|
||||||
static class TestConfig {
|
|
||||||
|
|
||||||
@Bean(name = "gameEngineEventConsumer")
|
|
||||||
public Consumer<Object> eventConsumer() {
|
|
||||||
return event -> {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(100000);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user