Skip to content

Commit c4e1e07

Browse files
committed
Updated tests and README.md
1 parent eb5dba6 commit c4e1e07

33 files changed

+403
-371
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ src/
5555
│ │ │ └── TestCategory.java
5656
│ │ ├── AuthTest.java # Authentication tests
5757
│ │ ├── BaseTest.java # Base test class setup
58-
│ │ ├── CreateUserTest.java # API test for creating a user
59-
│ │ ├── DeleteUserTest.java # API test for deleting a user
60-
│ │ ├── GetAllUsersTest.java # API test for fetching all users
61-
│ │ └── UpdateUserTest.java # API test for updating a user
58+
│ │ ├── CreateBookingTest.java # API test for creating a booking
59+
│ │ ├── DeleteBookingTest.java # API test for deleting a booking
60+
│ │ ├── GetAllBookingsTest.java # API test for fetching all bookings
61+
│ │ └── UpdateBookingTest.java # API test for updating a booking
6262
│ └── resources/
6363
│ └── env/ # Environment configurations
6464
│ ├── dev.properties
@@ -75,6 +75,11 @@ pom.xml # Maven configuration
7575
README.md # Repository overview and instructions (This file)
7676
```
7777

78+
## ⚠️ Important: Steps to update the APIs
79+
* Go to `com.restassured.example.util.RestClient`
80+
* **Uncomment line 131** to enable your actual API functionality.
81+
* Remove the **"TODO: "** comment, as it is no longer relevant
82+
7883
## How to run tests
7984
1. Using IntelliJ IDEA
8085
* Go to Maven Profiles

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<rest.assured.version>5.5.0</rest.assured.version>
1818
<testng.version>7.10.2</testng.version>
1919
<mockneat.version>0.4.8</mockneat.version>
20-
<json.version>20240303</json.version>
20+
<jackson-databind>2.17.2</jackson-databind>
2121
<extent.report.version>5.1.2</extent.report.version>
2222
<log4j.api.version>2.24.0</log4j.api.version>
2323
<log4j.core.version>2.24.0</log4j.core.version>
@@ -164,9 +164,9 @@
164164
<version>${mockneat.version}</version>
165165
</dependency>
166166
<dependency>
167-
<groupId>org.json</groupId>
168-
<artifactId>json</artifactId>
169-
<version>${json.version}</version>
167+
<groupId>com.fasterxml.jackson.core</groupId>
168+
<artifactId>jackson-databind</artifactId>
169+
<version>${jackson-databind}</version>
170170
</dependency>
171171
<dependency>
172172
<groupId>com.aventstack</groupId>

src/main/java/com/restassured/example/constant/ApplicationConstant.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
public class ApplicationConstant {
66
// Base URLs
7-
public static final String AUTH_SERVICE_BASE_URL = getEnvironmentConfig("auth_service_base_url");
8-
public static final String GO_REST_SERVICE_BASE_URL = getEnvironmentConfig("go_rest_service_base_url");
7+
public static final String RESTFUL_BOOKER_BASE_URL = getEnvironmentConfig("restful_booker_base_url");
98

109
// API Endpoints
1110
public static final String AUTH_SERVICE_ENDPOINT = "/auth";
12-
public static final String USER_SERVICE_ENDPOINT = "/public-api/users";
11+
public static final String BOOKING_SERVICE_ENDPOINT = "/booking";
1312

1413
// Headers
15-
public static final String AUTH_HEADER_NAME = "Authorization";
16-
public static final String AUTH_TOKEN_PREFIX = "Bearer ";
14+
public static final String AUTH_HEADER_NAME = "Cookie";
15+
public static final String AUTH_TOKEN_PREFIX = "token=";
1716
}

src/main/java/com/restassured/example/constant/AuthenticationConstant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import static com.restassured.example.util.FileReader.getEnvironmentConfig;
44

55
public class AuthenticationConstant {
6-
public static final String EMAIL = getEnvironmentConfig("email_address");
6+
public static final String USERNAME = getEnvironmentConfig("username");
77
public static final String PASSWORD = getEnvironmentConfig("password");
88
}

src/main/java/com/restassured/example/constant/ReporterConstant.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
33
import com.restassured.example.util.FileReader;
44

55
import java.io.File;
6+
import java.nio.file.Path;
7+
import java.nio.file.Paths;
68

79
public class ReporterConstant {
810
public static final String FILE_SEPARATOR = File.separator;
911
public static final String PROJECT_DIRECTORY = System.getProperty("user.dir");
10-
public static final String TEST_REPORTER_PROPERTY_FILE_DIRECTORY = PROJECT_DIRECTORY + FILE_SEPARATOR
11-
+ "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "resources" + FILE_SEPARATOR
12-
+ "test-reporter.properties";
13-
public static final String EXTENT_FULL_REPORT_DIRECTORY = FileReader.getTestReporterProperty("extent_full_report_dir");
14-
public static final String EXTENT_REPORT_FILE_NAME_PREFIX = FileReader.getTestReporterProperty("extent_report_file_name_prefix");
15-
public static final String EXTENT_REPORT_THEME = FileReader.getTestReporterProperty("extent_reporter_theme");
16-
public static final String EXTENT_REPORT_DOCUMENT_TITLE = FileReader.getTestReporterProperty("extent_document_title");
17-
public static final String EXTENT_REPORT_REPORTER_NAME = FileReader.getTestReporterProperty("extent_reporter_name");
18-
public static final String APPLICATION_NAME = FileReader.getTestReporterProperty("application_name");
19-
public static final String TEST_DEVELOPER = FileReader.getTestReporterProperty("test_developer");
12+
public static final Path TEST_REPORTER_PROPERTY_FILE_DIRECTORY
13+
= Paths.get(PROJECT_DIRECTORY, "src", "main", "resources", "test-reporter.properties");
14+
public static final String EXTENT_FULL_REPORT_DIRECTORY
15+
= FileReader.getTestReporterProperty("extent_full_report_dir");
16+
public static final String EXTENT_REPORT_FILE_NAME_PREFIX
17+
= FileReader.getTestReporterProperty("extent_report_file_name_prefix");
18+
public static final String EXTENT_REPORT_THEME
19+
= FileReader.getTestReporterProperty("extent_reporter_theme");
20+
public static final String EXTENT_REPORT_DOCUMENT_TITLE
21+
= FileReader.getTestReporterProperty("extent_document_title");
22+
public static final String EXTENT_REPORT_REPORTER_NAME
23+
= FileReader.getTestReporterProperty("extent_reporter_name");
24+
public static final String APPLICATION_NAME
25+
= FileReader.getTestReporterProperty("application_name");
26+
public static final String TEST_DEVELOPER
27+
= FileReader.getTestReporterProperty("test_developer");
2028
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.restassured.example.model;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Getter
7+
@Setter
8+
public class AuthenticationRequest {
9+
private String username;
10+
private String password;
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.restassured.example.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
7+
@Getter
8+
@Setter
9+
public class BookingDates {
10+
11+
@JsonProperty("checkin")
12+
private String checkIn;
13+
14+
@JsonProperty("checkout")
15+
private String checkOut;
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.restassured.example.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
7+
@Getter
8+
@Setter
9+
public class BookingRequest {
10+
@JsonProperty("firstname")
11+
private String firstName;
12+
13+
@JsonProperty("lastname")
14+
private String lastName;
15+
16+
@JsonProperty("totalprice")
17+
private int totalPrice;
18+
19+
@JsonProperty("depositpaid")
20+
private boolean depositPaid;
21+
22+
@JsonProperty("bookingdates")
23+
private BookingDates bookingDates;
24+
25+
@JsonProperty("additionalneeds")
26+
private String additionalNeeds;
27+
}

src/main/java/com/restassured/example/service/app/AuthenticationService.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
package com.restassured.example.service.app;
22

3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.restassured.example.model.AuthenticationRequest;
36
import com.restassured.example.util.RestClient;
4-
import org.json.JSONObject;
57

68
import java.util.Collections;
79
import java.util.Map;
810

911
import static com.restassured.example.HttpMethod.POST;
1012
import static com.restassured.example.constant.ApplicationConstant.*;
11-
import static com.restassured.example.constant.AuthenticationConstant.EMAIL;
1213
import static com.restassured.example.constant.AuthenticationConstant.PASSWORD;
14+
import static com.restassured.example.constant.AuthenticationConstant.USERNAME;
1315

1416
public class AuthenticationService {
1517
public static Map<String, String> getAuthenticationHeaders() {
16-
JSONObject authRequestJson = new JSONObject();
17-
authRequestJson.put("email", EMAIL);
18-
authRequestJson.put("password", PASSWORD);
18+
AuthenticationRequest authenticationRequest = new AuthenticationRequest();
19+
authenticationRequest.setUsername(USERNAME);
20+
authenticationRequest.setPassword(PASSWORD);
1921

20-
String token = new RestClient(AUTH_SERVICE_BASE_URL, AUTH_SERVICE_ENDPOINT, authRequestJson.toString())
22+
ObjectMapper objectMapper = new ObjectMapper();
23+
String authRequestJson;
24+
try {
25+
authRequestJson = objectMapper.writeValueAsString(authenticationRequest);
26+
} catch (JsonProcessingException e) {
27+
throw new RuntimeException(e);
28+
}
29+
30+
String token = new RestClient(RESTFUL_BOOKER_BASE_URL, AUTH_SERVICE_ENDPOINT, authRequestJson)
2131
.sendRequest(POST)
2232
.extract()
2333
.body()

src/main/java/com/restassured/example/service/app/UserService.java renamed to src/main/java/com/restassured/example/service/app/BookingService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
import com.restassured.example.util.RestClient;
44

55
import static com.restassured.example.HttpMethod.GET;
6-
import static com.restassured.example.constant.ApplicationConstant.GO_REST_SERVICE_BASE_URL;
7-
import static com.restassured.example.constant.ApplicationConstant.USER_SERVICE_ENDPOINT;
6+
import static com.restassured.example.constant.ApplicationConstant.BOOKING_SERVICE_ENDPOINT;
7+
import static com.restassured.example.constant.ApplicationConstant.RESTFUL_BOOKER_BASE_URL;
88
import static org.apache.commons.lang3.StringUtils.EMPTY;
99
import static org.apache.http.HttpStatus.SC_OK;
1010

11-
public class UserService {
12-
public static String getUserIdFromUserDb() {
13-
return new RestClient(GO_REST_SERVICE_BASE_URL, USER_SERVICE_ENDPOINT, EMPTY)
11+
public class BookingService {
12+
public static String getBookingIdFromBookingDb() {
13+
return new RestClient(RESTFUL_BOOKER_BASE_URL, BOOKING_SERVICE_ENDPOINT, EMPTY)
1414
.sendRequest(GET)
1515
.statusCode(SC_OK)
1616
.extract()
1717
.body()
1818
.jsonPath()
19-
.get("data[0].id")
19+
.get("[0].bookingid")
2020
.toString();
2121
}
2222
}

0 commit comments

Comments
 (0)