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 2009/09/29 13:15:03 UTC

svn commit: r819888 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ test/java/org/apache/camel/impl/

Author: davsclaus
Date: Tue Sep 29 11:15:03 2009
New Revision: 819888

URL: http://svn.apache.org/viewvc?rev=819888&view=rev
Log:
MR-187: Added more unit tests

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java   (with props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionAdapterTest.java
      - copied, changed from r819836, camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProxyInstantiationExceptionTest.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java?rev=819888&r1=819887&r2=819888&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java Tue Sep 29 11:15:03 2009
@@ -103,7 +103,10 @@
         }
     }
 
-    public void startService(Service service) throws Exception {
+    /**
+     * Stats the given service
+     */
+    protected void startService(Service service) throws Exception {
         getCamelContext().addService(service);
     }
 

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java?rev=819888&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java Tue Sep 29 11:15:03 2009
@@ -0,0 +1,212 @@
+/**
+ * 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.impl;
+
+import java.lang.reflect.Method;
+
+import org.apache.camel.Consume;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.Producer;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * @version $Revision$
+ */
+public class CamelPostProcessorHelperTest extends ContextTestSupport {
+
+    public void testConstructor() {
+        CamelPostProcessorHelper helper = new CamelPostProcessorHelper();
+        assertNull(helper.getCamelContext());
+
+        helper.setCamelContext(context);
+        assertNotNull(helper.getCamelContext());
+    }
+
+    public void testConstructorCamelContext() {
+        CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
+        assertNotNull(helper.getCamelContext());
+    }
+
+    public void testMatchContext() {
+        CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
+        assertTrue(helper.matchContext(context.getName()));
+        assertFalse(helper.matchContext("foo"));
+    }
+
+    public void testConsume() throws Exception {
+        CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
+
+        MyConsumeBean my = new MyConsumeBean();
+        Method method = my.getClass().getMethod("consumeSomething", String.class);
+        helper.consumerInjection(method, my);
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+
+        template.sendBody("seda:foo", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testEndpointInjectProducerTemplate() throws Exception {
+        CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
+
+        MyEndpointInjectBeanProducerTemplate bean = new MyEndpointInjectBeanProducerTemplate();
+        Method method = bean.getClass().getMethod("setProducer", ProducerTemplate.class);
+        
+        EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
+        Class<?>[] parameterTypes = method.getParameterTypes();
+        for (Class type : parameterTypes) {
+            String propertyName = ObjectHelper.getPropertyName(method);
+            Object value = helper.getInjectionValue(type, endpointInject.uri(), endpointInject.name(), propertyName);
+            ObjectHelper.invokeMethod(method, bean, value);
+        }
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+
+        assertNotNull(bean.getProducer());
+        bean.send("Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testEndpointInjectProducer() throws Exception {
+        CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
+
+        MyEndpointBeanProducer bean = new MyEndpointBeanProducer();
+        Method method = bean.getClass().getMethod("setProducer", Producer.class);
+        
+        EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
+        Class<?>[] parameterTypes = method.getParameterTypes();
+        for (Class type : parameterTypes) {
+            String propertyName = ObjectHelper.getPropertyName(method);
+            Object value = helper.getInjectionValue(type, endpointInject.uri(), endpointInject.name(), propertyName);
+            ObjectHelper.invokeMethod(method, bean, value);
+        }
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+
+        assertNotNull(bean.getProducer());
+
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setBody("Hello World");
+
+        bean.send(exchange);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testEndpointInjectPollingConsumer() throws Exception {
+        CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
+
+        MyEndpointBeanPollingConsumer bean = new MyEndpointBeanPollingConsumer();
+        Method method = bean.getClass().getMethod("setConsumer", PollingConsumer.class);
+
+        EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
+        Class<?>[] parameterTypes = method.getParameterTypes();
+        for (Class type : parameterTypes) {
+            String propertyName = ObjectHelper.getPropertyName(method);
+            Object value = helper.getInjectionValue(type, endpointInject.uri(), endpointInject.name(), propertyName);
+            ObjectHelper.invokeMethod(method, bean, value);
+        }
+
+        template.sendBody("seda:foo", "Hello World");
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+
+        assertNotNull(bean.getConsumer());
+
+        Exchange exchange = bean.consume();
+        template.send("mock:result", exchange);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public class MyConsumeBean {
+
+        @Consume(uri = "seda:foo")
+        public void consumeSomething(String body) {
+            assertEquals("Hello World", body);
+            template.sendBody("mock:result", body);
+        }
+    }
+
+    public class MyEndpointInjectBeanProducerTemplate {
+
+        private ProducerTemplate producer;
+
+        @EndpointInject(uri = "mock:result")
+        public void setProducer(ProducerTemplate producer) {
+            this.producer = producer;
+        }
+
+        public ProducerTemplate getProducer() {
+            return producer;
+        }
+
+        public void send(String message) {
+            producer.sendBody(message);
+        }
+    }
+
+    public class MyEndpointBeanProducer {
+
+        private Producer producer;
+
+        @EndpointInject(uri = "mock:result")
+        public void setProducer(Producer producer) {
+            this.producer = producer;
+        }
+
+        public Producer getProducer() {
+            return producer;
+        }
+
+        public void send(Exchange exchange) throws Exception {
+            producer.process(exchange);
+        }
+
+    }
+
+    public class MyEndpointBeanPollingConsumer {
+
+        private PollingConsumer consumer;
+
+        @EndpointInject(uri = "seda:foo")
+        public void setConsumer(PollingConsumer consumer) {
+            this.consumer = consumer;
+        }
+
+        public PollingConsumer getConsumer() {
+            return consumer;
+        }
+
+        public Exchange consume() throws Exception {
+            return consumer.receive(1000);
+        }
+
+    }
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java?rev=819888&r1=819887&r2=819888&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java Tue Sep 29 11:15:03 2009
@@ -199,6 +199,16 @@
         assertEquals("Hello", body);
     }
 
+    public void testConsumeReceiveEndpointBodyTimeout() throws Exception {
+        template.sendBody("seda:foo", "Hello");
+
+        assertNotNull(consumer.getCamelContext());
+        Endpoint endpoint = context.getEndpoint("seda:foo");
+
+        Object body = consumer.receiveBody(endpoint, 1000);
+        assertEquals("Hello", body);
+    }
+
     public void testConsumeReceiveEndpointBodyType() throws Exception {
         template.sendBody("seda:foo", "Hello");
 
@@ -226,7 +236,7 @@
         assertEquals("Hello", body);
     }
 
-    public void testConsumeReceiveEndpointBodyNoWait() throws Exception {
+    public void testConsumeReceiveEndpointBodyTypeNoWait() throws Exception {
         assertNotNull(consumer.getCamelContext());
         Endpoint endpoint = context.getEndpoint("seda:foo");
 
@@ -242,6 +252,22 @@
         assertEquals("Hello", out);
     }
 
+    public void testConsumeReceiveEndpointBodyNoWait() throws Exception {
+        assertNotNull(consumer.getCamelContext());
+        Endpoint endpoint = context.getEndpoint("seda:foo");
+
+        Object out = consumer.receiveBodyNoWait(endpoint);
+        assertNull(out);
+
+        template.sendBody("seda:foo", "Hello");
+
+        // a little delay to let the consumer see it
+        Thread.sleep(200);
+
+        out = consumer.receiveBodyNoWait(endpoint);
+        assertEquals("Hello", out);
+    }
+
     public void testReceiveException() throws Exception {
         Exchange exchange = new DefaultExchange(context);
         exchange.setException(new IllegalArgumentException("Damn"));

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionAdapterTest.java (from r819836, camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionAdapterTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionAdapterTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java&r1=819836&r2=819888&rev=819888&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionAdapterTest.java Tue Sep 29 11:15:03 2009
@@ -22,9 +22,9 @@
 /**
  * @version $Revision$
  */
-public class ExpressionSupportTest extends ContextTestSupport {
+public class ExpressionAdapterTest extends ContextTestSupport {
 
-    private class MyExpression extends ExpressionSupport {
+    private class MyExpression extends ExpressionAdapter {
 
         protected String assertionFailureMessage(Exchange exchange) {
             return "foo";
@@ -39,7 +39,7 @@
         }
     }
 
-    public void testExpressionSupport() throws Exception {
+    public void testExpressionAdapter() throws Exception {
         MyExpression my = new MyExpression();
 
         Exchange e = new DefaultExchange(context);
@@ -48,7 +48,7 @@
         my.assertMatches("bar", e);
     }
 
-    public void testExpressionSupportFail() throws Exception {
+    public void testExpressionAdapterFail() throws Exception {
         MyExpression my = new MyExpression();
 
         Exchange e = new DefaultExchange(context);
@@ -60,4 +60,4 @@
             assertTrue(ae.getMessage().contains("foo"));
         }
     }
-}
+}
\ No newline at end of file

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProxyInstantiationExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProxyInstantiationExceptionTest.java?rev=819888&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProxyInstantiationExceptionTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProxyInstantiationExceptionTest.java Tue Sep 29 11:15:03 2009
@@ -0,0 +1,40 @@
+/**
+ * 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.impl;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+
+/**
+ * @version $Revision$
+ */
+public class ProxyInstantiationExceptionTest extends ContextTestSupport {
+
+    public void testProxyException() {
+        Endpoint endpoint = context.getEndpoint("mock:foo");
+        ProxyInstantiationException e = new ProxyInstantiationException(CamelContext.class, endpoint, new IllegalArgumentException("Damn"));
+
+        assertNotNull(e);
+        assertNotNull(e.getMessage());
+        assertSame(endpoint, e.getEndpoint());
+        assertEquals(CamelContext.class, e.getType());
+        assertNotNull(e.getCause());
+        assertEquals("Damn", e.getCause().getMessage());
+    }
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProxyInstantiationExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProxyInstantiationExceptionTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date