From af5b725911f036bbf8d4e2407b8ed28d0f2e1d8d Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 27 Sep 2023 16:09:00 +0300 Subject: [PATCH] Add tests for new main method launch protocol --- .../InstanceMainCommandModeTestCase.java | 34 +++++++++++++++++++ ...InstanceMainNoArgsCommandModeTestCase.java | 34 +++++++++++++++++++ ...onPublicStaticMainCommandModeTestCase.java | 34 +++++++++++++++++++ .../PrivateStaticMainCommandModeTestCase.java | 33 ++++++++++++++++++ ...edStaticMainNoArgsCommandModeTestCase.java | 34 +++++++++++++++++++ .../StaticMainNoArgsCommandModeTestCase.java | 34 +++++++++++++++++++ 6 files changed, 203 insertions(+) create mode 100644 integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/InstanceMainCommandModeTestCase.java create mode 100644 integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/InstanceMainNoArgsCommandModeTestCase.java create mode 100644 integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/NonPublicStaticMainCommandModeTestCase.java create mode 100644 integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/PrivateStaticMainCommandModeTestCase.java create mode 100644 integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/ProtectedStaticMainNoArgsCommandModeTestCase.java create mode 100644 integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/StaticMainNoArgsCommandModeTestCase.java diff --git a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/InstanceMainCommandModeTestCase.java b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/InstanceMainCommandModeTestCase.java new file mode 100644 index 0000000000000..53797b869b488 --- /dev/null +++ b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/InstanceMainCommandModeTestCase.java @@ -0,0 +1,34 @@ +package io.quarkus.commandmode; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.runtime.annotations.QuarkusMain; +import io.quarkus.test.QuarkusProdModeTest; + +public class InstanceMainCommandModeTestCase { + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar + .addClasses(HelloWorldMain.class)) + .setApplicationName("run-exit") + .setApplicationVersion("0.1-SNAPSHOT") + .setExpectExit(true) + .setRun(true); + + @Test + public void testRun() { + Assertions.assertThat(config.getStartupConsoleOutput()).contains("Hello World"); + Assertions.assertThat(config.getExitCode()).isEqualTo(0); + } + + @QuarkusMain + public static class HelloWorldMain { + + void main(String[] args) { + System.out.println("Hello World"); + } + } + +} diff --git a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/InstanceMainNoArgsCommandModeTestCase.java b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/InstanceMainNoArgsCommandModeTestCase.java new file mode 100644 index 0000000000000..e5e86384388c2 --- /dev/null +++ b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/InstanceMainNoArgsCommandModeTestCase.java @@ -0,0 +1,34 @@ +package io.quarkus.commandmode; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.runtime.annotations.QuarkusMain; +import io.quarkus.test.QuarkusProdModeTest; + +public class InstanceMainNoArgsCommandModeTestCase { + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar + .addClasses(HelloWorldMain.class)) + .setApplicationName("run-exit") + .setApplicationVersion("0.1-SNAPSHOT") + .setExpectExit(true) + .setRun(true); + + @Test + public void testRun() { + Assertions.assertThat(config.getStartupConsoleOutput()).contains("Hello World"); + Assertions.assertThat(config.getExitCode()).isEqualTo(0); + } + + @QuarkusMain + public static class HelloWorldMain { + + void main() { + System.out.println("Hello World"); + } + } + +} diff --git a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/NonPublicStaticMainCommandModeTestCase.java b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/NonPublicStaticMainCommandModeTestCase.java new file mode 100644 index 0000000000000..3e6c8b8064709 --- /dev/null +++ b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/NonPublicStaticMainCommandModeTestCase.java @@ -0,0 +1,34 @@ +package io.quarkus.commandmode; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.runtime.annotations.QuarkusMain; +import io.quarkus.test.QuarkusProdModeTest; + +public class NonPublicStaticMainCommandModeTestCase { + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar + .addClasses(HelloWorldMain.class)) + .setApplicationName("run-exit") + .setApplicationVersion("0.1-SNAPSHOT") + .setExpectExit(true) + .setRun(true); + + @Test + public void testRun() { + Assertions.assertThat(config.getStartupConsoleOutput()).contains("Hello World"); + Assertions.assertThat(config.getExitCode()).isEqualTo(0); + } + + @QuarkusMain + public static class HelloWorldMain { + + public static void main(String[] args) { + System.out.println("Hello World"); + } + } + +} diff --git a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/PrivateStaticMainCommandModeTestCase.java b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/PrivateStaticMainCommandModeTestCase.java new file mode 100644 index 0000000000000..3cb3d69c7c746 --- /dev/null +++ b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/PrivateStaticMainCommandModeTestCase.java @@ -0,0 +1,33 @@ +package io.quarkus.commandmode; + +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.runtime.annotations.QuarkusMain; +import io.quarkus.test.QuarkusProdModeTest; + +public class PrivateStaticMainCommandModeTestCase { + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar + .addClasses(HelloWorldMain.class)) + .setApplicationName("run-exit") + .setApplicationVersion("0.1-SNAPSHOT") + .setExpectedException(IllegalStateException.class); + + @Test + public void shouldNeverRun() { + fail(); + } + + @QuarkusMain + public static class HelloWorldMain { + + public static void main2(String[] args) { + System.out.println("Hello World"); + } + } + +} diff --git a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/ProtectedStaticMainNoArgsCommandModeTestCase.java b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/ProtectedStaticMainNoArgsCommandModeTestCase.java new file mode 100644 index 0000000000000..4434c82f31fed --- /dev/null +++ b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/ProtectedStaticMainNoArgsCommandModeTestCase.java @@ -0,0 +1,34 @@ +package io.quarkus.commandmode; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.runtime.annotations.QuarkusMain; +import io.quarkus.test.QuarkusProdModeTest; + +public class ProtectedStaticMainNoArgsCommandModeTestCase { + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar + .addClasses(HelloWorldMain.class)) + .setApplicationName("run-exit") + .setApplicationVersion("0.1-SNAPSHOT") + .setExpectExit(true) + .setRun(true); + + @Test + public void testRun() { + Assertions.assertThat(config.getStartupConsoleOutput()).contains("Hello World"); + Assertions.assertThat(config.getExitCode()).isEqualTo(0); + } + + @QuarkusMain + public static class HelloWorldMain { + + protected static void main() { + System.out.println("Hello World"); + } + } + +} diff --git a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/StaticMainNoArgsCommandModeTestCase.java b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/StaticMainNoArgsCommandModeTestCase.java new file mode 100644 index 0000000000000..f1a4979fa4948 --- /dev/null +++ b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/commandmode/StaticMainNoArgsCommandModeTestCase.java @@ -0,0 +1,34 @@ +package io.quarkus.commandmode; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.runtime.annotations.QuarkusMain; +import io.quarkus.test.QuarkusProdModeTest; + +public class StaticMainNoArgsCommandModeTestCase { + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar + .addClasses(HelloWorldMain.class)) + .setApplicationName("run-exit") + .setApplicationVersion("0.1-SNAPSHOT") + .setExpectExit(true) + .setRun(true); + + @Test + public void testRun() { + Assertions.assertThat(config.getStartupConsoleOutput()).contains("Hello World"); + Assertions.assertThat(config.getExitCode()).isEqualTo(0); + } + + @QuarkusMain + public static class HelloWorldMain { + + static void main() { + System.out.println("Hello World"); + } + } + +}