Testing a SOAP API GET request using Rest Assured is possible but requires understanding how SOAP works. However, SOAP typically uses POST, not GET, because it sends a full XML envelope in the body. But if the SOAP service is exposed via GET (rare, usually for testing or WSDL fetching), we can use RestAssured.get()
.
Key Concepts:
SOAP (Simple Object Access Protocol) is a protocol for exchanging structured XML data.
WSDL (Web Services Description Language) is used to describe SOAP services.
SOAP API is generally tested using POST, but for some services (like fetching WSDL), GET is used.
Example SOAP GET Use Case:
Fetch the WSDL file or perform a test GET to an endpoint.
Let’s use this public SOAP service for currency conversion WSDL (GET example):
http://www.dneonline.com/calculator.asmx?WSDL
This WSDL can be fetched using a GET request.
Step-by-step: Testing SOAP GET using Rest Assured:
Maven Dependency:
<dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>5.3.1</version> <scope>test</scope> </dependency>
import io.restassured.RestAssured; import io.restassured.response.Response; public class SoapGetTest { public static void main(String[] args) { // Base URI for the SOAP service String url = "http://www.dneonline.com/calculator.asmx?WSDL"; // Send GET request Response response = RestAssured .given() .when() .get(url) .then() .extract() .response(); // Print status code and response System.out.println("Status Code: " + response.getStatusCode()); System.out.println("Content-Type: " + response.getContentType()); System.out.println("Response Body:\n" + response.getBody().asString()); } }
Optional: Add Test Assertion
import static io.restassured.RestAssured.*; import static org.hamcrest.Matchers.*; public class SoapGetTest { public static void main(String[] args) { given() .when() .get("http://www.dneonline.com/calculator.asmx?WSDL") .then() .statusCode(200) .contentType("text/xml; charset=utf-8") .body(containsString("definitions")); } }
No comments:
Post a Comment