jMeter Webservice Test Plan

In this chapter, we will learn how to create a Test Plan to test a WebService. For our test purpose, we have created a simple webservice project and deployed it on the Tomcat server locally.

Create Webservice Project

To create a webservice project, we have used Eclipse IDE. First write the Service Endpoint Interface HelloWorld under the packagecom.tutorialspoint.ws. The contents of the HelloWorld.java are as follows −
package com.tutorialspoint.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)

public interface HelloWorld{

   @WebMethod String getHelloWorldMessage(String string);

}
This service has a method getHelloWorldMessage which takes a String parameter.
Next, create the implementation class HelloWorldImpl.java under the package com.tutorialspoint.ws.
package com.tutorialspoint.ws;

import javax.jws.WebService;

@WebService(endpointInterface="com.tutorialspoint.ws.HelloWorld")
public class HelloWorldImpl  implements HelloWorld  {
   @Override
 
   public String getHelloWorldMessage(String myName){
      return("Hello "+myName+" to JAX WS world");
   }
}
Let us now publish this web service locally by creating the Endpoint publisher and expose the service on the server.
The publish method takes two parameters −
  • Endpoint URL String.
  • Implementor object, in this case the HelloWorld implementation class, which is exposed as a Web Service at the endpoint identified by the URL mentioned in the parameter above.
The contents of HelloWorldPublisher.java are as follows −
package com.tutorialspoint.endpoint;

import javax.xml.ws.Endpoint;

import com.tutorialspoint.ws.HelloWorldImpl;

public class HelloWorldPublisher {

   public static void main(String[] args){
      Endpoint.publish("http://localhost:9000/ws/hello", new HelloWorldImpl());
   }
}
Modify the web.xml contents as shown below −
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

<web-app>

   <listener>
      <listener-class>
         com.sun.xml.ws.transport.http.servlet.WSServletContextListener
      </listener-class>
   </listener>
 
   <servlet>
      <servlet-name>hello</servlet-name>
      <servlet-class>
         com.sun.xml.ws.transport.http.servlet.WSServlet
      </servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>
 
   <servlet-mapping>
      <servlet-name>hello</servlet-name>
      <url-pattern>/hello</url-pattern>
   </servlet-mapping>
 
   <session-config>
      <session-timeout>120</session-timeout>
   </session-config>
 
</web-app>
To deploy this application as a webservice, we would need another configuration file sun-jaxws.xml. The contents of this file are as follows −
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">

   <endpoint name="HelloWorld" implementation="com.tutorialspoint.ws.HelloWorldImpl" url-pattern="/hello"/>
 
</endpoints>
Now that all the files are ready, the directory structure would look as shown in the following screenshot −
Webservice Dir structure
  • Now create a WAR file of this application.
  • Choose the project > right click > Export > WAR file.
  • Save this as hello.war file under the webapps folder of Tomcat server.
  • Now start the Tomcat server.
  • Once the server is started, you should be able to access the webservice with the URL − http://localhost:8080/hello/hello

Create JMeter Test plan

Now let us create a test plan to test the above webservice.

Rename the Test Plan

  • Open the JMeter window by clicking /home/manisha/apache-jmeter2.9/bin/jmeter.sh.
  • Click the Test Plan node.
  • Rename this Test Plan node as WebserviceTest.
WS Test Plan

Add Thread Group

Add one Thread Group, which is placeholder for all other elements like Samplers, Controllers, and Listeners.
  • Right click on WebserviceTest (our Test Plan) > Add > Threads (Users) > Thread Group. Thread Group will get added under the Test Plan (WebserviceTest) node.
  • Next, let us modify the default properties of the Thread Group to suit our testing. Following properties are changed −
    • Name − webservice user
    • Number of Threads (Users) − 2
    • Ramp-Up Period − leave the the default value of 0 seconds.
    • Loop Count − 2
WS Test Users

Add Sampler - SOAP/XML-RPC Request

Now that we have defined the users, it is time to define the tasks that they will be performing.
We will add SOAP/XML-RPC Request element −
  • Right-click mouse button to get the Add menu.
  • Select Add > Sampler > SOAP/XML-RPC Request.
  • Select the SOAP/XML-RPC Request element in the tree
  • Edit the following properties as in the image below −
  • The following details are entered in this element −
    • Name − SOAP/XML-RPC Request
    • URL − http://localhost:8080/hello/hello?wsdl
    • Soap/XML-RPC Data − Enter the below contents
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://ws.tutorialspoint.com/">

   <soapenv:Header/>
 
   <soapenv:Body>
 
      <web:getHelloWorldMessage>
         <arg0>Manisha</arg0>
      </web:getHelloWorldMessage>
  
   </soapenv:Body>
 
</soapenv:Envelope>
WS Test request

Add Listener

The final element you need to add to your Test Plan is a Listener. This element is responsible for storing all of the results of your HTTP requests in a file and presenting a visual model of the data.
  • Select the webservice user element.
  • Add a View Results Tree listener by selecting Add > Listener > View Results Tree.
WS Test request

Run the Test Plan

Now save the above test plan as test_webservice.jmx. Execute this test plan using Run > Start option.

View the Output

The following output can be seen in the listener.
WS Sample ResultWS Result RequestWS Response Data
In the last image, you can see the response message "Hello Manisha to JAX WS world".

jMeter - FTP Test Plan

In this chapter, we will see how to test a FTP site using JMeter. Let us create a Test Plan to test the FTP site.

Rename Test Plan

  • Open the JMeter window by clicking /home/Subbu/apache-jmeter-2.9/bin/jmeter.sh
  • Click on the Test Plan node.
  • Rename this Test Plan node as TestFTPSite.

Add Thread Group

Add one Thread Group, which is placeholder for all other elements like Samplers, Controllers, and Listeners.
  • Right click on TestFTPSite (our Test Plan)
  • Select Add > Threads(Users) > Thread Group. Thread Group will get added under the Test Plan (TestFTPSite) node.
  • Modify the default properties of the Thread Group to suit our testing as follows −
    • Name − FTPusers
    • Number of Threads (Users) − 4
    • Ramp-Up Period − leave the the default value of 0 seconds.
    • Loop Count − 1
FTP Test Users

Add Sampler − FTP Request

Now that we have defined our users, it is time to define the tasks that they will be performing. Add FTP Request elements. We add two FTP request elements, one which retrieves a file and the other which puts a file on the ftp site.
  • Select the FTPusers element.
  • Right-click the mouse button to get the Add menu
  • Select Add > Sampler > FTP Request.
  • Select the FTP Request element in the tree.
  • Edit the following properties as shown below −
FTP Request Get
The following details are entered in this element −
  1. Name − FTP Request Get
  2. Server Name or IP − 184.168.74.29
  3. Remote File − /home/Subbu/sample_ftp.txt
  4. Local File − sample_ftp.txt
  5. Select get(RETR)
  6. Username − Subbu
  7. Password − Subbu123
Now add another FTP request as above and edit the properties as shown in the following screenshot −
FTP Request Put
The following details are entered in this element −
  1. Name − FTP Request Put
  2. Server Name or IP − 184.168.74.29
  3. Remote File − /home/Subbu/examplefile.txt
  4. Local File − /home/Subbu/work/examplefile.txt
  5. Select put(STOR)
  6. Username − Subbu
  7. Password −Subbu123

Add Listener

The final element you need to add to your Test Plan is a Listener. This element is responsible for storing all of the results of your FTP requests in a file and presenting a visual model of the data.
  • Select the FTPusers element.
  • Add a View Results Tree listener by selecting Add > Listener > View Results Tree.
FTP Test Listener

Run the Test Plan

Now save the above test plan as ftpsite_test.jmx. Execute this test plan usingRun > Start option.

View the Output

The following output can be seen in the listener.
FTP Get Result1FTP Test Result2FTP Put ResultFTP Get Result
You can see that four requests are made for each FTP request and the test is successful. The retrieved file for GET request is stored in the /bin folder. In our case, it is /home/Subbu/apache-jmeter-2.9/bin/. For PUT request, the file is uploaded at the path /home/Subbu/.

jMeter - Database Test Plan

In this chapter, we will see how to create a simple test plan to test the database server. For our test purpose we use the MYSQL database server. You can use any other database for testing. For installation and table creation in MYSQL please refer MYSQL Tutorial.
Once MYSQL is installed, follow the steps below to setup the database −
  • Create a database with name "tutorial".
  • Create a table tutorials_tbl.
  • Insert records into tutorials_tbl as shown below −
mysql> use TUTORIALS;

Database changed

mysql> INSERT INTO tutorials_tbl 
     ->(tutorial_title, tutorial_author, submission_date)
     ->VALUES
     ->("Learn PHP", "John Poul", NOW());
   
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO tutorials_tbl
     ->(tutorial_title, tutorial_author, submission_date)
     ->VALUES
     ->("Learn MySQL", "Abdul S", NOW());
   
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO tutorials_tbl
     ->(tutorial_title, tutorial_author, submission_date)
     ->VALUES
     ->("JAVA Tutorial", "Sanjay", '2007-05-06');
   
Query OK, 1 row affected (0.01 sec)

mysql>
  • Copy the appropriate JDBC driver to /home/manisha/apache-jmeter-2.9/lib.

Create JMeter Test Plan

Let us start the JMeter from /home/manisha/apache-jmeter-2.9/bin/jmeter.sh.

Add Users

To create a Thread group,
  • Right-click on Test Plan.
  • Select Add > Threads (Users) > Thread Group.
  • Thus, thread group gets added under the Test Plan node.
  • Rename this Thread Group as JDBC Users.
Thread Group Added
We will not change the default properties of the Thread Group.

Adding JDBC Requests

Now that we defined our users, it is time to define the tasks that they will be performing. In this section, specify the JDBC requests to perform.
  • Right-click on the JDBC Users element.
  • Select Add > Config Element > JDBC Connection Configuration.
  • Set up the following fields (we are using MySQL database called tutorial) −
    • Variable name bound to pool. This needs to identify the configuration uniquely. It is used by the JDBC Sampler to identify the configuration to be used. We have named it as test.
    • Database URL − jdbc:mysql://localhost:3306/tutorial.
    • JDBC Driver class: com.mysql.jdbc.Driver.
    • Username: root.
    • Password: password for root.
The other fields on the screen are left as defaults as shown below −
JDBC Configuration Pool
Now add a JDBC Request which refers to the JDBC Configuration pool defined above. Select JDBC Users element.
  • Click your right mouse button to get the Add menu
  • Select Add > Sampler > JDBC Request.
  • Select this new element to view its Control Panel.
  • Edit the properties as shown below −
    • Variable name bound to pool. This needs to uniquely identify the configuration. It is used by the JDBC Sampler to identify the configuration to be used. Named it as test.
    • Name − Learn.
    • Enter the Pool Name − test (same as in the configuration element).
    • Query Type − Select statement.
    • Enter the SQL Query String field.
JDBC Request

Create Listener

Now add the Listener element. This element is responsible for storing all of the results of your JDBC requests in a file and presenting a visual model of the data.
  • Select the JDBC Users element
  • Add a View Results Tree listener (Add > Listener > View Results Tree).
JDBC Test Listener

Save and Execute Test Plan

Now save the above test plan as db_test.jmx. Execute this test plan using Run > Start option.

Verify the Output

JDBC Test Output1JDBC Test Output2JDBC Test Output3
In the last image, you can see that two records are selected.