Testing webservice integration with soapUI
A good way to test the server side of the web services deployed by our applications is to use soapUI tool. Do not have soapUI installed yet in your development environment ? Start here.
Create your soapUI project
To create a new soapUI project, you only have to enter the URL of the wsdl file of the web service you want to test. Sample requests will be created based on the methods exposed by the endpoint. You may want to customize those requests in order to provide users of your webservices with examples.
Create your test project
Once you have created your project and configured some sample requests, you can create your test suites. If you want to, you can ask soapUI to create the test cases based on the sample requests you have previously configured. Once it's done, you also have the ability to add assertions to each test cases. This is very useful when your run tests otherwise the outcome of your test might often be "unknown". For an example, take a look at the attached file, you only have to open it in soapUI to get its content.
Not that those tests are useful to test the server part of your webservice. You might also write tests for the client side to ensure that the response sent by the server is still understandable and parsable from the point of view of the client.
Configure properties
To use the Gazelle plugin dedicated to the execution of soapUI tests, you need to define a custom property named ServiceEndpoint, follow the instructions available in this tutorial to do so.
Use Gazelle plugin
soapui-tests gazelle plugin is available from gazelle-plugins:1.46, gazelle-seam:1.222 and gazelle-tools:2.131. Commonly, you will want to update the version of your parent pom, that's mean gazelle-tools.
The plugin is configured to be executed during test phase. That means that if the plugin is configured in your project, it will be executed each time the test phase is run. The plugin requires the following input parameters:
- testConfigurations is a list of testConfiguration elements
where testConfiguration is made of the following attributes:
- serviceEndpoint (optional) targets the endpoint to be queried by soapUI tests (eg. 127.0.0.1:8080)
- one of the following parameters (only one of them can be specified at the same time)
- soapUIProjects which is a list of soapui project files to be executed
- soapUIProjectDirectory which is the path to the directory which contains the XML files representing the soapui projects to be executed.
See below an example of configuration
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>gazelle-plugins</artifactId> <configuration> <testConfigurations> <testConfiguration> <serviceEndpoint>127.0.0.1:8080</serviceEndpoint> <!-- <soapUIProjects> <param>/home/aberge/workspace/webservice-test-runner/src/main/resources/soapui-projects/GazelleHL7v2Validator-soapui-project.xml</param> </soapUIProjects> --> <soapUIProjectDirectory>/home/aberge/workspace/webservice-test-runner/src/main/resources/soapui-projects</soapUIProjectDirectory> </testConfiguration> </testConfigurations> </configuration> <executions> <execution> <phase>test</phase> <goals> <goal>soapui-tests</goal> </goals> </execution> </executions> </plugin>
When you execute maven, the plugin will be automatically executing at test phase and you will get the logs within the terminal output
You can also choose to execute only the plugin:
- Go to the module in which the plugin is defined
- execute
mvn gazelle:soapui-tests