diff options
author | Benjamin Jones <bjones@galois.com> | 2013-07-05 16:01:03 -0700 |
---|---|---|
committer | Benjamin Jones <bjones@galois.com> | 2013-07-05 16:01:03 -0700 |
commit | 867f5c62c9e21790d305e7f43727c90e1d5628c2 (patch) | |
tree | 57ad8e17f2dcfc4f05ac5593fa94f6d0752793c8 /src | |
parent | 202cce4d8c124a80c6637459b9fffb33b50d167a (diff) |
get the unit tests working again
Diffstat (limited to 'src')
4 files changed, 101 insertions, 99 deletions
diff --git a/src/batchtools/headless/src/main/java/com/galois/fiveui/HeadlessRunDescription.java b/src/batchtools/headless/src/main/java/com/galois/fiveui/HeadlessRunDescription.java index 8b41fe4..a6b6402 100644 --- a/src/batchtools/headless/src/main/java/com/galois/fiveui/HeadlessRunDescription.java +++ b/src/batchtools/headless/src/main/java/com/galois/fiveui/HeadlessRunDescription.java @@ -111,13 +111,11 @@ public class HeadlessRunDescription { * @return string property or null if the prop doesn't resolve */ public static String objGetString(JsonObject obj, String prop) { - try { - return obj.get(prop).getAsString(); - } catch (NullPointerException e) { - logger.error("HeadlessRunDescription.parse: failed to lookup JSON property: " + prop); - logger.error(e.toString()); - return null; + JsonElement value = obj.get(prop); + if (null == value) { + logger.warn("HeadlessRunDescription.parse: failed to lookup JSON property: " + prop); } + return null == value ? null : value.getAsString(); } public HeadlessRunDescription deserialize(JsonElement json, Type typeOfT, @@ -136,15 +134,16 @@ public class HeadlessRunDescription { String ffProfile = objGetString(obj, "firefoxProfile"); if (null != ffProfile) { - ffProfile = runDescDir + File.separator + ffProfile; + ffProfile = runDescDir + File.separator + ffProfile; } _firefoxProfile = ffProfile; _crawlType = objGetString(obj, "crawlType"); arr = obj.get("runs").getAsJsonArray(); - } else if (json.isJsonArray()) { + } else if (json.isJsonArray()) { // description has only a list of URL/rule pairs ruleSetDir = _ctxDir; _crawlType = "none"; + _firefoxProfile = null; // indicates that webdriver setup code should make a blank temp profile arr = json.getAsJsonArray(); } else { reportError(json); diff --git a/src/batchtools/headless/src/main/java/com/galois/fiveui/Reporter.java b/src/batchtools/headless/src/main/java/com/galois/fiveui/Reporter.java index f0461d4..344e46d 100644 --- a/src/batchtools/headless/src/main/java/com/galois/fiveui/Reporter.java +++ b/src/batchtools/headless/src/main/java/com/galois/fiveui/Reporter.java @@ -254,8 +254,11 @@ public class Reporter { html.li().b().text("Severity:").end(); html.text(r.getType().toString()).end(); - html.li().b().text("Browser:").end(); - html.text(r.getDriver().toString()).end(); + html.li().b().text("Browser:").end(); + // unit tests use a null webdriver object + if (null != r.getDriver()) { + html.text(r.getDriver().toString()).end(); + } html.li().b().text("Url:").end(); html.a().href(r.getURL()).text(r.getURL()).end().end(); diff --git a/src/batchtools/headless/src/test/java/com/galois/fiveui/HeadlessRunnerTest.java b/src/batchtools/headless/src/test/java/com/galois/fiveui/HeadlessRunnerTest.java index 28954fd..22c5343 100644 --- a/src/batchtools/headless/src/test/java/com/galois/fiveui/HeadlessRunnerTest.java +++ b/src/batchtools/headless/src/test/java/com/galois/fiveui/HeadlessRunnerTest.java @@ -63,97 +63,97 @@ import com.google.common.collect.Lists; */ @RunWith(Parameterized.class) public class HeadlessRunnerTest { - private static Logger logger = - Logger.getLogger(HeadlessRunnerTest.class); + private static Logger logger = + Logger.getLogger(HeadlessRunnerTest.class); - static { - BasicConfigurator.configure(); + static { + BasicConfigurator.configure(); logger.setLevel(Level.DEBUG); Logger root = Logger.getRootLogger(); root.setLevel(Level.ERROR); - } - - /** - * Set up the tests via the parameterized runner: - * - * @return - * @throws Throwable - */ - @Parameters(name = "{0} {1}") - public static Collection<Object[]> buildtests() throws Throwable { - - List<Object[]> tests = Lists.newArrayList(); - - // webRoot, startingUrl, runDescr, oracle - Object[][] rawTests = new Object[][] { - { "../../../exampleData/sites/", - "src/test/resources/runDescriptions/headlessSample1.json", - ImmutableList.of(Result.error(null, "Headings are capitalized"), - Result.error(null, "Headings are capitalized"), - Result.error(null, "Disallow Empty Headers")) - }, - { - "../../../exampleData/sites/", - "src/test/resources/runDescriptions/headlessSample4.json", - ImmutableList.of(Result.error(null, "Generate Errors")) - }, - { - "../../../exampleData/sites/", - "src/test/resources/runDescriptions/headlessSample3.json", - ImmutableList.of(Result.error(null, "Generate Errors - custom")) - } - }; - - for (Object[] descr : rawTests) { - tests.add(descr); - } - - return tests; - } - - private final String _webRoot; - - private final String _runDescrPath; - - private final ImmutableList<Result> _oracle; - - private NanoHTTPD _httpServer; - - public HeadlessRunnerTest(String webRoot, String runDescrPath, - ImmutableList<Result> oracle) { - super(); - this._webRoot = webRoot; - this._runDescrPath = runDescrPath; - this._oracle = oracle; - } - - @Before - public void setup() { - File dir = new File(_webRoot); - int port = 8000; - logger.info("Starting NanoHTTPD webserver in " + dir.getAbsolutePath() + " on port "+port); - try { - _httpServer = new NanoHTTPD(port, dir); - } catch (BindException e) { - logger.debug("assuming that local web server is already running"); - } catch (IOException e1) { - e1.printStackTrace(); - Assert.assertTrue("failed to start NanoHTTPD in current directory " + dir.getAbsolutePath(), false); - } - } - - @After - public void teardown() { - _httpServer.stop(); - } - - @Test - public void test() throws FileNotFoundException { - HeadlessRunDescription descr = - HeadlessRunDescription.parse(_runDescrPath); - BatchRunner runner = new BatchRunner(); - ImmutableList<Result> actual = runner.runHeadless(descr); - Assert.assertEquals("Expected results differ from actual.", _oracle, actual); - } + } + + /** + * Set up the tests via the parameterized runner: + * + * @return + * @throws Throwable + */ + @Parameters(name = "{0} {1}") + public static Collection<Object[]> buildtests() throws Throwable { + + List<Object[]> tests = Lists.newArrayList(); + + // webRoot, startingUrl, runDescr, oracle + Object[][] rawTests = new Object[][] { + { "../../../exampleData/sites/", + "src/test/resources/runDescriptions/headlessSample1.json", + ImmutableList.of(Result.error(null, "Headings are capitalized"), + Result.error(null, "Headings are capitalized"), + Result.error(null, "Disallow Empty Headers")) + }, + { + "../../../exampleData/sites/", + "src/test/resources/runDescriptions/headlessSample4.json", + ImmutableList.of(Result.error(null, "Generate Errors")) + }, + { + "../../../exampleData/sites/", + "src/test/resources/runDescriptions/headlessSample3.json", + ImmutableList.of(Result.error(null, "Generate Errors - custom")) + } + }; + + for (Object[] descr : rawTests) { + tests.add(descr); + } + + return tests; + } + + private final String _webRoot; + + private final String _runDescrPath; + + private final ImmutableList<Result> _oracle; + + private NanoHTTPD _httpServer; + + public HeadlessRunnerTest(String webRoot, String runDescrPath, + ImmutableList<Result> oracle) { + super(); + this._webRoot = webRoot; + this._runDescrPath = runDescrPath; + this._oracle = oracle; + } + + @Before + public void setup() { + File dir = new File(_webRoot); + int port = 8000; + logger.info("Starting NanoHTTPD webserver in " + dir.getAbsolutePath() + " on port "+port); + try { + _httpServer = new NanoHTTPD(port, dir); + } catch (BindException e) { + logger.debug("assuming that local web server is already running"); + } catch (IOException e1) { + e1.printStackTrace(); + Assert.assertTrue("failed to start NanoHTTPD in current directory " + dir.getAbsolutePath(), false); + } + } + + @After + public void teardown() { + _httpServer.stop(); + } + + @Test + public void test() throws FileNotFoundException { + HeadlessRunDescription descr = + HeadlessRunDescription.parse(_runDescrPath); + BatchRunner runner = new BatchRunner(); + ImmutableList<Result> actual = runner.runHeadless(descr); + Assert.assertEquals("Expected results differ from actual.", _oracle, actual); + } } diff --git a/src/batchtools/rsTester/src/main/java/com/galois/fiveui/RuleSetTester.java b/src/batchtools/rsTester/src/main/java/com/galois/fiveui/RuleSetTester.java index 3c85b22..33594e5 100644 --- a/src/batchtools/rsTester/src/main/java/com/galois/fiveui/RuleSetTester.java +++ b/src/batchtools/rsTester/src/main/java/com/galois/fiveui/RuleSetTester.java @@ -72,7 +72,7 @@ public class RuleSetTester { private static ImmutableList<WebDriver> getDrivers() { return ImmutableList.<WebDriver>of( - Drivers.buildFFDriver() + Drivers.buildFFDriver("") // , Drivers.buildChromeDriver() ); } |