1717
1818import java .sql .Connection ;
1919import java .util .LinkedHashMap ;
20+ import java .util .LinkedHashSet ;
2021import java .util .List ;
2122
2223import org .springframework .core .style .ToStringCreator ;
@@ -37,7 +38,9 @@ public class Run {
3738 private Integer infoCount ;
3839 private String errorStack ;
3940 private String serverOutput ;
41+ private final LinkedHashSet <Item > items ;
4042 private LinkedHashMap <String , Test > tests ;
43+ private LinkedHashMap <String , ItemNode > itemNodes ;
4144 private String status ;
4245 private Long start ;
4346 // to abort connections, producerConn is handled by UtplsqlRunner
@@ -60,6 +63,7 @@ public String toString() {
6063 .append ("errorStack" , errorStack )
6164 .append ("serverOutput" , serverOutput )
6265 .append ("tests" , tests )
66+ .append ("rootNode" , itemNodes .get (reporterId ))
6367 .append ("status" , status )
6468 .append ("start" , start )
6569 .append ("endTime" , endTime )
@@ -72,7 +76,10 @@ public Run(final String reporterId, final String connectionName, final List<Stri
7276 this .connectionName = connectionName ;
7377 this .pathList = pathList ;
7478 counter = new Counter ();
79+ items = new LinkedHashSet <>();
7580 tests = new LinkedHashMap <>();
81+ itemNodes = new LinkedHashMap <>();
82+ createRootNode ();
7683 }
7784
7885 public void setStartTime (final String startTime ) {
@@ -86,17 +93,54 @@ public String getName() {
8693 return time + " (" + conn + ")" ;
8794 }
8895
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+ */
89102 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 ) {
90119 for (final Item item : items ) {
91- if (item instanceof Test ) {
92- tests .put (item .getId (), (Test ) item );
93- }
120+ this .items .add (item );
94121 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 );
96125 }
97126 }
98127 }
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+
100144 public Test getTest (final String id ) {
101145 return tests .get (id );
102146 }
@@ -222,6 +266,14 @@ public LinkedHashMap<String, Test> getTests() {
222266 public void setTests (final LinkedHashMap <String , Test > tests ) {
223267 this .tests = tests ;
224268 }
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+ }
225277
226278 public String getStatus () {
227279 return status ;
@@ -246,4 +298,5 @@ public Connection getConsumerConn() {
246298 public void setConsumerConn (Connection consumerConn ) {
247299 this .consumerConn = consumerConn ;
248300 }
301+
249302}
0 commit comments