aboutsummaryrefslogtreecommitdiff
path: root/headless
diff options
context:
space:
mode:
authorGravatar Benjamin Jones <bjones@galois.com>2012-12-12 15:42:29 -0800
committerGravatar Benjamin Jones <bjones@galois.com>2012-12-12 15:42:29 -0800
commiteea0cd57534e981ec15ffb7864c1372843d4f95f (patch)
tree8742c8b5befed746d57104530bec08ba5108ab7a /headless
parent198bbd0bdbc01e8caafcdcb70304dee8cbba4487 (diff)
updated BatchRunner and Reporter classes to take advantage of refectored Result class
Diffstat (limited to 'headless')
-rw-r--r--headless/src/main/java/com/galois/fiveui/BatchRunner.java32
-rw-r--r--headless/src/main/java/com/galois/fiveui/Reporter.java87
-rw-r--r--headless/src/test/java/com/galois/fiveui/ReporterTest.java33
3 files changed, 93 insertions, 59 deletions
diff --git a/headless/src/main/java/com/galois/fiveui/BatchRunner.java b/headless/src/main/java/com/galois/fiveui/BatchRunner.java
index 61c7984..639c7a2 100644
--- a/headless/src/main/java/com/galois/fiveui/BatchRunner.java
+++ b/headless/src/main/java/com/galois/fiveui/BatchRunner.java
@@ -139,7 +139,8 @@ public class BatchRunner {
} catch (Exception e) {
String errStr = "failed to complete webcrawl of" + seedUrl + "\n";
errStr += e.toString();
- builder.add(Result.exception(_driver, errStr));
+ builder.add(new Result(ResType.Exception, _driver, errStr, seedUrl,
+ rs.getName(), rs.getDescription(), ""));
logger.error(errStr);
continue;
} finally {
@@ -163,7 +164,8 @@ public class BatchRunner {
} catch (Exception e) {
String errStr = "exception during runRule: " + rs.getName() + "\n";
errStr += e.toString();
- builder.add(Result.exception(_driver, errStr));
+ builder.add(new Result(ResType.Exception, _driver, errStr, url,
+ rs.getName(), rs.getDescription(), ""));
logger.error(errStr);
}
try {
@@ -213,8 +215,8 @@ public class BatchRunner {
if (res.getClass() == String.class) {
// we received an error via the expected mechanisms:
logger.error("exception running rule: " + res);
- builder.add(Result.exception(_driver,
- (String) res + ", state: " + state));
+ builder.add(new Result(ResType.Exception, _driver, "", _driver.getCurrentUrl(),
+ ruleSet.getName(), ruleSet.getDescription(), ""));
return builder.build();
} else {
try {
@@ -222,9 +224,9 @@ public class BatchRunner {
List<Map<String, Map<String, String>>> results = (List) res;
if (0 == results.size()) {
- builder.add(Result.pass(_driver,
+ builder.add(new Result(ResType.Pass, _driver,
"passed " + ruleSet.getRules().size() + " tests",
- _driver.getCurrentUrl(), ruleSet.getName()));
+ _driver.getCurrentUrl(), ruleSet.getName(), ruleSet.getDescription(), ""));
}
for (Map<String, Map<String, String>> r : results) {
@@ -234,16 +236,22 @@ public class BatchRunner {
//
// Probably we should just pass along the Map<String, String>
// and let the reporter deal with it.
- builder.add(Result.error(_driver, problem.toString(),
- _driver.getCurrentUrl(),
- ruleSet.getName()));
+ builder.add(new Result(ResType.Error, _driver, "",
+ _driver.getCurrentUrl(),
+ ruleSet.getName(),
+ ruleSet.getDescription(),
+ problem.toString()));
}
} catch (ClassCastException e) {
// An unexpected error happened:
- builder.add(Result.exception(_driver, "Unexpected object returned: "
- + res + ", state: " + state));
- logger.error("unexpected object returned: " + e.toString());
+ logger.error("unexpected object returned: " + e.toString());
+ builder.add(new Result(ResType.Exception, _driver,
+ "Unexpected object returned: " + res + ", state: " + state,
+ _driver.getCurrentUrl(),
+ ruleSet.getName(),
+ ruleSet.getDescription(),
+ ""));
}
}
return builder.build();
diff --git a/headless/src/main/java/com/galois/fiveui/Reporter.java b/headless/src/main/java/com/galois/fiveui/Reporter.java
index 7fc1a4e..a1d8b9a 100644
--- a/headless/src/main/java/com/galois/fiveui/Reporter.java
+++ b/headless/src/main/java/com/galois/fiveui/Reporter.java
@@ -47,19 +47,22 @@ import com.googlecode.jatl.Html;
public class Reporter {
/** see sortBy* and computeSummaryStats methods for map semantics */
- private final Map<String, List<String>> _byURLMap;
- private final Map<String, List<String>> _byRuleMap;
+ private final Map<String, List<Result>> _byURLMap;
+ private final Map<String, List<Result>> _byRuleMap;
private final Map<String, int[]> _passFailMap;
+ private Map<String, String> _ruleNameToDesc;
private static String GLOBAL_CSS =
"h1 { font-size: 150%; }" +
"h2 { font-size: 110%; }" +
+ "li { margin: 5 0 0 0; }" +
"table { border: 1px solid grey; cellpadding: 5%; width: 200px; }\n" +
"td.pass-number{ text-align: right;color: green; }\n" +
"td.fail-number{ text-align: right;color: red; }\n" +
"td.text{ text-align: left; }\n" +
"th { font-weight: bold; }\n" +
"td, th { border: 1px solid grey; }\n" +
- "tr.hlRow { background: #EEEEEE; }\n";
+ ".hlRow { background: #EEEEEE; }\n" +
+ ".regRow { background: #FFFFFF; }\n";
/**
* Construct a Reporter object. The constructor takes a list of results
@@ -71,6 +74,7 @@ public class Reporter {
this._byURLMap = sortByURL(results);
this._byRuleMap = sortByRule(results);
this._passFailMap = computeSummaryStats(results);
+ this._ruleNameToDesc = extractRuleDesc(results);
}
/**
@@ -148,7 +152,7 @@ public class Reporter {
*/
public String getByURL() {
StringWriter byURLPage = new StringWriter();
- final Map<String, List<String>> scopedMap = this._byURLMap;
+ final Map<String, List<Result>> scopedMap = this._byURLMap;
Html page = new Html(byURLPage);
page = makeHead(page, "Results sorted by URL");
page = new Html(page) {{
@@ -161,8 +165,12 @@ public class Reporter {
for (String url: sortedKeys) {
li().h2().a().href(url).text(url).end().end();
ul();
- for (String entry: scopedMap.get(url)) {
- li().text(entry).end();
+ int i = 0;
+ for (Result r: scopedMap.get(url)) {
+ li().classAttr(i % 2 == 0 ? "regRow" : "hlRow");
+ text(r.getRuleName() + ": " + r.getRuleDesc()).br();
+ text(r.getProblem()).end();
+ i++;
}
end();
end();
@@ -180,7 +188,8 @@ public class Reporter {
*/
public String getByRule() {
StringWriter byRulePage = new StringWriter();
- final Map<String, List<String>> scopedMap = this._byRuleMap;
+ final Map<String, List<Result>> scopedMap = this._byRuleMap;
+ final Map<String, String> scopedRuleNameToDesc = this._ruleNameToDesc;
Html page = new Html(byRulePage);
page = makeHead(page, "Results sorted by rule");
page = new Html(page) {{
@@ -190,10 +199,15 @@ public class Reporter {
sortedKeys.addAll(scopedMap.keySet());
Collections.sort(sortedKeys);
for (String rule: sortedKeys) {
- li().h2().text(rule).end();
+ li();
+ b().text(rule).end().text(": " + scopedRuleNameToDesc.get(rule));
ul();
- for (String url: scopedMap.get(rule)) {
- li().a().href(url).text(url).end().end();
+ int i = 0;
+ for (Result r: scopedMap.get(rule)) {
+ li().classAttr(i % 2 == 0 ? "regRow" : "hlRow");
+ text("Problem: " + r.getProblem()).br();
+ text("URL: ").a().href(r.getURL()).text(r.getURL()).end().end();
+ i++;
}
end();
end();
@@ -237,28 +251,25 @@ public class Reporter {
}
/**
- * Populate a Map<String, List<String>> representing the results sorted by
+ * Populate a Map<String, List<Result>> representing the results sorted by
* URL.
*
* @param results a list of results
* @return a map representing the results sorted by URL.
*/
- private Map<String, List<String>>sortByURL(List<Result> results) {
+ private Map<String, List<Result>>sortByURL(List<Result> results) {
/** map semantics: Map< url, [rule1, rule2, ...] > */
- Map<String, List<String>> map = new HashMap<String, List<String>>();
- String url, rule;
- List<String> list;
- ResType type;
+ Map<String, List<Result>> map = new HashMap<String, List<Result>>();
+ String url;
+ List<Result> list;
for (Result r: results) {
url = r.getURL();
- rule = r.getRuleName();
- type = r.getType();
if (map.containsKey(url)) {
list = map.get(url);
- list.add(type.toString() + ": " + rule);
+ list.add(r);
} else {
- list = new ArrayList<String>();
- list.add(type.toString() + ": " + rule);
+ list = new ArrayList<Result>();
+ list.add(r);
map.put(url, list);
}
}
@@ -266,32 +277,46 @@ public class Reporter {
}
/**
- * Populate a Map<String, List<String>> representing the results sorted by
+ * Populate a Map<String, List<Result>> representing the results sorted by
* rule name.
*
* @param results a list of results
* @return a map representing the results sorted by rule name.
*/
- private Map<String, List<String>>sortByRule(List<Result> results) {
+ private Map<String, List<Result>>sortByRule(List<Result> results) {
/** map semantics: Map< rule, [url1, url2, ...] > */
- Map<String, List<String>> map = new HashMap<String, List<String>>();
- String url, rule;
- List<String> list;
+ Map<String, List<Result>> map = new HashMap<String, List<Result>>();
+ String rule;
+ List<Result> list;
for (Result r: results) {
- url = r.getURL();
rule = r.getRuleName();
if (map.containsKey(rule)) {
list = map.get(rule);
- list.add(url);
+ list.add(r);
} else {
- list = new ArrayList<String>();
- list.add(url);
+ list = new ArrayList<Result>();
+ list.add(r);
map.put(rule, list);
}
}
return map;
}
+ /**
+ * Build a map of ruleName -> ruleDesc entries occurring in the given list of
+ * results.
+ *
+ * @param results a list of results
+ * @return a map associating rule names to rule descriptions
+ */
+ private Map<String, String> extractRuleDesc(List<Result> results) {
+ Map<String, String> assoc = new HashMap<String, String>();
+ for (Result r: results)
+ if (!assoc.containsKey(r.getRuleName()))
+ assoc.put(r.getRuleName(), r.getRuleDesc());
+ return assoc;
+ }
+
/**
* Compute summary statistics from the results list. This includes number of
* passes and fails for each URL checked.
@@ -313,7 +338,7 @@ public class Reporter {
url = result.getURL();
if (result.getType() == ResType.Pass) {
// now we have to parse out how many tests passed
- matcher = numberPassedPattern.matcher(result.getDesc());
+ matcher = numberPassedPattern.matcher(result.getMsg());
if (matcher.find())
pass = Integer.parseInt(matcher.group(1)); // throws exception if parse fails
} else if (result.getType() == ResType.Error) {
diff --git a/headless/src/test/java/com/galois/fiveui/ReporterTest.java b/headless/src/test/java/com/galois/fiveui/ReporterTest.java
index 3896a75..39a8e5c 100644
--- a/headless/src/test/java/com/galois/fiveui/ReporterTest.java
+++ b/headless/src/test/java/com/galois/fiveui/ReporterTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import org.junit.Test;
+import org.openqa.selenium.WebDriver;
import com.google.common.collect.ImmutableList;
@@ -32,9 +33,9 @@ public class ReporterTest {
@Test
public void testConstructor() {
ImmutableList<Result> r = ImmutableList.of(
- Result.pass(null, "OK", "http://nonexistant", "test rule 1"),
- Result.pass(null, "OK", "http://intransigent", "test rule 1"),
- Result.error(null, "ERROR", "http://nonexistant", "test rule 2"));
+ new Result(ResType.Pass, (WebDriver) null, "OK", "http://nonexistant", "test rule 1", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Pass, (WebDriver) null, "OK", "http://intransigent", "test rule 1", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Error, (WebDriver) null, "ERROR", "http://nonexistant", "test rule 2", "a desc or test rule 1", "problem!"));
Reporter kermit = new Reporter(r);
System.out.println("Summary page size: " + kermit.getSummary().length() + " bytes");
System.out.println("Summary page size: " + kermit.getByURL().length() + " bytes");
@@ -50,19 +51,19 @@ public class ReporterTest {
File tmpPath = new File("/tmp/");
System.out.println("Writing test summary page to: " + tmpPath.toString() + File.separator);
ImmutableList<Result> r = ImmutableList.of(
- Result.pass(null, "OK", "http://nonexistant", "test rule 1"),
- Result.pass(null, "OK", "http://intransigent", "test rule 1"),
- Result.pass(null, "OK", "http://intransigent", "test rule 3"),
- Result.pass(null, "OK", "http://intransigent", "test rule 4"),
- Result.pass(null, "OK", "http://intransigent", "test rule 5"),
- Result.pass(null, "OK", "http://foo.com", "test rule 1"),
- Result.error(null, "ERROR", "http://foo.com", "test rule 5"),
- Result.error(null, "ERROR", "http://foo.com", "test rule 2"),
- Result.error(null, "ERROR", "http://bar.com", "test rule 3"),
- Result.error(null, "ERROR", "http://bar.com", "test rule 3"), // multiple fails for same url+rule combo
- Result.error(null, "ERROR", "http://bar.com", "test rule 3"),
- Result.error(null, "ERROR", "http://bar.com", "test rule 3"),
- Result.error(null, "ERROR", "http://nonexistant", "test rule 2"));
+ new Result(ResType.Pass, (WebDriver) null, "OK", "http://nonexistant", "test rule 1", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Pass, (WebDriver) null, "OK", "http://intransigent", "test rule 1", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Pass, (WebDriver) null, "OK", "http://intransigent", "test rule 3", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Pass, (WebDriver) null, "OK", "http://intransigent", "test rule 4", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Pass, (WebDriver) null, "OK", "http://intransigent", "test rule 5", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Pass, (WebDriver) null, "OK", "http://foo.com", "test rule 1", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Error, (WebDriver) null, "ERROR", "http://foo.com", "test rule 5", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Error, (WebDriver) null, "ERROR", "http://foo.com", "test rule 2", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Error, (WebDriver) null, "ERROR", "http://bar.com", "test rule 3", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Error, (WebDriver) null, "ERROR", "http://bar.com", "test rule 3", "a desc or test rule 1", "problem!"), // multiple fails for same url+rule combo
+ new Result(ResType.Error, (WebDriver) null, "ERROR", "http://bar.com", "test rule 3", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Error, (WebDriver) null, "ERROR", "http://bar.com", "test rule 3", "a desc or test rule 1", "problem!"),
+ new Result(ResType.Error, (WebDriver) null, "ERROR", "http://nonexistant", "test rule 2", "a desc or test rule 1", "problem!"));
Reporter kermit = new Reporter(r);
kermit.writeReportsToDir(tmpPath.toString());
assertTrue("made it!", true);