From b2233f4d08e922416c1c10080744e6dd5513be9b Mon Sep 17 00:00:00 2001 From: Benjamin Jones Date: Mon, 12 Nov 2012 18:07:51 -0800 Subject: initial commit of headless rule set tester --- .../java/com/galois/fiveui/BatchExecutorTest.java | 109 +++++++++++++++++++++ .../test/java/com/galois/fiveui/HeadlessTest.java | 104 ++++++++++++++++++++ .../src/test/resources/ruleSets/emptyRuleSet.json | 4 + .../test/resources/ruleSets/headingGuidelines.json | 37 +++++++ .../runDescriptions/headlessRunTest0.json | 4 + .../runDescriptions/headlessRunTestCNN.json | 4 + .../runDescriptions/headlessRunTestGalois.json | 11 +++ .../resources/runDescriptions/headlessSample0.json | 4 + .../resources/runDescriptions/headlessSample1.json | 4 + .../resources/runDescriptions/headlessSample2.json | 9 ++ 10 files changed, 290 insertions(+) create mode 100644 headless/src/test/java/com/galois/fiveui/BatchExecutorTest.java create mode 100644 headless/src/test/java/com/galois/fiveui/HeadlessTest.java create mode 100644 headless/src/test/resources/ruleSets/emptyRuleSet.json create mode 100644 headless/src/test/resources/ruleSets/headingGuidelines.json create mode 100644 headless/src/test/resources/runDescriptions/headlessRunTest0.json create mode 100644 headless/src/test/resources/runDescriptions/headlessRunTestCNN.json create mode 100644 headless/src/test/resources/runDescriptions/headlessRunTestGalois.json create mode 100644 headless/src/test/resources/runDescriptions/headlessSample0.json create mode 100644 headless/src/test/resources/runDescriptions/headlessSample1.json create mode 100644 headless/src/test/resources/runDescriptions/headlessSample2.json (limited to 'headless/src/test') diff --git a/headless/src/test/java/com/galois/fiveui/BatchExecutorTest.java b/headless/src/test/java/com/galois/fiveui/BatchExecutorTest.java new file mode 100644 index 0000000..f72c5a1 --- /dev/null +++ b/headless/src/test/java/com/galois/fiveui/BatchExecutorTest.java @@ -0,0 +1,109 @@ +/** + * Module : BatchExecutorTest.java + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Portable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.galois.fiveui; + +import java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.WebDriver; + +import com.galois.fiveui.BatchRunner; +import com.galois.fiveui.HeadlessRunDescription; +import com.galois.fiveui.Result; +import com.galois.fiveui.drivers.Drivers; +import com.google.common.collect.ImmutableList; + +import junit.framework.Assert; + + +/** + * @author bjones + * + */ +public class BatchExecutorTest { + + private static final String RUN_DESCRIPTION_DIR = "src/test/resources/runDescriptions/"; + + @Test + public void simpleTest() { + Assert.assertEquals("Booleans are not equal.", true, true); + } + + /** + * This unit test requires that a webserver be running locally on port 8000, + * what it serves does not matter. + * + * @throws IOException + * @throws FileNotFoundException + */ + @Test + public void headlessRunTest0() throws IOException { + String jsonFileName = RUN_DESCRIPTION_DIR + "headlessRunTest0.json"; + testHeadlessRun(jsonFileName); + } + + /** + * This unit test requires internet access to http://www.cnn.com + * + * @throws IOException + * @throws FileNotFoundException + */ + @Test + public void headlessRunTestCNN() throws IOException { + String jsonFileName = RUN_DESCRIPTION_DIR + "headlessRunTestCNN.json"; + testHeadlessRun(jsonFileName); + } + + /** + * This unit test requires internet access to http://www.cnn.com + * + * @throws IOException + * @throws FileNotFoundException + */ + @Test + public void headlessRunTestMil() throws IOException { + String jsonFileName = RUN_DESCRIPTION_DIR + "headlessRunTestMil.json"; + testHeadlessRun(jsonFileName); + } + + /** + * Helper method for headless run unit tests. + * + * @param fn filename of a .json file containing a headless run description + */ + private static void testHeadlessRun(String fn) { + WebDriver driver = Drivers.buildFFDriver(); // initialize the webdriver + boolean flag = true; + try { + HeadlessRunDescription descr = HeadlessRunDescription.parse(fn); + BatchRunner runner = new BatchRunner(driver); // setup the batch runner + ImmutableList results = runner.runHeadless(descr); // excecute the run + System.out.println(results.toString()); // print out results + } catch (Exception e) { + System.err.println("testHeadlessRun: exception caught while running a headless run description"); + flag = false; + } finally { + driver.quit(); + } + assert(flag); + } + +} diff --git a/headless/src/test/java/com/galois/fiveui/HeadlessTest.java b/headless/src/test/java/com/galois/fiveui/HeadlessTest.java new file mode 100644 index 0000000..e878661 --- /dev/null +++ b/headless/src/test/java/com/galois/fiveui/HeadlessTest.java @@ -0,0 +1,104 @@ +/** + * + */ +package com.galois.fiveui; + +import java.io.IOException; + +import junit.framework.Assert; + +import org.junit.Test; + +import com.galois.fiveui.HeadlessAtom; +import com.galois.fiveui.HeadlessRunDescription; +import com.galois.fiveui.RuleSet; +import com.galois.fiveui.Utils; +import com.google.common.collect.ImmutableList; + +/** + * @author bjones + * + */ +public class HeadlessTest { + private static final String RUN_DESCRIPTION_DIR = "src/test/resources/runDescriptions/"; + + /** + * Test method for {@link com.galois.com.galois.fiveui.HeadlessRunDescription}, parses + * 'src/test/resources/runDescriptions/headlessSample0.json'. + * + * @throws IOException + */ + @Test + public final void testDeserialize_headlessSample0() throws IOException { + + String jsonFileName = RUN_DESCRIPTION_DIR + "headlessSample0.json"; + String ruleSetLoc = + RUN_DESCRIPTION_DIR + "../ruleSets/emptyRuleSet.json"; + RuleSet ruleSetOracle = RuleSet.parse(Utils.readFile(ruleSetLoc)); + HeadlessAtom headlessAtomOracle = + new HeadlessAtom("http://testhost", ruleSetOracle); + HeadlessRunDescription oracle = + new HeadlessRunDescription(ImmutableList.of(headlessAtomOracle)); + + HeadlessRunDescription actual = HeadlessRunDescription.parse(jsonFileName); + assertObjEqual("Object deserialized incorrectly.", oracle, actual); + } + + /** + * Test method for {@link com.galois.com.galois.fiveui.HeadlessRunDescription}, parses + * 'src/test/resources/runDescriptions/headlessSample1.json'. + * + * @throws IOException + */ + @Test + public final void testDeserialize_headlessSample1() throws IOException { + + String jsonFileName = RUN_DESCRIPTION_DIR + "headlessSample1.json"; + String ruleSetLoc = + RUN_DESCRIPTION_DIR + "../ruleSets/headingGuidelines.json"; + RuleSet ruleSetOracle = RuleSet.parse(Utils.readFile(ruleSetLoc)); + HeadlessAtom headlessAtomOracle = + new HeadlessAtom("http://testhost", ruleSetOracle); + HeadlessRunDescription oracle = + new HeadlessRunDescription(ImmutableList.of(headlessAtomOracle)); + + HeadlessRunDescription actual = HeadlessRunDescription.parse(jsonFileName); + assertObjEqual("Object deserialized incorrectly.", oracle, actual); + } + + /** + * Test method for {@link com.galois.com.galois.fiveui.HeadlessRunDescription}, parses + * 'src/test/resources/runDescriptions/headlessSample2.json'. + * + * @throws IOException + */ + @Test + public final void testDeserialize_headlessSample2() throws IOException { + + String jsonFileName = RUN_DESCRIPTION_DIR + "headlessSample2.json"; + // manually build first HeadlessAtom + String ruleSetLoc1 = + RUN_DESCRIPTION_DIR + "../ruleSets/emptyRuleSet.json"; + RuleSet ruleSetOracle1 = RuleSet.parse(Utils.readFile(ruleSetLoc1)); + HeadlessAtom headlessAtomOracle1 = + new HeadlessAtom("http://testhost1", ruleSetOracle1); + // manually build second HeadlessAtom + String ruleSetLoc2 = + RUN_DESCRIPTION_DIR + "../ruleSets/headingGuidelines.json"; + RuleSet ruleSetOracle2 = RuleSet.parse(Utils.readFile(ruleSetLoc2)); + HeadlessAtom headlessAtomOracle2 = + new HeadlessAtom("http://testhost2", ruleSetOracle2); + + HeadlessRunDescription oracle = + new HeadlessRunDescription(ImmutableList.of(headlessAtomOracle1, + headlessAtomOracle2)); + + HeadlessRunDescription actual = HeadlessRunDescription.parse(jsonFileName); + assertObjEqual("Object deserialized incorrectly.", oracle, actual); + } + + private void assertObjEqual(String msg, Object oracle, Object actual) { + Assert.assertTrue(msg + ";\n expected: "+oracle+"\n actual: "+actual, + oracle.equals(actual)); + } +} diff --git a/headless/src/test/resources/ruleSets/emptyRuleSet.json b/headless/src/test/resources/ruleSets/emptyRuleSet.json new file mode 100644 index 0000000..a01bc68 --- /dev/null +++ b/headless/src/test/resources/ruleSets/emptyRuleSet.json @@ -0,0 +1,4 @@ +{ "name": "emptyRuleSet" +, "description": "" +, "rules": [] +} diff --git a/headless/src/test/resources/ruleSets/headingGuidelines.json b/headless/src/test/resources/ruleSets/headingGuidelines.json new file mode 100644 index 0000000..be69fac --- /dev/null +++ b/headless/src/test/resources/ruleSets/headingGuidelines.json @@ -0,0 +1,37 @@ +{ "name": "Heading Guidelines" +, "description": "Guidelines pertaining to the formatting and content of headings." +, "rules": [ { "id": 1 + , "name": "Headings are capitalized" + , "description": "Check to see if all headings use leading capital letters." + , "rule": + function() { + var badHeadings = + fiveui.query(':header').filter( + function(idx) { + var ch = $(this).text()[0]; + if (ch) { + return (ch == ch.toLowerCase() ); + } else { + return false; + } + }); + $(badHeadings).map(function(idx, elt){ + report('Heading does not start with a capitol letter.', elt); + }); + + } + }, + { "id": 2 + , "name": "Disallow Empty Headers" + , "description": "Heading elements should contain text." + , "rule": function() { + fiveui.query(':header').each( + function(ix, elt) { + if($(elt).text() == '') { + report('Heading does not contain text', elt); + } + }); + } + } + ] +} \ No newline at end of file diff --git a/headless/src/test/resources/runDescriptions/headlessRunTest0.json b/headless/src/test/resources/runDescriptions/headlessRunTest0.json new file mode 100644 index 0000000..e6c4c3b --- /dev/null +++ b/headless/src/test/resources/runDescriptions/headlessRunTest0.json @@ -0,0 +1,4 @@ +[{ + 'url': 'http://localhost:8000', + 'ruleSet': '../ruleSets/emptyRuleSet.json' +}] diff --git a/headless/src/test/resources/runDescriptions/headlessRunTestCNN.json b/headless/src/test/resources/runDescriptions/headlessRunTestCNN.json new file mode 100644 index 0000000..07aaab8 --- /dev/null +++ b/headless/src/test/resources/runDescriptions/headlessRunTestCNN.json @@ -0,0 +1,4 @@ +[{ + 'url': 'http://www.cnn.com', + 'ruleSet': '../ruleSets/headingGuidelines.json' +}] diff --git a/headless/src/test/resources/runDescriptions/headlessRunTestGalois.json b/headless/src/test/resources/runDescriptions/headlessRunTestGalois.json new file mode 100644 index 0000000..d12f9b0 --- /dev/null +++ b/headless/src/test/resources/runDescriptions/headlessRunTestGalois.json @@ -0,0 +1,11 @@ +{ + 'rulePath' : '/Users/bjones/galois/FiveUI/exampleData/ruleSets', + 'crawlType' : 'none', + 'runs': [ + { 'url': 'http://corp.galois.com', 'ruleSet': 'colorRulesRF.json' }, + { 'url': 'http://corp.galois.com', 'ruleSet': 'emptyHeadings.json' }, + { 'url': 'http://corp.galois.com', 'ruleSet': 'fontRules.json' }, + { 'url': 'http://corp.galois.com', 'ruleSet': 'headingGuidelines.json' }, + { 'url': 'http://corp.galois.com', 'ruleSet': 'imageRules.json' } + ] +} diff --git a/headless/src/test/resources/runDescriptions/headlessSample0.json b/headless/src/test/resources/runDescriptions/headlessSample0.json new file mode 100644 index 0000000..2b3a51a --- /dev/null +++ b/headless/src/test/resources/runDescriptions/headlessSample0.json @@ -0,0 +1,4 @@ +[{ + 'url': 'http://testhost', + 'ruleSet': '../ruleSets/emptyRuleSet.json' +}] diff --git a/headless/src/test/resources/runDescriptions/headlessSample1.json b/headless/src/test/resources/runDescriptions/headlessSample1.json new file mode 100644 index 0000000..a3ee34d --- /dev/null +++ b/headless/src/test/resources/runDescriptions/headlessSample1.json @@ -0,0 +1,4 @@ +[{ + 'url': 'http://testhost', + 'ruleSet': '../ruleSets/headingGuidelines.json' +}] diff --git a/headless/src/test/resources/runDescriptions/headlessSample2.json b/headless/src/test/resources/runDescriptions/headlessSample2.json new file mode 100644 index 0000000..277bd4d --- /dev/null +++ b/headless/src/test/resources/runDescriptions/headlessSample2.json @@ -0,0 +1,9 @@ +[ +{ + 'url': 'http://testhost1', + 'ruleSet': '../ruleSets/emptyRuleSet.json' +}, +{ + 'url': 'http://testhost2', + 'ruleSet': '../ruleSets/headingGuidelines.json' +}] -- cgit v1.2.3