Skip to content

Commit 33ceec8

Browse files
authored
add support for inherited annotations (via allure-framework#537)
1 parent 03bc59f commit 33ceec8

3 files changed

Lines changed: 54 additions & 7 deletions

File tree

allure-java-commons/src/main/java/io/qameta/allure/util/AnnotationUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private AnnotationUtils() {
6262
* @return discovered links.
6363
*/
6464
public static Set<Link> getLinks(final AnnotatedElement annotatedElement) {
65-
return getLinks(annotatedElement.getDeclaredAnnotations());
65+
return getLinks(annotatedElement.getAnnotations());
6666
}
6767

6868
/**
@@ -94,7 +94,7 @@ public static Set<Link> getLinks(final Collection<Annotation> annotations) {
9494
* @return discovered labels.
9595
*/
9696
public static Set<Label> getLabels(final AnnotatedElement annotatedElement) {
97-
return getLabels(annotatedElement.getDeclaredAnnotations());
97+
return getLabels(annotatedElement.getAnnotations());
9898
}
9999

100100
/**

allure-java-commons/src/test/java/io/qameta/allure/util/AnnotationUtilsTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,39 @@ void complexCase() {
416416
tuple("owner", "tester2")
417417
);
418418
}
419+
420+
@Issue("i-1")
421+
@Link("example")
422+
@Feature("a")
423+
static class InheritedParentTest1 {
424+
}
425+
426+
@Issue("i-2")
427+
@Story("b")
428+
static class InheritedChildTest1 extends InheritedParentTest1 {
429+
}
430+
431+
@Test
432+
void inheritedLabelAnnotationsTest() {
433+
final Set<Label> labels1 = getLabels(InheritedChildTest1.class);
434+
435+
assertThat(labels1)
436+
.extracting(Label::getName, Label::getValue)
437+
.containsExactlyInAnyOrder(
438+
tuple("feature", "a"),
439+
tuple("story", "b")
440+
);
441+
}
442+
443+
@Test
444+
void inheritedLinkAnnotationsTest() {
445+
final Set<io.qameta.allure.model.Link> links = getLinks(InheritedChildTest1.class);
446+
447+
assertThat(links)
448+
.extracting(io.qameta.allure.model.Link::getName, io.qameta.allure.model.Link::getType)
449+
.containsExactlyInAnyOrder(
450+
tuple("i-2", "issue"),
451+
tuple("example", "custom")
452+
);
453+
}
419454
}

allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,23 @@ public void ownerTest() {
671671
final AllureResults results = runTestNgSuites("suites/owner.xml");
672672
List<TestResult> testResults = results.getTestResults();
673673
assertThat(testResults)
674-
.hasSize(8)
675-
.flatExtracting(TestResult::getLabels)
676-
.filteredOn(label -> "owner".equals(label.getName()))
677-
.extracting(Label::getValue)
678-
.containsExactly("charlie", "charlie", "other-guy", "eroshenkoam", "eroshenkoam", "other-guy");
674+
.extracting(TestResult::getFullName, tr -> tr.getLabels()
675+
.stream()
676+
.filter(label -> "owner".equals(label.getName()))
677+
.map(Label::getValue)
678+
.sorted()
679+
.collect(Collectors.joining(",","[","]"))
680+
)
681+
.containsExactlyInAnyOrder(
682+
tuple("io.qameta.allure.testng.samples.OwnerMethodTest.testWithOwner", "[charlie]"),
683+
tuple("io.qameta.allure.testng.samples.OwnerMethodTest.testWithOwner", "[charlie]"),
684+
tuple("io.qameta.allure.testng.samples.OwnerMethodTest.testWithoutOwner", "[]"),
685+
tuple("io.qameta.allure.testng.samples.OwnerMethodTest.testWithoutOwner", "[]"),
686+
tuple("io.qameta.allure.testng.samples.OwnerClassTest.testWithOwner", "[eroshenkoam,other-guy]"),
687+
tuple("io.qameta.allure.testng.samples.OwnerClassTest.testWithOwner", "[eroshenkoam,other-guy]"),
688+
tuple("io.qameta.allure.testng.samples.OwnerClassTest.testWithoutOwner", "[eroshenkoam]"),
689+
tuple("io.qameta.allure.testng.samples.OwnerClassTest.testWithoutOwner", "[eroshenkoam]")
690+
);
679691
}
680692

681693
@AllureFeatures.Attachments

0 commit comments

Comments
 (0)