Skip to content

Commit

Permalink
Allow suite timestamp to be retrieved from XML results (#1406)
Browse files Browse the repository at this point in the history
* Add date and page history link to XML responses, #1396
  • Loading branch information
fhoeben authored Dec 23, 2022
1 parent b191bb9 commit f47b28d
Show file tree
Hide file tree
Showing 29 changed files with 274 additions and 175 deletions.
1 change: 1 addition & 0 deletions FitNesseRoot/FitNesse/ReleaseNotes/content.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
!2 Pending Changes
* Add date and page history link to XML responses. ([[1396][https://github.com/unclebob/fitnesse/issues/1396]])

!2 20221219
* Add a new optional command line parameter to specify the maximum number of workers to use for handling incoming requests.
Expand Down
7 changes: 4 additions & 3 deletions src/fitnesse/fixtures/ClockFixture.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package fitnesse.fixtures;

import java.text.ParseException;

import fitnesse.util.Clock;
import fitnesse.util.DateAlteringClock;
import fitnesse.util.DateTimeUtil;

import java.text.ParseException;
import java.util.TimeZone;

public class ClockFixture {
public void freezeClockAt(String dateTime) throws ParseException {
System.out.println("Freezing time at " + dateTime);
new DateAlteringClock(DateTimeUtil.getDateFromString(dateTime)).freeze();
new DateAlteringClock(DateTimeUtil.getDateFromString(dateTime), TimeZone.getDefault()).freeze();
}

public String simulationDate() {
Expand Down
10 changes: 5 additions & 5 deletions src/fitnesse/fixtures/PageDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.fixtures;

import java.text.SimpleDateFormat;
import java.util.Date;

import fitnesse.FitNesseExpediter;
import fitnesse.http.MockRequest;
import fitnesse.http.MockResponseSender;
import fitnesse.reporting.history.PageHistory;
import fitnesse.responders.editing.EditResponder;
import fitnesse.util.MockSocket;
import fitnesse.util.SerialExecutorService;
import fitnesse.wiki.PageCrawler;
import fitnesse.wiki.PageData;
import fitnesse.wiki.PathParser;
import fitnesse.wiki.SymbolicPage;
import fitnesse.wiki.WikiPage;
import fitnesse.wiki.WikiPagePath;
import org.htmlparser.Node;
Expand All @@ -29,6 +26,9 @@
import org.htmlparser.util.NodeList;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Date;

public class PageDriver {
private PageCreator creator = new PageCreator();
private ResponseRequester requester = new ResponseRequester();
Expand Down Expand Up @@ -204,7 +204,7 @@ private NodeList getMatchingTags(NodeFilter filter) throws Exception {
}

public String pageHistoryDateSignatureOf(Date date) {
SimpleDateFormat dateFormat = new SimpleDateFormat(fitnesse.reporting.history.PageHistory.TEST_RESULT_FILE_DATE_PATTERN);
SimpleDateFormat dateFormat = PageHistory.getDateFormat();
return dateFormat.format(date);
}

Expand Down
6 changes: 3 additions & 3 deletions src/fitnesse/fixtures/PageHistory.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package fitnesse.fixtures;

import static fitnesse.fixtures.FitnesseFixtureContext.context;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import static fitnesse.fixtures.FitnesseFixtureContext.context;

public class PageHistory {
private String name;
private Date date;
private int right;
private int wrong;
private int ignores;
private int exceptions;
private SimpleDateFormat dateFormat = new SimpleDateFormat(fitnesse.reporting.history.PageHistory.TEST_RESULT_FILE_DATE_PATTERN);
private SimpleDateFormat dateFormat = fitnesse.reporting.history.PageHistory.getDateFormat();

public void setName(String name) {
this.name = name;
Expand Down
10 changes: 10 additions & 0 deletions src/fitnesse/reporting/history/ExecutionReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -193,6 +194,15 @@ public void setDate(Date date) {
this.date = new Date(date.getTime());
}

public String getDateString() {
return DateTimeUtil.formatDate(date);
}

public String getResultDate() {
SimpleDateFormat pageHistoryFormatter = PageHistory.getDateFormat();
return pageHistoryFormatter.format(date);
}

public boolean hasRunTimes() {
return totalRunTimeInMillis != NO_RUN_TIME;
}
Expand Down
2 changes: 1 addition & 1 deletion src/fitnesse/reporting/history/HistoryPurger.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private Date getDateFromPageHistoryFileName(String name) {
}

private Date tryExtractDateFromTestHistoryName(String testHistoryName) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat(PageHistory.TEST_RESULT_FILE_DATE_PATTERN);
SimpleDateFormat dateFormat = PageHistory.getDateFormat();
String dateString = testHistoryName.split("_")[0];
return dateFormat.parse(dateString);
}
Expand Down
28 changes: 22 additions & 6 deletions src/fitnesse/reporting/history/PageHistory.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
package fitnesse.reporting.history;

import fitnesse.testsystems.ExecutionResult;
import fitnesse.util.Clock;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

import fitnesse.testsystems.ExecutionResult;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

public class PageHistory extends PageHistoryReader{
public static final String TEST_RESULT_FILE_DATE_PATTERN = "yyyyMMddHHmmss";
private static final String TEST_RESULT_FILE_DATE_PATTERN = "yyyyMMddHHmmss";

public static SimpleDateFormat getDateFormat() {
SimpleDateFormat format = new SimpleDateFormat(TEST_RESULT_FILE_DATE_PATTERN);
format.setTimeZone(Clock.currentTimeZone());
return format;
}

private int failures = 0;
private int passes = 0;
Expand Down Expand Up @@ -172,8 +189,7 @@ public static class PassFailReport {
private ExecutionResult result;

public PassFailReport(Date date, ExecutionResult result) {
SimpleDateFormat dateFormat = new SimpleDateFormat(TEST_RESULT_FILE_DATE_PATTERN);
this.date = dateFormat.format(date);
this.date = getDateFormat().format(date);
this.result = result;
}

Expand Down
6 changes: 3 additions & 3 deletions src/fitnesse/reporting/history/PageHistoryReader.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package fitnesse.reporting.history;

import util.FileUtil;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import util.FileUtil;

import static java.lang.String.format;

public class PageHistoryReader {

private SimpleDateFormat dateFormat = new SimpleDateFormat(PageHistory.TEST_RESULT_FILE_DATE_PATTERN);
private SimpleDateFormat dateFormat = PageHistory.getDateFormat();
public static final String TEST_FILE_FORMAT = "\\A\\d{14}_\\d+_\\d+_\\d+_\\d+(.xml)*\\Z";

void readHistoryFromPageDirectory(File pageDirectory) {
Expand Down
2 changes: 1 addition & 1 deletion src/fitnesse/reporting/history/SuiteExecutionReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public String getDateString() {
}

public String getResultDate() {
SimpleDateFormat pageHistoryFormatter = new SimpleDateFormat(PageHistory.TEST_RESULT_FILE_DATE_PATTERN);
SimpleDateFormat pageHistoryFormatter = PageHistory.getDateFormat();
return pageHistoryFormatter.format(new Date(time));
}

Expand Down
5 changes: 4 additions & 1 deletion src/fitnesse/reporting/history/SuiteHistoryFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.Closeable;
import java.io.IOException;
import java.io.Writer;
import java.util.Date;
import java.util.List;

public class SuiteHistoryFormatter extends BaseFormatter implements ExecutionLogListener, Closeable {
Expand All @@ -43,8 +44,10 @@ public SuiteHistoryFormatter(FitNesseContext context, WikiPage page, TestXmlForm

@Override
public void testSystemStarted(TestSystem testSystem) {
if (suiteTime == null)
if (suiteTime == null) {
suiteTime = new TimeMeasurement().start();
getSuiteExecutionReport().setDate(new Date(suiteTime.startedAt()));
}
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/fitnesse/resources/templates/suiteHistoryXML.vm
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<suiteResults>
<FitNesseVersion>$suiteExecutionReport.version</FitNesseVersion>
<rootPath>#escape($suiteExecutionReport.rootPath)</rootPath>
<date>$suiteExecutionReport.dateString</date>
<pageHistoryLink>#escape($suiteExecutionReport.rootPath)?pageHistory&amp;resultDate=$suiteExecutionReport.resultDate</pageHistoryLink>
#foreach ($reference in $suiteExecutionReport.pageHistoryReferences)
<pageHistoryReference>
<name>#escape($reference.pageName)</name>
<date>$reference.dateString</date>
<pageHistoryLink>$reference.pageName?pageHistory&amp;resultDate=$reference.resultDate</pageHistoryLink>
<pageHistoryLink>#escape($reference.pageName)?pageHistory&amp;resultDate=$reference.resultDate</pageHistoryLink>
<counts>
<right>$reference.testSummary.right</right>
<wrong>$reference.testSummary.wrong</wrong>
Expand Down
6 changes: 4 additions & 2 deletions src/fitnesse/resources/templates/suiteXML.vm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<testResults>
<FitNesseVersion>$suiteExecutionReport.version</FitNesseVersion>
<rootPath>#escape($suiteExecutionReport.rootPath)</rootPath>
<date>$suiteExecutionReport.dateString</date>
<pageHistoryLink>#escape($suiteExecutionReport.rootPath)?pageHistory&amp;resultDate=$suiteExecutionReport.resultDate</pageHistoryLink>
#foreach ($reference in $suiteExecutionReport.pageHistoryReferences)
<result>
<counts>
Expand All @@ -13,7 +15,7 @@
<date>$reference.dateString</date>
<runTimeInMillis>$reference.runTimeInMillis</runTimeInMillis>
<relativePageName>#escape($reference.relativePageName)</relativePageName>
<pageHistoryLink>$reference.pageName?pageHistory&amp;resultDate=$reference.resultDate</pageHistoryLink>
<pageHistoryLink>#escape($reference.pageName)?pageHistory&amp;resultDate=$reference.resultDate</pageHistoryLink>
#set($testResult = $formatter.getTestResult($reference))
#if($testResult.tags)
<tags>#escape($testResult.tags)</tags>
Expand Down Expand Up @@ -80,4 +82,4 @@
<exceptions>$suiteExecutionReport.finalCounts.exceptions</exceptions>
</finalCounts>
<totalRunTimeInMillis>$suiteExecutionReport.totalRunTimeInMillis</totalRunTimeInMillis>
</testResults>
</testResults>
2 changes: 1 addition & 1 deletion src/fitnesse/responders/run/SuiteResponder.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public static String makePageHistoryFileName(FitNesseContext context, WikiPage p
}

public static String makeResultFileName(TestSummary summary, long time) {
SimpleDateFormat format = new SimpleDateFormat(PageHistory.TEST_RESULT_FILE_DATE_PATTERN);
SimpleDateFormat format = PageHistory.getDateFormat();
String datePart = format.format(new Date(time));
return String.format("%s_%d_%d_%d_%d.xml", datePart, summary.getRight(), summary.getWrong(), summary.getIgnores(), summary.getExceptions());
}
Expand Down
17 changes: 9 additions & 8 deletions src/fitnesse/responders/testHistory/ExecutionLogResponder.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package fitnesse.responders.testHistory;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import fitnesse.FitNesseContext;
import fitnesse.authentication.SecureOperation;
import fitnesse.authentication.SecureResponder;
import fitnesse.authentication.SecureReadOperation;
import fitnesse.authentication.SecureResponder;
import fitnesse.html.template.HtmlPage;
import fitnesse.html.template.PageTitle;
import fitnesse.http.Request;
Expand All @@ -23,8 +18,13 @@
import fitnesse.wiki.PathParser;
import util.FileUtil;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ExecutionLogResponder implements SecureResponder {
private SimpleDateFormat dateFormat = new SimpleDateFormat(PageHistory.TEST_RESULT_FILE_DATE_PATTERN);
private SimpleDateFormat dateFormat = PageHistory.getDateFormat();
private File resultsDirectory;
private FitNesseContext context;

Expand All @@ -40,7 +40,8 @@ public Response makeResponse(FitNesseContext context, Request request) throws Ex
try {
resultDate = dateFormat.parse(date);
} catch (ParseException e) {
throw new IllegalArgumentException("Invalid date format provided: should be " + PageHistory.TEST_RESULT_FILE_DATE_PATTERN + ".", e);
String message = "Invalid date format provided: should be " + PageHistory.getDateFormat().toPattern() + ".";
return new ErrorResponder(message).makeResponse(context, request);
}
}
TestResultRecord testResultRecord = pageHistory.get(resultDate);
Expand Down
19 changes: 9 additions & 10 deletions src/fitnesse/responders/testHistory/HistoryComparerResponder.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package fitnesse.responders.testHistory;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Set;

import fitnesse.FitNesseContext;
import fitnesse.Responder;
import fitnesse.html.template.HtmlPage;
Expand All @@ -23,10 +15,17 @@
import fitnesse.wiki.WikiPage;
import fitnesse.wiki.WikiPagePath;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Set;

public class HistoryComparerResponder implements Responder {
public HistoryComparer comparer;
private SimpleDateFormat dateFormat = new SimpleDateFormat(
PageHistory.TEST_RESULT_FILE_DATE_PATTERN);
private SimpleDateFormat dateFormat = PageHistory.getDateFormat();
private String firstFileName = "";
private String secondFileName = "";
private String firstFilePath;
Expand Down
33 changes: 16 additions & 17 deletions src/fitnesse/responders/testHistory/PageHistoryResponder.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
package fitnesse.responders.testHistory;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;

import fitnesse.reporting.history.PageHistory;
import fitnesse.reporting.history.TestHistory;
import fitnesse.reporting.history.TestResultRecord;
import org.apache.velocity.VelocityContext;

import util.FileUtil;
import fitnesse.FitNesseContext;
import fitnesse.authentication.SecureOperation;
import fitnesse.authentication.SecureResponder;
import fitnesse.authentication.SecureReadOperation;
import fitnesse.authentication.SecureResponder;
import fitnesse.html.template.HtmlPage;
import fitnesse.html.template.PageTitle;
import fitnesse.http.Request;
import fitnesse.http.Response;
import fitnesse.http.Response.Format;
import fitnesse.http.SimpleResponse;
import fitnesse.responders.ErrorResponder;
import fitnesse.reporting.history.ExecutionReport;
import fitnesse.reporting.history.PageHistory;
import fitnesse.reporting.history.SuiteExecutionReport;
import fitnesse.reporting.history.TestExecutionReport;
import fitnesse.html.template.HtmlPage;
import fitnesse.html.template.PageTitle;
import fitnesse.reporting.history.TestHistory;
import fitnesse.reporting.history.TestResultRecord;
import fitnesse.responders.ErrorResponder;
import fitnesse.testsystems.ExecutionResult;
import fitnesse.wiki.PathParser;
import org.apache.velocity.VelocityContext;
import util.FileUtil;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class PageHistoryResponder implements SecureResponder {
private SimpleDateFormat dateFormat = new SimpleDateFormat(PageHistory.TEST_RESULT_FILE_DATE_PATTERN);
private SimpleDateFormat dateFormat = PageHistory.getDateFormat();
private SimpleResponse response;
private PageHistory pageHistory;
private HtmlPage page;
Expand Down
Loading

0 comments on commit f47b28d

Please sign in to comment.