Introduction

This page shows how you can verify whether some Mime Message is present or not in some IMAP folder



Constructing the verification object

 

Define the connection and credential parameters for the IMAP folder of a particular user

import com.axway.ats.rbv.clients.ImapVerification;

ImapVerification imapVerification = new ImapVerification( SERVER_IP, "test1", "password" );

 


Add verification rules

Using the different check... methods you can add as many checks as you need

// check the subject
imapVerification.checkSubject( "RE: Hi" );

// check some custom header
imapVerification.checkHeader( "MY-CUSTOM-HEADER-NAME", "MY-CUSTOM-HEADER-VALUE", HeaderMatchMode.EQUALS );

// check body contains some string
imapVerification.checkBody( "Financing of the transaction" );

// check the number of attachments
imapVerification.checkAttachmentNumber( 1 );

// check the only attachment contains some string
imapVerification.checkStringInAttachment( "Instructions for Mobile phone installation ", 0 );

// check the name of the only attachment using regular expression
imapVerification.checkRegexInAttachmentName( ".*nokia3310.*", 0 );

 

So far we have just specified what kind of message we are interested in.

But the actual verification starts at the moment you call one of the verify... methods

 


Verify a message exists

Keep polling until verify the searched mail is present.

Fail if the searched mail is not found for all polling attempts.

imapVerification.verifyMessageExists();

 


Verify a message does not exist

Keep polling until verify the searched mail is NOT present.

Fail if the searched mail is present for all polling attempts.

imapVerification.verifyMessageDoesNotExist();

 


Verify a message always exists

The next code will succeed if the searched mail is present for all polling attempts, otherwise it will fail.

imapVerification.verifyMessageAlwaysExists();

 


Verify a message never exists

The next code will succeed if the searched mail is NOT present for all polling attempts, otherwise it will fail.

imapVerification.verifyMessageNeverExists();

 


Working with a nested message

All message checks are also available on nested messages.
You just have to use a method with the same name, but with an additional argument(s) used to identify the nested message to work with.

Have a look at the following example:

// check the subject of the main(top level) message
imapVerification.checkSubject( "RE: Hi" );

// check the subject of the first nested message
imapVerification.checkSubject( "This is the first nested message", 0 );

// check the subject of the second nested message
imapVerification.checkSubject( "This is the second nested message", 1 );

// check the subject of the second nested message of the first nested message
imapVerification.checkSubject( "This is the second nested message of the first nested message", 0, 1 );

Note that nested message indexes start from 0.

So 0 points to the first nested message, 1 points to the first nested message etc.

 


Extract the content of a message

Sometimes upon verifying the message existence, you may need to extract some data from the message itself.

For example in the message body there might be some URL which you need in order to download some file. If we imagine this URL is generated on the fly by the message server, you need a way to extract it in order to do the next test step.

For this purpose two of the ImapVerification methods return the matched message. These are the verifyMessageExists and verifyMessageAlwaysExists. Have a look at the next example:

import com.axway.ats.action.objects.MimePackage;
import com.axway.ats.rbv.clients.ImapVerification;

// get the message(represented as a MIME package) upon successful verification
MimePackage mimePackage = imapVerification.verifyMessageExists();

// get the plain text content of the top level message
String plainBody = mimePackage.getPlainTextBody();

// get the html text content of the top level message
String htmlBody = mimePackage.getHtmlTextBody();

// get the value of some custom header
String customHeaderValue = mimePackage.getHeader( "MY-CUSTOM-HEADER-NAME" );

// get the message sender
String sender = mimePackage.getSender();

// get the file name of the first attachment
String firstAttachmentFileName = mimePackage.getAttachmentFileName( 0 );

The number of  get  methods is very long. Lookup the code or java doc for the whole list.

 


Customize the java mail session

Following are examples showing how to configure the way java mail works.

    // Disable NTLM authentication. By default java mail tries NTLM authentication
    RbvConfigurator.getInstance().setCustomProperty( "mail.imap.auth.ntlm.disable", "true" );

    // set connection timeout period in milliseconds
    RbvConfigurator.getInstance().setCustomProperty( "mail.smtp.connectiontimeout", "10000" );

Note that we will apply any property starting with "mail" prefix.

 


Back to parent page

Go to Table of Contents