Author: janstey
Date: Tue Nov 17 17:09:25 2009
New Revision: 881379
URL: http://svn.apache.org/viewvc?rev=881379&view=rev
Log:
add test case for configuring JMS within a camel-test testcase
Added:
camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/JMSFilterTest.java
Modified:
camel/trunk/components/camel-test/pom.xml
Modified: camel/trunk/components/camel-test/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test/pom.xml?rev=881379&r1=881378&r2=881379&view=diff
==============================================================================
--- camel/trunk/components/camel-test/pom.xml (original)
+++ camel/trunk/components/camel-test/pom.xml Tue Nov 17 17:09:25 2009
@@ -45,6 +45,16 @@
<artifactId>camel-spring</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jms</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Added:
camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/JMSFilterTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/JMSFilterTest.java?rev=881379&view=auto
==============================================================================
---
camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/JMSFilterTest.java
(added)
+++
camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/JMSFilterTest.java
Tue Nov 17 17:09:25 2009
@@ -0,0 +1,85 @@
+/**
+ * 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.test.patterns;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.CamelTestSupport;
+import org.apache.camel.component.jms.JmsComponent;
+
+/**
+ * Tests filtering using Camel Test
+ * @version $Revision: 724291 $
+ */
+// START SNIPPET: example
+public class JMSFilterTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ public void testSendMatchingMessage() throws Exception {
+ String expectedBody = "<matched/>";
+
+ resultEndpoint.expectedBodiesReceived(expectedBody);
+
+ template.sendBodyAndHeader(expectedBody, "foo", "bar");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ public void testSendNotMatchingMessage() throws Exception {
+ resultEndpoint.expectedMessageCount(0);
+
+ template.sendBodyAndHeader("<notMatched/>", "foo",
"notMatchedHeaderValue");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+
+ // connect to embedded ActiveMQ JMS broker
+ ConnectionFactory connectionFactory =
+ new ActiveMQConnectionFactory("vm://localhost");
+ camelContext.addComponent("jms",
+ JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
+
+ return camelContext;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start").to("jms:myQueue");
+
from("jms:myQueue").filter(header("foo").isEqualTo("bar")).to("mock:result");
+ }
+ };
+ }
+}
+// END SNIPPET: example