Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Adding Issues, Layer, Tag, Tags annotations for Allure Server. (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorobtsov authored Apr 9, 2020
1 parent 03df03c commit 7cd0244
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.qameta.allure.android.annotations


import java.lang.annotation.Inherited

/**
* Wrapper annotation for [Issue].
*/
@Inherited
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CLASS, AnnotationTarget.FILE)
annotation class Issues(vararg val value: Issue)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.qameta.allure.android.annotations

import java.lang.annotation.Inherited

/**
* Used to set layer for tests.
*/
@Inherited
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CLASS, AnnotationTarget.FILE)
annotation class Layer(val value: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.qameta.allure.android.annotations

import java.lang.annotation.Inherited

/**
* Used to set tag for tests.
*/
@Inherited
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CLASS, AnnotationTarget.FILE)
annotation class Tag(val value: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.qameta.allure.android.annotations

import java.lang.annotation.Inherited

/**
* Wrapper annotation for [Tag].
*/
@Inherited
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CLASS, AnnotationTarget.FILE)
annotation class Tags(vararg val value: Tag)
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.qameta.allure.android.utils

import org.junit.runner.Description
import io.qameta.allure.android.annotations.Issues
import io.qameta.allure.android.annotations.Layer
import io.qameta.allure.android.annotations.Tag
import io.qameta.allure.android.annotations.Tags
import io.qameta.allure.android.SeverityLevel
import io.qameta.allure.android.annotations.DisplayName
import io.qameta.allure.android.annotations.Epic
Expand All @@ -15,6 +18,7 @@ import io.qameta.allure.android.annotations.Story
import io.qameta.allure.android.annotations.TmsLink
import io.qameta.allure.android.model.Label
import io.qameta.allure.android.model.Link
import org.junit.runner.Description
import java.math.BigInteger
import java.security.MessageDigest
import java.util.Collections.emptyList
Expand All @@ -32,6 +36,8 @@ const val OWNER_LABEL_NAME = "owner"
const val EPIC_LABEL_NAME = "epic"
const val FEATURE_LABEL_NAME = "feature"
const val STORY_LABEL_NAME = "story"
const val LAYER_LABEL_NAME = "layer"
const val ISSUE_LABEL_TYPE = "issue"


fun getMethodDisplayName(description: Description): String {
Expand All @@ -43,10 +49,6 @@ fun getClassDisplayName(description: Description): String? {
?: description.className
}

fun createTagLabel(tag: String): Label {
return createLabel(TAG_LABEL_NAME, tag)
}

fun createOwnerLabel(owner: String): Label {
return createLabel(OWNER_LABEL_NAME, owner)
}
Expand Down Expand Up @@ -75,8 +77,8 @@ fun createLink(link: io.qameta.allure.android.annotations.Link): Link {
return createLink(link.value, link.name, link.url, link.type)
}

fun createLink(link: Issue): Link {
return createIssueLink(link.value)
fun createLink(issue: Issue): Link {
return createIssueLink(issue.value)
}

fun createIssueLink(value: String): Link {
Expand Down Expand Up @@ -126,12 +128,32 @@ fun createFeatureLabel(value: String): Label {
return createLabel(name = FEATURE_LABEL_NAME, value = value)
}

fun createLabels(features: Stories): List<Label> {
return features.value.map { createLabel(it) }
fun createLabels(stories: Stories): List<Label> {
return stories.value.map { createLabel(it) }
}

fun createLabel(story: Story): Label {
return createStoryLabel(story.value)
}

fun createLabel(layer: Layer): Label {
return createLabel(name = LAYER_LABEL_NAME, value = layer.value)
}

fun createLabels(tags: Tags): List<Label> {
return tags.value.map { createLabel(it) }
}

fun createLabel(feature: Story): Label {
return createStoryLabel(feature.value)
fun createLabel(tag: Tag): Label {
return createLabel(name = TAG_LABEL_NAME, value = tag.value)
}

fun createLabels(tags: Issues): List<Label> {
return tags.value.map { createLabel(it) }
}

fun createLabel(issue: Issue): Label {
return createLabel(name = ISSUE_LABEL_TYPE, value = issue.value)
}

fun createStoryLabel(value: String): Label {
Expand All @@ -153,6 +175,15 @@ fun getLabels(description: Description): List<Label> {
getAnnotationsOnClass(description, Severity::class.java).map { createLabel(it) } +
getAnnotationsOnMethod(description, Severity::class.java).map { createLabel(it) } +

getAnnotationsOnClass(description, Layer::class.java).map { createLabel(it) } +
getAnnotationsOnMethod(description, Layer::class.java).map { createLabel(it) } +

getAnnotationsOnClass(description, Issues::class.java).flatMap { createLabels(it) } +
getAnnotationsOnMethod(description, Issues::class.java).flatMap { createLabels(it) } +

getAnnotationsOnClass(description, Issue::class.java).map { createLabel(it) } +
getAnnotationsOnMethod(description, Issue::class.java).map { createLabel(it) } +

getAnnotationsOnClass(description, Epics::class.java).flatMap { createLabels(it) } +
getAnnotationsOnMethod(description, Epics::class.java).flatMap { createLabels(it) } +

Expand All @@ -169,14 +200,20 @@ fun getLabels(description: Description): List<Label> {
getAnnotationsOnMethod(description, Stories::class.java).flatMap { createLabels(it) } +

getAnnotationsOnClass(description, Story::class.java).map { createLabel(it) } +
getAnnotationsOnMethod(description, Story::class.java).map { createLabel(it) }
getAnnotationsOnMethod(description, Story::class.java).map { createLabel(it) } +

getAnnotationsOnClass(description, Tags::class.java).flatMap { createLabels(it) } +
getAnnotationsOnMethod(description, Tags::class.java).flatMap { createLabels(it) } +

getAnnotationsOnClass(description, Tag::class.java).map { createLabel(it) } +
getAnnotationsOnMethod(description, Tag::class.java).map { createLabel(it) }
}

fun <T : Annotation> getAnnotationsOnMethod(description: org.junit.runner.Description, clazz: Class<T>): List<T> {
fun <T : Annotation> getAnnotationsOnMethod(description: Description, clazz: Class<T>): List<T> {
return listOfNotNull(description.getAnnotation(clazz)) + extractRepeatable(clazz)
}

fun <T : Annotation> getAnnotationsOnClass(description: org.junit.runner.Description, clazz: Class<T>): List<T> {
fun <T : Annotation> getAnnotationsOnClass(description: Description, clazz: Class<T>): List<T> {
return listOfNotNull(description.testClass.getAnnotation(clazz))
}

Expand All @@ -196,4 +233,4 @@ fun getHistoryId(description: Description): String {

fun md5(source: String): ByteArray {
return MessageDigest.getInstance("md5").digest(source.toByteArray())
}
}

0 comments on commit 7cd0244

Please sign in to comment.