Serialization
Try on your own
Prerequisites
- JDK 1.8
- IntelliJ
Steps to follow:
- Clone my GitHub repository
git clone git@github.com:smarigowda/serialization-demo-java.git
cd serialization-demo-java
- Change the branch
git checkout serialization-demo
- Clean, install and run the test on command line
mvn clean install -Dtest=AppTest
- Open the project in IntelliJ
- Run the test
Notes
Tools, Libraries and Features used in this project
REST Assured
- A framework for REST API TestingTestNG
- Test RunnerMaven
- Dependency Manager++POJO Classes
- Blue print for data. Getter and setter methods
What is Serialisation
Converting Java Object to a JSON (json is text format) is one example of serialization.
What are we testing
We are testing the Create Place REST API.
Details are given below:
Base URI: https://rahulshettyacademy.com
Resource: /maps/api/place/add/json
HTTP Method: POST
Query Parameters: key=qaclick123
Sample Request
{
"location": {
"lat": -38.383494,
"lng": 33.427362
},
"accuracy": 50,
"name": "Frontline house",
"phone_number": "(+91) 983 893 3937",
"address": "29, side layout, cohen 09",
"types": ["shoe park", "shop"],
"website": "http://google.com",
"language": "French-IN"
}
Sample Response
{
"status": "OK",
"place_id": "928b51f64aed18713b0d164d9be8d67f",
"scope": "APP",
"reference": "736f3c9bec384af62a184a1936d42bb0736f3c9bec384af62a184a1936d42bb0",
"id": "736f3c9bec384af62a184a1936d42bb0"
}
How the program works ?
- We first create POJO Classes to match the Request Body
- Then create an instance of the top level POJO Class (a java object) and set the data for all the fields
- And then we give this object to the
body
method of REST Assured framework - REST Assured converts the java object into JSON and sends the request. This is an example of the use of Serialization.
How REST Assured supports Serialisation
REST Assured has documented this very well (link below)
https://github.com/rest-assured/rest-assured/wiki/Usage#serialization