Http : post- Body with Text,JavaScript,XML,HTML,Multipart,PDF
HTTP -post- Body with Text,JavaScript,XML,HTML,Multipart,PDF
public class postwithDifferentData {
@Test
public void bodywithsimpleText() {
RestAssured.baseURI = "http://httpbin.org";
String BodyText = "Hello world API!!!";
given().log().all()
.contentType(ContentType.TEXT)
.body(BodyText)
.when().log().all().
post("/post")
.then().log().all()
.assertThat().statusCode(200).body("data", equalTo("Hello world API!!!"));
}
Body with Java Script:
public void bodywithsimpleJavaScript() {
RestAssured.baseURI = "http://httpbin.org";
String JavaScript = "<script>\r\n"
+ "var x, y, z; \r\n"
+ "x = 5; \r\n"
+ "y = 6; \r\n"
+ "z = x + y; \r\n"
+ "document.getElementById(\"demo\").innerHTML =\r\n"
+ "\"The value of z is \" + z + \".\";\r\n"
+ "</script>";
given().log().all()
.contentType("application/javascript")
.body(JavaScript)
.when().log().all().
post("/post")
.then().log().all()
.assertThat().statusCode(200);
}
}
Post body with HTML: Content-Type=text/html
@Test
public void bodywithsimpleHTML() {
RestAssured.baseURI = "http://httpbin.org";
String JavaScript = "<html>\r\n"
+ "<body>\r\n"
+ "<h1>My First Heading</h1>\r\n"
+ "<p>My first paragraph.</p>\r\n"
+ "</body>\r\n"
+ "</html>";
given().log().all()
.contentType(ContentType.HTML)
.body(JavaScript)
.when().log().all().
post("/post")
.then().log().all()
.assertThat().statusCode(200);
}
}
Post body with HTML: Content-Type==application/xml
@Test
public void bodywithsimpleXML() {
RestAssured.baseURI = "http://httpbin.org";
String xml = "<dependency>\r\n"
+ " <groupId>io.rest-assured</groupId>\r\n"
+ " <artifactId>rest-assured</artifactId>\r\n"
+ " <version>5.5.0</version>\r\n"
+ "\r\n"
+ " </dependency>";
given().log().all()
//.contentType("application/xml")
.contentType(ContentType.XML)
.body(xml)
.when().log().all().
post("/post")
.then().log().all()
.assertThat().statusCode(200);
}
Post body with File and Text "Content-Type": "multipart/form-data;
@Test
public void bodywithsMulti() {
RestAssured.baseURI = "http://httpbin.org";
given().log().all()
//.contentType("application/xml")
.contentType(ContentType.MULTIPART).multiPart("filename", new File("C:/Users/windo/Downloads/AutomationQualityEngineer_10 - Ks.docx"))
.multiPart("name","sudheer")
.when().log().all().
post("/post")
.then().log().all()
.assertThat().statusCode(200);
}
Post body with PDF-"Content-Type": "application/pdf;
@Test
public void bodywithsPDF() {
RestAssured.baseURI = "http://httpbin.org";
given().log().all()
.contentType("application/pdf").
body(new File("C://Users//windo//Downloads//AEPS Family Report 1.pdf .pdf"))
.when().log().all().
post("/post")
.then().log().all()
.assertThat().statusCode(200);
}
Comments
Post a Comment