Integration testing emails

Recently I received a task where I had to modify a function I’ve wrote a long time ago that send out emails to users based on some criteria. The problem is that when I wrote that function I:

1. Didn’t have that good understanding and knowledge of Alfresco
2. Alfresco’s email sending capabilities weren’t as good as today
3. It was for a 3.x version of Alfresco

I then decided to first write a test for the function. The thing is that the essential thing in the function is the actual subject, content and other properties of the mail. I also want this to work regardless of where the test is executed (dev computer, CI environment, etc). I googled some and found some rather nice frameworks for setting up a simple SMTP server in a junit test. I also found out that one of the more simple ones to use is actually included in Alfresco, GreenMail.

I promptly started to write my integration test. Define a private variable for the test first.

private GreenMail _mailServer;

In the “@Before” part (or similar) create and start the SMTP instance.

_mailServer = new GreenMail(ServerSetupTest.SMTP);
_mailServer.start();

In the “@After” part (or similar) stop the SMTP instance.

_mailServer.stop();

You also have to modify the alfresco-global.properties file for your test suite so that Alfresco sends emails to the correct port. As default GreenMail ServerSetupTest.SMTP picks 25 + an offset number (3000) as it’s port, so set the value to:

mail.port=3025

Now, in your test just execute the code that sends the emails. Now comes the nice stuff. GreenMail has a function to get all received messages. Getting the messages and doing the proper assertions is now a walk in the park :)

MimeMessage[] messages = _mailServer.getReceivedMessages();
assertEquals(1, messages.length);

assertThat(message.getSubject(), containsString("Urget message!"));
assertThat(message.getContent().toString(), containsString("Kind regards,"));

No more excuses not to test your email sending capabilities…

This entry was posted in Uncategorized. Bookmark the permalink.

130 Responses to Integration testing emails

  1. Very useful information I will post the post and come back to find out your information. Thanks for the dark post that will definitely come back.

  2. Name says:

    comment text
    link

  3. Leo says:

    Thanks for taking the time to go over this, I’m strongly about it and enjoy learning longer on this issue. amazon.faimbd.com

  4. aqua fashion says:

    Thanks a lot for the blog post.Much thanks again. Cool.

  5. flesh ligt says:

    Major thankies for the post.Thanks Again. Keep writing.

  6. sihns says:

    Looking forward to reading more. Great blog article.Really looking forward to read more. Awesome.

  7. SMM says:

    Thanks for the article.Thanks Again. Fantastic.

  8. C_TS4C_2020 says:

    Im thankful for the blog.Much thanks again. Much obliged.

  9. Tattoo says:

    Some truly fantastic information, Gladiolus I detected this.

  10. Tattoo says:

    Muchos Gracias for your article post.Thanks Again. Fantastic.

  11. Thanks again for the blog post.Much thanks again.

  12. You are my function designs. Many thanks for that post

  13. wow, awesome article post.Really thank you! Much obliged.

  14. účtovník says:

    It as not that I want to duplicate your web site, but I really like the design. Could you tell me which design are you using? Or was it tailor made?

  15. Mp3 download says:

    Im no pro, but I imagine you just crafted the best point. You definitely know what youre talking about, and I can definitely get behind that. Thanks for being so upfront and so truthful.

  16. selection says:

    This is one awesome blog article.Much thanks again. Keep writing.

  17. This site may Hi there! I just wish to give an enormous thumbs up for the nice info you?ve right here on this post. I shall be coming again to your blog for extra soon.

  18. This is my first time pay a visit at here and i am really impressed to read all at alone place.

  19. Some times its a pain in the ass to read what website owners wrote but this site is rattling user genial!

  20. tech says:

    Thanks-a-mundo for the post.Really thank you! Awesome.

  21. very couple of internet sites that come about to become comprehensive beneath, from our point of view are undoubtedly very well really worth checking out

  22. Thank you, I have just been searching for info about this subject for ages and yours is the greatest I have discovered so far. But, what about the conclusion? Are you sure about the source?

  23. Really informative post.Really thank you! Want more.

  24. visit says:

    Just a smiling visitant here to share the love (:, btw outstanding style and design. Reading well is one of the great pleasures that solitude can afford you. by Harold Bloom.

  25. It as nearly impossible to find educated people in this particular subject, but you seem like you know what you are talking about! Thanks

  26. You don at have to remind Air Max fans, the good people of New Orleans.

  27. walops says:

    you could be a great author. I will make certain to bookmark your blog and

  28. bwi says:

    This is a really good tip especially to those fresh to the blogosphere. Short but very precise info Thanks for sharing this one. A must read post!

  29. Perfectly written content material, Really enjoyed looking through.

  30. Lumident says:

    you continue to care for to stay it sensible. I can not wait to read

  31. Major thanks for the article post. Awesome.

  32. usually posts some extremely exciting stuff like this. If you are new to this site

  33. Many thanks for sharing this excellent post. Very inspiring! (as always, btw)

  34. 부커취 says:

    of the math that people should bear in mind, I want to add couple of other qualitative pieces

  35. out the entire thing without having side-effects , folks could take a signal.

  36. Sex with me says:

    Loving the info on this web site , you have done great job on the posts.

  37. psihologija says:

    Rattling fantastic info can be found on site.

  38. Pinganillos says:

    Wow! Thank you! I permanently needed to write on my site something like that. Can I take a part of your post to my website?

  39. Just thought i would comment and say neat design, did you code it yourself? Looks great. Just found here

  40. Relationship says:

    I went over this web site and I conceive you have a lot of great information, saved to bookmarks (:.

  41. yeah bookmaking this wasn at a risky determination outstanding post!.

  42. Looking forward to reading more. Great blog post.Really thank you! Keep writing.

  43. Big Blue says:

    There is definately a great deal to know about this issue. I really like all of the points you have made.

  44. lushacre.com.sg I want to start a blog but would like to own the domain. Any ideas how to go about this?.

  45. Very informative blog post.Thanks Again. Awesome.

  46. Really appreciate you sharing this post. Great.

  47. So content to possess located this publish.. Seriously beneficial perspective, many thanks for giving.. Great feelings you have here.. Extremely good perception, many thanks for posting..

  48. game virtual says:

    Very good blog post.Thanks Again. Really Cool.

  49. Wow, great blog post.Thanks Again. Keep writing.

  50. Muchos Gracias for your blog article.Thanks Again. Keep writing.

  51. ITyAyjiGstR says:

    Really informative blog article.Much thanks again. Really Great.

  52. simple tweeks would really make my blog stand out. Please let me know

  53. giuong go says:

    Looking around I like to browse around the internet, regularly I will just go to Digg and follow thru

  54. This blog is without a doubt entertaining and also factual. I have picked up a bunch of useful stuff out of this amazing blog. I ad love to return again and again. Cheers!

  55. Search engine optimization, link management services is one of the

  56. You developed some decent points there. I looked on the net for the problem and discovered most of the people goes coupled with with all of your website.

  57. Tempobet says:

    I truly appreciate this blog.Really thank you! Keep writing.

  58. Your style is very unique in comparison to other folks I ave read stuff from. Many thanks for posting when you ave got the opportunity, Guess I all just book mark this site.

  59. Looking forward to reading more. Great article.Much thanks again. Much obliged.

  60. Im thankful for the article.Really looking forward to read more. Much obliged.

  61. This text is worth everyone as attention. Where can I find out more?|

  62. Valuable information. Lucky me I found your website by accident, and I am shocked why this accident didn at happened earlier! I bookmarked it.

  63. Really enjoyed this blog article.Much thanks again. Much obliged.

  64. KiwiGambling says:

    Really appreciate you sharing this blog.Really looking forward to read more. Will read on…

  65. sandra day says:

    Yes, Sovereignity!

  66. PLKM says:

    LIVE AND LET LIVE

  67. There as definately a great deal to learn about this subject. I like all the points you have made.

  68. NEYMAR says:

    GOD IS GOOD FOR LIFE

  69. NEYMAR says:

    GET IN TOUCH

  70. NEYMAR says:

    THIS IS THE BEST WEB

  71. Its hard to find good help I am constantnly saying that its difficult to find good help, but here is

  72. Very informative blog post.Thanks Again.

  73. Magento SEO says:

    wow, awesome post.Really looking forward to read more. Keep writing.

  74. NEYMAR says:

    It is better to fail in originality than to succeed in imitation

  75. NEYMAR says:

    The road to success and the road to failure are almost exactly the same

  76. I was very pleased to find this website. I wanted to thank you for your time for this wonderful post!! I definitely enjoy reading it and I have you bookmarked to check out new stuff you blog post.

  77. offshorededi says:

    Offshore Hosting with 100% DMCA ignored Hosting, Offshore Dedicated Server, Offshore VPS Hosting. offshorededi is the Most Secure Offshore Host. Providing Offshore Streaming Servers as well.

  78. view says:

    This is one awesome article post.Thanks Again.

  79. Major thanks for the post.Really looking forward to read more. Will read on

  80. Marvelous, what a weblog it is! This web site provides helpful information to us, keep it up.

  81. sure, study is having to pay off. So pleased to have located this post.. So content to have located this post.. So content to get located this article..

  82. shine900 says:

    Cuhel doesn’t want to return from vacation at the end of July to an empty city and get stuck at work at the time while most of his colleagues are away enjoying their August leisure time on the beach. Besides, August for him also means better weather, guaranteed sunshine.

  83. yert200.com says:

    But for many juilletistes, a less crowded beach is more valuable than a sunnier and hotter one. Plus, celebrating July 14 on an empty and relaxing beach is equally fun as throwing a party in Paris.
    카지노사이트

  84. kkr789.com says:

    The most infamous annual traffic jam in France takes place every year on the Saturday of the week when July meets August. It’s the day when returning juilletistes clash with departing aoûtiens which results in congestions across the country, called the “jam of crisscrossing.”

  85. gain777.com says:

    In the summer of 1936, for the first time since forever, hundreds of thousands of French factory workers took to the beach and enjoyed their vacation, a privilege previously reserved to the bourgeoisie and aristocracy.

  86. aace777.com says:

    French people’s love for vacation also means that American tourists planning to visit Paris this summer, especially in August, will find most of the restaurants and cafés closed.
    카지노사이트

  87. A Paris native, Cyril Choisne, 40, has been working in the gastronomic world of the French capital since 2006. Eclipses, his own Michelin Guide-recommended restaurant near Musée d’Orsay, like most other restaurants in Paris, shuts its doors during the first half of August because most of their customers are gone.
    메리트카지노

  88. hgame789 says:

    It is the third diamond of more than 1,000 carats found at the site, and it will now be made into “valuable collections of top colour polished diamonds,” Canadian mining firm Lucara Diamond said in a press release.
    카지노사이트

  89. hgame56.com says:

    Naseem Lahri, the managing director of Lucara Botswana, said its unearthing “is history in the making, for us and Botswana as well.”
    카지노사이트

  90. Dyno says:

    makes some sense

  91. Marty says:

    what a weblog this is! This web site provides helpful information

  92. Cheryl Ho says:

    levitra dosage generic levitra is used for levitra cost comparison

  93. Pearl Viernes says:

    buspirone ptsd buspirone rxlist buspirone overdoes

  94. Byron Garcia says:

    careprost careprost 5ml careprost from canada

  95. Tina Wong says:

    metronidazole injectable flagyl metronidazole canine metronidazole dose iv

  96. Mary Jackson says:

    domperidone for dogs domperidone gel domperidone 10mg picture

  97. Tamie Greenwald says:

    Thanks, Tamie Greenwald for redpill-linpro.com

  98. Zachary Kelley says:

    tamoxifen medication chemo menses on tamoxifen tamoxifen dose gynecomastia

  99. Kenneth Hazlett says:

    xenical generico xenical reviews from patients orlistat plm

  100. Daniel Skurka says:

    side effects for zanaflex tizanidine medication zanaflex for back pain

  101. NEYMAR says:

    NICE PROCESS

  102. NEYMAR says:

    SPREAD LOVE

  103. NEYMAR says:

    ACTIVE BLOG

  104. John Kilgallen says:

    zithromax cream keflex siadh ciprofloxacin 500

  105. Pedro Warner says:

    sildigra aristocort mircette

  106. NEYMAR says:

    GUARDIAN ANGEL

  107. Brian Salcido says:

    diovan altace klonopin

  108. Edward Decker says:

    clozaril sovaldi myambutol

  109. Roland Rodriguez says:

    zocor inderal flonase

  110. Larry Curry says:

    medrol abhigra zithromax

  111. Mary Klecka says:

    klonopin motrin seroquel

  112. Joseph Gupta says:

    prilosec levaquin trileptal

  113. Allyson Caraballo says:

    urispas levitra ilosone

  114. Eileen Paglio says:

    pamelor sustiva precose

  115. Margaret Gorley says:

    risperdal trileptal tenormin

  116. Esther Hockey says:

    clomid zanaflex avapro

Leave a Reply to hgame56.com Cancel reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>