You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/09/20 14:14:31 UTC

svn commit: r998903 - in /camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet: ./ RestletTest.java

Author: davsclaus
Date: Mon Sep 20 12:14:31 2010
New Revision: 998903

URL: http://svn.apache.org/viewvc?rev=998903&view=rev
Log:
CAMEL-3126: Added more osgi tests.

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/RestletTest.java
      - copied, changed from r998895, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java

Copied: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/RestletTest.java (from r998895, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/RestletTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/RestletTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java&r1=998895&r2=998903&rev=998903&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/restlet/RestletTest.java Mon Sep 20 12:14:31 2010
@@ -14,11 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.itest.osgi.freemarker;
+package org.apache.camel.itest.osgi.restlet;
+
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
@@ -36,49 +37,50 @@ import static org.ops4j.pax.exam.contain
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
 
 @RunWith(JUnit4TestRunner.class)
-public class FreemarkerTest extends OSGiIntegrationTestSupport {
-    
-    @Test
-    public void testReceivesResponse() throws Exception {        
-        assertRespondsWith("foo", "<hello>foo</hello>");
-        assertRespondsWith("bar", "<hello>bar</hello>");
-    }
+public class RestletTest extends OSGiIntegrationTestSupport {
 
-    protected void assertRespondsWith(final String value, String expectedBody) throws InvalidPayloadException {
-        Exchange response = template.request("direct:a", new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                Message in = exchange.getIn();
-                in.setBody("answer");
-                in.setHeader("cheese", value);
-            }
-        });
-        assertOutMessageBodyEquals(response, expectedBody);
+    @Test
+    public void testRestletProducer() throws Exception {
+        Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put("username", "homer");
+        String response = (String)template.requestBodyAndHeaders("restlet:http://localhost:9080/users/{username}?restletMethod=POST", "<request>message</request>", headers);
+        assertEquals("The response is wrong ", response, "{homer}");
     }
 
+    @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
-            public void configure() {
-                from("direct:a").to("freemarker:org/apache/camel/itest/osgi/freemarker/example.ftl");
+            @Override
+            public void configure() throws Exception {
+                from("restlet:http://localhost:9080/users/{username}?restletMethod=POST").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        String userName = exchange.getIn().getHeader("username", String.class);
+                        assertNotNull("userName should not be null", userName);
+                        exchange.getOut().setBody("{" + userName + "}");
+                        exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, "417");
+                        exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/JSON");
+                    }
+                });
             }
         };
     }
-    
+
     @Configuration
     public static Option[] configure() {
         Option[] options = options(
-            // install the spring dm profile            
-            profile("spring.dm").version("1.2.0"),    
+            // install the spring dm profile
+            profile("spring.dm").version("1.2.0"),
             // this is how you set the default log level when using pax logging (logProfile)
             org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
-            
-            // using the features to install the camel components             
-            scanFeatures(getCamelKarafFeatureUrl(),                         
-                          "camel-core", "camel-spring", "camel-test", "camel-freemarker"),
-            
+
+            // using the features to install the camel components
+            scanFeatures(getCamelKarafFeatureUrl(),
+                    "camel-core", "camel-spring", "camel-test", "camel-restlet"),
+
             workingDirectory("target/paxrunner/"),
 
             felix(), equinox());
-        
+
         return options;
     }
 }
\ No newline at end of file