Skip to content

Commit e503bab

Browse files
Artem Eroshenkobaev
authored andcommitted
fix link patterns in java-migration (via allure-framework#93)
1 parent 2c64f94 commit e503bab

4 files changed

Lines changed: 43 additions & 17 deletions

File tree

allure-java-migration/src/main/java/io/qameta/allure/aspects/Allure1Annotations.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.qameta.allure.aspects;
22

33
import io.qameta.allure.model.Label;
4+
import io.qameta.allure.model.Link;
45
import io.qameta.allure.model.Parameter;
56
import io.qameta.allure.model.TestResult;
67
import org.apache.commons.lang3.reflect.FieldUtils;
@@ -37,7 +38,6 @@ final class Allure1Annotations {
3738

3839
private final Object[] args;
3940

40-
4141
Allure1Annotations(final Object target, final MethodSignature signature, final Object... args) {
4242
this.args = Arrays.copyOf(args, args.length);
4343
this.signature = signature;
@@ -77,6 +77,10 @@ public void updateLabels(final TestResult result) {
7777
result.getLabels().addAll(getLabels());
7878
}
7979

80+
public void updateLinks(final TestResult result) {
81+
result.getLinks().addAll(getLinks());
82+
}
83+
8084
public void updateParameters(final TestResult result) {
8185
final Map<String, String> parameters = getParameters();
8286
result.getParameters().stream()
@@ -123,12 +127,17 @@ private List<Label> getLabels() {
123127
final Method method = getMethod();
124128
final List<Label> labels = new ArrayList<>();
125129
labels.addAll(Allure1Utils.getLabels(method, Severity.class, Allure1Utils::createLabels));
126-
labels.addAll(Allure1Utils.getLabels(method, TestCaseId.class, Allure1Utils::createLabels));
127-
labels.addAll(Allure1Utils.getLabels(method, Issue.class, Allure1Utils::createLabels));
128-
labels.addAll(Allure1Utils.getLabels(method, Issues.class, Allure1Utils::createLabels));
129130
labels.addAll(Allure1Utils.getLabels(method, Stories.class, Allure1Utils::createLabels));
130131
labels.addAll(Allure1Utils.getLabels(method, Features.class, Allure1Utils::createLabels));
131132
return labels;
132133
}
133134

135+
public List<Link> getLinks() {
136+
final Method method = getMethod();
137+
final List<Link> links = new ArrayList<>();
138+
links.addAll(Allure1Utils.getLinks(method, TestCaseId.class, Allure1Utils::createLinks));
139+
links.addAll(Allure1Utils.getLinks(method, Issue.class, Allure1Utils::createLinks));
140+
links.addAll(Allure1Utils.getLinks(method, Issues.class, Allure1Utils::createLinks));
141+
return links;
142+
}
134143
}

allure-java-migration/src/main/java/io/qameta/allure/aspects/Allure1TestCaseAspects.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private void updateTestCase(final JoinPoint joinPoint) {
3737
getLifecycle().updateTestCase(uuid, annotations::updateDescription);
3838
getLifecycle().updateTestCase(uuid, annotations::updateParameters);
3939
getLifecycle().updateTestCase(uuid, annotations::updateLabels);
40+
getLifecycle().updateTestCase(uuid, annotations::updateLinks);
4041
});
4142
}
4243

allure-java-migration/src/main/java/io/qameta/allure/aspects/Allure1Utils.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.qameta.allure.aspects;
22

33
import io.qameta.allure.model.Label;
4+
import io.qameta.allure.model.Link;
5+
import io.qameta.allure.util.ResultsUtils;
46
import ru.yandex.qatools.allure.annotations.Features;
57
import ru.yandex.qatools.allure.annotations.Issue;
68
import ru.yandex.qatools.allure.annotations.Issues;
@@ -32,8 +34,6 @@ final class Allure1Utils {
3234

3335
private static final String STORY_LABEL = "story";
3436

35-
private static final String ISSUE_LABEL = "issue";
36-
3737
/**
3838
* Don't instance this class.
3939
*/
@@ -115,6 +115,22 @@ private static <T extends Annotation> List<Label> getLabels(final AnnotatedEleme
115115
: Collections.emptyList();
116116
}
117117

118+
public static <T extends Annotation> List<Link> getLinks(final Method method, final Class<T> annotation,
119+
final Function<T, List<Link>> extractor) {
120+
final List<Link> labels = new ArrayList<>();
121+
labels.addAll(getLinks((AnnotatedElement) method, annotation, extractor));
122+
labels.addAll(getLinks(method.getDeclaringClass(), annotation, extractor));
123+
return labels;
124+
}
125+
126+
private static <T extends Annotation> List<Link> getLinks(final AnnotatedElement element,
127+
final Class<T> annotation,
128+
final Function<T, List<Link>> extractor) {
129+
return element.isAnnotationPresent(annotation)
130+
? extractor.apply(element.getAnnotation(annotation))
131+
: Collections.emptyList();
132+
}
133+
118134
public static List<Label> createLabels(final Stories stories) {
119135
return Arrays.stream(stories.value())
120136
.map(value -> new Label().withName(STORY_LABEL).withValue(value))
@@ -131,22 +147,22 @@ public static List<Label> createLabels(final Severity severity) {
131147
return Collections.singletonList(new Label().withName(SEVERITY_LABEL).withValue(severity.value().value()));
132148
}
133149

134-
public static List<Label> createLabels(final Issues issues) {
150+
public static List<Link> createLinks(final Issues issues) {
135151
return Arrays.stream(issues.value())
136-
.map(Allure1Utils::createLabel)
152+
.map(Allure1Utils::createLink)
137153
.collect(Collectors.toList());
138154
}
139155

140-
public static List<Label> createLabels(final Issue issue) {
141-
return Collections.singletonList(new Label().withName(ISSUE_LABEL).withValue(issue.value()));
156+
public static List<Link> createLinks(final Issue issue) {
157+
return Collections.singletonList(createLink(issue));
142158
}
143159

144-
public static List<Label> createLabels(final TestCaseId issue) {
145-
return Collections.singletonList(new Label().withName(ISSUE_LABEL).withValue(issue.value()));
160+
public static List<Link> createLinks(final TestCaseId issue) {
161+
return Collections.singletonList(ResultsUtils.createTmsLink(issue.value()));
146162
}
147163

148-
private static Label createLabel(final Issue issue) {
149-
return new Label().withName(ISSUE_LABEL).withValue(issue.value());
164+
private static Link createLink(final Issue issue) {
165+
return ResultsUtils.createIssueLink(issue.value());
150166
}
151167

152168
public static String getParameterName(final Field field) {

allure-java-migration/src/test/java/io/qameta/allure/aspects/Allure1TestCaseAspectsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.qameta.allure.AllureLifecycle;
44
import io.qameta.allure.model.Label;
5+
import io.qameta.allure.model.Link;
56
import io.qameta.allure.model.TestResult;
67
import io.qameta.allure.test.AllureResultsWriterStub;
78
import org.junit.Before;
@@ -96,9 +97,8 @@ public void shouldProcessSeverityAnnotation() {
9697
@Test
9798
public void shouldProcessIssuesAnnotation() {
9899
assertThat(results.getTestResults())
99-
.flatExtracting(TestResult::getLabels)
100-
.filteredOn(label -> label.getName().equals("issue"))
101-
.extracting(Label::getValue)
100+
.flatExtracting(TestResult::getLinks)
101+
.extracting(Link::getName)
102102
.containsExactlyInAnyOrder("ISSUE-1", "ISSUE-11", "ISSUE-2", "ISSUE-22", "TEST-1");
103103

104104
}

0 commit comments

Comments
 (0)