martes, abril 10, 2012

Why does the rain fall from above? Why do fools fall in love? Why do they fall in love? (Why Do Fools Fall In Love - Frankie Lymon)

More often than not our applications need to send emails to users notifying for example that its account has been created, they have purchased an item, or simply password remaining. When you are writing unit tests there is no problem because probably you will be mocking up interface responsible of sending an email. But what's happen with integration tests?

Maybe the logical path to resolve this problem is installing an email server and execute these tests against it. It is not  a bad idea, but note that you will need to configure your environment before executing your tests.  Your tests will depend on external resources, and this is a bad idea for integration tests. Furthermore these integration tests would not be portable against multiple machines if an email server is not installed previously.

To avoid this problem Dumbster comes to save us. Dumbster is a fake smtp server designed for testing applications that send email messages. It is written in Java so you can start and stop it directly from your tests.

Let's see an example, suppose we are developing an electronic shop, and when an order is placed and email to customer should be sent.

In this case we are going to use Spring Framework 3.1 to create our service layer and will also help us in testing.

Because of teaching purpose, I am not using mail templates, or rich mime types.

First class I am going to show you is Order, which as you can imagine represents an order:

Most important method here is toEmail() that returns email body message.

Next class is service responsible of place an order to delivery system:

This service class uses Spring classes to send an email to customer. See that two methods are present, one that sends a simple message, and the other one called placeOrderWithInvoice that sends an email with an attachment, concretely an invoice in jpg format.

And finally Spring context file:

Note that mail configuration is surrounded by a profile. This means that Spring will only create these beans when application is started up in production mode, and in this case production smtp location is set.

And now let's start with testing:

First of all we must create a Spring context file to configure smtp server location.

See that we are importing application-context.xml file but now we are defining  a new beans profile called integration, where we are redefining smtp connection (changing hostname and port) pointing to fake server.

And finally the test itself.

It is important to explain next parts:
  • @ActiveProfiles is an annotation to tell Spring context which environment should be loaded.
  • SimpleSmtpServer is the main class of Dumbster.
  • @Rule is responsible of starting and stopping smtp server for each method execution.
We have created two tests one that sends a plain message (an_email_should_be_sent_to_customer_confirming_purchase()) and the other one that sends a message with an attachment (an_email_with_invoice_should_be_sent_to_special_customer_confirming_purchase()).

The private methods are simply helper classes to create required classes.

Note that Hamcrest matcher bodyEqualTo comes from BodySmtpMessage class developed specifically for this example.

I wish you have found this post useful, and can give you an alternative when you want to write integration tests involving smtp email service.

Keep Learning,

74 comentarios:

bmatthews68 dijo...

You readers might be interested in a Maven plugin that I recently created to launch a Dumbster server. The idea was to support the development of integration tests for web applications that rely need an e-mail server. The URL is:

Unknown dijo...

Thank you very much for your suggestion, now you can choose between running Dumbster server within Maven lifecycle or JUnit.

Unknown dijo...

On serverside forum Cary Clark wrote a review about this post that I found so useful, I leave here so anyone can read too, thanks Cary.

"I created a fake email server based on Dumbster that accepts incoming email and has a simple UI to display and manage them. The number of emails retained in memory is configurable. When I got tired of Dumbster's bugs, I switched the backend to Wiser: I'm not affiliated with either."

Unknown dijo...

Also may be use FakeSMTP for testing

Unknown dijo...شركة-ديكور-بالرياض/تركيب-طارد-الحمام-بالرياض/شركة-دهانات-بالرياض/نقل-اثاث-الرياض-الكويت/نقل-اثاث-من-الرياض-الى-الدمام/

Unknown dijo...

Obat Aborsi Ampuh
Jual Cytotec Asli
Obat Penggugur Kandungan Janin
Jual Obat Aborsi Cytotec Asli Penggugur Kandungan Tuntas
Jual Obat Aborsi Ampuh
Obat Aborsi
Obat Aborsi Garansi Tuntas

alisha5050 dijo...

All the information in this post is excellent and very useful for all of us, so thanks for sharing this kind of brilliant post. Gurgaon Call Girls

alisha5050 dijo...

Glad to see this kind of brilliant and very interesting informative post. Call Girls in Gurgaon

alisha5050 dijo...

This is a brilliant informative post and great work is done in this post. Gurgaon Escort

alisha5050 dijo...

I really enjoy reading this post because there are so many great and very interesting information is mention in this post.
Escorts in Gurgaon
Escorts Service in Gurgaon
Call Girls Service in Gurgaon

riya4521 dijo...

Delhi has experienced the origin of housewives offering their services. Housewife Delhi escorts . I am riya here work as a high profile Call girl in delhi . I am here for last 6 years and have ability of fulfilling every sexual desires of every man. I am truly a self-independent and always ready to enjoy with you. refer to the women who have already been married and stay in the house to perform the household chores.
housewives are cunning enough to keep their personal lives hidden under a veil of ignorance and innocence. Noida escorts for you night. then luckily you are landed on the right webpage. I am seema a hot sexy high demanding. my demand is the proof of my popularity among my clients. if you looking for Noida call girls sexy killer queen I am perfect for you. I am professional in husbands believe that their wives have gone to give coaching to infants or children in school. Faridabad escorts This is pretty unfortunate as the truth is never revealed and the men are none the wiser.
gurgaon Call girls
Ghaziabad call girls
Haldwani escorts
Ghaziabad escorts
gurgaon Escorts
escorts in delhi

escort datting dijo...

Welcome to Sohna Road Escorts Service. Sohna Road offers you online Kalinga for getting erotic call girls. Call fast at cheap and good rate Escort Service In Gurgaon With Mobile Number

escort datting dijo...

Welcome to Sohna Road Escorts Service. Sohna Road offers you online Kalinga for getting erotic call girls. Call fast at cheap and good rate Escort Service In Gurgaon With Mobile Number

Call Girls In Gurgaon With Whatsapp Number dijo...

Welcome to Gurgaon Escorts Agency, we give you complete discount of receiving Russian and erotic call girls in Gurgaon, you can contact us on our website to get them. Call Girls In Gurgaon With Whatsapp Number

angeleena dijo...

Network Architect is a professional who takes care of communication networks, such as local area networks (LANs), wide area networks (WANs), and intranets.

Network Architect

Tuckerjackk dijo...

Shop Online
Banggood Branding
Great information you shared through this blog.Keep it up and best of luck for your future blogs and posts.

Monika Sahay dijo...

The escort service in Nainital, among the most prestigious independent escorts in Nainital, provides one of the very best women escorts in Nainital. Our beautiful call girls in Nainital buddy for people who want assistance for a short time or should appearing spend the entire night in Nainital at 5-star accommodation room.
Nainital Escorts
Ramnagar Escort service
Bhimtal Escort service
Haldwani Escort service
Rudrapur Escort service

Monika Sahay dijo...

Just how it may be carried out? Yes, it is a clear concern for the ones that are new to the place and completed have sufficient concept concerning such Hyderabad escort services. Within this kind of circumstance where an individual has much less comprehension, chances are really greater to get from the grab of an artificial firm.
Hyderabad Escorts
Ahmedabad Escorts
Jodhpur Call Girls
Dehradun Escorts

Monika Sahay dijo...

We can without a great deal of stretch find your game to complete your puzzle fantasies. We can without a great deal of stretch restrain the cravings of every man of the word. Our Udaipur escorts service demand one and only real thing out of you they need a confidence and affection.
Udaipur Escorts
Goa Escorts
Jaipur Escorts

Ankita Sharma dijo...

We have the most excellent collection of Escort Service in Gurgaon that will impress you with joy and satisfaction with their services. There is a lot of doing which takes pleasure in Call Girls in Gurgaon, a lot of which excludes lovemaking and other smutty activities. However, there is more that you can do to capitalize on your stay at Gurgaon Escorts, but that is only a portion of the proposition.

Sapna choudhary dijo...

This is nice and awesome thanks for share us.Fantastic Blog...I will definitly share your blog with other people.Thank you

Gurgaon Escort Service | Gurgaon Call Girls 9990765904
Get Escort Service in Gurgaon at low price by Miss Sapna 9990765904. Our escorts agency offers luxurious and beautiful Gurgaon female model escorts.

Call Girls in Gurgaon
Call Girl in Gurgaon
Gurgaon Call Girls
Call Girls Gurgaon
Call Girl Gurgaon
Gurgaon Call Girls
Gurgaon Escorts
Gurgaon Escorts Service
Gurgaon Call Girls
escorts in gurgaon
Gurgaon Escorts
Call girls Gurgaon
Escorts in Gurgaon
Call girls in gurgaon

Sapna choudhary dijo...
Genuinely I capitalize on your site with capable and significant information. It is consolidated to a great degree good post with a huge amount of our resources.thanks for share. I welcome this post.
You will find all the High Class Escort service in Gurgaon, who give you the services for which you are here. find top rated escort girl in gurgaon have young high profile call girls who have additional stamina for long-lasting sex. These girls are caring and adorable females.
We have groups of astonishing young high profile call girls who simply make your mind-set and turn on you. Our Escort will be your partner in the room, you can share your sexual dreams with her and she will assist you with completing it. Contact high profile Escorts service in Gurgaon and complete your needs with our high profile models
gurgaon call girls, call girls in gurgaon, young girls, call girls gurgaon, escorts in gurgaon, call girls in gurgaon, gurgaon call girls, gurgaon escort, escort in gurgaon, gurgaon escort service, hariyana escorts service, Gurgaon independent Escort

gurgaon escort service dijo...

Welcome to Gurgaon Escorts Agency, we give you complete discount of receiving Russian and erotic call girls in Gurgaon, you can contact us on our website to get them. Escorts Service In Gurgaon

John Miller Sakht dijo...

I’m Sakht. I’m a writer living in London, UK. I am a fan of technology. You can visit my store.

officecomsetup dijo...

Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative.

yahoomailforgotpassword dijo...

Steps to follow for Yahoo email was hacked ? There are mainly two methods to recuperate your hacked Yahoo Mail account.Go to the account settings in your Yahoo email was hacked and check in case hackers edited some info. You can restore any settings if necessary.

Okseoabhinav dijo...

Hi…this is Abhinav here, from few months I am visiting and following you. What I really like about you is that your writing style. Please keep making such as information for us.
Top CA firms in India, Top CA in India.

Russian Call Girls In Gurgaon dijo...

Gurgaon is a famous place for receiving gurgaon call girls. Here call girls are categorized as many categories, you can contact us on our website to get them. Call Girls In Gurgaon With Whatsapp Number

Russian Call Girls In Gurgaon dijo...

Gurgaon is a famous place for receiving gurgaon call girls. Here call girls are categorized as many categories, you can contact us on our website to get them.Cheap Call Girls In Gurgaon

John Miller Sakht dijo...

Greetings, I’m Sakht. I’m a writer living in Newark, New Jersey 07108, USA. I am a fan of technology and writing.

PcWorld247 dijo...

great blog thank you.

mcafee activation

Gurgaon EScort Service dijo...

Welcome to Gurgaon Escort Agency. We provide sexy and erotic girls service for you. To avail the service, please contact our website. Independent Escort Service in Gurgaon

Kelly Cain dijo...

Nice Blog. Thanks for sharing with us. Such amazing information.

Role of Branding in Making a Business Successful


Guest Blogger

Guest Blogging Site

Guest Blogging Website

Guest Posting Site

Escorts Service In Gurgaon dijo...

Welcome to Gurgaon Escort Service. We provide one to one sexiest girls and provide cheap service rates. You can visit our website to take advantage of the service. Cheap Escort Service In Gurgaon

Ascorts Club dijo...

We have various type of Celebrity Escorts service in Mumbai that available for All over Mumbai at your place. Our Model Escorts are very beautiful and ready at any time for 100% satisfaction to you. Ascorts Club is The Trustable Escorts Agency in Mumbai.

Celebrity Escorts in Mumbai

Escorts Service In Gurgaon dijo...

Gurgaon is a famous place for call girls. The sensual and beautiful call girls in Gurgaon take a free trip to fulfill your wish. If you are interested in call girls, then you can contact us on our website for a holiday with them..Cheap Escort Service In Gurgaon

Schloka Free Classifieds dijo...

If Your Looking For Call Girls and Escorts Services in Your City? Schloka - Free Adult classifieds in India, Browse in our call girl category To Post Ads, Book Escorts and Find Contact No For Hire Call Girls.

Schloka Escorts Volaba
Schloka Escorts Bandra
Schloka Escorts Andheri
Schloka Escorts Panvel
Schloka Escorts Kalyan
Schloka Escorts Kolhapur

Royal Model dijo...

behala call girl||
cheap call girls near me||
best escort service kolkata||
call girl in dumdum||
escorts service kolkata||
call girls online booking||
kolkata call girl com||
call girl number and image in kolkata||
www kolkata call girl com||
salt lake call girl||
kolkata female escort||
cheap call girl kolkata||
kolkata cheap call girls||
kolkata escorts girls||
lady escort service||
sexy girls in kolkata||
kolkata call girl number||
callgirl in kolkata||
bengali call girl in kolkata||
female escorts kolkata||
high profile call girl in kolkata||
kolkata escort agency||
cheap escort in kolkata||
hot call girl in kolkata||
girls escorts||
sexy girl in kolkata||
callgirl in kolkata||
escort service in||
calcutta call girl||
kolkata escort girls||
call girl in park street kolkata||
call girl booking online||
sex parlour in kolkata||
calcutta escorts||
best call girl in kolkata||
escorts services in kolkata||
kolkata high profile call girl||
female escort services||
hot girls of kolkata||
kolkata call girl mobile number and photo||
www kolkata call girl||
fucking place in kolkata||

Royal Model dijo...

escorts girls in kolkata||
best escort in kolkata||
locanto com kolkata||
best escorts in kolkata||
kolkata call girl service||
bengali escort service||
kolkata scott service||
kolkata sexy call girl||
scot service in kolkata||
escort service in calcutta||
kolkata callgirl||
kolkata call girl phone no||
www call girl in kolkata||
kolkata female escort service||
sexy call girl in kolkata||
kolkata model escorts||
sexy escort kolkata||
kolkata girl escort||
call girl in howrah||
escort girl service||
call girl in kolkatta||
kolkata callgirl||
call garl no||
calcutta escort||
online call girl booking||
kolkata hot call girl||
escort agency kolkata||
escorts at kolkata||
escort at kolkata||
bengali call girl kolkata||
kolkata model escorts||
coll girl kolkata||
kolkata call girl picture and mobile number||
sex service kolkata||
kolkata escorts service||
call girl howrah||
cheap escort services||
call girl in kolkatta||
callgirl kolkata||
sexy call girl kolkata||
call girl of kolkata||
call girl rate in kolkata||
kolkata vip escorts||

Rupali sen dijo...

Get the best Noida Escort service by independent Noida escorts or Noida call girls. Book call girls in Noida or escorts in Noida online visit

Get the best Delhi Escort service by independent Delhi escorts or Delhi call girls. Book call girls in Delhi or escorts in Delhi online visit

Rupali sen dijo...

Escort services in Guwahati
Escort services in Guwahati
Escort services in Guwahati
Escort services in Guwahati
Escort services in Guwahati
Escort services in Guwahati

Escort services in Jaipur
Escort services in Jaipur
Escort services in Jaipur
Escort services in Jaipur

Escort services in Cuttack
Escort services in Dehradun
Escort services in Lucknow
Escort services in Delhi
Call girls in Jammu

spetslaw dijo...

If you're feeling such as you have lost the zeal and intimacy of your sexual life then a reliable sexologist in Delhi are a few things that you just actually would like. He has registered himself within the list of the highest purported sexologist. you've got got it here! he's Associate in Nursing honorable name within the trade of sexologist treatment. and best sexologist in Delhi or top sexologist in Faridabad.

Purple Arrow LLC dijo...

Amazing website, Love it. Great work done. Nice website. Love it. This is really nice.

Unknown dijo... allows you to download and activate the Microsoft Office setup. Microsoft 365 plans for personal and home provides robust Office desktop apps including Word, PowerPoint, Excel, Outlook, and OneNote.Microsoft 365 subscribers can always install the latest version of MS Office and get frequent software updates. If you have a Microsoft account, sign in and enter the product key at to activate your product. Install and set up your Office 365 apps with the given instructions.

activate setup dijo...

Microsoft 365 is based on a subscription model, which ensures that users must pay to use Microsoft 365’s services. Microsoft 365 all-time helps you to keep your product up to date while Microsoft updates it. | |

activate setup dijo...

Defend against the unknown threats and proceed for Trend micro download with having Advanced Machine Learning Technology. Trend micro security is the best way to save your Connected World to all the digital part. Install www.trendmicro/activate from the official site and get the trend micro activation key to complete the process.

mack zayn dijo...

Microsoft 365 or Office on your computer. If you are using any other Microsoft service such as OneDrive, Outlook, Skype, or Xbox Live, it means you already have an account that you can use for any Microsoft activity.

Unknown dijo...

A Quick Guide to Canon Printer SetupMake sure your printer hardware is configured.
On your PC browser, go to
Click Set Up.
Using your Canon IJ printer model, the download printer software.
Double click to install it.
Connect a network to your printer and PC.
Finish the Canon IJ printer setup.
HP LaserJet Printer Setup
Configure your HP Printer hardware.
Visit from the browser.Using your LaserJet model name, download software.Double click to start the installation.Connect the printer via wireless network or USB.Add the LaserJet printer to your system devices.Finish the HP LaserJet setup.

Unknown dijo...

A new purchased (or older) Canon printer needs to be set up.https://ij.start.cannon | https //ij.start.cannon | http://ij.start.cannon
PIXMA MG2522 all-in-one printer is the best choice for all home printing needs and small businesses as well. First, visit mg2522 |
Use your Outlook, Skype, Xbox or any other Microsoft account to sign in. To avoid any error during Microsoft 365 installation, follow the instructions mentioned below. |

Arpita roy dijo...

My body is very hot shape that is sure to entice you when you meet me. My curves are one of the most important bodily characteristics of me. It is easy to see my body as I wear clothes because of my curvaceous physical features. I'm a sensual woman who allows you to imagine an action-packed evening with me when you see my smile.
Call arpita girl in amritsar

Anonymous dijo...

The perfect way to get started with is gathering enough information and purchasing depending on your requirement. You can then easily download and install the software package by visiting .

Anonymous dijo...

Canon printers are ideal for every situation wherever you need a document, paper, or photo print or even if you wish to scan, fax, and do more will make you learn how to set up a canon printer to get advanced printing features , ij.start.cannon .

Unknown dijo...

Use your Microsoft account through for everything you want to with Microsoft 365. Create an account or use the account of services such as OneDrive, Skype, Outlook, or Xbox Live. Use the site to download and install Microsoft 365 setup that will allow you to use multiple apps like Word, Excel, OneNote, PowerPoint, or more.

Unknown dijo...

The Canon printer that can be downloaded via page is the best wireless printer that you can connect to your device and print data smoothly. Ij.start canon CD is not the well-suited technique to use installation for longer. One can install from another origin if your device is having issues in the online installation or any other.Use ij.start cannon to set up your Canon product.Get started to Canon inkjet setup with guidelines of ij.start.cannon site.

JOE MILLER dijo...

Thank you for this brief explanation and very nice information. This post gives truly quality information. Hope to see you again. I find that this post is really amazing.
I am an I.T Consultant living in the U.S. I am very much involved in software issues in computers and Mac and providing a suitable solution to customers.

JOE MILLER dijo...

Being a software engineer and SEO Expert currently living in the United States. My interests range from writing technology blogs to entrepreneurship. I am also interested in web development and programming.

Unknown dijo...

Visit and open the door to the world of HP smart printing solutions. HP wireless printer is a versatile printing device that helps you print, scan, copy and fax your documents as per the requirement.
Visit | ij.start canon and find out the best way to download Canon printer drivers. Canon printers are ideal for every situation wherever you need a document, paper, or photo print or even if you wish to scan, fax, and do more will make you learn how to set up a canon printer to get advanced printing features.

ankit singh dijo...

MMA training aims to make you learn how to defeat your opponent using techniques of throwing, striking and grappling. MMA classes in Dehradun | best martial arts training in dehradun

ankit singh dijo...

Mixed Martial Arts classes aims to make you learn how to defeat your opponent using techniques of throwing, striking and grappling. MMA training in Dehradun

VISIT US dijo...

I haven't checked in here for some time since I thought it was getting boring, but the last several posts are good quality so I guess I'll add you back to my everyday blog list. You deserve it my friend 🙂

카지노사이트 dijo...

Well I definitely enjoyed studying it. This information provided by you is very practical for good planning. 포커게임 dijo...

Rattling wonderful visual appeal on this web site, I’d value it 10 over 10. 카지노사이트 dijo...

Thank you for providing a good quality article 토토사이트

badugisitenet dijo...

This paragraph will assist the internet people for creating new website or even a weblog from start to end. 바둑이사이트

Janny kayle dijo...

I am a Microsoft Office expert and a full-time blogger with 5 years of experience in the technology industry. I have written technical blogs, white papers, and reviews for a variety of websites.


roulettesitetop dijo...

Hi! Please know how much I appreciate your site and how much I look forward to the new content you provide. 룰렛사이트탑

Unknown dijo...

Visit ij.start canon | ij.start.cannon and find out the best way to download Canon printer drivers. Canon printers are ideal for every situation wherever you need a document, paper, or photo print or even if you wish to scan, fax, and do more.

All-in-one Canon Inkjet printers are suitable for home, business, school, and others to improve productivity. You can easily set up your Canon printer through drivers from | canon.come/ijsetup , wireless connection, USB, and a few components.

Unknown dijo...

Canon IJ Network Tool you to watch out for the points mentioned below considerably:
If you want a LAN setup for your printer, you should have the required connectivity equipment such as Network Access Point (Router/ Modem), LAN Cable etc.To get your IJ Network tool to work, you first need to check your printer’s connectivity via LAN connection. Next, check your LAN cable carefully.Canon IJ Printer Utility you can alter your printer’s ink cartridge settings according to your requirements. If any ink cartridges get empty, you can continue to print with other available cartridges after changing the settings.

Unknown dijo... is an easy and speedy method to provide the ability to connect your printer to any other device, such as Windows, Mac or iPhone. Furthermore, ij.start.cannon is a web address which provides access to download driver and software of Canon printer for your device.You can easily set up your Canon printer through drivers from, wireless connection, USB, and a few components.

davidwalker23 dijo...

ij.start canon helps to set up canon printer. It’s the online support platform to download and install canon printer drivers, firmware, and software , Canon IJ Network Tool

Unknown dijo...
is the manufacturer site to download Canon printer drivers. Install and set up Canon Printer from https: // and obtain high-quality printing documents straightforwardly.

https//ij.start.cannon is actually the official site of ij start canon that helps you install the latest printer drivers and software. Visiting http //ij.start.cannon
provides you a complete list of all canon printers where you’ve to select your printer model and download the correct setup file

naina k dijo...

thanks sharing valuable information..

types of laser hair removal

Great Assignment Helper dijo...

We take pride in having onboard the most qualified and experienced domain experts with us. We have been successfully offering excellent Online programming assignment help services to students securing them only the best academic grades.

Angel17 dijo...

It's a nice feeling to be in love. Thanks for sharing! property management Siesta Key, FL