Skip to content

Commit

Permalink
chore(camel): Add step to create Camel route from file
Browse files Browse the repository at this point in the history
  • Loading branch information
christophd committed Feb 19, 2024
1 parent 503ffdc commit 3b64984
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 12 additions & 2 deletions java/docs/steps-camel.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Given New Spring Camel context
In Apache Camel you need to create routes in order to start producing/consuming data from endpoints. The routes can be defined
in XML or Groovy.

.@Given("^Camel route {name}\\.xml")
.@Given("^Camel route {name}.xml")
[source,gherkin]
----
Given Camel route hello.xml
Expand All @@ -71,7 +71,7 @@ Given Camel route hello.xml

In addition to XML route definitions YAKS also supports the Groovy DSL.

.@Given("^Camel route {name}\\.groovy")
.@Given("^Camel route {name}.groovy")
[source,gherkin]
----
Given Camel route hello.groovy
Expand All @@ -87,6 +87,16 @@ from("direct:hello")
The above steps create the Camel routes and automatically starts them in the current context. The given routes start
to consume messages from the endpoint `direct:hello`.

You can also load the Camel route from a file resource.

.@Given("^load Camel route path/to/{name}.{language}")
[source,gherkin]
----
Given load Camel route hello.groovy
----

Currently, the languages `xml` and `groovy` are supported.

[[camel-routes-manage]]
=== Start/stop Camel routes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.Resource;
import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
import org.citrusframework.xml.StringSource;
import org.citrusframework.yaks.groovy.GroovyShellUtils;
Expand Down Expand Up @@ -265,6 +266,19 @@ protected void configureRoute(RouteDefinition route) {
camelContext().addRoutes(routeBuilder);
}

@Given("^load Camel route ([^\\s]+)\\.(groovy|xml)")
public void loadCamelRoute(String fileName, String language) throws Exception {
String route = FileUtils.readToString(Resources.create(fileName));
switch (language) {
case "groovy":
camelRouteGroovy(fileName, route);
break;
case "xml":
camelRouteXml(fileName, route);
break;
}
}

@Given("^start Camel route ([^\\s]+)$")
public void startRoute(String routeId) {
runner.run(camel().context(camelContext())
Expand Down

0 comments on commit 3b64984

Please sign in to comment.