From 33f1e6c8d1ba87b8bf849d89fd5164c9441f4d0c Mon Sep 17 00:00:00 2001 From: Adler Fleurant <2609856+AdlerFleurant@users.noreply.github.com> Date: Sun, 25 Sep 2022 11:25:23 -0400 Subject: [PATCH] Ignore non-existing class and resource paths during JVM test Some resource and class locations may not exist when resolving paths. We now ensure that these non-existing path are not added to the application root. Signed-off-by: Adler Fleurant <2609856+AdlerFleurant@users.noreply.github.com> --- .../java/io/quarkus/maven/it/PackageIT.java | 8 ++ .../deployment/pom.xml | 44 +++++++++ .../integration-tests/pom.xml | 93 +++++++++++++++++++ .../test/java/org/example/ExampleTest.java | 12 +++ .../extension-test-with-no-main/pom.xml | 77 +++++++++++++++ .../runtime/pom.xml | 50 ++++++++++ .../AbstractJvmQuarkusTestExtension.java | 36 +++---- 7 files changed, 299 insertions(+), 21 deletions(-) create mode 100644 integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/deployment/pom.xml create mode 100644 integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/integration-tests/pom.xml create mode 100644 integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/integration-tests/src/test/java/org/example/ExampleTest.java create mode 100644 integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/pom.xml create mode 100644 integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/runtime/pom.xml diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java index 0f9806b0f26b3..84d1a2efb5e15 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java @@ -51,6 +51,14 @@ public void testExtensionRemovedResources() throws Exception { assertThat(result.getProcess().waitFor()).isEqualTo(0); } + @Test + public void testExtensionTestWithNoMain() throws Exception { + testDir = initProject("projects/extension-test-with-no-main"); + running = new RunningInvoker(testDir, false); + final MavenProcessInvocationResult result = running.execute(List.of("verify"), Map.of()); + assertThat(result.getProcess().waitFor()).isEqualTo(0); + } + @Test public void testUberJarMavenPluginConfiguration() throws MavenInvocationException, IOException, InterruptedException { diff --git a/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/deployment/pom.xml b/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/deployment/pom.xml new file mode 100644 index 0000000000000..9a2863adf1ba0 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/deployment/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + org.example + extension-test-with-no-main + 1.0.0-SNAPSHOT + + runtime-deployment + Extension test with no main - Deployment + + + io.quarkus + quarkus-arc-deployment + + + org.example + runtime + \${project.version} + + + io.quarkus + quarkus-junit5-internal + test + + + + + + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + \${quarkus.version} + + + + + + + diff --git a/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/integration-tests/pom.xml b/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/integration-tests/pom.xml new file mode 100644 index 0000000000000..8e400633eec0b --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/integration-tests/pom.xml @@ -0,0 +1,93 @@ + + + 4.0.0 + + org.example + extension-test-with-no-main + 1.0.0-SNAPSHOT + + extension-test-with-no-main-integration-tests + Extension test with no main - Integration Tests + + true + + + + io.quarkus + quarkus-resteasy + + + org.example + runtime + \${project.version} + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + io.quarkus + quarkus-maven-plugin + + + + build + + + + + + maven-failsafe-plugin + + + + integration-test + verify + + + + \${project.build.directory}/\${project.build.finalName}-runner + org.jboss.logmanager.LogManager + \${maven.home} + + + + + + + + + + native-image + + + native + + + + + + maven-surefire-plugin + + \${native.surefire.skip} + + + + + + false + native + + + + diff --git a/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/integration-tests/src/test/java/org/example/ExampleTest.java b/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/integration-tests/src/test/java/org/example/ExampleTest.java new file mode 100644 index 0000000000000..89b9cc85fd5a2 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/integration-tests/src/test/java/org/example/ExampleTest.java @@ -0,0 +1,12 @@ +package org.example; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +@QuarkusTest +public class ExampleTest { + + @Test + public void test() {} + +} \ No newline at end of file diff --git a/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/pom.xml b/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/pom.xml new file mode 100644 index 0000000000000..e92c9ddb51621 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + org.example + extension-test-with-no-main + 1.0.0-SNAPSHOT + pom + Extension test with no main + + deployment + runtime + integration-tests + + + 3.8.1 + ${surefire-plugin.version} + 11 + UTF-8 + UTF-8 + @project.version@ + 3.0.0-M7 + + + + + io.quarkus + quarkus-bom + \${quarkus.version} + pom + import + + + + + + + + io.quarkus + quarkus-maven-plugin + \${quarkus.version} + + + maven-surefire-plugin + \${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + \${maven.home} + \${settings.localRepository} + + + + + maven-failsafe-plugin + \${failsafe-plugin.version} + + + org.jboss.logmanager.LogManager + \${maven.home} + \${settings.localRepository} + + + + + maven-compiler-plugin + \${compiler-plugin.version} + + + -parameters + + + + + + + diff --git a/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/runtime/pom.xml b/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/runtime/pom.xml new file mode 100644 index 0000000000000..352593d4e387a --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/extension-test-with-no-main/runtime/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + org.example + extension-test-with-no-main + 1.0.0-SNAPSHOT + + runtime + Extension test with no main - Runtime + + + io.quarkus + quarkus-arc + + + + + + io.quarkus + quarkus-extension-maven-plugin + \${quarkus.version} + + + compile + + extension-descriptor + + + \${project.groupId}:\${project.artifactId}-deployment:\${project.version} + + + + + + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + \${quarkus.version} + + + + + + + diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java index 9021f60b113b7..629dd7c3df92f 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java @@ -12,6 +12,7 @@ import java.util.Deque; import java.util.HashMap; import java.util.Map; +import java.util.function.Consumer; import java.util.stream.Collectors; import javax.enterprise.inject.Alternative; @@ -59,20 +60,21 @@ protected PrepareResult createAugmentor(ExtensionContext context, Class addToBuilderIfConditionMet = path -> { + if (path != null && Files.exists(path) && !rootBuilder.contains(path)) { + rootBuilder.add(path); + } + }; + if (!appClassLocation.equals(testClassLocation)) { - rootBuilder.add(testClassLocation); + addToBuilderIfConditionMet.accept(testClassLocation); // if test classes is a dir, we should also check whether test resources dir exists as a separate dir (gradle) // TODO: this whole app/test path resolution logic is pretty dumb, it needs be re-worked using proper workspace discovery final Path testResourcesLocation = PathTestHelper.getResourcesForClassesDirOrNull(testClassLocation, "test"); - if (testResourcesLocation != null) { - rootBuilder.add(testResourcesLocation); - } + addToBuilderIfConditionMet.accept(testResourcesLocation); } originalCl = Thread.currentThread().getContextClassLoader(); - Map sysPropRestore = new HashMap<>(); - sysPropRestore.put(ProfileManager.QUARKUS_TEST_PROFILE_PROP, - System.getProperty(ProfileManager.QUARKUS_TEST_PROFILE_PROP)); // clear the test.url system property as the value leaks into the run when using different profiles System.clearProperty("test.url"); @@ -99,17 +101,15 @@ protected PrepareResult createAugmentor(ExtensionContext context, Class