Hi there,
while trying to get testing with camel and spring work. I've got some
trouble with this testcase.
The route starts with activemq:queue:a.data when the header is correctly
set it will be delivered to bean A or bean B (if completely wrong to bean
C).
But when I use the producer the endpoint mock:activemq:/queue:a.data is
called and the message is also successfully delivered to the endpoint of
mock:bean://processorA. (There is also an output which shows the successful
delivery. BUT the counter in MockEndpoint (of mock:bean://processorA) isn't
incremented. So the test fails.
Is there anything I'm missing?
Thanks for your help.
Marc
If I run this test this is my output:
2015-08-03 13:34:42,580 DEBUG [main]
o.a.camel.component.jms.JmsConfiguration [JmsConfiguration.java:341]
Sending JMS message to: queue://a.data with message: ActiveMQTextMessage
{commandId = 0, responseRequired = false, messageId = null,
originalDestination = null, originalTransactionId = null, producerId =
null, destination = null, transactionId = null, expiration = 0, timestamp =
0, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null,
replyTo = null, persistent = true, type = null, priority = 0, groupID =
null, groupSequence = 0, targetConsumerId = null, compressed = false,
userID = null, content = null, marshalledProperties = null, dataStructure =
null, redeliveryCounter = 0, size = 0, properties = {data_origin=A,
breadcrumbId=ID-Marc-Ende-local-54290-1438601681543-0-1},
readOnlyProperties = false, readOnlyBody = false, droppable = false,
jmsXGroupFirstForConsumer = false, text = <message>test</message>}
activemq.broker=localhost
2015-08-03 13:34:42,589 DEBUG [Camel (camel-1) thread #0 -
JmsConsumer[a.data]] o.a.c.c.j.DefaultJmsMessageListenerContainer
[AbstractPollingMessageListenerContainer.java:296] Received message of type
[class org.apache.activemq.command.ActiveMQTextMessage] from consumer
[PooledMessageConsumer { ActiveMQMessageConsumer {
value=ID:Marc-Ende.local-54293-1438601682328-3:1:1:1, started=true } }] of
session [PooledSession { ActiveMQSession
{id=ID:Marc-Ende.local-54293-1438601682328-3:1:1,started=true} }]
activemq.broker=localhost
2015-08-03 13:34:42,592 INFO [main] ProcessingRouteTest
[ProcessingRouteTest.java:61] assertion:0 activemq.broker=localhost
2015-08-03 13:34:42,591 DEBUG [Camel (camel-1) thread #0 -
JmsConsumer[a.data]] o.a.c.c.jms.EndpointMessageListener
[EndpointMessageListener.java:68] Endpoint[activemq://queue:a.data]
consumer received JMS message: ActiveMQTextMessage {commandId = 7,
responseRequired = true, messageId =
ID:Marc-Ende.local-54293-1438601682328-3:1:2:1:1, originalDestination =
null, originalTransactionId = null, producerId =
ID:Marc-Ende.local-54293-1438601682328-3:1:2:1, destination =
queue://a.data, transactionId = null, expiration = 0, timestamp =
1438601682584, arrival = 0, brokerInTime = 1438601682585, brokerOutTime =
1438601682588, correlationId = null, replyTo = null, persistent = true,
type = null, priority = 4, groupID = null, groupSequence = 0,
targetConsumerId = null, compressed = false, userID = null, content = null,
marshalledProperties = null, dataStructure = null, redeliveryCounter = 0,
size = 1070, properties = {data_origin=A,
breadcrumbId=ID-Marc-Ende-local-54290-1438601681543-0-1},
readOnlyProperties = true, readOnlyBody = true, droppable = false,
jmsXGroupFirstForConsumer = false, text = <message>test</message>}
activemq.broker=localhost
2015-08-03 13:34:42,592 INFO [main] o.a.camel.component.mock.MockEndpoint
[MockEndpoint.java:377] Asserting:
Endpoint[mock://bean://processorA?method=processContent] is satisfied
activemq.broker=localhost
2015-08-03 13:34:42,593 DEBUG [main] o.a.camel.component.mock.MockEndpoint
[MockEndpoint.java:1370] Waiting on the latch for: 3000 millis
activemq.broker=localhost
2015-08-03 13:34:42,603 DEBUG [Camel (camel-1) thread #0 -
JmsConsumer[a.data]] org.apache.camel.processor.SendProcessor
[SendProcessor.java:125] >>>>
Endpoint[bean://processorA?method=processContent]
Exchange[JmsMessage[JmsMessageID:
ID:Marc-Ende.local-54293-1438601682328-3:1:2:1:1]] activemq.broker=localhost
2015-08-03 13:34:42,612 DEBUG [Camel (camel-1) thread #0 -
JmsConsumer[a.data]] ProcessorAImpl [ProcessorAImpl.java:20] A-Received
Message: <message>test</message> (Exchange[JmsMessage[JmsMessageID:
ID:Marc-Ende.local-54293-1438601682328-3:1:2:1:1]])
activemq.broker=localhost
2015-08-03 13:34:45,598 DEBUG [main] o.a.camel.component.mock.MockEndpoint
[MockEndpoint.java:1357] Took 3005 millis to complete latch
activemq.broker=localhost
2015-08-03 13:34:45,599 INFO [main] ProcessingRouteTest
[StopWatchTestExecutionListener.java:53]
********************************************************************************
activemq.broker=localhost
2015-08-03 13:34:45,599 INFO [main] ProcessingRouteTest
[StopWatchTestExecutionListener.java:54] Testing done:
testRouteToA(ProcessingRouteTest) activemq.broker=localhost
2015-08-03 13:34:45,600 INFO [main] ProcessingRouteTest
[StopWatchTestExecutionListener.java:55] Took: 3.046 seconds (3046 millis)
activemq.broker=localhost
2015-08-03 13:34:45,600 INFO [main] ProcessingRouteTest
[StopWatchTestExecutionListener.java:56]
********************************************************************************
My testcase:
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(
classes = {ProcessingRouteTestConfig.class, CamelTestConfig.class},
loader = CamelSpringDelegatingTestContextLoader.class
)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class ProcessingRouteTest {
private static final Logger LOG =
LoggerFactory.getLogger(ProcessingRouteTest.class);
@Autowired
private CamelContext camelContext;
@EndpointInject(uri = "mock:bean://processorA?method=processContent")
protected MockEndpoint processingEndpointA;
@EndpointInject(uri = "mock:bean://processorB?method=processContent")
protected MockEndpoint processingEndpointB;
@EndpointInject(uri = "mock:bean://processor?method=processContent")
protected MockEndpoint processingEndpointUnknown;
@Produce(uri ="mock:activemq://queue:a.data")
protected ProducerTemplate testProducer;
@Before
public void setUp() {
camelContext.setTracing(true);
}
@Test
@DirtiesContext
public void testRouteToA() throws InterruptedException {
processingEndpointA.expectedBodiesReceived("<message>test</message>");
LOG.info("produce");
testProducer.sendBodyAndHeader("<message>test</message>",
Constants.JMS_HEADER_DATA_SOURCE, Constants.DEFAULT_JMS_HEADER_A);
LOG.info("assertion:" + processingEndpointA.getReceivedCounter());
processingEndpointA.assertIsSatisfied(camelContext, 3,
TimeUnit.SECONDS);
LOG.info("finish");
}