Skip to content

Commit f8d79e3

Browse files
committed
updated headers in all api request with free api keys by reqres
1 parent 5a0692f commit f8d79e3

8 files changed

+18
-2
lines changed

src/test/java/com/faisalkhatri/okhttppoc/TestAuthentication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class TestAuthentication {
5050
public static Map<String, Object> getToken (String email, String password) {
5151
final AuthenticationPojo requestBody = new AuthenticationPojo (email, password);
5252
final String response = given ().contentType (ContentType.JSON)
53+
.header ("x-api-key", "reqres-free-v1")
5354
.body (requestBody)
5455
.when ()
5556
.log ()
@@ -114,6 +115,7 @@ public void testAuthenticationToken (String email, String password) {
114115
final AuthenticationPojo requestBody = new AuthenticationPojo (email, password);
115116

116117
given ().contentType (ContentType.JSON)
118+
.header ("x-api-key", "reqres-free-v1")
117119
.body (requestBody)
118120
.when ()
119121
.log ()

src/test/java/com/faisalkhatri/okhttppoc/TestDeleteRequests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public Iterator<Object[]> deleteokHttpUsers () {
7171
@Test (dataProvider = "deleteUserRestAssured", groups = "DeleteTests")
7272
public void testDeleUsingRestAsured (final int userId) {
7373
given ().when ()
74+
.header ("x-api-key", "reqres-free-v1")
7475
.delete (URL + userId)
7576
.then ()
7677
.assertThat ()
@@ -89,6 +90,7 @@ public void testDeleUsingRestAsured (final int userId) {
8990
public void testDeleteUsingOkHttp (final int userId) throws IOException {
9091
final OkHttpClient client = new OkHttpClient ();
9192
final Request request = new Request.Builder ().url (URL + userId)
93+
.header ("x-api-key", "reqres-free-v1")
9294
.delete ()
9395
.build ();
9496

src/test/java/com/faisalkhatri/okhttppoc/TestGetRequestWithRestAssuredConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class TestGetRequestWithRestAssuredConfig extends SetupConfig {
2626
@Test(groups = "GetTests")
2727
public void testGetRequestwithRestAssured() {
2828
given()
29+
.header ("x-api-key", "reqres-free-v1")
2930
.when()
3031
.get("/api/users/2")
3132
.then()

src/test/java/com/faisalkhatri/okhttppoc/TestGetRequests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void testGetRequestWithQueryParamOkHttp (final int userPage) throws IOExc
101101

102102
final String currentUrl = urlBuilder.build ()
103103
.toString ();
104-
final Request request = new Request.Builder ().url (currentUrl)
104+
final Request request = new Request.Builder ().url (currentUrl).header ("x-api-key", "reqres-free-v1")
105105
.build ();
106106
final Response response = client.newCall (request)
107107
.execute ();
@@ -128,6 +128,7 @@ public void testGetRequestWithQueryParamOkHttp (final int userPage) throws IOExc
128128
@Test (dataProvider = "getUserData", groups = "GetTests")
129129
public void testGetRequestWithQueryParamWithRestAssured (final int userPage) {
130130
given ().when ()
131+
.header ("x-api-key", "reqres-free-v1")
131132
.queryParam ("page", userPage)
132133
.get (URL)
133134
.then ()
@@ -154,6 +155,7 @@ public void testGetRequestWithQueryParamWithRestAssured (final int userPage) {
154155
@Test (dataProvider = "getUserData", groups = "GetTests")
155156
public void testGetRequestWithRestAssured (final int userId) {
156157
given ().when ()
158+
.header ("x-api-key", "reqres-free-v1")
157159
.get (URL + userId)
158160
.then ()
159161
.statusCode (200)

src/test/java/com/faisalkhatri/okhttppoc/TestPatchRequests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void testPatchWithOkHttp (final int id, final String name, final String j
8181

8282
final Request request = new Request.Builder ().url (URL + "/api/users/" + id)
8383
.addHeader ("Content-Type", "application/json;charset=utf-8")
84+
.header ("x-api-key", "reqres-free-v1")
8485
.patch (requestBody)
8586
.build ();
8687

@@ -115,6 +116,7 @@ public void testPatchWithRestAssured (final int id, final String name, final Str
115116

116117
final PostData postData = new PostData (name, job);
117118
final String response = given ().contentType (ContentType.JSON)
119+
.header ("x-api-key", "reqres-free-v1")
118120
.body (postData)
119121
.when ()
120122
.patch (URL + "/api/users/" + id)

src/test/java/com/faisalkhatri/okhttppoc/TestPostRequest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public void testPostWithOkHttp (final String name, final String job) throws IOEx
8282

8383
final Request request = new Request.Builder ().url (URL + "/api/users")
8484
.addHeader ("Content-Type", "application/json;charset=utf-8")
85+
.header ("x-api-key", "reqres-free-v1")
8586
.post (requestBody)
8687
.build ();
8788

@@ -114,6 +115,7 @@ public void testPostWithOkHttp (final String name, final String job) throws IOEx
114115
public void testPostWithRestAssured (final String name, final String job) {
115116
final PostData postData = new PostData (name, job);
116117
final String response = given ().contentType (ContentType.JSON)
118+
.header ("x-api-key", "reqres-free-v1")
117119
.body (postData)
118120
.when ()
119121
.post (URL + "/api/users")
@@ -153,6 +155,7 @@ public void testPostwithOkHttpForm (final String name, final String job) throws
153155
.add ("job", job)
154156
.build ();
155157
final Request request = new Request.Builder ().url (URL + "/api/users")
158+
.header ("x-api-key", "reqres-free-v1")
156159
.post (formBody)
157160
.build ();
158161

src/test/java/com/faisalkhatri/okhttppoc/TestPostRequestBuilderExample.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public class TestPostRequestBuilderExample extends SetupConfig {
2929
public void postUsingBuilderPatternWithRestAssured () {
3030

3131
UserData userData = userDataBuilder ();
32-
given ().body (userData)
32+
given ()
33+
.header ("x-api-key", "reqres-free-v1")
34+
.body (userData)
3335
.when ()
3436
.post ("/api/users")
3537
.then ()

src/test/java/com/faisalkhatri/okhttppoc/TestPutRequests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void testPutWithOkHttp (final int id, final String name, final String job
8181

8282
final Request request = new Request.Builder ().url (URL + "/api/users/" + id)
8383
.addHeader ("Content-Type", "application/json;charset=utf-8")
84+
.header ("x-api-key", "reqres-free-v1")
8485
.put (requestBody)
8586
.build ();
8687

@@ -116,6 +117,7 @@ public void testPutWithRestAssured (final int id, final String name, final Strin
116117

117118
final PostData postData = new PostData (name, job);
118119
final String response = given ().contentType (ContentType.JSON)
120+
.header ("x-api-key", "reqres-free-v1")
119121
.body (postData)
120122
.when ()
121123
.put (URL + "/api/users/" + id)

0 commit comments

Comments
 (0)