camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r774208 - /camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsUseOriginalInBodyTest.java
Date Wed, 13 May 2009 05:17:56 GMT
Author: davsclaus
Date: Wed May 13 05:17:55 2009
New Revision: 774208

URL: http://svn.apache.org/viewvc?rev=774208&view=rev
Log:
CAMEL-1600: added unit test in camel-jms

Added:
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsUseOriginalInBodyTest.java
      - copied, changed from r774185, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java

Copied: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsUseOriginalInBodyTest.java
(from r774185, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsUseOriginalInBodyTest.java?p2=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsUseOriginalInBodyTest.java&p1=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java&r1=774185&r2=774208&rev=774208&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java
(original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsUseOriginalInBodyTest.java
Wed May 13 05:17:55 2009
@@ -16,62 +16,85 @@
  */
 package org.apache.camel.component.jms;
 
-import java.io.File;
-
 import javax.jms.ConnectionFactory;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.DeadLetterChannelBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.IOConverter;
-
 import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
 
 /**
- * Unit test that we can consume JMS message and store it as file (to avoid regression bug)
+ * Unit test for useOriginalInBody unit test
  */
-public class JmsRouteToFileTest extends ContextTestSupport {
+public class JmsUseOriginalInBodyTest extends ContextTestSupport {
+
+    public void testUseOriginalnBody() throws Exception {
+        MockEndpoint dead = getMockEndpoint("mock:a");
+        dead.expectedBodiesReceived("Hello");
 
-    protected String componentName = "activemq";
+        template.sendBody("activemq:queue:a", "Hello");
 
-    public void testRouteToFile() throws Exception {
-        MockEndpoint result = getMockEndpoint("mock:result");
-        result.expectedMessageCount(1);
-        
-        deleteDirectory("target/routetofile");
-
-        template.sendBody("activemq:queue:hello", "Hello World");
-
-        // pause to let file producer save the file
-        result.assertIsSatisfied();
-        
-        // do file assertions
-        File dir = new File("./target/routetofile");
-        assertTrue("Should be directory", dir.isDirectory());
-        File file = dir.listFiles()[0];
-        assertTrue("File should exists", file.exists());
-        String body = IOConverter.toString(file);
-        assertEquals("Hello World", body);
+        assertMockEndpointsSatisfied();
     }
 
-    protected CamelContext createCamelContext() throws Exception {
-        CamelContext camelContext = super.createCamelContext();
+    public void testDoNotUseOriginalInBody() throws Exception {
+        MockEndpoint dead = getMockEndpoint("mock:b");
+        dead.expectedBodiesReceived("Hello World");
 
-        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
-        camelContext.addComponent(componentName, jmsComponentClientAcknowledge(connectionFactory));
+        template.sendBody("activemq:queue:b", "Hello");
 
-        return camelContext;
+        assertMockEndpointsSatisfied();
     }
 
+    @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
+            @Override
             public void configure() throws Exception {
-                // using mock endpoint here purely for testing. You would normally write
this route as
-                // from("activemq:queue:hello").to("file://target/routetofile");
-                from("activemq:queue:hello").to("file://target/routetofile").to("mock:result");
+                // will use original
+                DeadLetterChannelBuilder a = deadLetterChannel("mock:a")
+                    .maximumRedeliveries(2).delay(0).logStackTrace(false).useOriginalInBody().handled(true);
+
+                // will NOT use original
+                DeadLetterChannelBuilder b = deadLetterChannel("mock:b")
+                    .maximumRedeliveries(2).delay(0).logStackTrace(false).handled(true);
+
+                from("activemq:queue:a")
+                    .errorHandler(a)
+                    .setBody(body().append(" World"))
+                    .process(new MyThrowProcessor());
+
+                from("activemq:queue:b")
+                    .errorHandler(b)
+                    .setBody(body().append(" World"))
+                    .process(new MyThrowProcessor());
             }
         };
     }
-}
+
+    public static class MyThrowProcessor implements Processor {
+
+        public MyThrowProcessor() {
+        }
+
+        public void process(Exchange exchange) throws Exception {
+            assertEquals("Hello World", exchange.getIn().getBody(String.class));
+            throw new IllegalArgumentException("Forced");
+        }
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+        camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
+
+        return camelContext;
+    }
+
+}
\ No newline at end of file



Mime
View raw message