Skip to content

Commit 141998a

Browse files
Merge pull request #68 from testomatio/javadoc
Added javadoc and tests for the core module
2 parents 9be3492 + dffe3d0 commit 141998a

37 files changed

+2231
-157
lines changed

java-reporter-core/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@
6767
<artifactId>jackson-databind</artifactId>
6868
<version>${jackson.version}</version>
6969
</dependency>
70+
71+
<!-- Test dependencies -->
72+
<dependency>
73+
<groupId>org.junit.jupiter</groupId>
74+
<artifactId>junit-jupiter</artifactId>
75+
<version>5.10.1</version>
76+
<scope>test</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.mockito</groupId>
80+
<artifactId>mockito-core</artifactId>
81+
<version>5.8.0</version>
82+
<scope>test</scope>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.mockito</groupId>
86+
<artifactId>mockito-junit-jupiter</artifactId>
87+
<version>5.8.0</version>
88+
<scope>test</scope>
89+
</dependency>
7090
</dependencies>
7191

7292
<distributionManagement>
@@ -93,6 +113,18 @@
93113
</configuration>
94114
</plugin>
95115

116+
<plugin>
117+
<groupId>org.apache.maven.plugins</groupId>
118+
<artifactId>maven-surefire-plugin</artifactId>
119+
<version>${maven.surefire.plugin.version}</version>
120+
<configuration>
121+
<includes>
122+
<include>**/*Test.java</include>
123+
<include>**/*Tests.java</include>
124+
</includes>
125+
</configuration>
126+
</plugin>
127+
96128
<plugin>
97129
<groupId>org.apache.maven.plugins</groupId>
98130
<artifactId>maven-jar-plugin</artifactId>

java-reporter-core/src/main/java/io/testomat/core/batch/BatchResultManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* Manages batch processing of test results for efficient API reporting.
2020
* Collects test results in batches and periodically flushes them to Testomat.io.
2121
* Provides automatic retry mechanism and graceful shutdown handling.
22+
*
23+
* <p>Thread-safe for concurrent test execution with configurable batch size and flush intervals.
2224
*/
2325
public class BatchResultManager {
2426

@@ -40,7 +42,6 @@ public class BatchResultManager {
4042
*
4143
* @param apiClient API client for reporting test results
4244
* @param runUid unique identifier of the test run
43-
* @throws NumberFormatException if batch size or flush interval properties are invalid
4445
*/
4546
public BatchResultManager(ApiInterface apiClient, String runUid) {
4647
this.apiClient = apiClient;

java-reporter-core/src/main/java/io/testomat/core/client/ApiInterface.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,46 @@
55
import java.util.List;
66

77
/**
8-
* API interface for interacting with Testomat.io platform.
9-
* Provides methods for test run lifecycle management and result reporting.
8+
* Primary interface for Testomat.io API operations.
9+
* Defines the contract for test run lifecycle management and result reporting.
10+
* Thread-safe implementations should support concurrent test execution scenarios.
1011
*/
1112
public interface ApiInterface {
1213

1314
/**
14-
* Creates new test run.
15+
* Creates a new test run in Testomat.io.
1516
*
16-
* @param title test run title
17-
* @return unique test run identifier
18-
* @throws IOException if API request fails
17+
* @param title descriptive title for the test run
18+
* @return unique test run identifier (UID) for subsequent operations
19+
* @throws IOException if network request fails or API returns error
1920
*/
2021
String createRun(String title) throws IOException;
2122

2223
/**
23-
* Reports single test result.
24+
* Reports a single test result to the specified test run.
2425
*
25-
* @param uid test run identifier
26-
* @param result test result to report
27-
* @throws IOException if API request fails
26+
* @param uid test run identifier from {@link #createRun(String)}
27+
* @param result test execution result with status and metadata
28+
* @throws IOException if network request fails or API returns error
2829
*/
2930
void reportTest(String uid, TestResult result) throws IOException;
3031

3132
/**
32-
* Reports multiple test results in batch.
33+
* Reports multiple test results in a single batch operation.
34+
* More efficient than individual calls for large test suites.
3335
*
34-
* @param uid test run identifier
35-
* @param results test results to report
36-
* @throws IOException if API request fails
36+
* @param uid test run identifier from {@link #createRun(String)}
37+
* @param results collection of test execution results
38+
* @throws IOException if network request fails or API returns error
3739
*/
3840
void reportTests(String uid, List<TestResult> results) throws IOException;
3941

4042
/**
41-
* Marks test run as finished.
43+
* Finalizes the test run and marks it as completed.
4244
*
43-
* @param uid test run identifier
44-
* @param duration test run duration in seconds
45-
* @throws IOException if API request fails
45+
* @param uid test run identifier from {@link #createRun(String)}
46+
* @param duration total test run duration in seconds
47+
* @throws IOException if network request fails or API returns error
4648
*/
4749
void finishTestRun(String uid, float duration) throws IOException;
4850
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package io.testomat.core.client;
22

33
/**
4-
* Factory for creating API client instances.
4+
* Abstract factory for creating {@link ApiInterface} implementations.
5+
* Provides a pluggable mechanism for different API client configurations.
56
*/
67
public interface ClientFactory {
78

89
/**
9-
* Creates configured API client instance.
10+
* Creates a fully configured API client instance.
11+
* Implementation should handle all necessary initialization including
12+
* authentication, HTTP client setup, and request/response handling.
1013
*
11-
* @return API client implementation
14+
* @return ready-to-use API client implementation
1215
*/
1316
ApiInterface createClient();
1417
}

java-reporter-core/src/main/java/io/testomat/core/client/NativeApiClient.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
import static io.testomat.core.constants.CommonConstants.RESPONSE_UID_KEY;
2020

2121
/**
22-
* HTTP client for Testomat.io API operations.
23-
* Handles test run lifecycle and result reporting with proper error handling.
22+
* Default HTTP-based implementation of {@link ApiInterface}.
23+
* Handles test run lifecycle and result reporting with comprehensive error handling
24+
* and automatic URL/request body construction for Testomat.io API endpoints.
2425
*/
2526
public class NativeApiClient implements ApiInterface {
2627
private static final Logger log = LoggerFactory.getLogger(NativeApiClient.class);
@@ -32,11 +33,12 @@ public class NativeApiClient implements ApiInterface {
3233
private final RequestBodyBuilder requestBodyBuilder;
3334

3435
/**
35-
* Creates API client with custom dependencies for testing.
36+
* Creates API client with injectable dependencies.
37+
* Primarily used for testing with mock implementations.
3638
*
37-
* @param apiKey API key for authentication
38-
* @param client HTTP client implementation
39-
* @param requestBodyBuilder request body builder for JSON payloads
39+
* @param apiKey Testomat.io API key for authentication
40+
* @param client HTTP client implementation for network requests
41+
* @param requestBodyBuilder builder for creating JSON request payloads
4042
*/
4143
public NativeApiClient(String apiKey,
4244
CustomHttpClient client,

java-reporter-core/src/main/java/io/testomat/core/client/TestomatClientFactory.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
import org.slf4j.LoggerFactory;
1212

1313
/**
14-
* Singleton factory for creating Testomat.io API client instances.
15-
* Loads API key from properties and creates configured client.
14+
* Default implementation of {@link ClientFactory} for Testomat.io API clients.
15+
* Singleton factory that loads API key from properties and creates production-ready
16+
* clients with native HTTP implementation and standard request builders.
1617
*/
1718
public class TestomatClientFactory implements ClientFactory {
1819
private static final PropertyProvider propertyProvider =
@@ -24,9 +25,10 @@ private TestomatClientFactory() {
2425
}
2526

2627
/**
27-
* Returns singleton factory instance.
28+
* Returns the singleton factory instance.
29+
* Thread-safe lazy initialization of factory.
2830
*
29-
* @return ClientFactory instance
31+
* @return configured ClientFactory instance
3032
*/
3133
public static ClientFactory getClientFactory() {
3234
if (instance == null) {

java-reporter-core/src/main/java/io/testomat/core/client/http/CustomHttpClient.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,32 @@
33
import java.io.IOException;
44

55
/**
6-
* HTTP client abstraction for making API requests.
6+
* HTTP client abstraction for Testomat.io API communication.
7+
* Provides type-safe request/response handling with JSON serialization support.
78
*/
89
public interface CustomHttpClient {
910

1011
/**
11-
* Executes HTTP POST request with JSON body.
12+
* Executes HTTP POST request with JSON payload.
1213
*
13-
* @param url target URL
14-
* @param requestBody JSON request body
15-
* @param responseType expected response type class
16-
* @param <T> response type
17-
* @return deserialized response object or null if no response expected
18-
* @throws IOException if request fails or response cannot be processed
14+
* @param url endpoint URL for the request
15+
* @param requestBody JSON-formatted request payload
16+
* @param responseType expected response class for deserialization, or null if no response needed
17+
* @param <T> response object type
18+
* @return deserialized response object, or null if responseType is null
19+
* @throws IOException if network request fails or JSON processing fails
1920
*/
2021
<T> T post(String url, String requestBody, Class<T> responseType) throws IOException;
2122

2223
/**
23-
* Executes HTTP PUT request with JSON body.
24+
* Executes HTTP PUT request with JSON payload.
2425
*
25-
* @param url target URL
26-
* @param requestBody JSON request body
27-
* @param responseType expected response type class
28-
* @param <T> response type
29-
* @return deserialized response object or null if no response expected
30-
* @throws IOException if request fails or response cannot be processed
26+
* @param url endpoint URL for the request
27+
* @param requestBody JSON-formatted request payload
28+
* @param responseType expected response class for deserialization, or null if no response needed
29+
* @param <T> response object type
30+
* @return deserialized response object, or null if responseType is null
31+
* @throws IOException if network request fails or JSON processing fails
3132
*/
3233
<T> T put(String url, String requestBody, Class<T> responseType) throws IOException;
3334
}

java-reporter-core/src/main/java/io/testomat/core/client/http/NativeHttpClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

21+
/**
22+
* Production HTTP client implementation using Java 11+ HttpClient.
23+
* Provides robust request execution with automatic retries, connection pooling,
24+
* and configurable timeouts for reliable Testomat.io API communication.
25+
*/
2126
public class NativeHttpClient implements CustomHttpClient {
2227
private static final String HEADER_CONTENT_NAME = "Content-Type";
2328
private static final String HEADER_CONTENT_VALUE = "application/json";

java-reporter-core/src/main/java/io/testomat/core/client/http/retryable/NativeRetryableRequestExecutor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
import org.slf4j.Logger;
1818
import org.slf4j.LoggerFactory;
1919

20+
/**
21+
* Default implementation of retry logic for HTTP requests.
22+
* Provides exponential backoff with configurable retry attempts for transient failures
23+
* including network timeouts, connection errors, and specific server error status codes.
24+
*/
2025
public class NativeRetryableRequestExecutor implements RetryableRequestExecutor {
2126

2227
private static final Logger log = LoggerFactory.getLogger(NativeRetryableRequestExecutor.class);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
package io.testomat.core.client.http.retryable;
22

3+
import io.testomat.core.exception.RequestExecutionFailedException;
4+
import io.testomat.core.exception.RequestStatusNotSuccessException;
5+
import io.testomat.core.exception.RequestTimeoutException;
36
import java.net.http.HttpClient;
47
import java.net.http.HttpRequest;
58
import java.net.http.HttpResponse;
69

10+
/**
11+
* Strategy interface for executing HTTP requests with retry logic.
12+
* Handles transient failures and implements backoff strategies for reliable API communication.
13+
*/
714
public interface RetryableRequestExecutor {
15+
16+
/**
17+
* Executes HTTP request with automatic retry on failures.
18+
* Implements retry logic for transient errors like timeouts and server errors.
19+
*
20+
* @param request HTTP request to execute
21+
* @param client HTTP client to use for execution
22+
* @return successful HTTP response
23+
* @throws RequestExecutionFailedException if all retry attempts fail
24+
* @throws RequestTimeoutException if request times out on all attempts
25+
* @throws RequestStatusNotSuccessException if server returns non-success status
26+
*/
827
HttpResponse<String> executeRetryable(HttpRequest request, HttpClient client);
928
}

0 commit comments

Comments
 (0)