This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-24727-jbang-export-golden in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0b0f8575a89a96f94ee1304b7aedcd7b2022811e Author: Claus Ibsen <[email protected]> AuthorDate: Thu Oct 29 15:26:03 2026 +0100 CAMEL-24727: camel-jbang - ExportTest restores the system properties of its parameterized tests junit-pioneer 2.3.0 does not restore @SetSystemProperty after a @ParameterizedTest, so camel.jbang.repos, camel.extra.repos and camel.default.extra.repos.default.value stayed set for the tests that ran after in the same JVM. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../camel/dsl/jbang/core/commands/ExportTest.java | 131 ++++++++++++--------- 1 file changed, 76 insertions(+), 55 deletions(-) diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java index c78805d3accb..fe5d08030ad0 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java +++ b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java @@ -1617,64 +1617,68 @@ class ExportTest { @ParameterizedTest @MethodSource("runtimeProvider") - @SetSystemProperty(key = "camel.extra.repos", value = "atlassian=https://packages.atlassian.com/maven-external/") public void shouldExportWithExtraReposSystemProperty(RuntimeType rt) throws Exception { - LOG.info("shouldExportWithExtraReposSystemProperty {}", rt); - Export command = createCommand(rt, new String[] { "src/test/resources/route.yaml" }, - "--gav=examples:route:1.0.0", "--dir=" + workingDir, "--quiet"); - int exit = command.doCall(); + try (AutoCloseable property + = systemProperty("camel.extra.repos", "atlassian=https://packages.atlassian.com/maven-external/")) { + LOG.info("shouldExportWithExtraReposSystemProperty {}", rt); + Export command = createCommand(rt, new String[] { "src/test/resources/route.yaml" }, + "--gav=examples:route:1.0.0", "--dir=" + workingDir, "--quiet"); + int exit = command.doCall(); - Assertions.assertEquals(0, exit); - Model model = readMavenModel(); + Assertions.assertEquals(0, exit); + Model model = readMavenModel(); - assertThat(model.getRepositories()) - .as("Expected extra repos from camel.extra.repos in generated pom.xml") - .anySatisfy(repo -> { - assertThat(repo.getId()).isEqualTo("atlassian"); - assertThat(repo.getUrl()).isEqualTo("https://packages.atlassian.com/maven-external/"); - }); + assertThat(model.getRepositories()) + .as("Expected extra repos from camel.extra.repos in generated pom.xml") + .anySatisfy(repo -> { + assertThat(repo.getId()).isEqualTo("atlassian"); + assertThat(repo.getUrl()).isEqualTo("https://packages.atlassian.com/maven-external/"); + }); + } } @ParameterizedTest @MethodSource("runtimeProvider") - @SetSystemProperty(key = "camel.extra.repos", - value = "repo1=https://repo1.example.com/maven2,repo2=https://repo2.example.com/releases") public void shouldExportWithMultipleExtraRepos(RuntimeType rt) throws Exception { - LOG.info("shouldExportWithMultipleExtraRepos {}", rt); - Export command = createCommand(rt, new String[] { "src/test/resources/route.yaml" }, - "--gav=examples:route:1.0.0", "--dir=" + workingDir, "--quiet"); - int exit = command.doCall(); + try (AutoCloseable property = systemProperty("camel.extra.repos", + "repo1=https://repo1.example.com/maven2,repo2=https://repo2.example.com/releases")) { + LOG.info("shouldExportWithMultipleExtraRepos {}", rt); + Export command = createCommand(rt, new String[] { "src/test/resources/route.yaml" }, + "--gav=examples:route:1.0.0", "--dir=" + workingDir, "--quiet"); + int exit = command.doCall(); - Assertions.assertEquals(0, exit); - Model model = readMavenModel(); + Assertions.assertEquals(0, exit); + Model model = readMavenModel(); - assertThat(model.getRepositories()) - .as("Expected both extra repos in generated pom.xml") - .anySatisfy(repo -> { - assertThat(repo.getId()).isEqualTo("repo1"); - assertThat(repo.getUrl()).isEqualTo("https://repo1.example.com/maven2"); - }) - .anySatisfy(repo -> { - assertThat(repo.getId()).isEqualTo("repo2"); - assertThat(repo.getUrl()).isEqualTo("https://repo2.example.com/releases"); - }); + assertThat(model.getRepositories()) + .as("Expected both extra repos in generated pom.xml") + .anySatisfy(repo -> { + assertThat(repo.getId()).isEqualTo("repo1"); + assertThat(repo.getUrl()).isEqualTo("https://repo1.example.com/maven2"); + }) + .anySatisfy(repo -> { + assertThat(repo.getId()).isEqualTo("repo2"); + assertThat(repo.getUrl()).isEqualTo("https://repo2.example.com/releases"); + }); + } } @ParameterizedTest @MethodSource("runtimeProvider") - @SetSystemProperty(key = "camel.jbang.repos", value = "https://packages.atlassian.com/maven-external/") public void shouldExportWithReposFromSystemProperty(RuntimeType rt) throws Exception { - LOG.info("shouldExportWithReposFromSystemProperty {}", rt); - Export command = createCommand(rt, new String[] { "src/test/resources/route.yaml" }, - "--gav=examples:route:1.0.0", "--dir=" + workingDir, "--quiet"); - int exit = command.doCall(); + try (AutoCloseable property = systemProperty("camel.jbang.repos", "https://packages.atlassian.com/maven-external/")) { + LOG.info("shouldExportWithReposFromSystemProperty {}", rt); + Export command = createCommand(rt, new String[] { "src/test/resources/route.yaml" }, + "--gav=examples:route:1.0.0", "--dir=" + workingDir, "--quiet"); + int exit = command.doCall(); - Assertions.assertEquals(0, exit); - Model model = readMavenModel(); + Assertions.assertEquals(0, exit); + Model model = readMavenModel(); - assertThat(model.getRepositories()) - .as("Expected camel.jbang.repos from system property in generated pom.xml") - .anySatisfy(repo -> assertThat(repo.getUrl()).isEqualTo("https://packages.atlassian.com/maven-external/")); + assertThat(model.getRepositories()) + .as("Expected camel.jbang.repos from system property in generated pom.xml") + .anySatisfy(repo -> assertThat(repo.getUrl()).isEqualTo("https://packages.atlassian.com/maven-external/")); + } } @ParameterizedTest @@ -1705,23 +1709,40 @@ class ExportTest { @ParameterizedTest @MethodSource("runtimeProvider") - @SetSystemProperty(key = "camel.default.extra.repos.default.value", - value = "atlassian=https://packages.atlassian.com/maven-external/") public void shouldExportWithExtraReposDefaultValueFallback(RuntimeType rt) throws Exception { - LOG.info("shouldExportWithExtraReposDefaultValueFallback {}", rt); - Export command = createCommand(rt, new String[] { "src/test/resources/route.yaml" }, - "--gav=examples:route:1.0.0", "--dir=" + workingDir, "--quiet"); - int exit = command.doCall(); + try (AutoCloseable property = systemProperty("camel.default.extra.repos.default.value", + "atlassian=https://packages.atlassian.com/maven-external/")) { + LOG.info("shouldExportWithExtraReposDefaultValueFallback {}", rt); + Export command = createCommand(rt, new String[] { "src/test/resources/route.yaml" }, + "--gav=examples:route:1.0.0", "--dir=" + workingDir, "--quiet"); + int exit = command.doCall(); - Assertions.assertEquals(0, exit); - Model model = readMavenModel(); + Assertions.assertEquals(0, exit); + Model model = readMavenModel(); - assertThat(model.getRepositories()) - .as("Expected extra repos from camel.default.extra.repos.default.value fallback in generated pom.xml") - .anySatisfy(repo -> { - assertThat(repo.getId()).isEqualTo("atlassian"); - assertThat(repo.getUrl()).isEqualTo("https://packages.atlassian.com/maven-external/"); - }); + assertThat(model.getRepositories()) + .as("Expected extra repos from camel.default.extra.repos.default.value fallback in generated pom.xml") + .anySatisfy(repo -> { + assertThat(repo.getId()).isEqualTo("atlassian"); + assertThat(repo.getUrl()).isEqualTo("https://packages.atlassian.com/maven-external/"); + }); + } + } + + /** + * Sets a system property until closed. junit-pioneer's @SetSystemProperty (2.3.0) does not restore the property + * after a @ParameterizedTest, so it was left set for the tests that ran after. + */ + private static AutoCloseable systemProperty(String key, String value) { + String previous = System.getProperty(key); + System.setProperty(key, value); + return () -> { + if (previous == null) { + System.clearProperty(key); + } else { + System.setProperty(key, previous); + } + }; } }
