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.11.4</version>
<version>0.11.5</version>
<packaging>jar</packaging>

<name>Testomat.io Reporter Core</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.testomat.core.constants;

public class CommonConstants {
public static final String REPORTER_VERSION = "0.11.4";
public static final String REPORTER_VERSION = "0.11.5";

public static final String TESTS_STRING = "tests";
public static final String API_KEY_STRING = "api_key";
Expand Down
2 changes: 1 addition & 1 deletion java-reporter-cucumber/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.11.4</version>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
2 changes: 1 addition & 1 deletion java-reporter-junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.11.4</version>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
2 changes: 1 addition & 1 deletion java-reporter-karate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.11.4</version>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.karatelabs</groupId>
Expand Down
2 changes: 1 addition & 1 deletion java-reporter-testng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.11.4</version>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
2 changes: 1 addition & 1 deletion testomat-allure-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.11.4</version>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package io.testomat.resolver;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Resolves attachment file path in Allure results directory by UUID.
*/
public class AttachmentFileResolverImpl implements AttachmentFileResolver {
private static final Logger log = LoggerFactory.getLogger(AttachmentFileResolverImpl.class);

private final String resultsDir;

public AttachmentFileResolverImpl() {
this.resultsDir = System.getProperty(
"allure.results.directory",
"allure-results"
);
this.resultsDir = resolveAllurePath();
}

public AttachmentFileResolverImpl(String resultsDir) {
Expand All @@ -32,16 +34,49 @@ public AttachmentFileResolverImpl(String resultsDir) {
*/
@Override
public String find(String uuid) throws IOException {
try (Stream<Path> paths = Files.list(Paths.get(resultsDir))) {
if (uuid == null || uuid.isBlank()) {
return null;
}

Path dir = Paths.get(resultsDir);

if (!Files.exists(dir)) {
return null;
}

try (Stream<Path> paths = Files.list(dir)) {
return paths
.filter(p ->
p.getFileName()
.toString()
.startsWith(uuid))
p.getFileName().toString().startsWith(uuid)
&& p.getFileName().toString().contains("-attachment"))
.map(Path::toString)
.findFirst()
.orElse(null);
}
}

private String resolveAllurePath() {
String systemProperty = System.getProperty("allure.results.directory");
if (systemProperty != null && !systemProperty.isBlank()) {
return systemProperty;
}

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

try (InputStream inputStream = classLoader.getResourceAsStream("allure.properties")) {
if (inputStream != null) {
Properties props = new Properties();
props.load(inputStream);

String result = props.getProperty("allure.results.directory");
if (result != null && !result.isBlank()) {
return result;
}
}
} catch (IOException e) {
log.trace("Failed to read allure.properties", e);
}

return "allure-results";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,104 @@ void shouldHandleEmptyDirectory() throws IOException {
assertThat(result).isNull();
}

@Test
void shouldFindCorrectAttachmentAmongMultipleFiles() throws IOException {
String uuid = "123";

Files.createFile(tempDir.resolve(uuid + "-attachment.txt"));
Files.createFile(tempDir.resolve(uuid + "-other.txt")); // не должен попасть
Files.createFile(tempDir.resolve("999-attachment.txt")); // другой uuid

AttachmentFileResolverImpl resolver =
new AttachmentFileResolverImpl(tempDir.toString());

String result = resolver.find(uuid);

assertThat(result).contains(uuid + "-attachment.txt");
}

@Test
void shouldIgnoreFilesWithoutAttachmentSuffix() throws IOException {
String uuid = "123";

Files.createFile(tempDir.resolve(uuid + "-log.txt"));

AttachmentFileResolverImpl resolver =
new AttachmentFileResolverImpl(tempDir.toString());

String result = resolver.find(uuid);

assertThat(result).isNull();
}

@Test
void shouldNotMatchDifferentUuid() throws IOException {
Files.createFile(tempDir.resolve("999-attachment.txt"));

AttachmentFileResolverImpl resolver =
new AttachmentFileResolverImpl(tempDir.toString());

String result = resolver.find("123");

assertThat(result).isNull();
}

@Test
void shouldReturnNullForNullUuid() throws IOException {
AttachmentFileResolverImpl resolver =
new AttachmentFileResolverImpl(tempDir.toString());

String result = resolver.find(null);

assertThat(result).isNull();
}

@Test
void shouldReturnNullForBlankUuid() throws IOException {
AttachmentFileResolverImpl resolver =
new AttachmentFileResolverImpl(tempDir.toString());

String result = resolver.find(" ");

assertThat(result).isNull();
}

@Test
void shouldReturnNullIfDirectoryDoesNotExist() throws IOException {
AttachmentFileResolverImpl resolver =
new AttachmentFileResolverImpl("non-existing-dir");

String result = resolver.find("123");

assertThat(result).isNull();
}

@Test
void shouldReturnOneOfMatchingFiles() throws IOException {
String uuid = "123";

Path file1 = Files.createFile(tempDir.resolve(uuid + "-attachment1.txt"));
Path file2 = Files.createFile(tempDir.resolve(uuid + "-attachment2.txt"));

AttachmentFileResolverImpl resolver =
new AttachmentFileResolverImpl(tempDir.toString());

String result = resolver.find(uuid);

assertThat(result).isIn(file1.toString(), file2.toString());
}

@Test
void shouldUseSystemProperty() {
System.setProperty("allure.results.directory", "custom-dir");

AttachmentFileResolverImpl resolver = new AttachmentFileResolverImpl();

assertThat(resolver)
.extracting("resultsDir")
.isEqualTo("custom-dir");

System.clearProperty("allure.results.directory");
}

}
Loading