Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/disable test history #1494

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The test result files are named using the following scheme !style_code(YYYYMMDDH

The test files contain the XML that describes the test run. The format of this XML is identical to the XML packet returned by the format=xml flag when you run a test. (See <UserGuide.RestfulTests).

You also have the possibility to disable !style_code(Test Histories) for a selected page by going to the !style_code(?properties) page and check the ''!-DisableTestHistory-!'' option. Setting this property on a Suite, will disable the !style_code(Test Histories) for the whole Suite.

!4 Purging
There are buttons at the top of the ''Test History'' page that allow you to purge old history files. You have your choice of ''all'', ''>7 days'', or ''>30 days''. If you want to purge a different number of days, you can use the RESTful URL form. (See [[!-RestfulServices-!][<UserGuide.AdministeringFitNesse.RestfulServices]]).

Expand Down
6 changes: 5 additions & 1 deletion src/fitnesse/reporting/history/TestXmlFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import fitnesse.util.TimeMeasurement;
import fitnesse.wiki.PageData;
import fitnesse.wiki.WikiPage;
import fitnesse.wiki.WikiPageProperty;
import fitnesse.wiki.WikiPageUtil;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
Expand Down Expand Up @@ -174,7 +175,10 @@ protected void setTotalRunTimeOnReport(TimeMeasurement totalTimeMeasurement) {
}

protected void writeResults() throws IOException {
writeResults(writerFactory.getWriter(context, getPage(), getPageCounts(), totalTimeMeasurement.startedAt()));
if (!getPage().getData().hasAttribute(WikiPageProperty.DISABLE_TESTHISTORY)) {
writeResults(writerFactory.getWriter(context, getPage(), getPageCounts(),
totalTimeMeasurement.startedAt()));
}
}

@Override
Expand Down
9 changes: 9 additions & 0 deletions src/fitnesse/resources/templates/propertiesPage.vm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
<label for="$security"><input type="checkbox" id="$security" name="$security"#checked( $security )/>$security</label>
#end
</fieldset>

#if ($disableTypes.size() > 0)
<fieldset>
<legend>Disable:</legend>
#foreach( $disableType in $disableTypes )
<label for="$disableType"><input type="checkbox" id="$disableType" name="$disableType"#checked( $disableType )/>$disableType</label>
#end
</fieldset>
#end
</div>

<div class="virtual-wiki-properties">
Expand Down
9 changes: 8 additions & 1 deletion src/fitnesse/responders/editing/PropertiesResponder.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
import java.util.Set;

import static fitnesse.wiki.PageData.ACTION_ATTRIBUTES;
import static fitnesse.wiki.PageData.DISABLE_ATTRIBUTES;
import static fitnesse.wiki.PageData.NAVIGATION_ATTRIBUTES;
import static fitnesse.wiki.PageData.PAGE_TYPE_ATTRIBUTES;
import static fitnesse.wiki.PageData.SECURITY_ATTRIBUTES;
import static fitnesse.wiki.PageType.SUITE;
import static fitnesse.wiki.PageType.TEST;
import static fitnesse.wiki.WikiPageProperty.DISABLE_TESTHISTORY;
import static fitnesse.wiki.WikiPageProperty.EDIT;
import static fitnesse.wiki.WikiPageProperty.FILES;
import static fitnesse.wiki.WikiPageProperty.HELP;
Expand Down Expand Up @@ -99,7 +101,7 @@ private JSONObject makeJson() {
EDIT, PROPERTIES, VERSIONS, REFACTOR,
WHERE_USED, RECENT_CHANGES, SUITE.toString(),
PRUNE, SECURE_READ, SECURE_WRITE,
SECURE_TEST, FILES };
SECURE_TEST, FILES, DISABLE_TESTHISTORY };
for (String attribute : attributes)
addJsonAttribute(jsonObject, attribute);
if (pageData.hasAttribute(HELP)) {
Expand Down Expand Up @@ -180,6 +182,7 @@ private void makePropertiesForm() {
makeTestActionCheckboxesHtml();
makeNavigationCheckboxesHtml();
makeSecurityCheckboxesHtml();
makeDisableCheckboxesHtml();
}

public void makePageTypeRadiosHtml(PageData pageData) {
Expand Down Expand Up @@ -261,6 +264,10 @@ public void makeNavigationCheckboxesHtml() {
public void makeSecurityCheckboxesHtml() {
html.put("securityTypes", SECURITY_ATTRIBUTES);
}

public void makeDisableCheckboxesHtml() {
html.put("disableTypes", DISABLE_ATTRIBUTES);
}


public static class Symlink {
Expand Down
4 changes: 3 additions & 1 deletion src/fitnesse/responders/run/SuiteResponder.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import fitnesse.wiki.WikiImportProperty;
import fitnesse.wiki.WikiPage;
import fitnesse.wiki.WikiPagePath;
import fitnesse.wiki.WikiPageProperty;
import fitnesse.wiki.WikiPageUtil;
import org.apache.commons.lang3.StringUtils;
import util.FileUtil;
Expand Down Expand Up @@ -262,7 +263,8 @@ protected void addFormatters(MultipleTestsRunner runner) {
}

private boolean withSuiteHistoryFormatter() {
return !request.hasInput("nohistory");
return !request.hasInput("nohistory")
&& !page.getData().hasAttribute(WikiPageProperty.DISABLE_TESTHISTORY);
}

protected void addHistoryFormatter(MultipleTestsRunner runner) {
Expand Down
8 changes: 6 additions & 2 deletions src/fitnesse/wiki/PageData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.wiki;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.stream.Stream;

import static fitnesse.wiki.PageType.*;

Expand Down Expand Up @@ -55,7 +55,11 @@ public class PageData implements ReadOnlyPageData, Serializable {
public static final String[] NAVIGATION_ATTRIBUTES = {
WikiPageProperty.RECENT_CHANGES, WikiPageProperty.FILES, WikiPageProperty.SEARCH };

public static final String[] NON_SECURITY_ATTRIBUTES = ArrayUtils.addAll(ACTION_ATTRIBUTES, NAVIGATION_ATTRIBUTES);
public static final String[] DISABLE_ATTRIBUTES = { WikiPageProperty.DISABLE_TESTHISTORY };

public static final String[] NON_SECURITY_ATTRIBUTES = Stream
.of(ACTION_ATTRIBUTES, NAVIGATION_ATTRIBUTES, DISABLE_ATTRIBUTES)
.flatMap(Stream::of).toArray(String[]::new);

@Deprecated
public static final String PropertySECURE_READ = WikiPageProperty.SECURE_READ;
Expand Down
1 change: 1 addition & 0 deletions src/fitnesse/wiki/WikiPageProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class WikiPageProperty implements Serializable {
public static final String VERSIONS = "Versions";
public static final String EDIT = "Edit";
public static final String SUITES = "Suites";
public static final String DISABLE_TESTHISTORY = "DisableTestHistory";

public static final String SECURE_READ = "secure-read";
public static final String SECURE_WRITE = "secure-write";
Expand Down
21 changes: 21 additions & 0 deletions test/fitnesse/reporting/history/TestXmlFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import fitnesse.wiki.PageData;
import fitnesse.wiki.WikiPage;
import fitnesse.wiki.WikiPageDummy;
import fitnesse.wiki.WikiPageProperty;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -33,6 +34,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

public class TestXmlFormatterTest {
Expand Down Expand Up @@ -221,4 +223,23 @@ public Writer getWriter(FitNesseContext context, WikiPage page, TestSummary coun
});
}

@Test
public void shouldNotCreateTestHistory() throws Exception {
WikiTestPage page = new WikiTestPage(new WikiPageDummy("name", "content", null));
page.getData().setAttribute(WikiPageProperty.DISABLE_TESTHISTORY, "true");
final LinkedList<StringWriter> writers = new LinkedList<>();
try (TestXmlFormatter formatter = new TestXmlFormatter(context,
page.getSourcePage(), new WriterFactory() {
@Override
public Writer getWriter(FitNesseContext context, WikiPage page,
TestSummary counts, long time) throws IOException {
StringWriter writer = new StringWriter();
writers.add(writer);
return writer;
}
})) {
}

assertTrue(writers.isEmpty());
}
}
15 changes: 14 additions & 1 deletion test/fitnesse/responders/editing/PropertiesResponderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public void testResponse() throws Exception {
for (String attribute : new String[]{"Search", "Edit", "Properties", "Versions", "Refactor", "WhereUsed", "RecentChanges"})
assertCheckboxChecked(attribute, content);

for (String attribute : new String[]{"Prune", WikiPageProperty.SECURE_READ, WikiPageProperty.SECURE_WRITE, WikiPageProperty.SECURE_TEST})
for (String attribute : new String[] { "Prune",
WikiPageProperty.SECURE_READ, WikiPageProperty.SECURE_WRITE,
WikiPageProperty.SECURE_TEST, WikiPageProperty.DISABLE_TESTHISTORY })
assertCheckboxNotChecked(content, attribute);
}

Expand Down Expand Up @@ -119,6 +121,7 @@ public void testJsonResponse() throws Exception {
assertFalse(jsonObject.getBoolean(WikiImportProperty.SECURE_READ));
assertFalse(jsonObject.getBoolean(WikiImportProperty.SECURE_WRITE));
assertFalse(jsonObject.getBoolean(WikiImportProperty.SECURE_TEST));
assertFalse(jsonObject.getBoolean(WikiImportProperty.DISABLE_TESTHISTORY));
}

@Test
Expand Down Expand Up @@ -151,6 +154,7 @@ public void testJsonResponseWithHelpTextAndTags() throws Exception {
assertFalse(jsonObject.getBoolean(WikiPageProperty.SECURE_READ));
assertFalse(jsonObject.getBoolean(WikiPageProperty.SECURE_WRITE));
assertFalse(jsonObject.getBoolean(WikiPageProperty.SECURE_TEST));
assertFalse(jsonObject.getBoolean(WikiPageProperty.DISABLE_TESTHISTORY));
}


Expand Down Expand Up @@ -388,6 +392,15 @@ public void testMakeSecurityPropertiesHtml() throws Exception {
assertSubString("<input type=\"checkbox\" id=\"secure-write\" name=\"secure-write\"/>", html);
assertSubString("<input type=\"checkbox\" id=\"secure-test\" name=\"secure-test\"/>", html);
}

@Test
public void testMakeTestHistoryPropertiesHtml() throws Exception {
SimpleResponse response = (SimpleResponse) new PropertiesResponder().makeResponse(context, request);
String html = response.getContent();
assertSubString("Disable:", html);
assertSubString("<input type=\"checkbox\" id=\"" + WikiPageProperty.DISABLE_TESTHISTORY + "\" name=\""
+ WikiPageProperty.DISABLE_TESTHISTORY + "\"/>", html);
}

@Test
public void testEmptySuitesForm() throws Exception {
Expand Down
20 changes: 20 additions & 0 deletions test/fitnesse/responders/run/SuiteResponderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import fitnesse.wiki.PageData;
import fitnesse.wiki.PathParser;
import fitnesse.wiki.WikiPage;
import fitnesse.wiki.WikiPageProperty;
import fitnesse.wiki.WikiPageUtil;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -483,6 +484,25 @@ public void NoHistory_avoidsProducingSuiteResultFile() throws Exception {
assertFalse(xmlResultsFile.exists());
}

@Test
public void DisableHistory_avoidsProducingSuiteResultFile() throws Exception {
File xmlResultsFile = expectedXmlResultsFile();

if (xmlResultsFile.exists())
xmlResultsFile.delete();

PageData data = suite.getData();
data.setAttribute(WikiPageProperty.DISABLE_TESTHISTORY);
suite.commit(data);
suite.getData();
responder.page = suite;

addTestToSuite("SlimTestOne", simpleSlimDecisionTable);
addTestToSuite("SlimTestTwo", simpleSlimDecisionTable);
runSuite();
assertFalse(xmlResultsFile.exists());
}

@Test
public void Includehtml_producesHTMLResultsInXMLSuite() throws Exception {
request.addInput("format", "xml");
Expand Down