From 411571856065ca4025b2e0365b70df49c9fe0581 Mon Sep 17 00:00:00 2001 From: Christoph Deppisch Date: Sat, 2 Nov 2024 15:19:46 +0100 Subject: [PATCH] chore(camel): Minor Camel DSL improvements --- .../camel/actions/CamelRouteActionBuilder.java | 8 -------- .../actions/CreateCamelComponentAction.java | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRouteActionBuilder.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRouteActionBuilder.java index b3ae3a827e..22c43147bf 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRouteActionBuilder.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRouteActionBuilder.java @@ -31,14 +31,6 @@ public class CamelRouteActionBuilder extends AbstractReferenceResolverAwareTestA private CamelContext camelContext; - /** - * Fluent API action building entry method used in Java DSL. - * @return - */ - public static CamelRouteActionBuilder camel() { - return new CamelRouteActionBuilder(); - } - /** * Processor calling given Camel route as part of the message processing. * @return diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelComponentAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelComponentAction.java index 0035f1d875..0fa2bad113 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelComponentAction.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelComponentAction.java @@ -19,6 +19,7 @@ import java.io.IOException; import org.citrusframework.camel.context.CamelReferenceResolver; +import org.citrusframework.common.InitializingPhase; import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.groovy.dsl.GroovySupport; @@ -50,6 +51,10 @@ public void doExecute(TestContext context) { toCreate = new GroovySupport() .withTestContext(context) .load(context.replaceDynamicContentInString(script), "org.apache.camel.*"); + + if (toCreate instanceof InitializingPhase) { + ((InitializingPhase) toCreate).initialize(); + } } else { toCreate = component; } @@ -84,6 +89,10 @@ public static Builder bind() { } public Builder component(String name, Object component) { + if (component instanceof String) { + return component(name, component.toString()); + } + this.name = name; this.component = component; return this; @@ -94,12 +103,16 @@ public Builder component(Resource resource) { } public Builder component(String name, Resource resource) { - this.name = name; try { - this.script = FileUtils.readToString(resource); + return component(name, FileUtils.readToString(resource)); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read Camel component from resource '%s'".formatted(resource.getLocation()), e); } + } + + public Builder component(String name, String script) { + this.name = name; + this.script = script; return this; }