-
Notifications
You must be signed in to change notification settings - Fork 405
Expand file tree
/
Copy pathElement.java
More file actions
168 lines (132 loc) · 4.26 KB
/
Element.java
File metadata and controls
168 lines (132 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package net.masterthought.cucumber.json;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang.StringUtils;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.json.support.Durationable;
import net.masterthought.cucumber.json.support.Status;
import net.masterthought.cucumber.json.support.StatusCounter;
import net.masterthought.cucumber.util.Util;
import java.time.LocalDateTime;
public class Element implements Durationable {
// Start: attributes from JSON file report
private final String id = null;
private String name = null;
private final String type = null;
private final String description = null;
private final String keyword = null;
private final Integer line = null;
/**
* @since cucumber-jvm v4.3.0
* The timestamp field in the json report allows plugins to correctly calculate
* the time a TestSuite takes when the TCs are run in parallel.
* The scenario startTime (which is what i currently added to the report) will be useful
* in a number of ways both for reporting and getting correct duration of parallel TC execution.
*/
@JsonProperty("start_timestamp")
private final LocalDateTime startTime = null;
private final Step[] steps = new Step[0];
private final Hook[] before = new Hook[0];
private final Hook[] after = new Hook[0];
private final Tag[] tags = new Tag[0];
// End: attributes from JSON file report
private static final String SCENARIO_TYPE = "scenario";
private static final String BACKGROUND_TYPE = "background";
private Status elementStatus;
private Status beforeStatus;
private Status afterStatus;
private Status stepsStatus;
private Feature feature;
private long duration;
public Step[] getSteps() {
return steps;
}
public Hook[] getBefore() {
return before;
}
public Hook[] getAfter() {
return after;
}
public Tag[] getTags() {
return tags;
}
public Status getStatus() {
return elementStatus;
}
public Status getBeforeStatus() {
return beforeStatus;
}
public Status getAfterStatus() {
return afterStatus;
}
public Status getStepsStatus() {
return stepsStatus;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getKeyword() {
return keyword;
}
public LocalDateTime getStartTime() {
return startTime;
}
public Integer getLine() {
return line;
}
public String getType() {
return type;
}
public String getDescription() {
return StringUtils.defaultString(description);
}
public boolean isScenario() {
return SCENARIO_TYPE.equalsIgnoreCase(type);
}
public boolean isBackground() {
return BACKGROUND_TYPE.equalsIgnoreCase(type);
}
public Feature getFeature() {
return feature;
}
@Override
public long getDuration() {
return duration;
}
@Override
public String getFormattedDuration() {
return Util.formatDuration(duration);
}
public void setMetaData(Feature feature, Configuration configuration) {
this.feature = feature;
for (Step step : steps) {
step.setMetaData();
}
beforeStatus = new StatusCounter(before).getFinalStatus();
afterStatus = new StatusCounter(after).getFinalStatus();
stepsStatus = new StatusCounter(steps, configuration.getNotFailingStatuses()).getFinalStatus();
elementStatus = calculateElementStatus();
calculateDuration();
}
private Status calculateElementStatus() {
StatusCounter statusCounter = new StatusCounter();
statusCounter.incrementFor(stepsStatus);
statusCounter.incrementFor(beforeStatus);
statusCounter.incrementFor(afterStatus);
return statusCounter.getFinalStatus();
}
private void calculateDuration() {
for (Step step : steps) {
duration += step.getResult().getDuration();
}
}
/**
* Append a string to the name.
* @param str The string to append.
*/
public void appendToName(String str) {
name += str;
}
}