api-automation-framework

API Reference

This document provides a comprehensive reference for all classes, methods, and annotations available in the current API Automation Framework.

Note: For future enhancements and roadmap, see Framework Analysis & Enhancement Roadmap and Technical Enhancements Guide.

Table of Contents

  1. Configuration Classes
  2. API Classes
  3. Request Management
  4. Validation Classes
  5. Annotations
  6. DTOs
  7. Exceptions
  8. Utilities

Configuration Classes

AppConfig

Package: org.aditi.api_automation.config

Singleton class that provides access to the configuration factory.

Methods

public static ConfigFactory getConfig()

Returns an instance of the configuration factory.

Returns: ConfigFactory - The configuration factory instance

Example:

ConfigFactory config = AppConfig.getConfig();
String baseUrl = config.getBaseUrl();

ConfigFactory

Package: org.aditi.api_automation.config

Interface defining configuration properties and methods for retrieving them.

Methods

String getProperty(String key)

Retrieves a configuration property by its key.

Parameters:

Returns: String - The property value

Example:

String value = config.getProperty("CUSTOM_PROPERTY");

Annotated Methods

@ConfigProperty("BASE_URL")
String getBaseUrl()

@ConfigProperty("BASE_API_PATH")
String getBaseApiPath()

@ConfigProperty("REQRES_BASE_URL")
String getReqResBaseUrl()

@ConfigProperty("REQRES_BASE_API_PATH")
String getReqResBaseApiPath()

@ConfigProperty("REGISTER_PATH")
String getRegistrationPath()

@ConfigProperty("LOGIN_PATH")
String getLoginPath()

@ConfigProperty("LOGOUT_PATH")
String getLogoutPath()

CustomConfigManager

Package: org.aditi.api_automation.config

Singleton class for loading and managing configuration properties.

Methods

public static CustomConfigManager getInstance()

Returns the singleton instance of CustomConfigManager.

Returns: CustomConfigManager - The singleton instance

public static String getProperty(String key)

Retrieves a property value by key.

Parameters:

Returns: String - The property value, or null if not found

API Classes

User

Package: org.aditi.api_automation.api

Example API class demonstrating user-related API operations.

Methods

public static Response userLogin(UserLoginRequest userLoginRequest)

Performs user login operation.

Parameters:

Returns: Response - The REST Assured response

Example:

UserLoginRequest request = new UserLoginRequest("username", "password");
Response response = User.userLogin(request);

Request Management

RequestFactory

Package: org.aditi.api_automation.requests

Interface for creating request specifications using JSON templates.

Methods

@RequestTemplateFile("requests/login.json")
RequestSpecBuilder loginRequest(String username, String password)

Creates a login request specification using the login.json template.

Parameters:

Returns: RequestSpecBuilder - The REST Assured request specification builder

Example:

RequestSpecBuilder spec = requestFactory.loginRequest("user", "pass");

AppRequests

Package: org.aditi.api_automation.requests

Utility class for accessing the request factory.

Methods

public static RequestFactory getRequestFactory()

Returns the request factory instance.

Returns: RequestFactory - The request factory instance

Example:

RequestFactory factory = AppRequests.getRequestFactory();

Validation Classes

ValidateResponse

Package: org.aditi.api_automation.asserts

Abstract base class for response validation with fluent API.

Methods

public SELF_TYPE httpStatusCodeIs(int statusCode)

Validates that the response has the specified HTTP status code.

Parameters:

Returns: SELF_TYPE - Self reference for method chaining

Example:

ValidateGenericResponse.assertThat(response)
    .httpStatusCodeIs(200);
public SELF_TYPE containsValue(String value)

Validates that the response body contains the specified value.

Parameters:

Returns: SELF_TYPE - Self reference for method chaining

Example:

ValidateGenericResponse.assertThat(response)
    .containsValue("success");
public SELF_TYPE matchesSchema(String fileClassPath)

Validates that the response matches the specified JSON schema.

Parameters:

Returns: SELF_TYPE - Self reference for method chaining

Example:

ValidateGenericResponse.assertThat(response)
    .matchesSchema("response/schemas/user-schema.json");
public SELF_TYPE validateJsonPathData(String jsonPath, Object expectedValue)

Validates that the JSON path expression returns the expected value.

Parameters:

Returns: SELF_TYPE - Self reference for method chaining

Example:

ValidateGenericResponse.assertThat(response)
    .validateJsonPathData("data.id", 1)
    .validateJsonPathData("data.name", "John Doe");
public void assertAll()

Executes all soft assertions and reports any failures.

Example:

ValidateGenericResponse.assertThat(response)
    .httpStatusCodeIs(200)
    .containsValue("success")
    .assertAll();

ValidateGenericResponse

Package: org.aditi.api_automation.asserts

Concrete implementation of ValidateResponse for generic response validation.

Methods

public static ValidateGenericResponse assertThat(Response response)

Creates a new ValidateGenericResponse instance for the given response.

Parameters:

Returns: ValidateGenericResponse - A new validation instance

Example:

ValidateGenericResponse.assertThat(response)
    .httpStatusCodeIs(200)
    .containsValue("success");

Annotations

@ConfigProperty

Package: org.aditi.api_automation.annotations

Annotation for marking configuration property methods.

Usage

@ConfigProperty("PROPERTY_KEY")
String getPropertyMethod();

Parameters:

Example:

@ConfigProperty("BASE_URL")
String getBaseUrl();

@RequestTemplateFile

Package: org.aditi.api_automation.annotations

Annotation for marking request template methods.

Usage

@RequestTemplateFile("requests/template.json")
RequestSpecBuilder methodName();

Parameters:

Example:

@RequestTemplateFile("requests/login.json")
RequestSpecBuilder loginRequest(String username, String password);

DTOs

UserLoginRequest

Package: org.aditi.api_automation.dto

Data transfer object for user login requests.

Fields

Constructors

public UserLoginRequest()

Default constructor.

public UserLoginRequest(String username, String password)

Parameterized constructor.

Parameters:

Methods

public String getUsername()

Gets the username.

Returns: String - The username

public void setUsername(String username)

Sets the username.

Parameters:

public String getPassword()

Gets the password.

Returns: String - The password

public void setPassword(String password)

Sets the password.

Parameters:

Example:

UserLoginRequest request = new UserLoginRequest("john.doe", "password123");

Exceptions

PropertyNotFoundException

Package: org.aditi.api_automation.exception

Exception thrown when a configuration property is not found.

Constructors

public PropertyNotFoundException(String message)

Creates a new PropertyNotFoundException with the specified message.

Parameters:

Example:

throw new PropertyNotFoundException("Property not found for key: " + key);

Utilities

ConfigFactoryProxy

Package: org.aditi.api_automation.handlers

Dynamic proxy implementation for the ConfigFactory interface.

Methods

public static ConfigFactory newInstance(CustomConfigManager configManager)

Creates a new ConfigFactory proxy instance.

Parameters:

Returns: ConfigFactory - A new proxy instance

Example:

ConfigFactory proxy = ConfigFactoryProxy.newInstance(configManager);

RequestFactoryInvocationHandler

Package: org.aditi.api_automation.handlers

Invocation handler for RequestFactory dynamic proxy.

Methods

public static RequestFactory newInstance()

Creates a new RequestFactory proxy instance.

Returns: RequestFactory - A new proxy instance

Example:

RequestFactory factory = RequestFactoryInvocationHandler.newInstance();

Constants

FrameworkConstants

Package: org.aditi.api_automation.constants

Constants used throughout the framework.

Fields

public static final String CONFIG_FILE_NAME = "config.properties"

The default configuration file name.

public static final String ENVIRONMENT_PROPERTY = "faasos_env"

The system property for specifying the environment.

public static final String DEFAULT_ENVIRONMENT = "dev"

The default environment if none is specified.

Quick Examples

Complete API Test Example

package org.aditi.api_automation.steps;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.restassured.response.Response;
import org.aditi.api_automation.api.User;
import org.aditi.api_automation.asserts.ValidateGenericResponse;
import org.aditi.api_automation.dto.UserLoginRequest;

public class UserSteps {
    
    private Response response;
    private UserLoginRequest loginRequest;
    
    @Given("I have valid user credentials")
    public void i_have_valid_user_credentials() {
        loginRequest = new UserLoginRequest("testuser", "testpass");
    }
    
    @When("I attempt to login")
    public void i_attempt_to_login() {
        response = User.userLogin(loginRequest);
    }
    
    @Then("I should receive a successful login response")
    public void i_should_receive_a_successful_login_response() {
        ValidateGenericResponse.assertThat(response)
            .httpStatusCodeIs(200)
            .matchesSchema("response/schemas/login-schema.json")
            .validateJsonPathData("token", "QpwL5tke4Pnpja7X4")
            .containsValue("success");
    }
}

Configuration Example

// ConfigFactory.java
@ConfigProperty("API_BASE_URL")
String getApiBaseUrl();

@ConfigProperty("AUTH_TOKEN")
String getAuthToken();

// api.properties
API_BASE_URL=https://api.example.com
AUTH_TOKEN=your-auth-token

// Usage
String baseUrl = AppConfig.getConfig().getApiBaseUrl();
String token = AppConfig.getConfig().getAuthToken();

Request Template Example

// RequestFactory.java
@RequestTemplateFile("requests/user-create.json")
RequestSpecBuilder createUserRequest(String name, String email);

// requests/user-create.json
{
  "headers": {
    "Content-Type": "application/json",
    "Authorization": "Bearer "
  },
  "body": {
    "name": "",
    "email": ""
  }
}

// Usage
RequestSpecBuilder spec = AppRequests.getRequestFactory()
    .createUserRequest("John Doe", "john@example.com");

This API reference provides comprehensive information about all the classes, methods, and annotations available in the current framework. For future enhancements and roadmap, refer to the Framework Analysis and Technical Enhancements documents.