Simpl 10952 test architecture + code formatter
Changes Summary - details below
-
big-onetouches almost all files with adding the formatter as requested by the coding guidelines - introduction of a BaseTest class to reduce complexity and increase maintainability
- prep for keycloak OAuth
- adding ServiceRegistry
ServiceRegistry
- Abstraction Layer: ServiceRegistry acts as an abstraction layer over the ConfigProvider, hiding the direct interaction with raw configuration data and providing a more domain-specific interface for service-related operations.
- Service-Oriented Organization: While ConfigProvider is a general configuration repository, ServiceRegistry specifically organizes and manages service configurations, making it easier to work with service-specific settings.
Centralized Service Access: As noted in its JavaDoc comment, ServiceRegistry "provides centralized access to service configurations" and "replaces the need for each test class to implement ServiceNameProvider." This centralizes service configuration logic in one place.
Filtering and Processing: ServiceRegistry filters out non-service entries (like "DEV_ENV_PARAMS" and "INT_ENV_PARAMS") and only registers valid service configurations, providing cleaner access to just service-related data.
Package-Based Service Discovery: The getServiceConfigForClass() method enables discovering the appropriate service configuration based on a class name, which is particularly useful in a test framework where you might need to determine which service a test class belongs to.
Lazy Loading of Base URIs: The ServiceConfig inner class implements lazy loading of base URIs, only retrieving them from ConfigProvider when needed.
Encapsulation: The ServiceConfig inner class encapsulates service-specific information (name, package, URI) in a cohesive object, rather than requiring consumers to work with separate maps as in ConfigProvider.
Reduced Dependency: Test classes can depend on ServiceRegistry without needing to know about the underlying ConfigProvider implementation details.
In summary, ServiceRegistry implements the Repository pattern on top of ConfigProvider, providing a more specialized, service-oriented interface that simplifies service configuration access for test classes and other components in the framework.
ConfigProvider:
- Singleton pattern implementation that loads configuration from a YAML file
- Provides access to various configuration settings like test classes, base URIs, packages, etc.
- Manages environment-specific parameters (DEV, INT)
- Primarily focused on raw configuration data access
ServiceRegistry:
- Also uses a Singleton pattern
- Uses ConfigProvider internally
- Creates a mapping of service configurations
- Provides methods to look up service configurations by name or by class
- Includes a ServiceConfig inner class that encapsulates service-specific information
Here’s a summary highlighting why this BaseTest.java is a top-notch approach for REST Assured testing:
Why This BaseTest.java is a Top-Notch Approach for REST Assured Testing
1. Code Reusability & Maintainability
statusCode validation, headers, request initialization) are centralized in BaseTest.java, reducing repetition in test classes.
verifyResponseContainsField() in one place.
2. Clean Test Design with Separation of Concerns
SearchTest.java, etc.) only contain the specific test logic, while BaseTest.java abstracts generic API interactions.
BaseTest.java uses an ApiClient that manages API requests, headers, and authentication. This ensures consistency and avoids hardcoded API details in test cases.
3. Robust Response Validation
verifySuccessResponse() and verifyErrorResponse() ensure uniform response validation across all tests.
verifyResponseContainsField(String field) allows easy validation of response content without repeating assertions in every test.
validateResponseSchema(String schemaFile) enforces standardized response structures, ensuring backward compatibility and API contract integrity.
4. Structured Request Handling
addHeader(), addQueryParam(), and addPathParam() provide a clean way to modify API requests dynamically.
initializeRequestSpecification() resets the API client’s request configuration before every test, preventing unintended state carryover.
5. Advanced Error Handling & Logging
handleTestFailure(String testName, AssertionError e) ensures errors are logged consistently before being rethrown, aiding debugging.
Why This Approach is Ideal for REST Assured Testing
rest
+---------------------------+
| BaseTest | (Superclass)
+---------------------------+
| - requestSpec |
| - response |
| + get() |
| + post() |
| + addHeader() |
| + verifySuccessResponse() |
| + handleTestFailure() |
+---------------------------+
▲
│
│ (inherits)
│
+---------------------------+
| SearchTest | (Subclass)
+---------------------------+
| + testAdvancedSearch() |
| + testQuickSearch() |
+---------------------------+