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 12:22:26 UTC
svn commit: r819873 - in
/camel/trunk/camel-core/src/test/java/org/apache/camel:
component/log/LogEndpointTest.java impl/DefaultConsumerTemplateTest.java
impl/MessageSupportTest.java
Author: davsclaus
Date: Tue Sep 29 10:22:26 2009
New Revision: 819873
URL: http://svn.apache.org/viewvc?rev=819873&view=rev
Log:
MR-187: Added more unit tests
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java (with props)
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.java?rev=819873&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.java Tue Sep 29 10:22:26 2009
@@ -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.component.log;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.processor.Logger;
+
+/**
+ * @version $Revision$
+ */
+public class LogEndpointTest extends ContextTestSupport {
+
+ private static Exchange logged;
+
+ private class MyLogger extends Logger {
+
+ @Override
+ public void process(Exchange exchange) {
+ super.process(exchange);
+ logged = exchange;
+ }
+
+ @Override
+ public String toString() {
+ return "myLogger";
+ }
+ }
+
+ public void testLogEndpoint() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ assertNotNull(logged);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ LogEndpoint end = new LogEndpoint();
+ end.setCamelContext(context);
+ end.setLogger(new MyLogger());
+
+ assertEquals("log:myLogger", end.getEndpointUri());
+ assertNotNull(end.getLogger());
+
+ from("direct:start").to(end).to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.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=819873&r1=819872&r2=819873&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 10:22:26 2009
@@ -17,7 +17,9 @@
package org.apache.camel.impl;
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
/**
* @version $Revision$
@@ -151,4 +153,116 @@
assertEquals("Hello", body);
}
+ public void testConsumeReceiveEndpoint() throws Exception {
+ template.sendBody("seda:foo", "Hello");
+
+ assertNotNull(consumer.getCamelContext());
+ Endpoint endpoint = context.getEndpoint("seda:foo");
+
+ Exchange out = consumer.receive(endpoint);
+ assertEquals("Hello", out.getIn().getBody());
+ }
+
+ public void testConsumeReceiveEndpointTimeout() throws Exception {
+ template.sendBody("seda:foo", "Hello");
+
+ assertNotNull(consumer.getCamelContext());
+ Endpoint endpoint = context.getEndpoint("seda:foo");
+
+ Exchange out = consumer.receive(endpoint, 1000);
+ assertEquals("Hello", out.getIn().getBody());
+ }
+
+ public void testConsumeReceiveEndpointNoWait() throws Exception {
+ assertNotNull(consumer.getCamelContext());
+ Endpoint endpoint = context.getEndpoint("seda:foo");
+
+ Exchange out = consumer.receiveNoWait(endpoint);
+ assertNull(out);
+
+ template.sendBody("seda:foo", "Hello");
+
+ // a little delay to let the consumer see it
+ Thread.sleep(200);
+
+ out = consumer.receiveNoWait(endpoint);
+ assertEquals("Hello", out.getIn().getBody());
+ }
+
+ public void testConsumeReceiveEndpointBody() throws Exception {
+ template.sendBody("seda:foo", "Hello");
+
+ assertNotNull(consumer.getCamelContext());
+ Endpoint endpoint = context.getEndpoint("seda:foo");
+
+ Object body = consumer.receiveBody(endpoint);
+ assertEquals("Hello", body);
+ }
+
+ public void testConsumeReceiveEndpointBodyType() throws Exception {
+ template.sendBody("seda:foo", "Hello");
+
+ assertNotNull(consumer.getCamelContext());
+ Endpoint endpoint = context.getEndpoint("seda:foo");
+
+ String body = consumer.receiveBody(endpoint, String.class);
+ assertEquals("Hello", body);
+ }
+
+ public void testConsumeReceiveEndpointBodyTimeoutType() throws Exception {
+ template.sendBody("seda:foo", "Hello");
+
+ assertNotNull(consumer.getCamelContext());
+ Endpoint endpoint = context.getEndpoint("seda:foo");
+
+ String body = consumer.receiveBody(endpoint, 1000, String.class);
+ assertEquals("Hello", body);
+ }
+
+ public void testConsumeReceiveBodyTimeoutType() throws Exception {
+ template.sendBody("seda:foo", "Hello");
+
+ String body = consumer.receiveBody("seda:foo", 1000, String.class);
+ assertEquals("Hello", body);
+ }
+
+ public void testConsumeReceiveEndpointBodyNoWait() throws Exception {
+ assertNotNull(consumer.getCamelContext());
+ Endpoint endpoint = context.getEndpoint("seda:foo");
+
+ String out = consumer.receiveBodyNoWait(endpoint, String.class);
+ assertNull(out);
+
+ template.sendBody("seda:foo", "Hello");
+
+ // a little delay to let the consumer see it
+ Thread.sleep(200);
+
+ out = consumer.receiveBodyNoWait(endpoint, String.class);
+ assertEquals("Hello", out);
+ }
+
+ public void testReceiveException() throws Exception {
+ Exchange exchange = new DefaultExchange(context);
+ exchange.setException(new IllegalArgumentException("Damn"));
+ template.send("seda:foo", exchange);
+
+ try {
+ consumer.receiveBody("seda:foo", String.class);
+ fail("Should have thrown an exception");
+ } catch (RuntimeCamelException e) {
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("Damn", e.getCause().getMessage());
+ }
+ }
+
+ public void testReceiveOut() throws Exception {
+ Exchange exchange = new DefaultExchange(context);
+ exchange.getOut().setBody("Bye World");
+ template.send("seda:foo", exchange);
+
+ String out = consumer.receiveBody("seda:foo", String.class);
+ assertEquals("Bye World", out);
+ }
+
}
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java?rev=819873&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java Tue Sep 29 10:22:26 2009
@@ -0,0 +1,53 @@
+/**
+ * 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.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+
+/**
+ * @version $Revision$
+ */
+public class MessageSupportTest extends ContextTestSupport {
+
+ public void testSetBodyType() throws Exception {
+ Exchange exchange = new DefaultExchange(context);
+ Message in = exchange.getIn();
+ in.setBody("123", Integer.class);
+
+ assertIsInstanceOf(Integer.class, in.getBody());
+ }
+
+ public void testGetMandatoryBody() throws Exception {
+ Exchange exchange = new DefaultExchange(context);
+ Message in = exchange.getIn();
+
+ try {
+ in.getMandatoryBody();
+ fail("Should have thrown an exception");
+ } catch (InvalidPayloadException e) {
+ // expected
+ }
+
+ in.setBody("Hello World");
+
+ assertEquals("Hello World", in.getMandatoryBody());
+ }
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date