diff --git a/connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/JBangSupport.java b/connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/JBangSupport.java index 3cf0bf3996..1ded03660b 100644 --- a/connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/JBangSupport.java +++ b/connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/JBangSupport.java @@ -94,7 +94,7 @@ public static JBangSupport jbang() { * Get JBang version. */ public String version() { - ProcessAndOutput p = execute(jBang("version"), envVars); + ProcessAndOutput p = execute(jBang("version"), null); return p.getOutput(); } @@ -175,7 +175,7 @@ public ProcessAndOutput runAsync(String command, String... args) { * Command can be a script file or an app command. */ public ProcessAndOutput runAsync(String command, List args) { - return executeAsync(jBang(systemProperties, constructAllArgs(command, args))); + return executeAsync(jBang(systemProperties, constructAllArgs(command, args)), envVars); } /** @@ -193,7 +193,7 @@ public ProcessAndOutput runAsync(String command, File output, String... args) { * Redirect the process output to given file. */ public ProcessAndOutput runAsync(String command, File output, List args) { - return executeAsync(jBang(systemProperties, constructAllArgs(command, args)), output); + return executeAsync(jBang(systemProperties, constructAllArgs(command, args)), output, envVars); } private List constructAllArgs(String command, List args) { @@ -333,7 +333,7 @@ private static String getSystemPropertyArgs(Map systemProperties return systemProperties.entrySet() .stream() - .map(entry -> "-D%s=%s".formatted(entry.getKey(), entry.getValue())) + .map(entry -> "-D%s=\"%s\"".formatted(entry.getKey(), entry.getValue())) .collect(Collectors.joining(" ")) + " "; } @@ -353,7 +353,7 @@ private static ProcessAndOutput execute(List command, Map command, Map command) { + private static ProcessAndOutput executeAsync(List command, Map envVars) { try { - Process p = new ProcessBuilder(command) - .redirectErrorStream(true) - .start(); + ProcessBuilder pBuilder = new ProcessBuilder(command) + .redirectErrorStream(true); + + if (envVars != null) { + pBuilder.environment().putAll(envVars); + } + + Process p = pBuilder.start(); return new ProcessAndOutput(p); } catch (IOException e) { throw new CitrusRuntimeException("Error while executing JBang", e); @@ -400,15 +406,20 @@ private static ProcessAndOutput executeAsync(List command) { * caller is able to access the exit code and process output. * @param command * @param outputFile + * @param envVars * @return */ - private static ProcessAndOutput executeAsync(List command, File outputFile) { + private static ProcessAndOutput executeAsync(List command, File outputFile, Map envVars) { try { - Process p = new ProcessBuilder(command) + ProcessBuilder pBuilder = new ProcessBuilder(command) .redirectErrorStream(true) - .redirectOutput(outputFile) - .start(); + .redirectOutput(outputFile); + if (envVars != null) { + pBuilder.environment().putAll(envVars); + } + + Process p = pBuilder.start(); return new ProcessAndOutput(p, outputFile); } catch (IOException e) { throw new CitrusRuntimeException("Error while executing JBang", e); diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java index 9984ed1d55..06dbc1866c 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java @@ -73,6 +73,7 @@ public class CamelRunIntegrationAction extends AbstractCamelJBangAction { private final boolean autoRemoveResources; private final boolean waitForRunningState; + private final boolean dumpIntegrationOutput; /** * Default constructor. @@ -89,6 +90,7 @@ public CamelRunIntegrationAction(Builder builder) { this.systemProperties = builder.systemProperties; this.autoRemoveResources = builder.autoRemoveResources; this.waitForRunningState = builder.waitForRunningState; + this.dumpIntegrationOutput = builder.dumpIntegrationOutput; } @Override @@ -113,6 +115,7 @@ public void doExecute(TestContext context) { throw new CitrusRuntimeException("Missing Camel integration source code or file"); } + camelJBang().dumpIntegrationOutput(dumpIntegrationOutput); camelJBang().camelApp().withEnvs(context.resolveDynamicValuesInMap(envVars)); camelJBang().camelApp().withSystemProperties(context.resolveDynamicValuesInMap(systemProperties)); @@ -191,6 +194,7 @@ public static final class Builder extends AbstractCamelJBangAction.Builder resources, St runArgs.add(file); runArgs.addAll(resources); - if (CamelJBangSettings.isCamelDumpIntegrationOutput()) { + if (dumpIntegrationOutput) { Path workDir = CamelJBangSettings.getWorkDir(); File outputFile = workDir.resolve(String.format("i-%s-output.txt", name)).toFile(); @@ -232,4 +234,9 @@ public List> getAll() { } } + public CamelJBang dumpIntegrationOutput(boolean enabled) { + this.dumpIntegrationOutput = enabled; + return this; + } + } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBangSettings.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBangSettings.java index 02ea705691..2d0377652c 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBangSettings.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBangSettings.java @@ -114,7 +114,7 @@ public static String[] getTrustUrl() { * When set to true JBang process output for Camel integrations will be redirected to a file in the current working directory. * @return */ - public static boolean isCamelDumpIntegrationOutput() { + public static boolean isDumpIntegrationOutput() { return Boolean.parseBoolean(System.getProperty(CAMEL_DUMP_INTEGRATION_OUTPUT_PROPERTY, System.getenv(CAMEL_DUMP_INTEGRATION_OUTPUT_ENV) != null ? System.getenv(CAMEL_DUMP_INTEGRATION_OUTPUT_ENV) : CAMEL_DUMP_INTEGRATION_OUTPUT_DEFAULT)); } diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/integration/CamelJBangIT.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/integration/CamelJBangIT.java index b957f52824..a039791085 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/integration/CamelJBangIT.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/integration/CamelJBangIT.java @@ -43,16 +43,18 @@ public void runIntegrationWithSourceCodeIT() { includeMetadata: true steps: - setBody: - simple: "Hello Camel #${header.CamelTimerCounter}" + simple: "{{greeting}} #${header.CamelTimerCounter}" - transform: simple: "${body.toUpperCase()}" - to: "log:info" - """)); + """) + .withSystemProperty("greeting", "Hello Camel")); then(camel().jbang() .verify("hello") .waitForLogMessage("HELLO CAMEL #10")); } + @Test @CitrusTest(name = "RunIntegration_Resource_IT") public void runIntegrationWithResourceIT() { @@ -62,7 +64,8 @@ public void runIntegrationWithResourceIT() { when(camel().jbang() .run() - .integration(Resources.fromClasspath("route.yaml", CamelJBangIT.class))); + .integration(Resources.fromClasspath("route.yaml", CamelJBangIT.class)) + .withEnv("GREETING", "Hello Camel")); then(camel().jbang() .verify("route") diff --git a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/integration/route.yaml b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/integration/route.yaml index 10251693aa..3348b9ff5d 100644 --- a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/integration/route.yaml +++ b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/integration/route.yaml @@ -5,7 +5,7 @@ includeMetadata: true steps: - setBody: - simple: "Hello Camel #${header.CamelTimerCounter}" + simple: "{{greeting}} #${header.CamelTimerCounter}" - transform: simple: "${body.toUpperCase()}" - to: "log:info" diff --git a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/xml/camel-jbang-test.xml b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/xml/camel-jbang-test.xml index 9cbfa789bc..c153081eaf 100644 --- a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/xml/camel-jbang-test.xml +++ b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/xml/camel-jbang-test.xml @@ -24,7 +24,11 @@ + file="classpath:org/citrusframework/camel/integration/route.yaml"> + + + + diff --git a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/yaml/camel-jbang-test.yaml b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/yaml/camel-jbang-test.yaml index 60379b164c..24dfb0eee4 100644 --- a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/yaml/camel-jbang-test.yaml +++ b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/yaml/camel-jbang-test.yaml @@ -10,6 +10,10 @@ actions: integration: name: "hello-yaml" file: "classpath:org/citrusframework/camel/integration/route.yaml" + systemProperties: + properties: + - name: greeting + value: Hello Camel - camel: jbang: verify: diff --git a/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase-4.4.0-SNAPSHOT.xsd b/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase-4.4.0-SNAPSHOT.xsd index 59d0f89f31..ba1319ac16 100644 --- a/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase-4.4.0-SNAPSHOT.xsd +++ b/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase-4.4.0-SNAPSHOT.xsd @@ -1028,7 +1028,7 @@ - + diff --git a/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase.xsd b/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase.xsd index 59d0f89f31..ba1319ac16 100644 --- a/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase.xsd +++ b/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase.xsd @@ -1028,7 +1028,7 @@ - +