From b9f120ce9fd703e6df474c3bf0db0c512da4f9ed Mon Sep 17 00:00:00 2001 From: Thomas Diesler Date: Wed, 4 Feb 2015 17:19:48 +0100 Subject: [PATCH] [resolves #35] Provide camel-script integration --- itests/standalone/pom.xml | 4 + .../test/script/BeanShellIntegrationTest.java | 78 +++++++++++++++++++ modules/etc/baseline/module-list.txt | 1 + modules/etc/smartics/camel-modules.xml | 5 ++ .../apache/camel/component/main/module.xml | 1 + modules/pom.xml | 5 ++ pom.xml | 8 ++ 7 files changed, 102 insertions(+) create mode 100644 itests/standalone/src/test/java/org/wildfly/camel/test/script/BeanShellIntegrationTest.java diff --git a/itests/standalone/pom.xml b/itests/standalone/pom.xml index b4cae0f13b..dcbe28347b 100644 --- a/itests/standalone/pom.xml +++ b/itests/standalone/pom.xml @@ -95,6 +95,10 @@ org.apache.camel camel-quartz2 + + org.apache.camel + camel-script + org.jboss jboss-dmr diff --git a/itests/standalone/src/test/java/org/wildfly/camel/test/script/BeanShellIntegrationTest.java b/itests/standalone/src/test/java/org/wildfly/camel/test/script/BeanShellIntegrationTest.java new file mode 100644 index 0000000000..715c487f5f --- /dev/null +++ b/itests/standalone/src/test/java/org/wildfly/camel/test/script/BeanShellIntegrationTest.java @@ -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"); + } + }; + } +} diff --git a/modules/etc/baseline/module-list.txt b/modules/etc/baseline/module-list.txt index e43bc49e93..e76b563cdd 100644 --- a/modules/etc/baseline/module-list.txt +++ b/modules/etc/baseline/module-list.txt @@ -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 diff --git a/modules/etc/smartics/camel-modules.xml b/modules/etc/smartics/camel-modules.xml index 63dfa91505..f96a2c9bd3 100644 --- a/modules/etc/smartics/camel-modules.xml +++ b/modules/etc/smartics/camel-modules.xml @@ -176,6 +176,11 @@ + + + + + diff --git a/modules/etc/wildfly/modules/system/layers/fuse/org/apache/camel/component/main/module.xml b/modules/etc/wildfly/modules/system/layers/fuse/org/apache/camel/component/main/module.xml index a697616d8d..a89a9692f7 100644 --- a/modules/etc/wildfly/modules/system/layers/fuse/org/apache/camel/component/main/module.xml +++ b/modules/etc/wildfly/modules/system/layers/fuse/org/apache/camel/component/main/module.xml @@ -43,6 +43,7 @@ + diff --git a/modules/pom.xml b/modules/pom.xml index 35d0403b93..7aa05f07e0 100644 --- a/modules/pom.xml +++ b/modules/pom.xml @@ -246,6 +246,11 @@ lucene-queryparser provided + + org.beanshell + bsh + provided + org.jboss.gravia gravia-jmx-cm diff --git a/pom.xml b/pom.xml index 70ee9e75a9..60c75d845a 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,7 @@ 1.8.0 1.0.6 4.10.2 + 2.0b5 1.1.2 2.2.1 2.2 @@ -163,6 +164,13 @@ ${version.jboss.arquillian.core} + + + org.beanshell + bsh + ${version.beanshell} + + co.freeside