Summer Internship 2013 Group IV - Enhancement of Jmeter Week 4 Report 1 9 th June 2013 Shekhar Saurav Report on Configuration Element Plugin 'SMTP Defaults' Configuration Elements or config elements are important component of the test plans designed in Apache Jmeter. They are mainly used to specify default values or variables to be used in the test plan. This helps in preventing the redundant specification of the values to be used by the samplers in the test plan. The existing Jmeter have several config element like Http Request Defaults which is used with http request samplers, Java Request Defaults which is used with Java request samplers, Ldap Request defaults, TCP Sampler config, JDBC Connection configuration which are all used for specific purposes. The existing version of Jmeter have a sampler called SMTP Sampler which is used for testing smtp mail servers. There is large number of fields to be specified within sampler before the test can be run like Server or IP address of the SMTP server, the port address of the smtp server, the mail address where the mail is to be sent, mail address of the person sending the mail, the mail addresses where the copies of the mail is to be sent. In the authorization settings, if required, the user-name and the password is to be specified. In the message settings the subject of the mail, headers to be added, message to be sent, any attachment to be sent along with the mail and other optional parameter which may or may not be selected depending upon the configuration of the mail server to be tested. In case if the test plan is having more than one sampler, like four or five or more, these data and settings have to be specified for all the samplers which is too cumbersome as well as several entries in the samplers are common which make these entries redundant. In this situation, there is a need of a SMTP config element where default values can be set which don't have to be specified in the samplers to be used. Smtp Defaults Config Element is a configuration element that can be used to set default values for Smtp samplers.
SMTP Defaults Fig 4.1.1 : Smtp Defaults (Apache Jmeter Configuration Element) This element is present in the config element section of the thread group. Currently this config element provides fields to specify smtp server name or IP address, server port address, mail address of the receiver of the mail. Once this element is used in the test plan these values need not be specified in the fields of the samplers, whatever be the number of the samplers. Although if some sampler has to use some specific values for these fields, they can be specified in the fields with in the samplers. In this situation this particular sampler will use the values specified in its fields while rest of the sampler use the value specified in the Smtp Defaults config element. A small example showing the use of the Smtp Config Element is described below. As shown in the figure 4.1.1 a smtp default config element is added to the thread group. In this component name of the config element can be set. In the server settings section server address can be set in this example a local smtp server has been setup in Ubuntu 13.04 using postfix and dovecot as mail transfer agent and mail delivery agent respectively. Config Element fields Server : localhost Port : 25 Address to : shekhar@localhost The next element in the test plan is smtp sampler where rest of the details related to the mail can be specified. As shown in the figure 4.1.2 below. Sampler 1 fields Server : (Blank) Port : (Blank) Address from : shekharsaurav@localserver.com (non existing) Address to : (Blank) Subject : Subject of the mail Message : Message of the mail
Fig-4.1.2 : smtp Sampler1 Sampler 2 fields: server : (Blank) port : (Blank) Address from : shekhar@localserver.com (non existing) Address to : (Blank) Subject : Subject for the mail 2 Message : Subject for mail 2 Fig-4.1.3 : smtp Sampler2
Running the test gives the successful result: For sampler 1: Fig-4.1.4 : Request for sampler 1 For Sampler 2: Fig-4.1.5 : Request for sampler 2
Mail Inbox : mail from sampler 1 Fig-4.1.6 : Mail Inbox for sampler 1 Mail Inbox : mail from sampler 2 Fig-4.1.7 : Mail Inbox for sampler 2
Code for Smtp Defaults: A new package was included under smtp package which already had sampler package under it. The Package heirarchy is as shown in the figure below src protocol mail org apache jmeter protocol smtp config gui SmtpConfigGui.java The components of the SmtpConfigGui Class variables : private JTextField server; // text field for server address Procedures : private JTextField port; // text field for the port address private JTextField addressto; // text field for the mail address public SmtpConfigGui() // constructor for the class, calling init function. private void init() // Setting the border layout for config element and adding various components within the element. public String getlabelresource() //setting label for the config element to be visible in the tree view of the test plan public TestElement createtestelement() //creates object of the ConfigTestElement class and passed to modifytestelement() where variables to be passed on to the samplers are modified. public void modifytestelement(testelement config) //Values taken from the text boxes in the gui is used to set the class variables used by the smtp samplers like SmtpSampler.SERVER, SmtpSampler.SERVER_PORT etc. public void configure(testelement element) // Used to set the values in the text fields in the gui in case the element is revisited or a new element is created. public void cleargui() // used to reset the fields of the elements public JPanel setaddressto() // used to add label and text field for mail address in the config element panel. public JPanel setserverto() // used to add label and text field for server address in the config element panel. public JPanel setserverportto() // used to add label and text field for port address in the config element panel. Following modification was done in the SmtpSampler class: private static final Set<String> APPLIABLE_CONFIG_CLASSES = new HashSet<String>( Arrays.asList(new String[]{ "org.apache.jmeter.protocol.smtp.config.gui.smtpconfiggui", "org.apache.jmeter.config.gui.simpleconfiggui"})); Highlighted value was added in the array list of APPLICABLE_CONFIG_CLASSES for the samplers to recognise the newly created class config element.