gnodet-bot commented on code in PR #26532: URL: https://github.com/apache/camel/pull/26532#discussion_r4034205414
########## dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunExportedProjectTest.java: ########## @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.dsl.jbang.core.commands; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import picocli.CommandLine; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Verifies how {@code camel run --runtime=quarkus|spring-boot} runs the exported project: the execution limits are + * passed to the child JVM like for Camel Main, and the log file is named after the name the application reports. + */ +class RunExportedProjectTest extends CamelCommandBaseTestSupport { + + @TempDir + Path dir; + + private static Run run(String... args) { + Run command = new Run(new CamelJBangMain()); + CommandLine.populateCommand(command, args); + return command; + } + + @Test + void durationLimitsArePassedToExportedRun() { + String args = run("--max-seconds=30", "--max-messages=5", "--max-idle-seconds=10", "route.yaml") + .buildExportedRunJvmArgs(); + + assertThat(args).isEqualTo("-Dcamel.main.durationMaxSeconds=30 -Dcamel.main.durationMaxMessages=5" + + " -Dcamel.main.durationMaxIdleSeconds=10"); + } + + @Test + void durationLimitsAreMergedWithJvmArgs() { + String args = run("--jvm-args=-Xmx512m", "--max-seconds=30", "route.yaml").buildExportedRunJvmArgs(); + + assertThat(args).isEqualTo("-Xmx512m -Dcamel.main.durationMaxSeconds=30"); + } + + @Test + void noJvmArgsWhenNothingToPass() { + assertThat(run("route.yaml").buildExportedRunJvmArgs()).isNull(); + } + + @Test + void jfrIsPassedAsJvmArgument() { + String args = run("--jfr", "route.yaml").buildExportedRunJvmArgs(); + + assertThat(args).contains("-XX:StartFlightRecording"); + } + + @Test + void durationLimitsAreTheSameForAllRuntimes() { + Run run = run("--max-seconds=30", "route.yaml"); + + List<String> limits = run.buildDurationLimitArgs(); + assertThat(limits).containsExactly("-Dcamel.main.durationMaxSeconds=30"); + assertThat(run.buildExistingProjectSystemProperties("server.port")).containsAll(limits); + assertThat(run.buildExportedRunJvmArgs()).isEqualTo(String.join(" ", limits)); Review Comment: ⚠️ **Test coverage gap — name promises more than the assertions deliver.** `durationLimitsAreTheSameForAllRuntimes` uses `buildExistingProjectSystemProperties("server.port")` as a stand-in for the existing-project Quarkus and Spring Boot run paths, but the actual methods invoked at runtime are `buildExistingQuarkusJvmArgs` and `buildExistingSpringBootJvmArgs`. If either of those is ever refactored to stop delegating to `buildExistingProjectSystemProperties`, the execution limits would silently disappear from those paths — and this test wouldn't notice. Either rename the test to reflect what it actually covers, or add direct assertions: ```suggestion void durationLimitsAreTheSameForAllRuntimes() { Run run = run("--max-seconds=30", "route.yaml"); List<String> limits = run.buildDurationLimitArgs(); assertThat(limits).containsExactly("-Dcamel.main.durationMaxSeconds=30"); // exported run paths (camel run foo.yaml --runtime=quarkus|spring-boot) assertThat(run.buildExistingProjectSystemProperties("server.port")).containsAll(limits); assertThat(run.buildExportedRunJvmArgs()).isEqualTo(String.join(" ", limits)); // existing-project run paths (camel run pom.xml --runtime=quarkus|spring-boot) assertThat(run.buildExistingQuarkusJvmArgs("my-app")).containsAll(limits); assertThat(run.buildExistingSpringBootJvmArgs()).containsAll(limits); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
