1515 */
1616package org .utplsql .sqldev .model .runner ;
1717
18+ import javax .swing .Icon ;
19+
1820import org .springframework .core .style .ToStringCreator ;
1921import org .utplsql .sqldev .model .JsonToStringStyler ;
22+ import org .utplsql .sqldev .resources .UtplsqlResources ;
2023
2124public abstract class Item {
2225 private String id ;
26+ private String name ;
27+ private String description ;
2328 private String startTime ;
2429 private String endTime ;
2530 private Double executionTime ;
@@ -36,15 +41,75 @@ public Item() {
3641 public String toString () {
3742 return new ToStringCreator (this , JsonToStringStyler .getInstance ())
3843 .append ("id" , id )
44+ .append ("name" , name )
45+ .append ("description" , description )
3946 .append ("startTime" , startTime )
4047 .append ("endTime" , endTime )
4148 .append ("executionTime" , executionTime )
4249 .append ("counter" , counter )
4350 .append ("errorStack" , errorStack )
4451 .append ("serverOutput" , serverOutput )
4552 .append ("warnings" , warnings )
53+ .append ("parentId" , getParentId ())
54+ .append ("statusIcon" , getStatusIcon ())
55+ .append ("warningIcon" , getWarningIcon ())
56+ .append ("infoIcon" , getInfoIcon ())
4657 .toString ();
4758 }
59+
60+ public String getParentId () {
61+ // Works only if id (suitepath) is build based on names delimited with a period
62+ // that's expected for real utPLSQL runs, but may fail for artificial runs.
63+ // Returning null is valid, it means this item has no parent and as a
64+ // consequence it will be shown on the top level in the runner.
65+ // A key is required to identify an item since suites can be delivered
66+ // multiple times, e.g. when running a chosen list of tests. This way
67+ // the tests will shown at the right position in the tree, regardless of the call
68+ // parameters.
69+ if (name != null && id != null && name .length () < id .length () && id .endsWith (name )) {
70+ return id .substring (0 , id .length () - name .length () - 1 );
71+ }
72+ return null ;
73+ }
74+
75+ public Icon getStatusIcon () {
76+ Icon icon = null ;
77+ if (getStartTime () != null && getEndTime () == null ) {
78+ icon = UtplsqlResources .getIcon ("PROGRESS_ICON" );
79+ } else {
80+ if (getCounter () != null ) {
81+ // Escalation logic as for the color of the progress bar.
82+ // A suite with errors or failed tests cannot be considered successful,
83+ // even if some tests completed successfully.
84+ if (getCounter ().getError () > 0 ) {
85+ icon = UtplsqlResources .getIcon ("ERROR_ICON" );
86+ } else if (getCounter ().getFailure () > 0 ) {
87+ icon = UtplsqlResources .getIcon ("FAILURE_ICON" );
88+ } else if (getCounter ().getSuccess () > 0 ) {
89+ icon = UtplsqlResources .getIcon ("SUCCESS_ICON" );
90+ } else if (getCounter ().getDisabled () > 0 ) {
91+ icon = UtplsqlResources .getIcon ("DISABLED_ICON" );
92+ }
93+ }
94+ }
95+ return icon ;
96+ }
97+
98+ public Icon getWarningIcon () {
99+ Icon icon = null ;
100+ if (getCounter () != null && getCounter ().getWarning () > 0 ) {
101+ icon = UtplsqlResources .getIcon ("WARNING_ICON" );
102+ }
103+ return icon ;
104+ }
105+
106+ public Icon getInfoIcon () {
107+ Icon icon = null ;
108+ if (getServerOutput () != null && getServerOutput ().length () > 0 ) {
109+ icon = UtplsqlResources .getIcon ("INFO_ICON" );
110+ }
111+ return icon ;
112+ }
48113
49114 public String getId () {
50115 return id ;
@@ -54,6 +119,22 @@ public void setId(final String id) {
54119 this .id = id ;
55120 }
56121
122+ public String getName () {
123+ return name ;
124+ }
125+
126+ public void setName (final String name ) {
127+ this .name = name ;
128+ }
129+
130+ public String getDescription () {
131+ return description ;
132+ }
133+
134+ public void setDescription (final String description ) {
135+ this .description = description ;
136+ }
137+
57138 public String getStartTime () {
58139 return startTime ;
59140 }
0 commit comments