17
17
18
18
import java .sql .Connection ;
19
19
import java .util .LinkedHashMap ;
20
+ import java .util .LinkedHashSet ;
20
21
import java .util .List ;
21
22
22
23
import org .springframework .core .style .ToStringCreator ;
@@ -37,7 +38,9 @@ public class Run {
37
38
private Integer infoCount ;
38
39
private String errorStack ;
39
40
private String serverOutput ;
41
+ private final LinkedHashSet <Item > items ;
40
42
private LinkedHashMap <String , Test > tests ;
43
+ private LinkedHashMap <String , ItemNode > itemNodes ;
41
44
private String status ;
42
45
private Long start ;
43
46
// to abort connections, producerConn is handled by UtplsqlRunner
@@ -60,6 +63,7 @@ public String toString() {
60
63
.append ("errorStack" , errorStack )
61
64
.append ("serverOutput" , serverOutput )
62
65
.append ("tests" , tests )
66
+ .append ("rootNode" , itemNodes .get (reporterId ))
63
67
.append ("status" , status )
64
68
.append ("start" , start )
65
69
.append ("endTime" , endTime )
@@ -72,7 +76,10 @@ public Run(final String reporterId, final String connectionName, final List<Stri
72
76
this .connectionName = connectionName ;
73
77
this .pathList = pathList ;
74
78
counter = new Counter ();
79
+ items = new LinkedHashSet <>();
75
80
tests = new LinkedHashMap <>();
81
+ itemNodes = new LinkedHashMap <>();
82
+ createRootNode ();
76
83
}
77
84
78
85
public void setStartTime (final String startTime ) {
@@ -86,17 +93,54 @@ public String getName() {
86
93
return time + " (" + conn + ")" ;
87
94
}
88
95
96
+ /**
97
+ * Is called after consuming the pre-run event to populate all items of a run.
98
+ * It's expected to be called only once.
99
+ *
100
+ * @param items items of a run, to be shown in the runner right after starting a run.
101
+ */
89
102
public void put (final List <Item > items ) {
103
+ populateItems (items );
104
+ populateItemNodes ();
105
+ populateItemNodeChildren ();
106
+ }
107
+
108
+ private void createRootNode () {
109
+ // Create pseudo root node as suite.
110
+ // The TreeTableModel requires a single root node, but it will not be displayed.
111
+ final Suite rootSuite = new Suite ();
112
+ rootSuite .setId (getReporterId ());
113
+ rootSuite .setName (getReporterId ());
114
+ ItemNode rootNode = new ItemNode (rootSuite );
115
+ itemNodes .put (rootSuite .getId (), rootNode );
116
+ }
117
+
118
+ private void populateItems (List <Item > items ) {
90
119
for (final Item item : items ) {
91
- if (item instanceof Test ) {
92
- tests .put (item .getId (), (Test ) item );
93
- }
120
+ this .items .add (item );
94
121
if (item instanceof Suite ) {
95
- put (((Suite ) item ).getItems ());
122
+ populateItems (((Suite ) item ).getItems ());
123
+ } else if (item instanceof Test ) {
124
+ this .tests .put (item .getId (), (Test ) item );
96
125
}
97
126
}
98
127
}
99
-
128
+
129
+ private void populateItemNodes () {
130
+ for (final Item item : items ) {
131
+ itemNodes .put (item .getId (), new ItemNode (item ));
132
+ }
133
+ }
134
+
135
+ private void populateItemNodeChildren () {
136
+ for (Item item : items ) {
137
+ String parentId = item .getParentId ();
138
+ ItemNode node = itemNodes .get (item .getId ());
139
+ ItemNode parent = itemNodes .get (parentId == null ? reporterId : parentId );
140
+ parent .add (node );
141
+ }
142
+ }
143
+
100
144
public Test getTest (final String id ) {
101
145
return tests .get (id );
102
146
}
@@ -222,6 +266,14 @@ public LinkedHashMap<String, Test> getTests() {
222
266
public void setTests (final LinkedHashMap <String , Test > tests ) {
223
267
this .tests = tests ;
224
268
}
269
+
270
+ public LinkedHashMap <String , ItemNode > getItemNodes () {
271
+ return itemNodes ;
272
+ }
273
+
274
+ public void setItemNodes (LinkedHashMap <String , ItemNode > itemNodes ) {
275
+ this .itemNodes = itemNodes ;
276
+ }
225
277
226
278
public String getStatus () {
227
279
return status ;
@@ -246,4 +298,5 @@ public Connection getConsumerConn() {
246
298
public void setConsumerConn (Connection consumerConn ) {
247
299
this .consumerConn = consumerConn ;
248
300
}
301
+
249
302
}
0 commit comments