Updated Branches:
  refs/heads/camel-2.12.x afb0c1b77 -> 873a4812f

CAMEL-7143: Added unit test.


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

Branch: refs/heads/camel-2.12.x
Commit: 873a4812fe602bc130b04c4460108051c1c2b82d
Parents: afb0c1b
Author: Claus Ibsen <davscl...@apache.org>
Authored: Mon Jan 27 18:02:46 2014 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Mon Jan 27 18:03:21 2014 +0100

----------------------------------------------------------------------
 .../restlet/example/RestletGroovyIssueTest.java | 73 +++++++++++++++++++
 .../example/SpringRestletGroovyIssueTest.java   | 77 ++++++++++++++++++++
 .../example/SpringRestletGroovyIssueTest.xml    | 40 ++++++++++
 3 files changed, 190 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/873a4812/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/RestletGroovyIssueTest.java
----------------------------------------------------------------------
diff --git 
a/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/RestletGroovyIssueTest.java
 
b/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/RestletGroovyIssueTest.java
new file mode 100644
index 0000000..dc97af5
--- /dev/null
+++ 
b/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/RestletGroovyIssueTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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.itest.restlet.example;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class RestletGroovyIssueTest extends CamelTestSupport {
+
+    private long port = AvailablePortFinder.getNextAvailable(16000);
+    private ExecutorService executorService = Executors.newFixedThreadPool(5);
+
+    @Test
+    public void testRestletGroovy() throws Exception {
+        for (int i = 0; i < 10; i++) {
+            final Integer num = i;
+            getMockEndpoint("mock:input").expectedMessageCount(10);
+            
getMockEndpoint("mock:output").expectedBodiesReceivedInAnyOrder("0", "1", "2", 
"3", "4", "5", "6", "7", "8", "9");
+
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    String s = "" + num;
+                    Object response = 
template.requestBody("restlet:http://localhost:"; + port + "/foo/" + s + 
"?restletMethod=GET", "");
+                    assertEquals(s, response);
+                };
+            });
+        }
+
+        assertMockEndpointsSatisfied();
+
+        executorService.shutdownNow();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                fromF("restlet:http://localhost:%s/foo/{id}";, port)
+                    .to("log:input?showHeaders=true")
+                    .to("mock:input")
+                    .transform().groovy("request.headers.id")
+                    // sleep a bit so multiple threads are in use
+                    .delay(1000)
+                    .to("log:output")
+                    .to("mock:output");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/873a4812/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/SpringRestletGroovyIssueTest.java
----------------------------------------------------------------------
diff --git 
a/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/SpringRestletGroovyIssueTest.java
 
b/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/SpringRestletGroovyIssueTest.java
new file mode 100644
index 0000000..1879db8
--- /dev/null
+++ 
b/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/SpringRestletGroovyIssueTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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.itest.restlet.example;
+
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+
+/**
+ * @version 
+ */
+public class SpringRestletGroovyIssueTest extends CamelSpringTestSupport {
+
+    private static int port = AvailablePortFinder.getNextAvailable(16001);
+    private ExecutorService executorService = Executors.newFixedThreadPool(5);
+
+    static {
+        //set them as system properties so Spring can use the property 
placeholder
+        //things to set them into the URL's in the spring contexts
+        System.setProperty("SpringRestletGroovyIssueTest.port", 
Integer.toString(port));
+    }
+
+    @Override
+    protected Properties useOverridePropertiesWithPropertiesComponent() {
+        Properties prop = new Properties();
+        prop.put("port", port);
+        return prop;
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/itest/restlet/example/SpringRestletGroovyIssueTest.xml");
+    }
+
+    @Test
+    public void testRestletGroovy() throws Exception {
+        for (int i = 0; i < 10; i++) {
+            final Integer num = i;
+            getMockEndpoint("mock:input").expectedMessageCount(10);
+            
getMockEndpoint("mock:output").expectedBodiesReceivedInAnyOrder("0", "1", "2", 
"3", "4", "5", "6", "7", "8", "9");
+
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    String s = "" + num;
+                    Object response = 
template.requestBody("restlet:http://localhost:"; + port + "/foo/" + s + 
"?restletMethod=GET", "");
+                    assertEquals(s, response);
+                };
+            });
+        }
+
+        assertMockEndpointsSatisfied();
+
+        executorService.shutdownNow();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/873a4812/tests/camel-itest/src/test/resources/org/apache/camel/itest/restlet/example/SpringRestletGroovyIssueTest.xml
----------------------------------------------------------------------
diff --git 
a/tests/camel-itest/src/test/resources/org/apache/camel/itest/restlet/example/SpringRestletGroovyIssueTest.xml
 
b/tests/camel-itest/src/test/resources/org/apache/camel/itest/restlet/example/SpringRestletGroovyIssueTest.xml
new file mode 100644
index 0000000..662d928
--- /dev/null
+++ 
b/tests/camel-itest/src/test/resources/org/apache/camel/itest/restlet/example/SpringRestletGroovyIssueTest.xml
@@ -0,0 +1,40 @@
+<?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";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd";>
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring";>
+    <route>
+      <from 
uri="restlet:http://localhost:{{SpringRestletGroovyIssueTest.port}}/foo/{id}"/>
+      <to uri="log:input?showHeaders=true"/>
+      <to uri="mock:input"/>
+      <transform>
+        <groovy>request.headers.id</groovy>
+      </transform>
+      <delay>
+        <constant>1000</constant>
+      </delay>
+      <to uri="log:output"/>
+      <to uri="mock:output"/>
+    </route>
+  </camelContext>
+
+</beans>

Reply via email to