Skip to content

Commit

Permalink
[resolves #35] Provide camel-script integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Diesler committed Feb 4, 2015
1 parent d406e2a commit b9f120c
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 0 deletions.
4 changes: 4 additions & 0 deletions itests/standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-script</artifactId>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-dmr</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* #%L
* Wildfly Camel :: Testsuite
* %%
* Copyright (C) 2013 - 2014 RedHat
* %%
* Licensed 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.
* #L%
*/

package org.wildfly.camel.test.script;

import static org.apache.camel.builder.script.ScriptBuilder.script;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class BeanShellIntegrationTest {

@Deployment
public static JavaArchive deployment() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "script-tests");
return archive;
}

@Test
public void testSendMatchingMessage() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(getRouteBuilder());
camelctx.start();

ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBodyAndHeader("direct:start", "mybody", "foo", "bar", String.class);
Assert.assertEquals("mybody", result);
}

@Test
public void testSendNonMatchingMessage() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(getRouteBuilder());
camelctx.start();

ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBodyAndHeader("direct:start", "mybody", "foo", "bad", String.class);
Assert.assertEquals("mybody unmatched", result);
}

private RouteBuilder getRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").choice()
.when(script("beanshell", "request.getHeaders().get(\"foo\").equals(\"bar\")")).to("mock:result")
.otherwise().transform(body().append(" unmatched")).to("mock:unmatched");
}
};
}
}
1 change: 1 addition & 0 deletions modules/etc/baseline/module-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
/org/apache/camel/component/rss/main/rome-1.0.jar
/org/apache/camel/component/saxon/main/Saxon-HE-9.5.1-5.jar
/org/apache/camel/component/saxon/main/camel-saxon-2.14.1.jar
/org/apache/camel/component/script/main/bsh-2.0b5.jar
/org/apache/camel/component/script/main/camel-script-2.14.1.jar
/org/apache/camel/component/soap/main/camel-soap-2.14.1.jar
/org/apache/camel/component/sql/main/camel-sql-2.14.1.jar
Expand Down
5 changes: 5 additions & 0 deletions modules/etc/smartics/camel-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@
</dependencies>
</module>

<module name="org.apache.camel.component.script">
<include artifact="org.apache.camel:camel-script" />
<include artifact="org.beanshell:bsh" />
</module>

<!-- rule to rename the remaining camel artifacts ids to better module names -->
<module name="org.apache.camel.component.$1">
<include artifact="org.apache.camel:camel-(.*)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<module name="org.apache.camel.component.quartz2" export="true" services="export" />
<module name="org.apache.camel.component.rss" export="true" services="export" />
<module name="org.apache.camel.component.saxon" export="true" services="export" />
<module name="org.apache.camel.component.script" export="true" services="export" />
<module name="org.apache.camel.component.weather" export="true" services="export" />
</dependencies>

Expand Down
5 changes: 5 additions & 0 deletions modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@
<artifactId>lucene-queryparser</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.gravia</groupId>
<artifactId>gravia-jmx-cm</artifactId>
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<version.apache.felix.scr.generator>1.8.0</version.apache.felix.scr.generator>
<version.apache.ftpserver>1.0.6</version.apache.ftpserver>
<version.apache.lucene>4.10.2</version.apache.lucene>
<version.beanshell>2.0b5</version.beanshell>
<version.freeside.betamax>1.1.2</version.freeside.betamax>
<version.groovy>2.2.1</version.groovy>
<version.hapi>2.2</version.hapi>
Expand Down Expand Up @@ -163,6 +164,13 @@
<version>${version.jboss.arquillian.core}</version>
</dependency>

<!-- Beanshell -->
<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>${version.beanshell}</version>
</dependency>

<!-- Betamax -->
<dependency>
<groupId>co.freeside</groupId>
Expand Down

0 comments on commit b9f120c

Please sign in to comment.