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

Commit

Permalink
Merge pull request #26 from Mefi100feLL/feature/behavior_structure
Browse files Browse the repository at this point in the history
added annotations for behaviors structure
  • Loading branch information
viclovsky authored Sep 4, 2019
2 parents bdcef5d + 35b986a commit 3c51b4e
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.tinkoff.allure.annotations

import java.lang.annotation.Inherited
import kotlin.annotation.Repeatable

/**
* Used to mark tests with epic label.
*/
@Inherited
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CLASS, AnnotationTarget.FILE)
@Repeatable
annotation class Epic(val value: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.tinkoff.allure.annotations

import java.lang.annotation.Inherited

/**
* Wrapper annotation for {@link Epic}.
*/
@Inherited
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CLASS, AnnotationTarget.FILE)
annotation class Epics(vararg val value: Epic)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.tinkoff.allure.annotations

import java.lang.annotation.Inherited

/**
* Used to mark tests with feature label.
*/
@Inherited
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CLASS, AnnotationTarget.FILE)
@Repeatable
annotation class Feature(val value: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.tinkoff.allure.annotations

import java.lang.annotation.Inherited

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

import java.lang.annotation.Inherited

/**
* Wrapper annotation for [Story].
*/
@Inherited
@MustBeDocumented
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
@kotlin.annotation.Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CLASS, AnnotationTarget.FILE)
annotation class Stories(vararg val value: Story)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.tinkoff.allure.annotations

import java.lang.annotation.Inherited

/**
* Used to mark test case with a story label.
*/
@Inherited
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CLASS, AnnotationTarget.FILE)
@Repeatable
annotation class Story(val value: String)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package ru.tinkoff.allure.utils

import org.junit.runner.Description
import ru.tinkoff.allure.SeverityLevel
import ru.tinkoff.allure.annotations.DisplayName
import ru.tinkoff.allure.annotations.Issue
import ru.tinkoff.allure.annotations.Owner
import ru.tinkoff.allure.annotations.Severity
import ru.tinkoff.allure.annotations.*
import ru.tinkoff.allure.model.Label
import ru.tinkoff.allure.model.Link
import java.math.BigInteger
Expand All @@ -19,6 +16,10 @@ const val ISSUE_LINK_TYPE = "issue"
const val SEVERITY_LABEL_NAME = "severity"
const val TAG_LABEL_NAME = "tag"
const val OWNER_LABEL_NAME = "owner"
const val EPIC_LABEL_NAME = "epic"
const val FEATURE_LABEL_NAME = "feature"
const val STORY_LABEL_NAME = "story"


fun getMethodDisplayName(description: Description): String {
return description.getAnnotation(DisplayName::class.java)?.value ?: description.methodName
Expand Down Expand Up @@ -78,6 +79,42 @@ fun getLinkUrl(name: String?, type: String): String? {
return pattern.replace("\\{}", name ?: "")
}

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

fun createLabel(epic: Epic): Label {
return createEpicLabel(epic.value)
}

fun createEpicLabel(value: String): Label {
return createLabel(name = EPIC_LABEL_NAME, value = value)
}

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

fun createLabel(feature: Feature): Label {
return createFeatureLabel(feature.value)
}

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 createLabel(feature: Story): Label {
return createStoryLabel(feature.value)
}

fun createStoryLabel(value: String): Label {
return createLabel(name = STORY_LABEL_NAME, value = value)
}

fun getLinks(description: Description): List<Link> {
return getAnnotationsOnClass(description, ru.tinkoff.allure.annotations.Link::class.java).map { createLink(it) } +
getAnnotationsOnMethod(description, ru.tinkoff.allure.annotations.Link::class.java).map { createLink(it) } +
Expand All @@ -88,8 +125,27 @@ fun getLinks(description: Description): List<Link> {
fun getLabels(description: Description): List<Label> {
return getAnnotationsOnClass(description, Owner::class.java).map { createLabel(it) } +
getAnnotationsOnMethod(description, Owner::class.java).map { createLabel(it) } +

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

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

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

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

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

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

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

fun <T : Annotation> getAnnotationsOnMethod(description: org.junit.runner.Description, clazz: Class<T>): List<T> {
Expand Down

0 comments on commit 3c51b4e

Please sign in to comment.