Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
99 changes: 97 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,97 @@
# api-automation
A template to start api automation
# API Automation Framework

A Maven-based Java framework for REST API automation and testing using RestAssured and TestNG.

## Project Structure

```
api-automation/
├── src/
│ ├── main/
│ │ ├── java/com/backend/
│ │ │ ├── apis/ # API test classes (e.g., GenderAPIs)
│ │ │ ├── helpers/ # Helper classes
│ │ │ │ ├── endpoints/ # Service and endpoint configurations
│ │ │ │ ├── common/ # Common utilities
│ │ │ │ ├── restassured/ # Rest client implementations
│ │ │ ├── pojo/ # Response models
│ │ │ └── utils/ # Utility classes
│ │ └── resources/ # Configuration files (log4j2.xml)
│ └── test/
│ └── java/ # Test cases (e.g., SampleTest)
├── src/test/resources/ # Test resources
├── Jenkinsfile # CI/CD pipeline configuration
├── pom.xml # Maven project configuration
├── README.md # This file
├── checkstyle.xml # Code style configuration
├── File.checkstyle # Checkstyle filter configuration
├── testNGsuite/ # TestNG suite configurations
└── .github/workflows/ # GitHub Actions workflows
```

## Technologies Used

- **Java 8** - Core programming language
- **Maven** - Build automation and dependency management
- **RestAssured** - REST API testing library
- **TestNG** - Testing framework
- **Lombok** - Reduce boilerplate code
- **Log4j2** - Logging framework
- **Test Results (Tesults)** - Test result reporting
- **Checkstyle** - Code quality enforcement

## Key Dependencies

| Dependency | Version | Purpose |
|------------|---------|-----|----|
| rest-assured | 4.3.1 | REST API testing |
| testng | 7.7.0 | Test execution framework |
| lombok | 1.18.34 | Annotation processing |
| log4j-api | 2.20.0 | Logging API |
| jackson-databind | 2.12.7.1 | JSON processing |
| groovy-all | 2.4.21 | Groovy scripting support |

## Setup Instructions

### Prerequisites
- JDK 1.8 or higher
- Maven 3.x

### Build the Project
```bash
mvn clean compile
```

### Run Tests
```bash
mvn clean test
```

### Run Specific Test Suite
```bash
mvn test -DsuiteXmlFile=testNGsuite/sample.xml
```

## How to Add New API Tests

1. Create a new test class under `src/main/java/com/backend/apis/`
2. Implement API test logic using `GenderAPIs` pattern
3. Create corresponding request models under `src/main/java/com/backend/pojo/`
4. Add configuration endpoints under `src/main/java/com/backend/helpers/endpoints/`

## Code Style

This project uses Checkstyle for code quality. Configuration is in `checkstyle.xml`.

## CI/CD Integration

- **Jenkinsfile** - Jenkins build pipeline
- **GitHub Actions** - Automated CI/CD in `.github/workflows/maven.yml`

## Logging Configuration

Logging is configured via `src/main/resources/log4j2.xml`. Customize log levels and appenders as needed.

## License

This project is a template for API automation projects.
140 changes: 0 additions & 140 deletions src/main/java/com/backend/apis/Abc.java

This file was deleted.

28 changes: 0 additions & 28 deletions src/main/java/com/backend/apis/DataUSA.java

This file was deleted.

20 changes: 8 additions & 12 deletions src/main/java/com/backend/apis/GenderAPIs.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
package com.backend.apis;

import com.backend.helpers.restassured.RequestType;
import io.restassured.builder.RequestSpecBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.backend.helpers.common.StatusCode;
import com.backend.helpers.endpoints.Service;
import com.backend.helpers.restassured.RestClient;
import com.backend.pojo.GenderApiResponse;
import lombok.extern.log4j.Log4j2;



import static com.backend.helpers.restassured.RequestType.GET;

@Log4j2
public class GenderAPIs {

private static final Logger log = LogManager.getLogger(GenderAPIs.class);

final RestClient restClient = new RestClient();

public GenderApiResponse getGenderByName(final String name, final StatusCode statusCode) {

log.info(String.format("sending request with name as : %s", name));
final RequestSpecBuilder request = new RequestSpecBuilder().setBaseUri(Service.GENDER.getService()).addQueryParam("name", name);
log.info("Sending request with name as : {}", name);
final RequestSpecBuilder request = new RequestSpecBuilder()
.setBaseUri(Service.GENDER.getService())
.addQueryParam("name", name);
// if you have headers
//.addHeaders(Util.getHeaders());

return restClient.getResponse(GET, request.build(), GenderApiResponse.class, statusCode.getCode());
return restClient.getResponse(RequestType.GET, request.build(), statusCode.getCode()).as(GenderApiResponse.class);
}
}
20 changes: 0 additions & 20 deletions src/main/java/com/backend/apis/Xyz.java

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/java/com/backend/helpers/common/APIToken.java

This file was deleted.

13 changes: 5 additions & 8 deletions src/main/java/com/backend/helpers/endpoints/Endpoints.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.backend.helpers.endpoints;

import lombok.AllArgsConstructor;
import lombok.Getter;

public final class Endpoints {

@AllArgsConstructor
@Getter
public enum DataUSA {

data("/api/data");

private final String uri;

DataUSA(String name) {
this.uri = name;
}

public String getService() {
return uri;
}
}

}
13 changes: 5 additions & 8 deletions src/main/java/com/backend/helpers/endpoints/Service.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.backend.helpers.endpoints;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum Service {

GENDER("https://api.genderize.io/"),
DATA_USA("https://datausa.io/");

private final String service;

Service(String name) {
this.service = name;
}

public String getService() {
return service;
}
}
Loading
Loading