Unit testing Active MQ

In the Apache Active MQ web page you can find some recommendations when unit testing JMS (ActiveMQ provides all the features from the Java Message Service specification and adds many more):

  • Use an embedded broker to avoid a separate broker process being required
  • Disable broker persistence so that no queue purging is required before/after tests
  • It’s often simpler and faster to just use Java code to create the broker via an XML configuration file using Spring etc.


In this test I will be also using Apache Camel to route the message from a socket to an Mock Endpoint through a queue. Previously, I have written a post where I explain how to unit testing Camel, which you can find it here.

First of all, we need to override the createCamelContext and create an ActiveMQConnectionFactory. This component will use an embedded broker, and we are going to disable the broker persistence setting the property broker.persistent to false.

[java]
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();

ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(“vm://localhost?broker.persistent=false”);
camelContext.addComponent(“activemq”, jmsComponentClientAcknowledge(connectionFactory));

return camelContext;
}
[/java]

 

Right after, we have to specify the routes in the createRouteBuilder method. In this case, I have created the endpoint where the messages will be coming through (localhost:6666). Note that Camel use the following syntax component:route. For this reason, the name of the component has to be the same as the name we have previously defined in the createCamelContext method (“activemq”).

[java]
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {

@Override
public void configure() throws Exception {

from(“mina:tcp://localhost:6666?textline=true&sync=false”)
.to(“activemq:processHL7”);

from(“activemq:processHL7”)
.to(“mock:end”);
}
};
}

[/java]
Finally, I have created a test which will be successful if the HL7 text messaged sent is received correctly.

[java]
@Test
public void testSendHL7Message() throws Exception {
MockEndpoint mock = getMockEndpoint(“mock:end”);

String m = “MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.5|\r” +
“EVN|A01|20130617154644\r” +
“PID|1|465 306 5961||407623|Wood^Patrick^^^MR||19700101|1|\r” +
“PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|”;

mock.expectedBodiesReceived(m);

template.sendBody(“mina:tcp://localhost:6666?textline=true&sync=false”, m);

mock.assertIsSatisfied();
}
[/java]
Please, find the entire unit test here.

You may also like...

39 Responses

  1. mmy says:

    Mmy? Never heard of it until today. Gave the site a quick look. Seems legit, but need more time to form opinion. Let me know what you guys reckon! mmy

  2. Agregator RSS says:

    Zauważyłem, że często angażujesz się w interakcje z czytelnikami w komentarzach. Jakie korzyści widzisz w tym dialogu? Czy to wpływa na kierunek, w którym zmierza twój blog, czy może jest to sposób na budowanie silniejszej społeczności czytelników?

    https://xmc.pl

  3. Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  4. Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/lv/register?ref=SMUBFN5I

  5. Prihlásení says:

    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://accounts.binance.info/register-person?ref=IHJUI7TF

  6. Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  7. Star says:

    I take pleasure in, cause I discovered exactly what I used to be taking a look
    for. You’ve ended my four day lengthy hunt! God Bless you man. Have a great day.
    Bye

    Also visit myy web site – injury compensation

  8. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  9. Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://www.binance.bh/register?ref=IXBIAFVY

  10. binance says:

    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  11. Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  12. Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  13. 注册 says:

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  14. Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  15. Cleo Lukesh says:

    Users can enjoy responsive access across desktop and mobile platforms with fast-loading performance.

    https://winbox8mys.com/

  16. Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  17. Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  18. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  19. Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.info/es/register?ref=RQUR4BEO

  20. Jason says:

    Hi, Neat post. There is a problem together with your website in web explorer, might check this?

    IE nonetheless is the market chief and a huge component to other people will leave out your excellent writing because of this problem.

    Here is my website :: İsmail Kaya Beşgen Vip Kurs

  21. Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.com/register?ref=W49FLGDN

  22. Тркелу says:

    Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  23. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  24. Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/register/person?ref=JW3W4Y3A

  25. Kristin says:

    Yesterday, while I was at work, my sister stole my
    iPad and tested to see if it can survive a thirty foot drop, just so she can be a
    youtube sensation. My apple ipad is now destroyed and she
    has 83 views. I know this is totally off topic but I had
    to share it with someone!

    Feel free to surf to my page … İsmail Kaya Beşgen Dershanesi

  26. Katherine says:

    Hi there, You’ve done a great job. I will definitely
    digg it and personally recommend to my friends. I’m sure they
    will be benefited from this website.

    My page: İsmail Kaya Beşgen Anadolu Lisesi

  27. Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.com/ru-UA/register?ref=JVDCDCK4

  28. Deon says:

    Great post. I was checking constantly this blog and I am impressed!
    Very useful information specifically the last part 🙂
    I care for such info a lot. I was looking for this particular info
    for a very long time. Thank you and good luck.

    Also visit my blog post – ankara dershaneler

  29. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://www.binance.bh/register?ref=GGYHGRE

  30. Margo says:

    Hello Dear, are you actually visiting this web site daily,
    if so then you will without doubt obtain good knowledge.

    Feel free to surf to my page; İsmail Kaya Beşgen

  31. Henrietta says:

    Hi there! I’m at work browsing your blog from my new iphone 4!
    Just wanted to say I love reading your blog
    and look forward to all your posts! Carry on the fantastic
    work!

    Also visit my page :: Kızılay’da YKS kursu seçenekleri

  32. Huey says:

    It’s not my first time to go to see this web page, i
    am visiting this website dailly and take good information from here all the time.

    My web-site … İsmail Kaya Beşgen Ortaokulu

  33. Rudy says:

    You have made some good points there. I looked on the
    internet for more info about the issue and found most people will go along with your views on this web site (frozen-pipe-repair-mobile-alabama.zzz-1.com).

  34. Velva says:

    Fantastic goods from you, man. I’ve understand your stuff previous
    to and you’re just extremely magnificent. I really like wha you have acquired here,
    really like wwhat you’re saying and the way in which you saay it.
    You make it etertaining and you still take care of too keep itt wise.
    I cann not wait to read far more from you. Thiis
    is actually a greqt website.

    my website; Lawyer Article

  35. Felipe says:

    Way cool! Some extremely valid points! I appreciate you penning this post and also the rest of
    the website is very good.

    My webpage photo

  36. Torri says:

    Outstanding story there. Whaat occurred after?
    Take care!

    Feel free to visit my blog post; Fernando

  37. Cameron says:

    Greaqt website. Plenty of useful info here. I am sending it to some buddies ans additionally sharing
    in delicious. And obviously, thank youu foor your
    sweat!

    My homepage: lawyer in my area

  38. Shantell says:

    First of alll I would like to say terrific blog!

    I had a quick question that I’d like tto ask if you don’t mind.
    I was interested to know how yyou center yourself annd clear your thoughts prior to writing.

    I habe had a tough time clearing my mind in getting my ideeas out
    there. I truly do enjoy writing however it just seems
    like the first 10 to 15 minutes are lost simply just
    trying to figure out how to begin. Any suggestions or hints?
    Thank you!

    Have a look att my website – Cheapest insurance

  39. Планирование путешествий says:

    Раздражают хвалебные истории, не приносящие никакой пользы?

    У меня всё устроено по-другому: делюсь только проверенными
    советами, рабочими схемами и эффективными алгоритмами для ваших поездок.

    Моя философия проста: хороший отдых — это результат
    правильных решений, а не случайности.
    Авиабилеты, проживание, страхование и логистика — всё это поддаётся разумному расчёту.
    Я покажу, как находить лучшие варианты, чтобы путешествие дарило эмоции, а не лишние расходы.

    Здесь отсутствуют пустые обещания —
    только практический путеводитель для комфортных путешествий
    по всему миру. Планирование
    путешествий https://t.me/tripkarta

Leave a Reply

Your email address will not be published. Required fields are marked *