Basic REST XML template using REST Assured
package com.sadakar.api.common;
import static org.testng.Assert.assertNotEqualsDeep;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
public class RESTXMLPost {
@Test
public void post() {
String requestBody =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
+"<tag1 subtag1=\"value1\" >\r\n"
+"<tag2>\r\n"
+"<tag2Subtag>value</tag2Subtag>\r\n"
+"</tag1>";
given()
.log().all()
.baseUri("https://testurl/api/endPoint")
.contentType("application/xml")
.accept("application/xml")
.header("headerName", "headerValue")
.body(requestBody)
.when()
.post()
.then()
.log().all()
.assertThat()
.statusCode(200)
.and()
.contentType("application/xml");
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>APIAutomation</groupId>
<artifactId>APIAutomation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.0.1</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>5.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
</dependency>
</dependencies>
</project>
No comments:
Post a Comment