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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.qameta.allure.aspects;

import io.qameta.allure.model.Label;
import io.qameta.allure.model.Link;
import io.qameta.allure.model.Parameter;
import io.qameta.allure.model.TestResult;
import org.apache.commons.lang3.reflect.FieldUtils;
Expand Down Expand Up @@ -37,7 +38,6 @@ final class Allure1Annotations {

private final Object[] args;


Allure1Annotations(final Object target, final MethodSignature signature, final Object... args) {
this.args = Arrays.copyOf(args, args.length);
this.signature = signature;
Expand Down Expand Up @@ -77,6 +77,10 @@ public void updateLabels(final TestResult result) {
result.getLabels().addAll(getLabels());
}

public void updateLinks(final TestResult result) {
result.getLinks().addAll(getLinks());
}

public void updateParameters(final TestResult result) {
final Map<String, String> parameters = getParameters();
result.getParameters().stream()
Expand Down Expand Up @@ -123,12 +127,17 @@ private List<Label> getLabels() {
final Method method = getMethod();
final List<Label> labels = new ArrayList<>();
labels.addAll(Allure1Utils.getLabels(method, Severity.class, Allure1Utils::createLabels));
labels.addAll(Allure1Utils.getLabels(method, TestCaseId.class, Allure1Utils::createLabels));
labels.addAll(Allure1Utils.getLabels(method, Issue.class, Allure1Utils::createLabels));
labels.addAll(Allure1Utils.getLabels(method, Issues.class, Allure1Utils::createLabels));
labels.addAll(Allure1Utils.getLabels(method, Stories.class, Allure1Utils::createLabels));
labels.addAll(Allure1Utils.getLabels(method, Features.class, Allure1Utils::createLabels));
return labels;
}

public List<Link> getLinks() {
final Method method = getMethod();
final List<Link> links = new ArrayList<>();
links.addAll(Allure1Utils.getLinks(method, TestCaseId.class, Allure1Utils::createLinks));
links.addAll(Allure1Utils.getLinks(method, Issue.class, Allure1Utils::createLinks));
links.addAll(Allure1Utils.getLinks(method, Issues.class, Allure1Utils::createLinks));
return links;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private void updateTestCase(final JoinPoint joinPoint) {
getLifecycle().updateTestCase(uuid, annotations::updateDescription);
getLifecycle().updateTestCase(uuid, annotations::updateParameters);
getLifecycle().updateTestCase(uuid, annotations::updateLabels);
getLifecycle().updateTestCase(uuid, annotations::updateLinks);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.qameta.allure.aspects;

import io.qameta.allure.model.Label;
import io.qameta.allure.model.Link;
import io.qameta.allure.util.ResultsUtils;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Issue;
import ru.yandex.qatools.allure.annotations.Issues;
Expand Down Expand Up @@ -32,8 +34,6 @@ final class Allure1Utils {

private static final String STORY_LABEL = "story";

private static final String ISSUE_LABEL = "issue";

/**
* Don't instance this class.
*/
Expand Down Expand Up @@ -115,6 +115,22 @@ private static <T extends Annotation> List<Label> getLabels(final AnnotatedEleme
: Collections.emptyList();
}

public static <T extends Annotation> List<Link> getLinks(final Method method, final Class<T> annotation,
final Function<T, List<Link>> extractor) {
final List<Link> labels = new ArrayList<>();
labels.addAll(getLinks((AnnotatedElement) method, annotation, extractor));
labels.addAll(getLinks(method.getDeclaringClass(), annotation, extractor));
return labels;
}

private static <T extends Annotation> List<Link> getLinks(final AnnotatedElement element,
final Class<T> annotation,
final Function<T, List<Link>> extractor) {
return element.isAnnotationPresent(annotation)
? extractor.apply(element.getAnnotation(annotation))
: Collections.emptyList();
}

public static List<Label> createLabels(final Stories stories) {
return Arrays.stream(stories.value())
.map(value -> new Label().withName(STORY_LABEL).withValue(value))
Expand All @@ -131,22 +147,22 @@ public static List<Label> createLabels(final Severity severity) {
return Collections.singletonList(new Label().withName(SEVERITY_LABEL).withValue(severity.value().value()));
}

public static List<Label> createLabels(final Issues issues) {
public static List<Link> createLinks(final Issues issues) {
return Arrays.stream(issues.value())
.map(Allure1Utils::createLabel)
.map(Allure1Utils::createLink)
.collect(Collectors.toList());
}

public static List<Label> createLabels(final Issue issue) {
return Collections.singletonList(new Label().withName(ISSUE_LABEL).withValue(issue.value()));
public static List<Link> createLinks(final Issue issue) {
return Collections.singletonList(createLink(issue));
}

public static List<Label> createLabels(final TestCaseId issue) {
return Collections.singletonList(new Label().withName(ISSUE_LABEL).withValue(issue.value()));
public static List<Link> createLinks(final TestCaseId issue) {
return Collections.singletonList(ResultsUtils.createTmsLink(issue.value()));
}

private static Label createLabel(final Issue issue) {
return new Label().withName(ISSUE_LABEL).withValue(issue.value());
private static Link createLink(final Issue issue) {
return ResultsUtils.createIssueLink(issue.value());
}

public static String getParameterName(final Field field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.model.Label;
import io.qameta.allure.model.Link;
import io.qameta.allure.model.TestResult;
import io.qameta.allure.test.AllureResultsWriterStub;
import org.junit.Before;
Expand Down Expand Up @@ -96,9 +97,8 @@ public void shouldProcessSeverityAnnotation() {
@Test
public void shouldProcessIssuesAnnotation() {
assertThat(results.getTestResults())
.flatExtracting(TestResult::getLabels)
.filteredOn(label -> label.getName().equals("issue"))
.extracting(Label::getValue)
.flatExtracting(TestResult::getLinks)
.extracting(Link::getName)
.containsExactlyInAnyOrder("ISSUE-1", "ISSUE-11", "ISSUE-2", "ISSUE-22", "TEST-1");

}
Expand Down