Add unit test with inlined groovt script for people who want to code in xml


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1c7a2d74
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1c7a2d74
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1c7a2d74

Branch: refs/heads/master
Commit: 1c7a2d749e5f75545aa9899e9b06cdef4cf1d614
Parents: 6584c32
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sat Feb 7 10:10:58 2015 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sat Feb 7 10:10:58 2015 +0100

----------------------------------------------------------------------
 .../groovy/InlinedGroovyScriptTest.java         | 44 +++++++++++++++++
 .../processor/groovy/inlinedGroovyScript.xml    | 51 ++++++++++++++++++++
 2 files changed, 95 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1c7a2d74/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/InlinedGroovyScriptTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/InlinedGroovyScriptTest.java
 
b/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/InlinedGroovyScriptTest.java
new file mode 100644
index 0000000..d8a42c2
--- /dev/null
+++ 
b/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/InlinedGroovyScriptTest.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.camel.processor.groovy;
+
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version 
+ */
+public class InlinedGroovyScriptTest extends CamelSpringTestSupport {
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/processor/groovy/inlinedGroovyScript.xml");
+    }
+
+    @Test
+    public void testGroovy() throws Exception {
+        
getMockEndpoint("mock:result").expectedBodiesReceived("HelloHelloHello");
+
+        template.sendBodyAndHeader("direct:start", "Hello", "foo", 123);
+        template.sendBodyAndHeader("direct:start", "3", "foo", 123);
+
+        assertMockEndpointsSatisfied();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/1c7a2d74/components/camel-groovy/src/test/resources/org/apache/camel/processor/groovy/inlinedGroovyScript.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-groovy/src/test/resources/org/apache/camel/processor/groovy/inlinedGroovyScript.xml
 
b/components/camel-groovy/src/test/resources/org/apache/camel/processor/groovy/inlinedGroovyScript.xml
new file mode 100644
index 0000000..09e2b17
--- /dev/null
+++ 
b/components/camel-groovy/src/test/resources/org/apache/camel/processor/groovy/inlinedGroovyScript.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:lang="http://www.springframework.org/schema/lang";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://www.springframework.org/schema/lang 
http://www.springframework.org/schema/lang/spring-lang.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- inline a groovy script to use for the aggregator -->
+  <lang:groovy id="myAggregate">
+    <lang:inline-script>
+      class MyAggregate {
+        String someNameHere(String prev, int next) {
+          return prev * next
+        }
+      }
+    </lang:inline-script>
+  </lang:groovy>
+
+  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
+    <route>
+      <from uri="direct:start"/>
+      <!-- we must declare the name of the method, as the inlined groovy 
script has additional methods -->
+      <aggregate strategyRef="myAggregate" strategyMethodName="someNameHere" 
completionSize="2">
+        <correlationExpression>
+          <header>foo</header>
+        </correlationExpression>
+        <to uri="mock:result"/>
+      </aggregate>
+    </route>
+  </camelContext>
+
+</beans>

Reply via email to