< prev index next >

src/com/sun/javatest/report/ResultSection.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


  41  * Summarize the status, pass/fail/error of the tests which we are reporting on.
  42  * Also generate output in failed.html, error.html, etc...
  43  */
  44 class ResultSection extends HTMLSection {
  45     ResultSection(HTMLReport parent, ReportSettings settings, File dir, I18NResourceBundle i18n,
  46             TreeSet<TestResult>[] sortedResults) {
  47         super(i18n.getString("result.title"), settings, dir, parent);
  48         this.i18n = i18n;
  49 
  50         headings = new String[] {
  51             i18n.getString("result.heading.passed"),
  52             i18n.getString("result.heading.failed"),
  53             i18n.getString("result.heading.errors"),
  54             i18n.getString("result.heading.notRun")
  55         };
  56 
  57         resultTable = settings.getInterview().getWorkDirectory().getTestResultTable();
  58         initFiles = settings.getInitialFiles();
  59         lists = sortedResults;
  60 
  61         for (TreeSet s: sortedResults)
  62             totalFound += s.size();
  63         /*
  64         lists = new TreeSet[Status.NUM_STATES];
  65         for (int i = 0; i < lists.length; i++ )
  66             lists[i] = new TreeSet(new TestResultsByNameComparator());
  67 
  68         Iterator iter;
  69         try {
  70             TestFilter[] fs = null;
  71 
  72             // Note: settings.filter should not really be null, modernized clients
  73             //   of this class should set the filter before asking for a report.
  74             if (settings.filter == null)
  75                 fs = new TestFilter[0];
  76             else
  77                 fs = new TestFilter[] {settings.filter};
  78 
  79 
  80             iter = ((initFiles == null)
  81                     ? resultTable.getIterator(fs)


  99 
 100     @Override
 101     void writeSummary(ReportWriter out) throws IOException {
 102         super.writeSummary(out);
 103 
 104         out.startTag(HTMLWriterEx.TABLE);
 105         out.writeAttr(HTMLWriterEx.BORDER, 1);
 106 
 107 
 108         boolean thirdColumn = false;
 109         boolean secondColumn = false;
 110         for (int i = 0; i < lists.length; i++ ) {
 111             thirdColumn |= (settings.isStateFileEnabled(i) && hasGroupedReport(i));
 112             secondColumn |= settings.isStateFileEnabled(i) ;
 113         }
 114         String grouped = i18n.getString("result.grouped");
 115         String plain = i18n.getString("result.plain");
 116 
 117         for (int i = 0; i < lists.length; i++ ) {
 118             String reportFile = HTMLReport.files[fileCodes[i]];
 119             TreeSet l = lists[i];
 120 
 121             int n = l.size();
 122             if (n > 0) {
 123                 out.startTag(HTMLWriterEx.TR);
 124                 out.writeTH(headings[i], HTMLWriterEx.ROW);
 125                 out.startTag(HTMLWriterEx.TD);
 126                 out.writeAttr(HTMLWriterEx.STYLE, HTMLWriterEx.TEXT_RIGHT);
 127                 out.write(Integer.toString(n));
 128                 out.endTag(HTMLWriterEx.TD);
 129 
 130                 if (secondColumn) {
 131                     out.startTag(HTMLWriterEx.TD);
 132                     if (settings.isStateFileEnabled(i)) {
 133                         out.writeLink(reportFile, plain);
 134                     } else {
 135                         out.writeLine(" ");
 136                     }
 137                     out.endTag(HTMLWriterEx.TD);
 138                 }
 139 


 183             if (!settings.isStateFileEnabled(i))
 184                 continue;
 185 
 186             writeUnGroupedReport(i);
 187 
 188             if (hasGroupedReport(i)) {
 189                 // re-sort it
 190                 TreeSet<TestResult> newS = new TreeSet<>(new TestResultsByStatusAndTitleComparator());
 191                 newS.addAll(lists[i]);
 192                 lists[i] = newS;
 193 
 194                 writeGroupedReport(i);
 195             }
 196        }
 197     }
 198 
 199     private void writeUnGroupedReport(int i) throws IOException {
 200 
 201         ReportWriter out = openAuxFile(fileCodes[i], headings[i], i18n);
 202         try {
 203             TreeSet list = lists[i];
 204             if (list.size() > 0) {
 205                 boolean inList = false;
 206 
 207                 for (Iterator iter = list.iterator(); iter.hasNext(); ) {
 208                     TestResult e = (TestResult) (iter.next());
 209                     String title;
 210                     try {
 211                         TestDescription e_td = e.getDescription();
 212                         title = e_td.getTitle();
 213                     }
 214                     catch (TestResult.Fault ex) {
 215                         title = null;
 216                     }
 217 
 218                     Status e_s = e.getStatus();
 219                     if (!inList) {
 220                         inList = true;
 221                     }
 222 
 223                     //File eFile = e.getFile();
 224                     String eWRPath = e.getWorkRelativePath();
 225                     File eFile = new File(workDirRoot, eWRPath.replace('/', File.separatorChar));
 226                     String eName = e.getTestName();
 227                     if (eFile == null || e_s.getType() == Status.NOT_RUN)
 228                         out.write(eName);


 230                         out.writeLink(eFile, eName);
 231 
 232                     if (title != null)
 233                         out.write(": " + title);
 234                     out.startTag(HTMLWriterEx.BR);
 235                     out.newLine();
 236                 }
 237             }
 238         }
 239         finally {
 240             out.close();
 241         }
 242 
 243 
 244     }
 245 
 246     private void writeGroupedReport(int i) throws IOException {
 247         ReportWriter out = openAuxFile(groupedFileCodes[i], headings[i], i18n);
 248         out.write(i18n.getString("result.groupByStatus"));
 249         try {
 250             TreeSet list = lists[i];
 251             if (list.size() > 0) {
 252                 boolean inList = false;
 253                 String currentHead = null;
 254                 for (Iterator iter = list.iterator(); iter.hasNext(); ) {
 255                     TestResult e = (TestResult) (iter.next());
 256                     String title;
 257                     try {
 258                         TestDescription e_td = e.getDescription();
 259                         title = e_td.getTitle();
 260                     }
 261                     catch (TestResult.Fault ex) {
 262                         title = null;
 263                     }
 264 
 265                     Status e_s = e.getStatus();
 266                     if (!e_s.getReason().equals(currentHead)) {
 267                         currentHead = e_s.getReason();
 268                         if (inList) {
 269                             inList = false;
 270                             out.endTag(HTMLWriterEx.UL);
 271                             out.newLine();
 272                         }
 273                         out.startTag(HTMLWriterEx.H4);
 274                         out.write(currentHead.length() == 0 ? i18n.getString("result.noReason") : currentHead);
 275                         out.endTag(HTMLWriterEx.H4);




  41  * Summarize the status, pass/fail/error of the tests which we are reporting on.
  42  * Also generate output in failed.html, error.html, etc...
  43  */
  44 class ResultSection extends HTMLSection {
  45     ResultSection(HTMLReport parent, ReportSettings settings, File dir, I18NResourceBundle i18n,
  46             TreeSet<TestResult>[] sortedResults) {
  47         super(i18n.getString("result.title"), settings, dir, parent);
  48         this.i18n = i18n;
  49 
  50         headings = new String[] {
  51             i18n.getString("result.heading.passed"),
  52             i18n.getString("result.heading.failed"),
  53             i18n.getString("result.heading.errors"),
  54             i18n.getString("result.heading.notRun")
  55         };
  56 
  57         resultTable = settings.getInterview().getWorkDirectory().getTestResultTable();
  58         initFiles = settings.getInitialFiles();
  59         lists = sortedResults;
  60 
  61         for (TreeSet<TestResult> s: sortedResults)
  62             totalFound += s.size();
  63         /*
  64         lists = new TreeSet[Status.NUM_STATES];
  65         for (int i = 0; i < lists.length; i++ )
  66             lists[i] = new TreeSet(new TestResultsByNameComparator());
  67 
  68         Iterator iter;
  69         try {
  70             TestFilter[] fs = null;
  71 
  72             // Note: settings.filter should not really be null, modernized clients
  73             //   of this class should set the filter before asking for a report.
  74             if (settings.filter == null)
  75                 fs = new TestFilter[0];
  76             else
  77                 fs = new TestFilter[] {settings.filter};
  78 
  79 
  80             iter = ((initFiles == null)
  81                     ? resultTable.getIterator(fs)


  99 
 100     @Override
 101     void writeSummary(ReportWriter out) throws IOException {
 102         super.writeSummary(out);
 103 
 104         out.startTag(HTMLWriterEx.TABLE);
 105         out.writeAttr(HTMLWriterEx.BORDER, 1);
 106 
 107 
 108         boolean thirdColumn = false;
 109         boolean secondColumn = false;
 110         for (int i = 0; i < lists.length; i++ ) {
 111             thirdColumn |= (settings.isStateFileEnabled(i) && hasGroupedReport(i));
 112             secondColumn |= settings.isStateFileEnabled(i) ;
 113         }
 114         String grouped = i18n.getString("result.grouped");
 115         String plain = i18n.getString("result.plain");
 116 
 117         for (int i = 0; i < lists.length; i++ ) {
 118             String reportFile = HTMLReport.files[fileCodes[i]];
 119             TreeSet<TestResult> l = lists[i];
 120 
 121             int n = l.size();
 122             if (n > 0) {
 123                 out.startTag(HTMLWriterEx.TR);
 124                 out.writeTH(headings[i], HTMLWriterEx.ROW);
 125                 out.startTag(HTMLWriterEx.TD);
 126                 out.writeAttr(HTMLWriterEx.STYLE, HTMLWriterEx.TEXT_RIGHT);
 127                 out.write(Integer.toString(n));
 128                 out.endTag(HTMLWriterEx.TD);
 129 
 130                 if (secondColumn) {
 131                     out.startTag(HTMLWriterEx.TD);
 132                     if (settings.isStateFileEnabled(i)) {
 133                         out.writeLink(reportFile, plain);
 134                     } else {
 135                         out.writeLine(" ");
 136                     }
 137                     out.endTag(HTMLWriterEx.TD);
 138                 }
 139 


 183             if (!settings.isStateFileEnabled(i))
 184                 continue;
 185 
 186             writeUnGroupedReport(i);
 187 
 188             if (hasGroupedReport(i)) {
 189                 // re-sort it
 190                 TreeSet<TestResult> newS = new TreeSet<>(new TestResultsByStatusAndTitleComparator());
 191                 newS.addAll(lists[i]);
 192                 lists[i] = newS;
 193 
 194                 writeGroupedReport(i);
 195             }
 196        }
 197     }
 198 
 199     private void writeUnGroupedReport(int i) throws IOException {
 200 
 201         ReportWriter out = openAuxFile(fileCodes[i], headings[i], i18n);
 202         try {
 203             TreeSet<TestResult> list = lists[i];
 204             if (list.size() > 0) {
 205                 boolean inList = false;
 206 
 207                 for (Iterator<TestResult> iter = list.iterator(); iter.hasNext(); ) {
 208                     TestResult e = (iter.next());
 209                     String title;
 210                     try {
 211                         TestDescription e_td = e.getDescription();
 212                         title = e_td.getTitle();
 213                     }
 214                     catch (TestResult.Fault ex) {
 215                         title = null;
 216                     }
 217 
 218                     Status e_s = e.getStatus();
 219                     if (!inList) {
 220                         inList = true;
 221                     }
 222 
 223                     //File eFile = e.getFile();
 224                     String eWRPath = e.getWorkRelativePath();
 225                     File eFile = new File(workDirRoot, eWRPath.replace('/', File.separatorChar));
 226                     String eName = e.getTestName();
 227                     if (eFile == null || e_s.getType() == Status.NOT_RUN)
 228                         out.write(eName);


 230                         out.writeLink(eFile, eName);
 231 
 232                     if (title != null)
 233                         out.write(": " + title);
 234                     out.startTag(HTMLWriterEx.BR);
 235                     out.newLine();
 236                 }
 237             }
 238         }
 239         finally {
 240             out.close();
 241         }
 242 
 243 
 244     }
 245 
 246     private void writeGroupedReport(int i) throws IOException {
 247         ReportWriter out = openAuxFile(groupedFileCodes[i], headings[i], i18n);
 248         out.write(i18n.getString("result.groupByStatus"));
 249         try {
 250             TreeSet<TestResult> list = lists[i];
 251             if (list.size() > 0) {
 252                 boolean inList = false;
 253                 String currentHead = null;
 254                 for (Iterator<TestResult> iter = list.iterator(); iter.hasNext(); ) {
 255                     TestResult e = (iter.next());
 256                     String title;
 257                     try {
 258                         TestDescription e_td = e.getDescription();
 259                         title = e_td.getTitle();
 260                     }
 261                     catch (TestResult.Fault ex) {
 262                         title = null;
 263                     }
 264 
 265                     Status e_s = e.getStatus();
 266                     if (!e_s.getReason().equals(currentHead)) {
 267                         currentHead = e_s.getReason();
 268                         if (inList) {
 269                             inList = false;
 270                             out.endTag(HTMLWriterEx.UL);
 271                             out.newLine();
 272                         }
 273                         out.startTag(HTMLWriterEx.H4);
 274                         out.write(currentHead.length() == 0 ? i18n.getString("result.noReason") : currentHead);
 275                         out.endTag(HTMLWriterEx.H4);


< prev index next >