Skip to content

Commit

Permalink
add @LabelAnnotation for @kjira to support integration between Allure…
Browse files Browse the repository at this point in the history
… TestOps and Jira (#11)

add @kTag annotation
  • Loading branch information
MuTalKing authored Aug 8, 2023
1 parent 7566ff0 commit e9af160
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/kotlin/ru/iopump/kotest/allure/annotation/KJira.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ru.iopump.kotest.allure.annotation

import io.qameta.allure.LabelAnnotation
import io.qameta.allure.LinkAnnotation
import ru.iopump.kotest.allure.api.KotestAllureConstant.JIRA.LABEL_NAME
import ru.iopump.kotest.allure.api.KotestAllureConstant.JIRA.LINK_TYPE
import java.lang.annotation.Inherited

Expand All @@ -9,5 +11,6 @@ import java.lang.annotation.Inherited
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@LinkAnnotation(type = LINK_TYPE)
@LabelAnnotation(name = LABEL_NAME)
@Repeatable
annotation class KJira(val value: String)
13 changes: 13 additions & 0 deletions src/main/kotlin/ru/iopump/kotest/allure/annotation/KTag.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.iopump.kotest.allure.annotation

import io.qameta.allure.LabelAnnotation
import io.qameta.allure.util.ResultsUtils.TAG_LABEL_NAME
import java.lang.annotation.Inherited

@MustBeDocumented
@Inherited
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@LabelAnnotation(name = TAG_LABEL_NAME)
@Repeatable
annotation class KTag(val value: String)
15 changes: 15 additions & 0 deletions src/main/kotlin/ru/iopump/kotest/allure/annotation/KTags.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ru.iopump.kotest.allure.annotation

import java.lang.annotation.Inherited

@MustBeDocumented
@Inherited
@Retention(AnnotationRetention.RUNTIME)
@Target(
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.ANNOTATION_CLASS,
AnnotationTarget.CLASS
)
annotation class KTags(val value: Array<KTag>)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ object KotestAllureConstant {
object JIRA {

const val LINK_TYPE = "jira"

const val LABEL_NAME = "jira"

internal const val PATTERN_DEFAULT = "\\[([a-zA-Z]+-\\d+)]"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.qameta.allure.model.Link
import ru.iopump.kotest.allure.helper.meta.AllureMetadataSupportDescriptions.kDescription
import ru.iopump.kotest.allure.helper.meta.AllureMetadataSupportLabels.allureIdsFromTestName
import ru.iopump.kotest.allure.helper.meta.AllureMetadataSupportLabels.epicFromPkg
import ru.iopump.kotest.allure.helper.meta.AllureMetadataSupportLabels.jiraLabelsFromTestName
import ru.iopump.kotest.allure.helper.meta.AllureMetadataSupportLabels.labelAnnotations
import ru.iopump.kotest.allure.helper.meta.AllureMetadataSupportLabels.severity
import ru.iopump.kotest.allure.helper.meta.AllureMetadataSupportLinks.issues
Expand All @@ -28,6 +29,7 @@ internal class AllureMetadata(
add(specClass.severity)
add(specClass.epicFromPkg)
addAll(description.allureIdsFromTestName)
addAll(description.jiraLabelsFromTestName)
}.filterNotNull()

internal val allLinks: List<Link> = buildList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.qameta.allure.model.Label
import io.qameta.allure.util.AnnotationUtils
import io.qameta.allure.util.ResultsUtils.*
import ru.iopump.kotest.allure.api.KotestAllureConstant
import ru.iopump.kotest.allure.api.KotestAllureConstant.JIRA
import ru.iopump.kotest.allure.helper.meta.AllureMetadataSupport.findAll
import kotlin.reflect.KClass
import kotlin.reflect.full.findAnnotation
Expand All @@ -28,4 +29,12 @@ internal object AllureMetadataSupportLabels {
.map { key -> createLabel(ALLURE_ID_LABEL_NAME, key) }
.toList()
}.orEmpty()

internal inline val Descriptor?.jiraLabelsFromTestName: Collection<Label>
get() = this?.run {
id.value
.findAll(JIRA.PATTERN)
.map { key -> createLabel(JIRA.LABEL_NAME, key) }
.toList()
}.orEmpty()
}
9 changes: 6 additions & 3 deletions src/test/kotlin/ru/iopump/kotest/allure/ExampleBddSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import io.qameta.allure.Issue
import io.qameta.allure.Issues
import io.qameta.allure.Link
import io.qameta.allure.Links
import ru.iopump.kotest.allure.annotation.KDescription
import ru.iopump.kotest.allure.annotation.KJira
import ru.iopump.kotest.allure.annotation.KJiras
import ru.iopump.kotest.allure.annotation.*

@Epic("Allure feature annotation on test class")
@Feature("Behavior")
Expand All @@ -30,6 +28,11 @@ import ru.iopump.kotest.allure.annotation.KJiras
@KJiras(
value = [KJira("TTT-111"), KJira("TTT-000")]
)
@KAllureId("888")
@KTag("autotest")
@KTags(
value = [KTag("auto"), KTag("test")]
)
class ExampleBddSpec : BehaviorSpec() {

init {
Expand Down

0 comments on commit e9af160

Please sign in to comment.