|
| 1 | +import static io.restassured.RestAssured.given; |
| 2 | +import static org.hamcrest.Matchers.*; |
| 3 | + |
| 4 | +import io.restassured.builder.RequestSpecBuilder; |
| 5 | +import io.restassured.builder.ResponseSpecBuilder; |
| 6 | +import io.restassured.http.ContentType; |
| 7 | +import io.restassured.specification.RequestSpecification; |
| 8 | +import io.restassured.specification.ResponseSpecification; |
| 9 | +import org.testng.annotations.BeforeClass; |
| 10 | +import org.testng.annotations.Test; |
| 11 | + |
| 12 | +public class XmlResponseTest { |
| 13 | + |
| 14 | + private static RequestSpecification ReqSpec; |
| 15 | + private static ResponseSpecification ResSpec; |
| 16 | + |
| 17 | + @BeforeClass |
| 18 | + public void RequestSpecificationBuilder() { |
| 19 | + ReqSpec = new RequestSpecBuilder(). |
| 20 | + setBaseUri("https://httpbin.org"). |
| 21 | + setAccept(ContentType.XML). |
| 22 | + build(); |
| 23 | + } |
| 24 | + |
| 25 | + @BeforeClass |
| 26 | + public void ResponseSpecificationBuilder() { |
| 27 | + ResSpec = new ResponseSpecBuilder(). |
| 28 | + expectContentType(ContentType.XML). |
| 29 | + expectStatusCode(200). |
| 30 | + build(); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void verifyXMLResponseTags(){ |
| 35 | + given().spec(ReqSpec). |
| 36 | + log().all(). |
| 37 | + when(). |
| 38 | + get("/xml"). |
| 39 | + then().log(). |
| 40 | + body(). |
| 41 | + spec(ResSpec). |
| 42 | + assertThat(). |
| 43 | + body("slideshow.slide[1].item[2].em", equalTo("buys")). |
| 44 | + body("slideshow.slide[1].@type", equalTo("all")). |
| 45 | + body("slideshow.slide[-1].item[2]", not(equalTo("who"))). |
| 46 | + body("slideshow.slide.findAll{it.title='all'}", notNullValue()); |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments