camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r567070 - /activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanRouteTest.java
Date Fri, 17 Aug 2007 15:34:08 GMT
Author: jstrachan
Date: Fri Aug 17 08:34:07 2007
New Revision: 567070

URL: http://svn.apache.org/viewvc?view=rev&rev=567070
Log:
added test case for discussion:  http://www.nabble.com/MethodName-in-header-is-ignored-by-beanRef%28%29-tf4285009s22882.html#a12197583

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanRouteTest.java
      - copied, changed from r566911, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanRouteTest.java
(from r566911, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanRouteTest.java?view=diff&rev=567070&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java&r1=566911&p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanRouteTest.java&r2=567070
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanRouteTest.java
Fri Aug 17 08:34:07 2007
@@ -17,77 +17,90 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Header;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.apache.camel.Processor;
-import org.apache.camel.ValidationException;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.bean.BeanProcessor;
 import org.apache.camel.util.jndi.JndiContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.naming.Context;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * @version $Revision: 1.1 $
  */
-public class BeanWithExceptionTest extends ContextTestSupport {
-    protected Processor validator = new MyValidator();
-    protected MockEndpoint validEndpoint;
-    protected MockEndpoint invalidEndpoint;
+public class BeanRouteTest extends ContextTestSupport {
+    private static final transient Log LOG = LogFactory.getLog(BeanRouteTest.class);
+    protected MyBean myBean = new MyBean();
 
-    public void testValidMessage() throws Exception {
-        validEndpoint.expectedMessageCount(1);
+    public void testSendingMessageWithMethodNameHeader() throws Exception {
+        String expectedBody = "Wobble";
 
-        template.sendBodyAndHeader("direct:start", "<valid/>", "foo", "bar");
+        template.sendBodyAndHeader("direct:in", expectedBody, BeanProcessor.METHOD_NAME,
"read");
 
-        MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint);
+        assertEquals("bean received correct value for: " + myBean, expectedBody, myBean.body);
     }
 
-    public void testInvalidMessage() throws Exception {
-        invalidEndpoint.expectedMessageCount(1);
+    public void testSendingMessageWithMethodNameHeaderWithMoreVerboseCoe() throws Exception
{
+        final String expectedBody = "Wibble";
 
-        template.sendBodyAndHeader("direct:start", "<invalid/>", "foo", "notMatchedHeaderValue");
-
-        MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint);
+        template.send("direct:in", new Processor() {
+            public void process(Exchange exchange) {
+                Message in = exchange.getIn();
+                in.setBody(expectedBody);
+                in.setHeader(BeanProcessor.METHOD_NAME, "read");
+            }
+        });
+        assertEquals("bean received correct value", expectedBody, myBean.body);
     }
 
     @Override
     protected void setUp() throws Exception {
         super.setUp();
 
-        validEndpoint = resolveMandatoryEndpoint("mock:valid", MockEndpoint.class);
-        invalidEndpoint = resolveMandatoryEndpoint("mock:invalid", MockEndpoint.class);
+        Object lookedUpBean = context.getRegistry().lookup("myBean");
+        assertSame("Lookup of 'myBean' should return same object!", myBean, lookedUpBean);
     }
 
     @Override
     protected Context createJndiContext() throws Exception {
         JndiContext answer = new JndiContext();
-        answer.bind("myBean", new ValidationBean());
+        answer.bind("myBean", myBean);
         return answer;
     }
 
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                exception(ValidationException.class).to("mock:invalid");
-
-                from("direct:start").
-                        beanRef("myBean").
-                        to("mock:valid");            }
+                from("direct:in").beanRef("myBean").to("seda:out");
+            }
         };
     }
 
-    public static class ValidationBean {
-        private static final transient Log LOG = LogFactory.getLog(ValidationBean.class);
+    public static class MyBean {
+        public String body;
+        private static AtomicInteger counter = new AtomicInteger(0);
+        private int id;
+
+        public MyBean() {
+            id = counter.incrementAndGet();
+        }
+
+        @Override
+        public String toString() {
+            return "MyBean:" + id;
+        }
+
+        public void read(String body) {
+            this.body = body;
+            LOG.info("read() method on " + this + " with body: " + body);
+        }
 
-        public void someMethod(String body, @Header(name = "foo") String header) throws ValidationException
{
-            if ("bar".equals(header)) {
-                LOG.info("someMethod() called with valid header and body: " + body);
-            }
-            else {
-                throw new ValidationException(null, "Invalid header foo: " + header);
-            }
+        public void wrongMethod(String body) {
+            fail("wrongMethod() called with: " + body);
         }
     }
 }



Mime
View raw message