Skip to content

Commit

Permalink
chore(camel): Minor Camel DSL improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
christophd committed Nov 2, 2024
1 parent 188fb53 commit 4115718
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 4115718

Please sign in to comment.