Pojo to Json - Serialization

 //jackson-databind library - it will convert pojo into json - serialization


1-Create a Pojo:

2-in Test class, create an object of the pojo class,call the pojo class and pass the constructor parameters

3.in Body(call the Object )

package UpdateUSer;-

public class ecampusconnectNewCoursePojo {

private String courseName;

private int courseDuration;

private String courseType;

public ecampusconnectNewCoursePojo(String courseName, int courseDuration, String courseType) {

this.courseName = courseName;

this.courseDuration = courseDuration;

this.courseType = courseType;

}

public String getCourseName() {

return courseName;

}

public void setCourseName(String courseName) {

this.courseName = courseName;

}

public int getCourseDuration() {

return courseDuration;

}

public void setCourseDuration(int courseDuration) {

this.courseDuration = courseDuration;

}

public String getCourseType() {

return courseType;

}

public void setCourseType(String courseType) {

this.courseType = courseType;

}

}



Testclass - calling the pojo object


package rahulshettyeg;

import static io.restassured.RestAssured.given;

import org.testng.Assert;
import org.testng.annotations.Test;

import UpdateUSer.ecampusconnectNewCoursePojo;
import UpdateUSer.rerespojodata;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;

public class ecampusconnectNewCoursePojoTest {

@Test
public void reqresTest() {
RestAssured.baseURI = "https://b1fd5849-2e3b-4b86-8bb7-27dcbfaf5220.mock.pstmn.io";
//jackson-databind library - it will convert pojo into json - serialization
ecampusconnectNewCoursePojo ecampus  = new ecampusconnectNewCoursePojo("computers sciece",234,"kumar");
//createUser
int courseId= given().log().all().contentType(ContentType.JSON).body(ecampus).when().log().all().post("/courses").then().log().all().assertThat().statusCode(201).and().extract().path("courseId");
Assert.assertNotNull(courseId);
System.out.println(courseId);
ecampus.setCourseName("Mech Engg");
ecampus.setCourseDuration(7777);
given().log().all().contentType(ContentType.JSON).body(ecampus).when().log().all().post("/courses").then().log().all().assertThat().statusCode(201);
//System.out.println(id);
}


}



Comments

Popular posts from this blog

Implicit and Explicit Waits,FluentWait,PageLoadTimeOut

A Interview Questions- selenium