Skip to content

Commit 467aa8f

Browse files
committed
rft cucumber labels builder
1 parent b03fcc8 commit 467aa8f

3 files changed

Lines changed: 58 additions & 72 deletions

File tree

allure-cucumber-jvm/src/main/java/io/qameta/allure/cucumberjvm/LabelBuilder.java

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
import gherkin.formatter.model.Feature;
44
import gherkin.formatter.model.Scenario;
55
import gherkin.formatter.model.Tag;
6-
import io.qameta.allure.util.ResultsUtils;
7-
import io.qameta.allure.Severity;
8-
import io.qameta.allure.SeverityLevel;
9-
import io.qameta.allure.Story;
106
import io.qameta.allure.model.Label;
117
import io.qameta.allure.model.Link;
8+
import io.qameta.allure.util.ResultsUtils;
129
import org.slf4j.Logger;
1310
import org.slf4j.LoggerFactory;
1411

15-
import java.lang.annotation.Annotation;
1612
import java.util.ArrayList;
1713
import java.util.Deque;
1814
import java.util.List;
1915

16+
import static io.qameta.allure.util.ResultsUtils.createFeatureLabel;
17+
import static io.qameta.allure.util.ResultsUtils.createSeverityLabel;
18+
import static io.qameta.allure.util.ResultsUtils.createStoryLabel;
19+
import static io.qameta.allure.util.ResultsUtils.createTagLabel;
2020
import static io.qameta.allure.util.ResultsUtils.getHostName;
2121
import static io.qameta.allure.util.ResultsUtils.getThreadName;
2222

2323
/**
2424
* Scenario labels and links builder.
2525
*/
2626
class LabelBuilder {
27-
private static final Logger LOG = LoggerFactory.getLogger(LabelBuilder.class);
27+
private static final Logger LOGGER = LoggerFactory.getLogger(LabelBuilder.class);
2828
private static final String COMPOSITE_TAG_DELIMITER = "=";
2929

3030
private static final String SEVERITY = "@SEVERITY";
@@ -37,8 +37,8 @@ class LabelBuilder {
3737
LabelBuilder(final Feature feature, final Scenario scenario, final Deque<Tag> tags) {
3838
final TagParser tagParser = new TagParser(feature, scenario);
3939

40-
getScenarioLabels().add(getFeatureLabel(feature.getName()));
41-
getScenarioLabels().add(getStoryLabel(scenario.getName()));
40+
getScenarioLabels().add(createFeatureLabel(feature.getName()));
41+
getScenarioLabels().add(createStoryLabel(scenario.getName()));
4242

4343
while (tags.peek() != null) {
4444
final Tag tag = tags.remove();
@@ -52,7 +52,7 @@ class LabelBuilder {
5252

5353
switch (tagKey) {
5454
case SEVERITY:
55-
getScenarioLabels().add(getSeverityLabel(tagValue));
55+
getScenarioLabels().add(createSeverityLabel(tagValue.toLowerCase()));
5656
break;
5757
case TMS_LINK:
5858
getScenarioLinks().add(ResultsUtils.createTmsLink(tagValue));
@@ -61,12 +61,12 @@ class LabelBuilder {
6161
getScenarioLinks().add(ResultsUtils.createIssueLink(tagValue));
6262
break;
6363
default:
64-
LOG.warn("Composite tag {} is not supported. adding it as RAW", tagKey);
64+
LOGGER.warn("Composite tag {} is not supported. adding it as RAW", tagKey);
6565
getScenarioLabels().add(getTagLabel(tag));
6666
break;
6767
}
6868
} else if (tagParser.isPureSeverityTag(tag)) {
69-
getScenarioLabels().add(getSeverityLabel(tagString.substring(1)));
69+
getScenarioLabels().add(createSeverityLabel(tagString.substring(1)));
7070
} else if (!tagParser.isResultTag(tag)) {
7171
getScenarioLabels().add(getTagLabel(tag));
7272
}
@@ -80,57 +80,8 @@ class LabelBuilder {
8080

8181
}
8282

83-
private Label getFeatureLabel(final String featureName) {
84-
85-
return ResultsUtils.createLabel(new io.qameta.allure.Feature() {
86-
@Override
87-
public String value() {
88-
return featureName;
89-
}
90-
91-
@Override
92-
public Class<? extends Annotation> annotationType() {
93-
return io.qameta.allure.Feature.class;
94-
}
95-
});
96-
}
97-
98-
private Label getSeverityLabel(final String severity) {
99-
return ResultsUtils.createLabel(new Severity() {
100-
@Override
101-
public SeverityLevel value() {
102-
try {
103-
return SeverityLevel.valueOf(severity.toUpperCase());
104-
} catch (IllegalArgumentException e) {
105-
LOG.warn("There is no severity level {} failing back to 'normal'", e);
106-
return SeverityLevel.NORMAL;
107-
108-
}
109-
}
110-
111-
@Override
112-
public Class<? extends Annotation> annotationType() {
113-
return Severity.class;
114-
}
115-
});
116-
}
117-
118-
private Label getStoryLabel(final String storyName) {
119-
return ResultsUtils.createLabel(new Story() {
120-
@Override
121-
public String value() {
122-
return storyName;
123-
}
124-
125-
@Override
126-
public Class<? extends Annotation> annotationType() {
127-
return Story.class;
128-
}
129-
});
130-
}
131-
13283
private Label getTagLabel(final Tag tag) {
133-
return new Label().withName("tag").withValue(tag.getName().substring(1));
84+
return createTagLabel(tag.getName().substring(1));
13485
}
13586

13687
public List<Label> getScenarioLabels() {

allure-cucumber-jvm/src/main/java/io/qameta/allure/cucumberjvm/TagParser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ protected boolean isResultTag(final Tag tag) {
4848
}
4949

5050
protected boolean isPureSeverityTag(final Tag tag) {
51-
return Arrays.asList(SeverityLevel.values()).stream()
52-
.anyMatch(value -> ("@" + value.name())
53-
.equalsIgnoreCase(tag.getName()));
51+
return Arrays.stream(SeverityLevel.values())
52+
.map(SeverityLevel::value)
53+
.map(value -> "@" + value)
54+
.anyMatch(value -> value.equalsIgnoreCase(tag.getName()));
5455
}
5556

5657
}

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

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.qameta.allure.Feature;
88
import io.qameta.allure.Owner;
99
import io.qameta.allure.Severity;
10+
import io.qameta.allure.SeverityLevel;
1011
import io.qameta.allure.Story;
1112
import io.qameta.allure.model.ExecutableItem;
1213
import io.qameta.allure.model.Label;
@@ -43,15 +44,20 @@
4344
public final class ResultsUtils {
4445

4546
public static final String ALLURE_HOST_NAME_SYSPROP = "allure.hostName";
46-
4747
public static final String ALLURE_HOST_NAME_ENV = "ALLURE_HOST_NAME";
4848
public static final String ALLURE_THREAD_NAME_SYSPROP = "allure.threadName";
49-
5049
public static final String ALLURE_THREAD_NAME_ENV = "ALLURE_THREAD_NAME";
51-
public static final String ISSUE_LINK_TYPE = "issue";
5250

51+
public static final String ISSUE_LINK_TYPE = "issue";
5352
public static final String TMS_LINK_TYPE = "tms";
5453

54+
public static final String EPIC_LABEL_NAME = "epic";
55+
public static final String FEATURE_LABEL_NAME = "feature";
56+
public static final String STORY_LABEL_NAME = "story";
57+
public static final String SEVERITY_LABEL_NAME = "severity";
58+
public static final String TAG_LABEL_NAME = "tag";
59+
public static final String OWNER_LABEL_NAME = "owner";
60+
5561
private static final Logger LOGGER = LoggerFactory.getLogger(ResultsUtils.class);
5662
private static final String ALLURE_DESCRIPTIONS_PACKAGE = "allureDescriptions/";
5763

@@ -61,24 +67,52 @@ private ResultsUtils() {
6167
throw new IllegalStateException("Do not instance");
6268
}
6369

70+
public static Label createEpicLabel(final String epic) {
71+
return new Label().withName(EPIC_LABEL_NAME).withValue(epic);
72+
}
73+
74+
public static Label createFeatureLabel(final String feature) {
75+
return new Label().withName(FEATURE_LABEL_NAME).withValue(feature);
76+
}
77+
78+
public static Label createStoryLabel(final String story) {
79+
return new Label().withName(STORY_LABEL_NAME).withValue(story);
80+
}
81+
82+
public static Label createTagLabel(final String tag) {
83+
return new Label().withName(TAG_LABEL_NAME).withValue(tag);
84+
}
85+
86+
public static Label createOwnerLabel(final String owner) {
87+
return new Label().withName(OWNER_LABEL_NAME).withValue(owner);
88+
}
89+
90+
public static Label createSeverityLabel(final SeverityLevel severity) {
91+
return createSeverityLabel(severity.value());
92+
}
93+
94+
public static Label createSeverityLabel(final String severity) {
95+
return new Label().withName(SEVERITY_LABEL_NAME).withValue(severity);
96+
}
97+
6498
public static Label createLabel(final Owner owner) {
65-
return new Label().withName("owner").withValue(owner.value());
99+
return createOwnerLabel(owner.value());
66100
}
67101

68102
public static Label createLabel(final Severity severity) {
69-
return new Label().withName("severity").withValue(severity.value().value());
103+
return createSeverityLabel(severity.value());
70104
}
71105

72106
public static Label createLabel(final Story story) {
73-
return new Label().withName("story").withValue(story.value());
107+
return createStoryLabel(story.value());
74108
}
75109

76110
public static Label createLabel(final Feature feature) {
77-
return new Label().withName("feature").withValue(feature.value());
111+
return createFeatureLabel(feature.value());
78112
}
79113

80114
public static Label createLabel(final Epic epic) {
81-
return new Label().withName("epic").withValue(epic.value());
115+
return createEpicLabel(epic.value());
82116
}
83117

84118
public static Link createIssueLink(final String value) {

0 commit comments

Comments
 (0)