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…
awesome blog.
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.
comment text
link
Thanks for taking the time to go over this, I’m strongly about it and enjoy learning longer on this issue. amazon.faimbd.com
Thanks a lot for the blog post.Much thanks again. Cool.
Major thankies for the post.Thanks Again. Keep writing.
Looking forward to reading more. Great blog article.Really looking forward to read more. Awesome.
Thanks for the article.Thanks Again. Fantastic.
Im thankful for the blog.Much thanks again. Much obliged.
Some truly fantastic information, Gladiolus I detected this.
Muchos Gracias for your article post.Thanks Again. Fantastic.
Thanks again for the blog post.Much thanks again.
You are my function designs. Many thanks for that post
wow, awesome article post.Really thank you! Much obliged.
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?
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.
This is one awesome blog article.Much thanks again. Keep writing.
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.
This is my first time pay a visit at here and i am really impressed to read all at alone place.
Some times its a pain in the ass to read what website owners wrote but this site is rattling user genial!
Thanks-a-mundo for the post.Really thank you! Awesome.
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
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?
Really informative post.Really thank you! Want more.
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.
It as nearly impossible to find educated people in this particular subject, but you seem like you know what you are talking about! Thanks
You don at have to remind Air Max fans, the good people of New Orleans.
you could be a great author. I will make certain to bookmark your blog and
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!
Perfectly written content material, Really enjoyed looking through.
you continue to care for to stay it sensible. I can not wait to read
Major thanks for the article post. Awesome.
usually posts some extremely exciting stuff like this. If you are new to this site
Many thanks for sharing this excellent post. Very inspiring! (as always, btw)
of the math that people should bear in mind, I want to add couple of other qualitative pieces
out the entire thing without having side-effects , folks could take a signal.
Loving the info on this web site , you have done great job on the posts.
Rattling fantastic info can be found on site.
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?
Just thought i would comment and say neat design, did you code it yourself? Looks great. Just found here
I went over this web site and I conceive you have a lot of great information, saved to bookmarks (:.
yeah bookmaking this wasn at a risky determination outstanding post!.
Looking forward to reading more. Great blog post.Really thank you! Keep writing.
There is definately a great deal to know about this issue. I really like all of the points you have made.
lushacre.com.sg I want to start a blog but would like to own the domain. Any ideas how to go about this?.
Very informative blog post.Thanks Again. Awesome.
Really appreciate you sharing this post. Great.
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..
Very good blog post.Thanks Again. Really Cool.
Wow, great blog post.Thanks Again. Keep writing.
Muchos Gracias for your blog article.Thanks Again. Keep writing.
Really informative blog article.Much thanks again. Really Great.
simple tweeks would really make my blog stand out. Please let me know
Looking around I like to browse around the internet, regularly I will just go to Digg and follow thru
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!
Search engine optimization, link management services is one of the