| 1 |
/** |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 |
* contributor license agreements. See the NOTICE file distributed with |
| 4 |
* this work for additional information regarding copyright ownership. |
| 5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 |
* (the "License"); you may not use this file except in compliance with |
| 7 |
* the License. You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
package org.apache.camel.component.jms; |
| 18 |
|
| 19 |
import javax.jms.ConnectionFactory; |
| 20 |
|
| 21 |
import org.apache.camel.CamelContext; |
| 22 |
import org.apache.camel.builder.RouteBuilder; |
| 23 |
import org.apache.camel.test.junit4.CamelTestSupport; |
| 24 |
import org.junit.Test; |
| 25 |
|
| 26 |
import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge; |
| 27 |
|
| 28 |
/** |
| 29 |
* @version |
| 30 |
*/ |
| 31 |
public class JmsInOnlyWithReplyToAsHeaderTest extends CamelTestSupport { |
| 32 |
|
| 33 |
@Test |
| 34 |
public void testSendInOnlyWithReplyTo() throws Exception { |
| 35 |
getMockEndpoint("mock:foo").expectedBodiesReceived("World"); |
| 36 |
getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World"); |
| 37 |
getMockEndpoint("mock:done").expectedBodiesReceived("World"); |
| 38 |
|
| 39 |
template.sendBodyAndHeader("direct:start", "World", "JMSReplyTo", "queue:bar"); |
| 40 |
|
| 41 |
assertMockEndpointsSatisfied(); |
| 42 |
} |
| 43 |
|
| 44 |
protected CamelContext createCamelContext() throws Exception { |
| 45 |
CamelContext camelContext = super.createCamelContext(); |
| 46 |
ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(); |
| 47 |
camelContext.addComponent("activemq", jmsComponentAutoAcknowledge(connectionFactory)); |
| 48 |
return camelContext; |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
protected RouteBuilder createRouteBuilder() throws Exception { |
| 53 |
return new RouteBuilder() { |
| 54 |
@Override |
| 55 |
public void configure() throws Exception { |
| 56 |
from("direct:start") |
| 57 |
// must enable preserveMessageQos to force Camel to use the JMSReplyTo header |
| 58 |
.to("activemq:queue:foo?preserveMessageQos=true") |
| 59 |
.to("mock:done"); |
| 60 |
|
| 61 |
from("activemq:queue:foo") |
| 62 |
.to("log:foo?showAll=true", "mock:foo") |
| 63 |
.transform(body().prepend("Bye ")); |
| 64 |
|
| 65 |
// we should disable reply to to avoid sending the message back to our self |
| 66 |
// after we have consumed it |
| 67 |
from("activemq:queue:bar?disableReplyTo=true") |
| 68 |
.to("log:bar?showAll=true", "mock:bar"); |
| 69 |
} |
| 70 |
}; |
| 71 |
} |
| 72 |
} |