camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r554624 - in /activemq/camel/trunk/components/camel-activemq/src: main/java/org/apache/camel/jms/ test/java/org/apache/camel/jms/ test/resources/org/apache/camel/jms/
Date Mon, 09 Jul 2007 12:51:11 GMT
Author: jstrachan
Date: Mon Jul  9 05:51:10 2007
New Revision: 554624

URL: http://svn.apache.org/viewvc?view=rev&rev=554624
Log:
changed the JMS client test cases to use the regular ActiveMQConnectionFactory; as its only
the CamelDestinations that are required. Also added a test case showing the consumer side
now works too (after I added the start() method calls :)

Modified:
    activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelDestination.java
    activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelMessageConsumer.java
    activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelMessageProducer.java
    activemq/camel/trunk/components/camel-activemq/src/test/java/org/apache/camel/jms/CamelJmsTest.java
    activemq/camel/trunk/components/camel-activemq/src/test/resources/org/apache/camel/jms/spring.xml

Modified: activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelDestination.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelDestination.java?view=diff&rev=554624&r1=554623&r2=554624
==============================================================================
--- activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelDestination.java
(original)
+++ activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelDestination.java
Mon Jul  9 05:51:10 2007
@@ -20,6 +20,7 @@
 import org.apache.activemq.ActiveMQSession;
 import org.apache.activemq.CustomDestination;
 import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.Endpoint;
 import org.apache.camel.component.jms.JmsBinding;
 
@@ -34,19 +35,17 @@
 /**
  * @version $Revision: $
  */
-public class CamelDestination implements CustomDestination {
-
-    private final String uri;
+public class CamelDestination implements CustomDestination, CamelContextAware {
+    private String uri;
     private Endpoint endpoint;
     private CamelContext camelContext;
     private JmsBinding binding = new JmsBinding();
 
-    public CamelDestination(String uri) {
-        this.uri = uri;
+    public CamelDestination() {
     }
 
-    public String getUri() {
-        return uri;
+    public CamelDestination(String uri) {
+        this.uri = uri;
     }
 
     public String toString() {
@@ -91,6 +90,14 @@
 
     // Properties
     //-----------------------------------------------------------------------
+
+    public String getUri() {
+        return uri;
+    }
+
+    public void setUri(String uri) {
+        this.uri = uri;
+    }
 
     public Endpoint getEndpoint() {
         return endpoint;

Modified: activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelMessageConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelMessageConsumer.java?view=diff&rev=554624&r1=554623&r2=554624
==============================================================================
--- activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelMessageConsumer.java
(original)
+++ activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelMessageConsumer.java
Mon Jul  9 05:51:10 2007
@@ -128,6 +128,7 @@
         try {
             if (pollingConsumer == null) {
                 pollingConsumer = endpoint.createPollingConsumer();
+                pollingConsumer.start();
             }
             return pollingConsumer;
         }
@@ -151,12 +152,14 @@
 
     protected Consumer createConsumer() throws JMSException {
         try {
-            return endpoint.createConsumer(new Processor() {
+            Consumer answer = endpoint.createConsumer(new Processor() {
                 public void process(Exchange exchange) throws Exception {
                     Message message = createMessage(exchange);
                     getMessageListener().onMessage(message);
                 }
             });
+            answer.start();
+            return answer;
         }
         catch (JMSException e) {
             throw e;

Modified: activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelMessageProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelMessageProducer.java?view=diff&rev=554624&r1=554623&r2=554624
==============================================================================
--- activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelMessageProducer.java
(original)
+++ activemq/camel/trunk/components/camel-activemq/src/main/java/org/apache/camel/jms/CamelMessageProducer.java
Mon Jul  9 05:51:10 2007
@@ -18,6 +18,7 @@
 
 import org.apache.activemq.ActiveMQMessageProducerSupport;
 import org.apache.activemq.ActiveMQSession;
+import org.apache.activemq.command.ActiveMQMessage;
 import org.apache.activemq.util.JMSExceptionSupport;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Producer;
@@ -80,7 +81,6 @@
     }
 
     public void send(Destination destination, Message message, int deliveryMode, int priority,
long timeToLive) throws JMSException {
-    	message.setJMSDestination(destination);
     	CamelDestination camelDestination = null;
         if (ObjectHelper.equals(destination, this.destination)) {
             camelDestination = this.destination;

Modified: activemq/camel/trunk/components/camel-activemq/src/test/java/org/apache/camel/jms/CamelJmsTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-activemq/src/test/java/org/apache/camel/jms/CamelJmsTest.java?view=diff&rev=554624&r1=554623&r2=554624
==============================================================================
--- activemq/camel/trunk/components/camel-activemq/src/test/java/org/apache/camel/jms/CamelJmsTest.java
(original)
+++ activemq/camel/trunk/components/camel-activemq/src/test/java/org/apache/camel/jms/CamelJmsTest.java
Mon Jul  9 05:51:10 2007
@@ -16,52 +16,75 @@
  */
 package org.apache.camel.jms;
 
+import org.apache.camel.CamelTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
 import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.ObjectMessage;
 import javax.jms.Session;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.spring.SpringTestSupport;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+import javax.jms.TextMessage;
 
 /**
  * @version $Revision: $
  */
 public class CamelJmsTest extends SpringTestSupport {
-
     protected String expectedBody = "<hello>world!</hello>";
 
-	public void testCamelJms() throws Exception {
-        CamelConnectionFactory factory = getMandatoryBean(CamelConnectionFactory.class, "connectionFactory");
+    public void testSendingViaJmsIsReceivedByCamel() throws Exception {
+        MockEndpoint result = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
+        result.expectedBodiesReceived(expectedBody);
+        result.message(0).header("foo").isEqualTo("bar");
 
-        CamelContext context = factory.getCamelContext();
-		assertNotNull("Should have a CamelContext!", context);
-        
-		MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
-		assertNotNull("Should have a MockEndpoint!", result);
-		
-		result.expectedBodiesReceived(expectedBody);
-		result.message(0).header("foo").isEqualTo("bar");
-		
         // lets create a message
+        Destination destination = getMandatoryBean(Destination.class, "sendTo");
+        ConnectionFactory factory = getMandatoryBean(ConnectionFactory.class, "connectionFactory");
+
         Connection connection = factory.createConnection();
         connection.start();
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        CamelQueue destination = new CamelQueue("mock:result");
-        destination.setCamelContext(context);
-		MessageProducer producer = session.createProducer(destination);
-		
-		// now lets send a message
-		ObjectMessage message = session.createObjectMessage(expectedBody);
-		message.setStringProperty("foo", "bar");
-		producer.send(message);
-		
-		result.assertIsSatisfied();
+        MessageProducer producer = session.createProducer(destination);
+
+        // now lets send a message
+        ObjectMessage message = session.createObjectMessage(expectedBody);
+        message.setStringProperty("foo", "bar");
+        producer.send(message);
+
+        result.assertIsSatisfied();
+
+        log.info("Received message: " + result.getReceivedExchanges());
+    }
+
+    public void testConsumingViaJMSReceivesMessageFromCamel() throws Exception {
+        // lets create a message
+        Destination destination = getMandatoryBean(Destination.class, "consumeFrom");
+        ConnectionFactory factory = getMandatoryBean(ConnectionFactory.class, "connectionFactory");
+        CamelTemplate template = getMandatoryBean(CamelTemplate.class, "camelTemplate");
+
+        Connection connection = factory.createConnection();
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        log.info("Consuming from: " + destination);
+        MessageConsumer consumer = session.createConsumer(destination);
+
+        // now lets send a message
+        template.sendBody("seda:consumer", expectedBody);
+
+        Message message = consumer.receive(5000);
+        assertNotNull("Should have received a message from destination: " + destination,
message);
+
+        TextMessage textMessage = assertIsInstanceOf(TextMessage.class, message);
+        assertEquals("Message body", expectedBody, textMessage.getText());
 
-		log.info("Received message: "+ result.getReceivedExchanges());
-	}
+        log.info("Received message: " + message);
+    }
 
     protected int getExpectedRouteCount() {
         return 0;

Modified: activemq/camel/trunk/components/camel-activemq/src/test/resources/org/apache/camel/jms/spring.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-activemq/src/test/resources/org/apache/camel/jms/spring.xml?view=diff&rev=554624&r1=554623&r2=554624
==============================================================================
--- activemq/camel/trunk/components/camel-activemq/src/test/resources/org/apache/camel/jms/spring.xml
(original)
+++ activemq/camel/trunk/components/camel-activemq/src/test/resources/org/apache/camel/jms/spring.xml
Mon Jul  9 05:51:10 2007
@@ -28,9 +28,25 @@
     
   </camelContext>
 
-  <bean id="connectionFactory" class="org.apache.camel.jms.CamelConnectionFactory">
+  <bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
     <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
   </bean>
+
+  <bean id="sendTo" class="org.apache.camel.jms.CamelDestination">
+    <property name="uri" value="mock:result"/>
+  </bean>
+
+  <bean id="consumeFrom" class="org.apache.camel.jms.CamelDestination">
+    <property name="uri" value="seda:consumer"/>
+  </bean>
+
+  <bean id="camelTemplate" class="org.apache.camel.spring.CamelTemplateFactoryBean"/>
   <!-- END SNIPPET: example -->
+
+<!--
+  <bean id="connectionFactory" class="org.apache.camel.jms.CamelConnectionFactory">
+    <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
+  </bean>
+-->
 
 </beans>



Mime
View raw message