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
2 changes: 1 addition & 1 deletion java-reporter-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.8.13</version>
<version>0.9.0</version>
<packaging>jar</packaging>

<name>Testomat.io Reporter Core</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* Default implementation of {@link RequestBodyBuilder} for Testomat.io API requests.
Expand Down Expand Up @@ -175,8 +176,13 @@ private Map<String, Object> buildTestResultMap(TestResult result) throws JsonPro
addLinks(body, rid);
}

body.put("overwrite", "true");
ReportedTestStorage.store(body);
body.put("overwrite", Optional.ofNullable(result.isOverwrite()).orElse(true));

Map<String, Object> storageEntry = new HashMap<>();
storageEntry.put(ApiRequestFields.TEST_ID, result.getTestId());
storageEntry.put(ApiRequestFields.RID, result.getRid());
ReportedTestStorage.store(storageEntry);

return body;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package io.testomat.core.facade.methods.artifact;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -15,12 +19,37 @@ public class ReportedTestStorage {
private static final List<Map<String, Object>> STORAGE = new CopyOnWriteArrayList<>();

/**
* Stores test execution data.
* Stores test execution metadata in the internal storage.
* <p>
* The method adds a new entry containing {@code test_id} and {@code rid}
* only if an entry with the same values does not already exist.
* The check and insertion are performed atomically using synchronization
* to prevent duplicates in concurrent environments.
*
* @param body test data map containing test results and metadata
* @param body a map containing test execution data; expected to include
* {@code "test_id"} and {@code "rid"} keys
*/
public static void store(Map<String, Object> body) {
STORAGE.add(body);

Object testId = body.get("test_id");
Object rid = body.get("rid");

synchronized (STORAGE) {

boolean exists = STORAGE.stream().anyMatch(m ->
Objects.equals(m.get("test_id"), testId) &&
Objects.equals(m.get("rid"), rid)
);

if (!exists) {
Map<String, Object> map = new HashMap<>();
map.put("test_id", testId);
map.put("rid", rid);

STORAGE.add(map);
}
}

log.debug("Stored body: {}", body);
}

Expand All @@ -39,11 +68,23 @@ public static List<Map<String, Object>> getStorage() {
* @param artifactLinkData list of artifact link data to associate with tests
*/
public static void linkArtifactsToTests(List<ArtifactLinkData> artifactLinkData) {
for (ArtifactLinkData data : artifactLinkData) {
Map<Object, Map<String, Object>> index =
STORAGE.stream()
.filter(body -> data.getRid().equals(body.get("rid")))
.forEach(body -> body.put("artifacts", data.getLinks()));
.collect(Collectors.toMap(
m -> m.get("rid"),
m -> m
));

for (ArtifactLinkData data : artifactLinkData) {
Map<String, Object> body = index.get(data.getRid());
if (body != null) {
@SuppressWarnings("unchecked")
List<String> artifacts =
(List<String>) body.computeIfAbsent("artifacts", k -> new ArrayList<>());
artifacts.addAll(data.getLinks());
}
}

for (ArtifactLinkData data : artifactLinkData) {
log.debug("Linked: testId - {}, testName - {}, rid - {}, links - {}",
data.getTestId(), data.getTestName(), data.getRid(), data.getLinks().get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ public class TestResult {
/** Test steps executed during the test */
private List<TestStep> steps;

/** Test result is overwritten when the test is executed multiple times */
private Boolean overwrite;

public TestResult() {
}

public TestResult(String title, String testId,
String suiteTitle, String file,
String status, String message, String stack,
Object example, String rid, List<TestStep> steps) {
Object example, String rid, Boolean overwrite,
List<TestStep> steps) {
this.title = title;
this.testId = testId;
this.suiteTitle = suiteTitle;
Expand All @@ -64,6 +68,7 @@ public TestResult(String title, String testId,
this.stack = stack;
this.example = example;
this.rid = rid;
this.overwrite = overwrite;
this.steps = steps;
}

Expand All @@ -81,6 +86,7 @@ public static class Builder {
private String stack;
private Object example;
private String rid;
private Boolean overwrite;
private List<TestStep> steps;

public Builder withTitle(String title) {
Expand Down Expand Up @@ -128,13 +134,18 @@ public Builder withRid(String rid) {
return this;
}

public Builder withOverwrite(Boolean overwrite) {
this.overwrite = overwrite;
return this;
}

public Builder withSteps(List<TestStep> steps) {
this.steps = steps;
return this;
}

public TestResult build() {
return new TestResult(title, testId, suiteTitle, file, status, message, stack, example, rid, steps);
return new TestResult(title, testId, suiteTitle, file, status, message, stack, example, rid, overwrite, steps);
}
}

Expand Down Expand Up @@ -223,6 +234,14 @@ public List<TestStep> getSteps() {
return steps;
}

public void setOverwrite(Boolean overwrite) {
this.overwrite = overwrite;
}

public Boolean isOverwrite() {
return overwrite;
}

public void setSteps(List<TestStep> steps) {
this.steps = steps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
Expand All @@ -25,21 +26,6 @@ void cleanup() {
ReportedTestStorage.getStorage().clear();
}

@Test
@DisplayName("Should store test data")
void testStoreTestData() {
Map<String, Object> body = new HashMap<>();
body.put("title", "Test 1");
body.put("status", "passed");

ReportedTestStorage.store(body);

List<Map<String, Object>> storage = ReportedTestStorage.getStorage();
assertEquals(1, storage.size());
assertEquals("Test 1", storage.get(0).get("title"));
assertEquals("passed", storage.get(0).get("status"));
}

@Test
@DisplayName("Should store multiple test data entries")
void testStoreMultipleEntries() {
Expand Down Expand Up @@ -190,69 +176,21 @@ void testEmptyArtifactLinkList() {
assertEquals(1, storage.size());
}

@Test
@DisplayName("Should store test data with various field types")
void testStoreWithVariousFieldTypes() {
Map<String, Object> body = new HashMap<>();
body.put("title", "Complex Test");
body.put("status", "passed");
body.put("duration", 150.5);
body.put("steps", Arrays.asList("step1", "step2"));
body.put("metadata", Map.of("key1", "value1", "key2", "value2"));

ReportedTestStorage.store(body);

List<Map<String, Object>> storage = ReportedTestStorage.getStorage();
Map<String, Object> stored = storage.get(storage.size() - 1);

assertEquals("Complex Test", stored.get("title"));
assertEquals("passed", stored.get("status"));
assertEquals(150.5, stored.get("duration"));
assertNotNull(stored.get("steps"));
assertNotNull(stored.get("metadata"));
}

@Test
@DisplayName("Should maintain insertion order")
void testInsertionOrder() {
for (int i = 0; i < 5; i++) {
Map<String, Object> body = new HashMap<>();
body.put("title", "Test " + i);
body.put("order", i);
ReportedTestStorage.store(body);
}

List<Map<String, Object>> storage = ReportedTestStorage.getStorage();

// Check that we have at least the 5 tests we just added
assertTrue(storage.size() >= 5);

// Find our tests and verify order
int lastIndex = storage.size();
for (int i = 0; i < 5; i++) {
Map<String, Object> test = storage.get(lastIndex - 5 + i);
assertEquals("Test " + i, test.get("title"));
assertEquals(i, test.get("order"));
}
}

@Test
@DisplayName("Should handle null values in test data")
void testNullValuesInTestData() {
Map<String, Object> body = new HashMap<>();
body.put("title", "Test with nulls");
body.put("message", null);
body.put("stack", null);
body.put("test_id", null);
body.put("rid", null);

ReportedTestStorage.store(body);

List<Map<String, Object>> storage = ReportedTestStorage.getStorage();
Map<String, Object> stored = storage.get(storage.size() - 1);

assertEquals("Test with nulls", stored.get("title"));
assertTrue(stored.containsKey("message"));
assertTrue(stored.containsKey("stack"));
assertEquals(null, stored.get("message"));
assertEquals(null, stored.get("stack"));
assertTrue(stored.containsKey("test_id"));
assertTrue(stored.containsKey("rid"));
assertNull(stored.get("test_id"));
assertNull(stored.get("rid"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void testConstructor() {
"stack trace",
"example data",
"rid-456",
true,
steps
);

Expand Down
4 changes: 2 additions & 2 deletions java-reporter-cucumber/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.testomat</groupId>
<artifactId>java-reporter-cucumber</artifactId>
<version>0.7.9</version>
<version>0.7.10</version>
<packaging>jar</packaging>

<name>Testomat.io Java Reporter Cucumber</name>
Expand Down Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.8.13</version>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
4 changes: 2 additions & 2 deletions java-reporter-junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.testomat</groupId>
<artifactId>java-reporter-junit</artifactId>
<version>0.8.0</version>
<version>0.8.1</version>
<packaging>jar</packaging>

<name>Testomat.io Java Reporter JUnit</name>
Expand Down Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.8.13</version>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import io.testomat.junit.exception.MethodExporterException;
import io.testomat.junit.methodexporter.parser.FileParser;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -347,19 +349,19 @@ void shouldHandleNullFilepathGracefully() {
@Test
@DisplayName("Should handle relative paths")
void shouldHandleRelativePaths(@TempDir Path tempDir) throws IOException {
// Given
String javaContent = "public class RelativePathTest {}";
Path testFile = tempDir.resolve("RelativePathTest.java");
java.nio.file.Files.write(testFile, javaContent.getBytes());

// Create relative path from current directory
Files.writeString(testFile, javaContent);
Path currentDir = Paths.get("").toAbsolutePath();
Path relativePath = currentDir.relativize(testFile);
Path pathToUse;

// When
CompilationUnit result = fileParser.parseFile(relativePath.toString());
if (Objects.equals(currentDir.getRoot(), testFile.getRoot())) {
pathToUse = currentDir.relativize(testFile);
} else {
pathToUse = testFile.toAbsolutePath();
}

// Then
CompilationUnit result = fileParser.parseFile(pathToUse.toString());
assertNotNull(result);
assertTrue(result.toString().contains("RelativePathTest"));
}
Expand Down
4 changes: 2 additions & 2 deletions java-reporter-karate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.testomat</groupId>
<artifactId>java-reporter-karate</artifactId>
<version>0.2.1</version>
<version>0.2.2</version>
<packaging>jar</packaging>

<name>Testomat.io Java Reporter Karate</name>
Expand Down Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.8.13</version>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>io.karatelabs</groupId>
Expand Down
Loading