From a8664102395dc9c899428ea6e31a64ff6f22046e Mon Sep 17 00:00:00 2001 From: Rogan Creswick Date: Sun, 2 Sep 2012 14:10:01 -0700 Subject: refactored the java-based apps: testrunner, rstester, batch-executor --- .../java/com/galois/fiveui/BatchExecutorTest.java | 38 ++++++++++ .../test/java/com/galois/fiveui/RuleSetTest.java | 57 +++++++++++++++ .../java/com/galois/fiveui/RunDescriptionTest.java | 82 ++++++++++++++++++++++ .../src/test/resources/ruleSets/emptyRuleSet.json | 4 ++ .../test/resources/ruleSets/headingGuidelines.json | 37 ++++++++++ .../test/resources/ruleSets/simpleRuleSet1.json | 9 +++ .../resources/runDescriptions/headingSample.json | 13 ++++ .../test/resources/runDescriptions/sample0.json | 4 ++ .../test/resources/runDescriptions/sample1.json | 4 ++ .../test/resources/runDescriptions/sample2.json | 10 +++ .../test/resources/runDescriptions/sample3.json | 7 ++ .../test/resources/runDescriptions/sample4.json | 10 +++ .../test/resources/runDescriptions/sample5.json | 13 ++++ 13 files changed, 288 insertions(+) create mode 100644 rsTester/src/test/java/com/galois/fiveui/BatchExecutorTest.java create mode 100644 rsTester/src/test/java/com/galois/fiveui/RuleSetTest.java create mode 100644 rsTester/src/test/java/com/galois/fiveui/RunDescriptionTest.java create mode 100644 rsTester/src/test/resources/ruleSets/emptyRuleSet.json create mode 100644 rsTester/src/test/resources/ruleSets/headingGuidelines.json create mode 100644 rsTester/src/test/resources/ruleSets/simpleRuleSet1.json create mode 100644 rsTester/src/test/resources/runDescriptions/headingSample.json create mode 100644 rsTester/src/test/resources/runDescriptions/sample0.json create mode 100644 rsTester/src/test/resources/runDescriptions/sample1.json create mode 100644 rsTester/src/test/resources/runDescriptions/sample2.json create mode 100644 rsTester/src/test/resources/runDescriptions/sample3.json create mode 100644 rsTester/src/test/resources/runDescriptions/sample4.json create mode 100644 rsTester/src/test/resources/runDescriptions/sample5.json (limited to 'rsTester/src/test') diff --git a/rsTester/src/test/java/com/galois/fiveui/BatchExecutorTest.java b/rsTester/src/test/java/com/galois/fiveui/BatchExecutorTest.java new file mode 100644 index 0000000..bb4dd31 --- /dev/null +++ b/rsTester/src/test/java/com/galois/fiveui/BatchExecutorTest.java @@ -0,0 +1,38 @@ +/** + * 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 org.junit.Test; + +import junit.framework.Assert; + + +/** + * @author creswick + * + */ +public class BatchExecutorTest { + + @Test + public void simpleTest() { + Assert.assertEquals("Booleans are not equal.", true, true); + } +} diff --git a/rsTester/src/test/java/com/galois/fiveui/RuleSetTest.java b/rsTester/src/test/java/com/galois/fiveui/RuleSetTest.java new file mode 100644 index 0000000..1cd4dae --- /dev/null +++ b/rsTester/src/test/java/com/galois/fiveui/RuleSetTest.java @@ -0,0 +1,57 @@ +/** + * Module : RuleSetTest.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 static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +import com.google.common.collect.ImmutableList; + +public class RuleSetTest { + @Test + public void testParseNoFns() { + testParse("the name", "a descr", "[]", new ArrayList()); + } + + @Ignore + @Test + public void testParseOneFn() { + List rules = ImmutableList.of("\n function () {\n }\n"); + testParse("the name", "a descr", "[function () {}]", rules); + } + + private void testParse(String name, String desc, String rules, List rulesOracle) { + RuleSet rs = RuleSet.parse("{ 'name': '" +name+"'" + + ", 'description': '"+desc+"'" + + ", 'rules': " + rules + + "};"); + + assertEquals("", name, rs.getName()); + assertEquals("", desc, rs.getDescription()); + Assert.assertArrayEquals("", rulesOracle.toArray(), rs.getRules().toArray()); + } +} diff --git a/rsTester/src/test/java/com/galois/fiveui/RunDescriptionTest.java b/rsTester/src/test/java/com/galois/fiveui/RunDescriptionTest.java new file mode 100644 index 0000000..4c58f74 --- /dev/null +++ b/rsTester/src/test/java/com/galois/fiveui/RunDescriptionTest.java @@ -0,0 +1,82 @@ +/** + * RunDescriptionTest.java + * + * Copyright (c) 2012 Galois, Inc. + */ +package com.galois.fiveui; + +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; + +import junit.framework.Assert; + +import org.junit.Test; + +import com.google.common.collect.ImmutableList; + +/** + * @author creswick + * + */ +public class RunDescriptionTest { + + private static final String RUN_DESCRIPTION_DIR = "src/test/resources/runDescriptions/"; + + /** + * Test method for {@link com.galois.fiveui.RSTestDescription#RunDescription(java.lang.String, java.util.List, com.galois.fiveui.RuleSet)}. + * @throws FileNotFoundException + */ + @Test + public final void testDeserialize_sample0() throws FileNotFoundException { + + String jsonFileName = RUN_DESCRIPTION_DIR + "sample0.json"; + String ruleSetLoc = + RUN_DESCRIPTION_DIR + "../ruleSets/emptyRuleSet.json"; + + ImmutableList emptyRuleList = ImmutableList.of(); + RuleSet rsOracle = + new RuleSet("emptyRuleSet", "", emptyRuleList); + + RSTestDescription oracle = + new RSTestDescription(ruleSetLoc, + new ArrayList(), rsOracle); + + + RSTestDescription actual = RSTestDescription.parse(jsonFileName); + assertObjEqual("Object deserialized incorrectly.", oracle, actual); + } + + /** + * Test method for {@link com.galois.fiveui.RSTestDescription#RunDescription(java.lang.String, java.util.List, com.galois.fiveui.RuleSet)}. + * @throws FileNotFoundException + */ + @Test + public final void testDeserialize_sample1() throws FileNotFoundException { + + String jsonFileName = RUN_DESCRIPTION_DIR + "sample1.json"; + String ruleSetLoc = + RUN_DESCRIPTION_DIR + "../ruleSets/simpleRuleSet1.json"; + + RuleSet rsOracle = + new RuleSet("simpleRuleSet1", "", ImmutableList.of( + new Rule("trivial check", "test desc", "", 42))); + + RSTestDescription oracle = + new RSTestDescription(ruleSetLoc, + new ArrayList(), rsOracle); + + + RSTestDescription actual = RSTestDescription.parse(jsonFileName); + assertObjEqual("Object deserialized incorrectly.", oracle, actual); + } + + private void assertObjEqual(String msg, Object oracle, Object actual) { + Assert.assertTrue(msg + "; expected: "+oracle+" actual: "+actual, + oracle.equals(actual)); + } + + +} diff --git a/rsTester/src/test/resources/ruleSets/emptyRuleSet.json b/rsTester/src/test/resources/ruleSets/emptyRuleSet.json new file mode 100644 index 0000000..a01bc68 --- /dev/null +++ b/rsTester/src/test/resources/ruleSets/emptyRuleSet.json @@ -0,0 +1,4 @@ +{ "name": "emptyRuleSet" +, "description": "" +, "rules": [] +} diff --git a/rsTester/src/test/resources/ruleSets/headingGuidelines.json b/rsTester/src/test/resources/ruleSets/headingGuidelines.json new file mode 100644 index 0000000..be69fac --- /dev/null +++ b/rsTester/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/rsTester/src/test/resources/ruleSets/simpleRuleSet1.json b/rsTester/src/test/resources/ruleSets/simpleRuleSet1.json new file mode 100644 index 0000000..8365d1d --- /dev/null +++ b/rsTester/src/test/resources/ruleSets/simpleRuleSet1.json @@ -0,0 +1,9 @@ +{ "name": "simpleRuleSet1" +, "description": "" +, "rules": [ { "id": 42 + , "name": "trivial check" + , "description": "test desc" + , "rule": + function() { } + }] +} diff --git a/rsTester/src/test/resources/runDescriptions/headingSample.json b/rsTester/src/test/resources/runDescriptions/headingSample.json new file mode 100644 index 0000000..e8228ca --- /dev/null +++ b/rsTester/src/test/resources/runDescriptions/headingSample.json @@ -0,0 +1,13 @@ +{ + 'ruleSet': '../ruleSets/headingGuidelines.json', + 'tests': [ { 'url': 'http://localhost:8000/exampleData/basic/headings.html', + 'oracle': [ { 'ruleId': 1 + , 'results': ['Error', 'Error'] + }, + { 'ruleId': 2 + , 'results': ['Error'] + } + ] + } + ] +} diff --git a/rsTester/src/test/resources/runDescriptions/sample0.json b/rsTester/src/test/resources/runDescriptions/sample0.json new file mode 100644 index 0000000..0c2bbb7 --- /dev/null +++ b/rsTester/src/test/resources/runDescriptions/sample0.json @@ -0,0 +1,4 @@ +{ + 'ruleSet': '../ruleSets/emptyRuleSet.json', + 'tests': [] +} diff --git a/rsTester/src/test/resources/runDescriptions/sample1.json b/rsTester/src/test/resources/runDescriptions/sample1.json new file mode 100644 index 0000000..91f8f34 --- /dev/null +++ b/rsTester/src/test/resources/runDescriptions/sample1.json @@ -0,0 +1,4 @@ +{ + 'ruleSet': '../ruleSets/simpleRuleSet1.json', + 'tests': [] +} diff --git a/rsTester/src/test/resources/runDescriptions/sample2.json b/rsTester/src/test/resources/runDescriptions/sample2.json new file mode 100644 index 0000000..a8ea9ec --- /dev/null +++ b/rsTester/src/test/resources/runDescriptions/sample2.json @@ -0,0 +1,10 @@ +{ + 'ruleSet': '../ruleSets/simpleRuleSet1.json', + 'tests': [ { 'url': 'http://localhost:8000/', + 'oracle': [ { 'ruleId': 42 + , 'results': ['Error', 'Error'] + } + ] + } + ] +} diff --git a/rsTester/src/test/resources/runDescriptions/sample3.json b/rsTester/src/test/resources/runDescriptions/sample3.json new file mode 100644 index 0000000..e4d1cea --- /dev/null +++ b/rsTester/src/test/resources/runDescriptions/sample3.json @@ -0,0 +1,7 @@ +{ + 'ruleSet': '../ruleSets/simpleRuleSet1.json', + 'tests': [ { 'url': 'http://localhost:8000/', + 'oracle': [ ] + } + ] +} diff --git a/rsTester/src/test/resources/runDescriptions/sample4.json b/rsTester/src/test/resources/runDescriptions/sample4.json new file mode 100644 index 0000000..c4f46cd --- /dev/null +++ b/rsTester/src/test/resources/runDescriptions/sample4.json @@ -0,0 +1,10 @@ +{ + 'ruleSet': '../ruleSets/simpleRuleSet1.json', + 'tests': [ { 'url': 'http://localhost:8000/', + 'oracle': [ ] + }, + { 'url': 'http://localhost:8000/', + 'oracle': [ ] + } + ] +} diff --git a/rsTester/src/test/resources/runDescriptions/sample5.json b/rsTester/src/test/resources/runDescriptions/sample5.json new file mode 100644 index 0000000..11ca957 --- /dev/null +++ b/rsTester/src/test/resources/runDescriptions/sample5.json @@ -0,0 +1,13 @@ +{ + 'ruleSet': '../ruleSets/simpleRuleSet1.json', + 'tests': [ { 'url': 'http://localhost:8000/', + 'oracle': [ { 'ruleId': 42 + , 'results': ['Error'] + } + ] + }, + { 'url': 'http://localhost:8000/', + 'oracle': [ ] + } + ] +} -- cgit v1.2.3