Skip to content

Added Happy and Sad Path tests for restful e-commerce APIs #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
7512d25
updated date format in booking data builder
mfaisalkhatri Sep 17, 2024
2533098
added example for post api
mfaisalkhatri Sep 17, 2024
800dc9d
added log4j for logging response details, added helper method to prin…
mfaisalkhatri Sep 18, 2024
c328322
added tests for get all order and get orders using order id, user id …
mfaisalkhatri Sep 18, 2024
4003b6d
added token generation and update order tests, modified the assertion…
mfaisalkhatri Sep 18, 2024
e304f4c
handled blank and empty response body while response log generation a…
mfaisalkhatri Sep 18, 2024
6a90974
updated Helper class name to Logger
mfaisalkhatri Sep 18, 2024
048b4c2
added docker compose file for restful ecommerce, updated testng.xml a…
mfaisalkhatri Sep 18, 2024
11cf04b
updated docker compose to use service-ports
mfaisalkhatri Sep 18, 2024
1e55f0a
updated the baseurl for running tests in github actions
mfaisalkhatri Sep 18, 2024
e3f6632
updated baseurl for ecommerce
mfaisalkhatri Sep 18, 2024
c810c93
updated github actions hosted runner to macos
mfaisalkhatri Sep 18, 2024
92c5f5c
added amd64 docker image and updated yml workflow to use ubuntu latest
mfaisalkhatri Sep 18, 2024
246d6bf
added steps to start docker service for restful ecommerce app
mfaisalkhatri Sep 18, 2024
fb40851
added gson dependency in pom, added sadpathtest class, updated logger…
mfaisalkhatri Sep 21, 2024
1caa00d
updated sad path scenario assertions and corrected spelling mistake i…
mfaisalkhatri Sep 21, 2024
f357975
updated happy and sad path tests
mfaisalkhatri Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
- name: Start restful booker service
run: docker compose -f ./docker-compose-restfulbooker.yml up -d

- name: Start restful ecommerce service
run: docker compose -f ./docker-compose-ecommerce.yml up -d

- name: Build Project
run: mvn clean install -DskipTests

Expand All @@ -46,6 +49,9 @@ jobs:
- name: Stop restful booker service
run: docker compose -f ./docker-compose-restfulbooker.yml down --remove-orphans

- name: Stop restful ecommerce service
run: docker compose -f ./docker-compose-ecommerce.yml down --remove-orphans

- name: Test Reporter
uses: dorny/test-reporter@v1.6.0
if: always()
Expand Down
8 changes: 8 additions & 0 deletions docker-compose-ecommerce.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# To execute this docker-compose yml file use `docker compose -f docker-compose-ecommerce.yml up -d`
# Add the `-d` flag at the end for detached execution
# To stop the execution, hit Ctrl+C, and then `docker compose -f docker-compose-ecommerce.yml down`
services:
restful-ecommerce:
image: mfaisalkhatri/restful-ecommerce-app
ports:
- 3004:3004
26 changes: 25 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<playwright-version>1.45.1</playwright-version>
<playwright-version>1.47.0</playwright-version>
<testng-version>7.10.2</testng-version>
<hamcrest-all-version>1.3</hamcrest-all-version>
<json-simple-version>1.1.1</json-simple-version>
<lombok-version>1.18.34</lombok-version>
<datafaker-version>2.3.1</datafaker-version>
<gson-version>2.11.0</gson-version>
<org-json-verion>20240303</org-json-verion>
<jackson-databind-version>2.17.2</jackson-databind-version>
<log4j-core-version>2.12.4</log4j-core-version>
<log4j-api-version>2.12.4</log4j-api-version>
<maven-compiler-plugin-version>3.13.0</maven-compiler-plugin-version>
<maven-surefire-plugin-version>3.3.1</maven-surefire-plugin-version>
<java-release-version>17</java-release-version>
Expand Down Expand Up @@ -54,6 +58,26 @@
<artifactId>datafaker</artifactId>
<version>${datafaker-version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j-api-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-core-version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand Down
114 changes: 114 additions & 0 deletions public/results/results.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="LogToConsole" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="io.github.mfaisalkhatri" level="info" additivity="false">
<AppenderRef ref="LogToConsole"/>
</Logger>
<Root level="error">
<AppenderRef ref="LogToConsole"/>
</Root>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public final class BookingDataBuilder {
private static final Faker FAKER = new Faker();

public static BookingData getBookingData() {
final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return BookingData.builder()
.firstname(FAKER.name()
.firstName())
Expand All @@ -24,11 +23,10 @@ public static BookingData getBookingData() {
.numberBetween(1, 2000))
.depositpaid(true)
.bookingdates(BookingDates.builder()
.checkin(formatter.format(FAKER.date()
.past(20, TimeUnit.DAYS)))
.checkout(formatter.format(FAKER.date()
.future(5, TimeUnit.DAYS)))
.build())
.checkin(FAKER.timeAndDate()
.past(20, TimeUnit.DAYS,"yyyy-MM-dd"))
.checkout(FAKER.timeAndDate()
.future(5, TimeUnit.DAYS, "yyyy-MM-dd")).build())
.additionalneeds("Breakfast")
.build();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.github.mfaisalkhatri.api.restfulecommerce;

import com.microsoft.playwright.APIRequest;
import com.microsoft.playwright.APIRequestContext;
import com.microsoft.playwright.Playwright;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import java.util.HashMap;
import java.util.Map;

public class BaseTest {

protected Playwright playwright;
protected APIRequestContext request;
private static final String BASE_URL = "http://localhost:3004";

@BeforeClass
public void setup() {
createPlaywright();
createAPIRequestContext();
}

@AfterClass
public void tearDown() {
disposeAPIRequestContext();
closePlaywright();

}

private void createPlaywright() {
playwright = Playwright.create();
}

private void createAPIRequestContext() {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");

request = playwright.request().newContext(new APIRequest.NewContextOptions()
.setBaseURL(BASE_URL)
.setExtraHTTPHeaders(headers));
}


private void closePlaywright() {
if (playwright != null) {
playwright.close();
playwright = null;
}
}

private void disposeAPIRequestContext() {
if (request != null) {
request.dispose();
request = null;
}
}


}
Loading
Loading