diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 7a7c18c..52f5eaa 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -27,10 +27,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'temurin' cache: maven diff --git a/.gitignore b/.gitignore index 3100fce..4d85546 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ /.idea/ /allure-results/ /allure-report/ -/.allure/ \ No newline at end of file +/.allure/ +/.DS_Store +/*.iml \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0eb486e..17ab061 100644 --- a/pom.xml +++ b/pom.xml @@ -12,16 +12,17 @@ UTF-8 - 1.31.0 - 7.7.1 + 1.37.0 + 7.8.0 1.3 1.1.1 - 1.18.26 - 1.8.0 - 3.10.1 - 3.0.0-M7 - 11 - 20230227 + 1.18.28 + 2.0.1 + 20230618 + 3.11.0 + 3.1.0 + 17 + 3.4.0 test-suite/testng.xml @@ -88,7 +89,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.1.0 + ${maven-enforcer-version} enforce-maven @@ -108,5 +109,4 @@ - diff --git a/src/test/java/io/github/mfaisalkhatri/api/manager/RequestManager.java b/src/test/java/io/github/mfaisalkhatri/api/manager/RequestManager.java index 8856b78..d7a86dc 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/manager/RequestManager.java +++ b/src/test/java/io/github/mfaisalkhatri/api/manager/RequestManager.java @@ -1,13 +1,13 @@ package io.github.mfaisalkhatri.api.manager; -import java.util.Map; - import com.microsoft.playwright.APIRequest; import com.microsoft.playwright.APIRequestContext; import com.microsoft.playwright.APIResponse; import com.microsoft.playwright.Playwright; import com.microsoft.playwright.options.RequestOptions; +import java.util.Map; + /** * @author Faisal Khatri * @since 2/28/2023 @@ -18,63 +18,63 @@ public class RequestManager { private APIRequestContext apiRequestContext; public void createPlaywright() { - playwright = Playwright.create(); + this.playwright = Playwright.create(); } - public void setApiRequestContext(String baseUrl, Map headers) { - apiRequestContext = playwright.request() + public void setApiRequestContext(final String baseUrl, final Map headers) { + this.apiRequestContext = this.playwright.request() .newContext(new APIRequest.NewContextOptions().setBaseURL(baseUrl) .setExtraHTTPHeaders(headers)); } - public APIResponse getRequest(String endpoint) { - return apiRequestContext.get(endpoint); + public APIResponse getRequest(final String endpoint) { + return this.apiRequestContext.get(endpoint); } - public APIResponse getRequest(String endpoint, RequestOptions options) { - return apiRequestContext.get(endpoint, options); + public APIResponse getRequest(final String endpoint, final RequestOptions options) { + return this.apiRequestContext.get(endpoint, options); } - public APIResponse postRequest(String endpoint) { - return apiRequestContext.post(endpoint); + public APIResponse postRequest(final String endpoint) { + return this.apiRequestContext.post(endpoint); } - public APIResponse postRequest(String endpoint, RequestOptions options) { - return apiRequestContext.post(endpoint, options); + public APIResponse postRequest(final String endpoint, final RequestOptions options) { + return this.apiRequestContext.post(endpoint, options); } - public APIResponse putRequest(String endpoint) { - return apiRequestContext.put(endpoint); + public APIResponse putRequest(final String endpoint) { + return this.apiRequestContext.put(endpoint); } - public APIResponse putRequest(String endpoint, RequestOptions options) { - return apiRequestContext.put(endpoint, options); + public APIResponse putRequest(final String endpoint, final RequestOptions options) { + return this.apiRequestContext.put(endpoint, options); } - public APIResponse patchRequest(String endpoint) { - return apiRequestContext.patch(endpoint); + public APIResponse patchRequest(final String endpoint) { + return this.apiRequestContext.patch(endpoint); } - public APIResponse patchRequest(String endpoint, RequestOptions options) { - return apiRequestContext.patch(endpoint, options); + public APIResponse patchRequest(final String endpoint, final RequestOptions options) { + return this.apiRequestContext.patch(endpoint, options); } - public APIResponse deleteRequest(String endpoint) { - return apiRequestContext.delete(endpoint); + public APIResponse deleteRequest(final String endpoint) { + return this.apiRequestContext.delete(endpoint); } - public APIResponse deleteRequest(String endpoint, RequestOptions options) { - return apiRequestContext.delete(endpoint, options); + public APIResponse deleteRequest(final String endpoint, final RequestOptions options) { + return this.apiRequestContext.delete(endpoint, options); } public void disposeAPIRequestContext() { - apiRequestContext.dispose(); + this.apiRequestContext.dispose(); } public void closePlaywright() { - playwright.close(); + this.playwright.close(); } } diff --git a/src/test/java/io/github/mfaisalkhatri/api/reqres/data/EmployeeData.java b/src/test/java/io/github/mfaisalkhatri/api/reqres/data/EmployeeData.java index ae0c565..643122d 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/reqres/data/EmployeeData.java +++ b/src/test/java/io/github/mfaisalkhatri/api/reqres/data/EmployeeData.java @@ -2,7 +2,6 @@ import lombok.Builder; import lombok.Getter; -import lombok.Setter; /** * @author Faisal Khatri diff --git a/src/test/java/io/github/mfaisalkhatri/api/reqres/data/EmployeeDataBuilder.java b/src/test/java/io/github/mfaisalkhatri/api/reqres/data/EmployeeDataBuilder.java index 5a10b44..19c5be6 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/reqres/data/EmployeeDataBuilder.java +++ b/src/test/java/io/github/mfaisalkhatri/api/reqres/data/EmployeeDataBuilder.java @@ -9,7 +9,7 @@ public class EmployeeDataBuilder { public static EmployeeData getEmployeeData() { - Faker faker = new Faker(); + final Faker faker = new Faker(); return EmployeeData.builder() .name(faker.name() .firstName()) diff --git a/src/test/java/io/github/mfaisalkhatri/api/reqres/tests/ApiTests.java b/src/test/java/io/github/mfaisalkhatri/api/reqres/tests/ApiTests.java index 96cda77..8cf6b88 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/reqres/tests/ApiTests.java +++ b/src/test/java/io/github/mfaisalkhatri/api/reqres/tests/ApiTests.java @@ -1,15 +1,15 @@ package io.github.mfaisalkhatri.api.reqres.tests; -import static io.github.mfaisalkhatri.api.reqres.data.EmployeeDataBuilder.getEmployeeData; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - import com.microsoft.playwright.APIResponse; import com.microsoft.playwright.options.RequestOptions; import io.github.mfaisalkhatri.api.reqres.data.EmployeeData; import org.json.JSONObject; import org.testng.annotations.Test; +import static io.github.mfaisalkhatri.api.reqres.data.EmployeeDataBuilder.getEmployeeData; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + /** * @author Faisal Khatri * @since 2/28/2023 @@ -17,11 +17,11 @@ public class ApiTests extends BaseTest { @Test public void testGetAPI() { - APIResponse response = manager.getRequest("/api/users/4"); + final APIResponse response = this.manager.getRequest("/api/users/4"); assertEquals(response.status(), 200); - JSONObject jsonObject = new JSONObject(response.text()); - JSONObject dataObject = jsonObject.getJSONObject("data"); + final JSONObject jsonObject = new JSONObject(response.text()); + final JSONObject dataObject = jsonObject.getJSONObject("data"); assertEquals(dataObject.get("email") .toString(), "eve.holt@reqres.in"); @@ -31,12 +31,12 @@ public void testGetAPI() { @Test public void testPostAPI() { - EmployeeData employeeData = getEmployeeData(); - APIResponse response = manager.postRequest("/api/users", RequestOptions.create() + final EmployeeData employeeData = getEmployeeData(); + final APIResponse response = this.manager.postRequest("/api/users", RequestOptions.create() .setData(employeeData)); assertEquals(response.status(), 201); - JSONObject jsonObject = new JSONObject(response.text()); + final JSONObject jsonObject = new JSONObject(response.text()); assertNotNull(jsonObject.get("id")); assertEquals(jsonObject.get("name"), employeeData.getName()); assertEquals(jsonObject.get("job"), employeeData.getJob()); @@ -44,12 +44,12 @@ public void testPostAPI() { @Test public void testPutAPI() { - EmployeeData employeeData = getEmployeeData(); - APIResponse response = manager.putRequest("/api/users/2", RequestOptions.create() + final EmployeeData employeeData = getEmployeeData(); + final APIResponse response = this.manager.putRequest("/api/users/2", RequestOptions.create() .setData(employeeData)); assertEquals(response.status(), 200); - JSONObject jsonObject = new JSONObject(response.text()); + final JSONObject jsonObject = new JSONObject(response.text()); assertNotNull(jsonObject.get("updatedAt")); assertEquals(jsonObject.get("name"), employeeData.getName()); assertEquals(jsonObject.get("job"), employeeData.getJob()); @@ -57,12 +57,12 @@ public void testPutAPI() { @Test public void testPatchAPI() { - EmployeeData employeeData = getEmployeeData(); - APIResponse response = manager.patchRequest("/api/users/2", RequestOptions.create() + final EmployeeData employeeData = getEmployeeData(); + final APIResponse response = this.manager.patchRequest("/api/users/2", RequestOptions.create() .setData(employeeData)); assertEquals(response.status(), 200); - JSONObject jsonObject = new JSONObject(response.text()); + final JSONObject jsonObject = new JSONObject(response.text()); assertNotNull(jsonObject.get("updatedAt")); assertEquals(jsonObject.get("name"), employeeData.getName()); assertEquals(jsonObject.get("job"), employeeData.getJob()); @@ -70,8 +70,8 @@ public void testPatchAPI() { @Test public void testDeleteAPI() { - EmployeeData employeeData = getEmployeeData(); - APIResponse response = manager.deleteRequest("/api/users/2", RequestOptions.create() + final EmployeeData employeeData = getEmployeeData(); + final APIResponse response = this.manager.deleteRequest("/api/users/2", RequestOptions.create() .setData(employeeData)); assertEquals(response.status(), 204); } diff --git a/src/test/java/io/github/mfaisalkhatri/api/reqres/tests/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/api/reqres/tests/BaseTest.java index a2377fb..bb8cffc 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/reqres/tests/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/api/reqres/tests/BaseTest.java @@ -1,12 +1,12 @@ package io.github.mfaisalkhatri.api.reqres.tests; -import java.util.HashMap; -import java.util.Map; - import io.github.mfaisalkhatri.api.manager.RequestManager; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; +import java.util.HashMap; +import java.util.Map; + /** * @author Faisal Khatri * @since 2/28/2023 @@ -17,17 +17,17 @@ public class BaseTest { @BeforeClass public void setup() { - manager = new RequestManager(); - manager.createPlaywright(); - String baseUrl = "https://reqres.in"; - Map headers = new HashMap<>(); + this.manager = new RequestManager(); + this.manager.createPlaywright(); + final String baseUrl = "https://reqres.in"; + final Map headers = new HashMap<>(); headers.put("content-type", "application/json"); - manager.setApiRequestContext(baseUrl, headers); + this.manager.setApiRequestContext(baseUrl, headers); } @AfterClass public void tearDown() { - manager.disposeAPIRequestContext(); - manager.closePlaywright(); + this.manager.disposeAPIRequestContext(); + this.manager.closePlaywright(); } } diff --git a/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/data/BookingDataBuilder.java b/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/data/BookingDataBuilder.java index c958b98..b5fc113 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/data/BookingDataBuilder.java +++ b/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/data/BookingDataBuilder.java @@ -1,20 +1,20 @@ package io.github.mfaisalkhatri.api.restfulbooker.data; +import net.datafaker.Faker; + import java.text.SimpleDateFormat; import java.util.concurrent.TimeUnit; -import net.datafaker.Faker; - /** * @author Faisal Khatri * @since 2/28/2023 **/ -public class BookingDataBuilder { +public final class BookingDataBuilder { private static final Faker FAKER = new Faker(); public static BookingData getBookingData() { - SimpleDateFormat formatter = new SimpleDateFormat("YYYY-MM-dd"); + final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); return BookingData.builder() .firstname(FAKER.name() .firstName()) diff --git a/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/data/TokenBuilder.java b/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/data/TokenBuilder.java index d8e9e1f..2d94b6a 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/data/TokenBuilder.java +++ b/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/data/TokenBuilder.java @@ -4,7 +4,7 @@ * @author Faisal Khatri * @since 2/28/2023 **/ -public class TokenBuilder { +public final class TokenBuilder { public static Tokencreds getToken() { return Tokencreds.builder() diff --git a/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/tests/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/tests/BaseTest.java index 42678da..1ab1fd0 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/tests/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/tests/BaseTest.java @@ -17,18 +17,18 @@ public class BaseTest { @BeforeTest public void setupBase() { - manager = new RequestManager(); - manager.createPlaywright(); + this.manager = new RequestManager(); + this.manager.createPlaywright(); final String baseUrl = "http://localhost:3001"; - Map headers = new HashMap<>(); + final Map headers = new HashMap<>(); headers.put("content-type", "application/json"); headers.put("Accept", "application/json"); - manager.setApiRequestContext(baseUrl, headers); + this.manager.setApiRequestContext(baseUrl, headers); } @AfterTest public void tearDown() { - manager.disposeAPIRequestContext(); - manager.closePlaywright(); + this.manager.disposeAPIRequestContext(); + this.manager.closePlaywright(); } } diff --git a/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/tests/RestfulBookerEndToEndTests.java b/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/tests/RestfulBookerEndToEndTests.java index 16e3ceb..90accb1 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/tests/RestfulBookerEndToEndTests.java +++ b/src/test/java/io/github/mfaisalkhatri/api/restfulbooker/tests/RestfulBookerEndToEndTests.java @@ -1,11 +1,5 @@ package io.github.mfaisalkhatri.api.restfulbooker.tests; -import static io.github.mfaisalkhatri.api.restfulbooker.data.BookingDataBuilder.getBookingData; -import static io.github.mfaisalkhatri.api.restfulbooker.data.BookingDataBuilder.getPartialBookingData; -import static io.github.mfaisalkhatri.api.restfulbooker.data.TokenBuilder.getToken; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - import com.microsoft.playwright.APIResponse; import com.microsoft.playwright.options.RequestOptions; import io.github.mfaisalkhatri.api.restfulbooker.data.BookingData; @@ -15,6 +9,12 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import static io.github.mfaisalkhatri.api.restfulbooker.data.BookingDataBuilder.getBookingData; +import static io.github.mfaisalkhatri.api.restfulbooker.data.BookingDataBuilder.getPartialBookingData; +import static io.github.mfaisalkhatri.api.restfulbooker.data.TokenBuilder.getToken; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + /** * @author Faisal Khatri * @since 2/28/2023 @@ -27,50 +27,50 @@ public class RestfulBookerEndToEndTests extends BaseTest { @BeforeClass public void setupTest() { - bookingData = getBookingData(); + this.bookingData = getBookingData(); } @Test public void createBookingTest() { - APIResponse response = manager.postRequest("/booking", RequestOptions.create() - .setData(bookingData)); + final APIResponse response = this.manager.postRequest("/booking", RequestOptions.create() + .setData(this.bookingData)); assertEquals(response.status(), 200); - JSONObject responseObject = new JSONObject(response.text()); + final JSONObject responseObject = new JSONObject(response.text()); assertNotNull(responseObject.get("bookingid")); - JSONObject bookingObject = responseObject.getJSONObject("booking"); - JSONObject bookingDatesObject = bookingObject.getJSONObject("bookingdates"); - assertEquals(bookingData.getFirstname(), bookingObject.get("firstname")); - assertEquals(bookingData.getBookingdates() + final JSONObject bookingObject = responseObject.getJSONObject("booking"); + final JSONObject bookingDatesObject = bookingObject.getJSONObject("bookingdates"); + assertEquals(this.bookingData.getFirstname(), bookingObject.get("firstname")); + assertEquals(this.bookingData.getBookingdates() .getCheckin(), bookingDatesObject.get("checkin")); - bookingId = responseObject.getInt("bookingid"); + this.bookingId = responseObject.getInt("bookingid"); } @Test public void getBookingTest() { - APIResponse response = manager.getRequest("/booking/" + bookingId); + final APIResponse response = this.manager.getRequest("/booking/" + this.bookingId); assertEquals(response.status(), 200); - JSONObject responseObject = new JSONObject(response.text()); - JSONObject bookingDatesObject = responseObject.getJSONObject("bookingdates"); + final JSONObject responseObject = new JSONObject(response.text()); + final JSONObject bookingDatesObject = responseObject.getJSONObject("bookingdates"); - assertEquals(bookingData.getFirstname(), responseObject.get("firstname")); - assertEquals(bookingData.getBookingdates() + assertEquals(this.bookingData.getFirstname(), responseObject.get("firstname")); + assertEquals(this.bookingData.getBookingdates() .getCheckin(), bookingDatesObject.get("checkin")); } @Test public void updateBookingTest() { - BookingData updateBookingData = getBookingData(); - APIResponse response = manager.putRequest("/booking/" + bookingId, RequestOptions.create() + final BookingData updateBookingData = getBookingData(); + final APIResponse response = this.manager.putRequest("/booking/" + this.bookingId, RequestOptions.create() .setData(updateBookingData) - .setHeader("Cookie", "token=" + token)); + .setHeader("Cookie", "token=" + this.token)); assertEquals(response.status(), 200); - JSONObject responseObject = new JSONObject(response.text()); - JSONObject bookingDatesObject = responseObject.getJSONObject("bookingdates"); + final JSONObject responseObject = new JSONObject(response.text()); + final JSONObject bookingDatesObject = responseObject.getJSONObject("bookingdates"); assertEquals(updateBookingData.getFirstname(), responseObject.get("firstname")); assertEquals(updateBookingData.getBookingdates() @@ -79,28 +79,28 @@ public void updateBookingTest() { @Test public void generateTokenTest() { - Tokencreds tokenData = getToken(); - APIResponse response = manager.postRequest("/auth", RequestOptions.create() + final Tokencreds tokenData = getToken(); + final APIResponse response = this.manager.postRequest("/auth", RequestOptions.create() .setData(tokenData)); assertEquals(response.status(), 200); - JSONObject responseObject = new JSONObject(response.text()); - String tokenValue = responseObject.getString("token"); + final JSONObject responseObject = new JSONObject(response.text()); + final String tokenValue = responseObject.getString("token"); assertNotNull(tokenValue); - token = tokenValue; + this.token = tokenValue; } @Test public void updatePartialBookingTest() { - PartialBookingData partialBookingData = getPartialBookingData(); + final PartialBookingData partialBookingData = getPartialBookingData(); - APIResponse response = manager.patchRequest("/booking/" + bookingId, RequestOptions.create() + final APIResponse response = this.manager.patchRequest("/booking/" + this.bookingId, RequestOptions.create() .setData(partialBookingData) - .setHeader("Cookie", "token=" + token)); + .setHeader("Cookie", "token=" + this.token)); assertEquals(response.status(), 200); - JSONObject responseObject = new JSONObject(response.text()); + final JSONObject responseObject = new JSONObject(response.text()); assertEquals(partialBookingData.getFirstname(), responseObject.get("firstname")); assertEquals(partialBookingData.getTotalprice(), responseObject.get("totalprice")); @@ -108,15 +108,15 @@ public void updatePartialBookingTest() { @Test public void deleteBookingTest() { - APIResponse response = manager.deleteRequest("/booking/" + bookingId, RequestOptions.create() - .setHeader("Cookie", "token=" + token)); + final APIResponse response = this.manager.deleteRequest("/booking/" + this.bookingId, RequestOptions.create() + .setHeader("Cookie", "token=" + this.token)); assertEquals(response.status(), 201); } @Test public void testBookingDeleted() { - APIResponse response = manager.getRequest("/booking/" + bookingId); + final APIResponse response = this.manager.getRequest("/booking/" + this.bookingId); assertEquals(response.status(), 404); } }