Click here to Skip to main content
15,867,704 members
Articles / Programming Languages / SQL

Testing Your Rest API Controller Methods - Using SoapUI

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
16 Oct 2015CPOL4 min read 27.9K   549   10   2
Validate your Restful Service Methods using SoapUI (which can then be integrated into TFS build CI)

Introduction

Download Database SQL Scripts & Data

Download VS2013 Web API Project (minus packages)

Download SoapUI Project (update your windows credentials)

For years I have used SoapUI to test my SOAP oriented services, creating SoapUI projects and integrating them into a TFS build, or simply having a SoapUI project open to quickly test the response (structure or data) from a service call - quick and simple...

Background

During an AngularJS Web API project, I needed to test the Web API methods in isolation, without the calls from the client, to track down a defect. To determine if the issue was in the WEB API or in the request from the client. So it was a simple matter of testing the Rest service method in isolation first. To do this I knew I would use SoapUI, but I hadn't used it with a Rest API project before - thus this tutorial!

Using the attached code

Firstly, download a set of SQL scripts and execute within your SQL Server to create the "Scratch" database objects.

Secondly, I have attached a simple Microsoft WEB API project (Visual Studio 2013), which you can download, compile (change connection string) and deploy to your IIS.

Then download the SoapUI project (Freeware version 5.2.0). I will step through in detail below, on how to create and test your SoapUI project requests.

Compile & Deploy WEB API Project to IIS

Open the solution in Visual Studio 2013, compile and add the missing packages through Nuget. Once you’re missing packages have been included into the project, it's time to publish the API project to your IIS.

Image 1

Deploy to a site called "WebApi-SoapUI"

Image 2

All going well your IIS should look something like this;

Image 3

Now, you can see the Controller that we wish to test against.

Execute SQL Scripts

Unzip the SQL package, and double click the "Scratch Database.sql" file to open in SQL Server. Execute this script to create a Scratch database with two tables and a stored procedure.

Image 4

Import the data from the two .txt files into the respective tables. Now, we have data that we can black box test against.

Create Soap UI Rest Project

Open Soap UI and click on the new Rest project toolbar button.

Image 5

This will render a dialog for you to enter in the Rest URL for the particular controller we wish to test against:

http://localhost/SoapUIWebAPI/api/People

Image 6

We are presented with a SoapUI Rest Project with a default Request - give your request a more meaningful name, like "All People".

Image 7

Because we have security enabled within the web site (Windows Authentication) - we will have to replicate it in the Rest request also (mimic the client request). We do this by clicking on the Authorize (NTLM) button (bottom of the page).

Image 8

Enter valid credentials for the web site (NB: make sure your App Pool account also has the correct credentials to access the controller API's).

Image 9

Image 10

Create Soap UI Rest Requests

Now we are ready to make a Rest request to our controller. Notice how the request URL is split up into server and controller and the method dropdown is "Get" by default (which is correct in this case). Click on the green arrow to initiate the request and you should see a JSON response.

Image 11

Json Data Response:

Image 12

To make a request for a particular record, we simple build the request up like we would in our browser address bar.

Add a new request for the People API like this:

Image 13

For eg., to retrieve the record with an ID of 5, we simply create a request like this - make sure to set the authorization (for each request)

Image 14

Create Soap UI Rest Post

To post like a form submit (like a client would), ensure to click the "Post QueryString" checkbox. Add your parameters and ensure that the action method is "Post", before submitting the request.

Image 15

Validate your post in SQL server, you can also use your Get method to retrieve the newly entered record (NB: ID is not an identity field, you might want to get the next valid ID value from SQL Server).

Image 16

 

If you add more action methods to the project, you should have a SoapUI project something like this (always remember to set the authorization settings for each request):

Image 17

 

Create Soap UI Rest Put

Image 18

Create Soap UI Rest Delete

Image 19

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Ireland Ireland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionSoapUI does not return a request file Pin
Member 1301781522-Feb-17 9:13
Member 1301781522-Feb-17 9:13 
Questionthanks Pin
Member 1142215420-Oct-15 23:15
Member 1142215420-Oct-15 23:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.