001    /**
002     *
003     * Licensed to the Apache Software Foundation (ASF) under one or more
004     * contributor license agreements.  See the NOTICE file distributed with
005     * this work for additional information regarding copyright ownership.
006     * The ASF licenses this file to You under the Apache License, Version 2.0
007     * (the "License"); you may not use this file except in compliance with
008     * the License.  You may obtain a copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    package org.apache.camel.itest.jms;
019    
020    import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
021    
022    import javax.jms.ConnectionFactory;
023    import javax.jms.Message;
024    import javax.jms.MessageListener;
025    
026    import junit.framework.TestCase;
027    
028    import org.apache.activemq.ActiveMQConnectionFactory;
029    import org.apache.camel.CamelContext;
030    import org.apache.camel.Producer;
031    import org.apache.camel.builder.RouteBuilder;
032    import org.apache.camel.component.jms.JmsEndpoint;
033    import org.apache.camel.component.jms.JmsExchange;
034    import org.apache.camel.component.jms.JmsMessage;
035    import org.apache.camel.component.pojo.PojoComponent;
036    import org.apache.camel.impl.DefaultCamelContext;
037    import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
038    import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
039    
040    /**
041     * @version $Revision:520964 $
042     */
043    public class JmsIntegrationTest extends TestCase {
044            
045        protected CamelContext container = new DefaultCamelContext();
046    
047        public void testDummy() {
048        }
049        
050        /**
051         * Commented out since this fails due to us not converting the JmsExchange to a PojoExchange
052         * 
053         * @throws Exception
054         */
055            public void xtestOneWayInJmsOutPojo() throws Exception {
056                    
057                    final CountDownLatch receivedCountDown = new CountDownLatch(1);
058                    
059            // Configure the components
060            ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
061            container.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
062            PojoComponent component = new PojoComponent();
063            component.addService("listener", new MessageListener(){
064                            public void onMessage(Message msg) {
065                                    System.out.println("Received: "+msg);
066                                    receivedCountDown.countDown();                          
067                            }
068                    });
069            container.addComponent("default", component);
070    
071            // lets add a jms -> pojo route
072            container.addRoutes(new RouteBuilder() {
073                public void configure() {
074                    from("jms:test").to("pojo:listener");
075                }
076            });
077            
078            container.start();
079            
080            // Send a message to the JMS endpoint
081            JmsEndpoint endpoint = (JmsEndpoint) container.getEndpoint("jms:test");        
082            Producer<JmsExchange> producer = endpoint.createProducer();
083            JmsExchange exchange = producer.createExchange();
084            JmsMessage in = exchange.getIn();
085            in.setBody("Hello");
086            in.setHeader("cheese", 123);
087            producer.process(exchange);
088            
089            // The Activated endpoint should send it to the pojo due to the configured route.
090            assertTrue("The message ware received by the Pojo", receivedCountDown.await(5, TimeUnit.SECONDS));
091            
092    
093            }
094    
095        @Override
096        protected void tearDown() throws Exception {
097            container.stop();
098    
099            super.tearDown();
100        }
101    }