- Java library (API) for testing RESTful web services.
- Used to test XML and JSON based web services.
- Supports GET, POST, PATCH, PUT, DELETE, HEAD, OPTIONS. Can be integrated with testing frameworks like JUnit, TestNG.
- Rest Assured is implement in Groovy. It uses Groovy under the hood to fetch the JSON object (GPath Expression)
REST:
- Representation State Transfer is an architectural style sending the representational state of an object at that particular time. - Rest API is Stateless (i.e., Server will not store any information about the client) JSON:
- Key value pair where key is always a String and Value can be String, number, boolean, JSON Object, JSON Array, null etc., - {} --> JSON Object - [] --> JSON Array
Path Param - Used to identify specific resource, it is mandatory. Query Param - Used to Sort/filter the resources, it is optional.
- Java
- IntelliJ IDE
- Maven
- TestNG
JSON Server: Used to create our own fake Rest API.
- Installing JSON Server
npm install -g json-server
- Start JSON Server
json-server --watch db.json
REFERENCE LINK: https://medium.com/codingthesmartway-com-blog/create-a-rest-api-with-json-server-36da8680136d
- Created API will be available in the local server
http://localhost:3000/
To start Json Server on the machine IP address
json-server --host <<ipaddress>> --watch db.json
https://reqres.in/
http://ergast.com/mrd/
- Create or Get JSON Schema
- Add JSON Schema file in src/test/resources path
- Add maven dependency for JSON Schema validator
- Create or Get XML Schema (XSD)
- Add XSD in src/test/resources path
Authorization gives the users permission to access a resource.
Process to prove that you are valid user or not Supports several authentication schemes - OAuth, digest, certificate, form and preemptive basic authentication. Basic authentication:
- Preemptive : Will supply the credentials as header before the server response. - Challanged : Will not supply credentials until the server asks for it.
- Open Standard for authorization protocol.
Dependency:
- Rest Assured
- ScribeJava-APIs
- Developer Account
NOTE: Developer account is mandatory to work with OAuth authentication.
- An HTTP cookie (Web cookie, browser cookie) is a small piece of data that a server sends to the user's web browser.
Example: Keeping a user logged in.
- Uses HTTP cookies to authenticate client requests and maintain session information.
- JSESSIONID is a cookie in J2EE web application which is used in session tracking.
- WireMock is a library for stubbing and mocking web services.
- It constructs an HTTP server that we could connect to as we would to an actual web service.
- When a WireMock server is in action, we can set up expectations, call the service, and then verify its behaviors.
- The WireMock server can be run in its own process, and configured via the Java API, JSON over HTTP or JSON files.
- Running it through Maven/gradle will start the mock service once the test start running and stops after test completes.
Once you have downloaded the standalone JAR you can run it simply by doing this
java -jar wiremock-jre8-standalone-2.33.1.jar
--port
: Set the HTTP port number e.g. java -jar wiremock-jre8-standalone-2.33.1.jar --port 9091
--https-port
: If specified, enables HTTPS on the supplied port. Note: When you specify this parameter, WireMock will
still, additionally, bind to an HTTP port (8080 by default). So when running multiple WireMock servers you will also
need to specify the --port parameter in order to avoid conflicts.
- As String
- From external file (.json file)
- Read it as String from external file (.json file) and replace values.
- Using HashMap (for Json Object {} ) and ArrayList (for Json Array []).
- Using external Json library (JSONObject, JSONArray).
Swagger Doc
https://jobportalkarate.herokuapp.com/swagger-ui.html
To access the application locally - Open terminal, navigate to the location of 'jobportal-0.0.1-SNAPSHOT' JAR file and execute the following command
java -jar -Dserver.port=5050 jobportal-0.0.1-SNAPSHOT.jar
This will start the server and the following url can be used to access the Swagger doc
http://localhost:5050/swagger-ui.html
docker build -t <imagename>:<tag> .
docker commit <<containerid>>
docker tag <<container/image id>> <<newImageName>>
docker build -t <<newImageName>>
docker login
docker push <<imagename>>