[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests AllTests.java,1.53,1.54 AssertXmlEqualsTest.jav
Brought to you by:
derrickoswald
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests In directory sc8-pr-cvs1:/tmp/cvs-serv21682 Modified Files: AllTests.java AssertXmlEqualsTest.java FunctionalTests.java LineNumberAssignedByNodeReaderTest.java ParserTest.java ParserTestCase.java Log Message: Consolidated the various testing main() methods into ParserTestCase. All unit test classes in the org.htmlparser.tests heirarchy should now be executable. Index: AllTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/AllTests.java,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** AllTests.java 13 Oct 2003 21:48:13 -0000 1.53 --- AllTests.java 21 Oct 2003 02:24:00 -0000 1.54 *************** *** 31,102 **** import junit.framework.TestSuite; ! public class AllTests extends junit.framework.TestCase { public AllTests(String name) { super(name); - } - - /** - * Mainline for all suites of tests. - * @param args Command line arguments. The following options - * are understood: - * <pre> - * -text -- use junit.textui.TestRunner - * -awt -- use junit.awtui.TestRunner - * -swing -- use junit.swingui.TestRunner (default) - * </pre> - * All other options are passed on to the junit framework. - */ - public static void main(String[] args) - { - String runner; - int i; - String arguments[]; - Class cls; - - runner = null; - for (i = 0; (i < args.length) && (null == runner); i++) - { - if (args[i].equalsIgnoreCase ("-text")) - runner = "junit.textui.TestRunner"; - else if (args[i].equalsIgnoreCase ("-awt")) - runner = "junit.awtui.TestRunner"; - else if (args[i].equalsIgnoreCase ("-swing")) - runner = "junit.swingui.TestRunner"; - } - if (null != runner) - { - // remove it from the arguments - arguments = new String[args.length - 1]; - System.arraycopy (args, 0, arguments, 0, i - 1); - System.arraycopy (args, i, arguments, i - 1, args.length - i); - args = arguments; - } - else - runner = "junit.swingui.TestRunner"; - - // append the test class - arguments = new String[args.length + 1]; - System.arraycopy (args, 0, arguments, 0, args.length); - arguments[args.length] = "org.htmlparser.tests.AllTests"; - - // invoke main() of the test runner - try - { - cls = Class.forName (runner); - java.lang.reflect.Method method = cls.getDeclaredMethod ( - "main", new Class[] { String[].class }); - method.invoke ( - null, - new Object[] { arguments }); - } - catch (Throwable t) - { - System.err.println ( - "cannot run unit test (" - + t.getMessage () - + ")"); - } } --- 31,45 ---- import junit.framework.TestSuite; ! import org.htmlparser.tests.ParserTestCase; ! ! public class AllTests extends ParserTestCase { + static + { + System.setProperty ("org.htmlparser.tests.AllTests", "AllTests"); + } public AllTests(String name) { super(name); } Index: AssertXmlEqualsTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/AssertXmlEqualsTest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AssertXmlEqualsTest.java 22 Sep 2003 02:40:03 -0000 1.13 --- AssertXmlEqualsTest.java 21 Oct 2003 02:24:00 -0000 1.14 *************** *** 34,37 **** --- 34,42 ---- public class AssertXmlEqualsTest extends ParserTestCase { + static + { + System.setProperty ("org.htmlparser.tests.AssertXmlEqualsTest", "AssertXmlEqualsTest"); + } + public AssertXmlEqualsTest(String name) { super(name); Index: FunctionalTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/FunctionalTests.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** FunctionalTests.java 20 Oct 2003 01:28:03 -0000 1.45 --- FunctionalTests.java 21 Oct 2003 02:24:00 -0000 1.46 *************** *** 48,52 **** import org.htmlparser.util.ParserException; ! public class FunctionalTests extends TestCase { public FunctionalTests(String arg0) { --- 48,57 ---- import org.htmlparser.util.ParserException; ! public class FunctionalTests extends ParserTestCase { ! ! static ! { ! System.setProperty ("org.htmlparser.tests.FunctionalTests", "FunctionalTests"); ! } public FunctionalTests(String arg0) { Index: LineNumberAssignedByNodeReaderTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/LineNumberAssignedByNodeReaderTest.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** LineNumberAssignedByNodeReaderTest.java 20 Oct 2003 01:28:03 -0000 1.24 --- LineNumberAssignedByNodeReaderTest.java 21 Oct 2003 02:24:00 -0000 1.25 *************** *** 46,49 **** --- 46,54 ---- public class LineNumberAssignedByNodeReaderTest extends ParserTestCase { + static + { + System.setProperty ("org.htmlparser.tests.LineNumberAssignedByNodeReaderTest", "LineNumberAssignedByNodeReaderTest"); + } + public LineNumberAssignedByNodeReaderTest(String name) { super(name); Index: ParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/ParserTest.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** ParserTest.java 5 Oct 2003 13:49:53 -0000 1.44 --- ParserTest.java 21 Oct 2003 02:24:00 -0000 1.45 *************** *** 53,57 **** import org.htmlparser.util.SimpleNodeIterator; ! public class ParserTest extends ParserTestCase { public ParserTest(String name) { --- 53,62 ---- import org.htmlparser.util.SimpleNodeIterator; ! public class ParserTest extends ParserTestCase ! { ! static ! { ! System.setProperty ("org.htmlparser.tests.ParserTest", "ParserTest"); ! } public ParserTest(String name) { Index: ParserTestCase.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/ParserTestCase.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** ParserTestCase.java 20 Oct 2003 01:28:03 -0000 1.33 --- ParserTestCase.java 21 Oct 2003 02:24:00 -0000 1.34 *************** *** 31,35 **** --- 31,37 ---- import java.io.BufferedReader; import java.io.StringReader; + import java.util.Enumeration; import java.util.Iterator; + import java.util.Properties; import java.util.Vector; *************** *** 303,310 **** { tag.setEmptyXmlTag (false); - // data = new TagData - // ("/" + tag.getTagName (), tag.elementEnd (), new Vector (), "", false); node = new Tag (tag.getPage (), tag.getStartPosition (), tag.getEndPosition (), tag.getAttributesEx ()); - //data.getTagBegin (), data.getTagEnd (), data.getAttributes ()); // cheat here and poink the new node into the iterator ((IteratorImpl)iterator).push (node); --- 305,309 ---- *************** *** 313,318 **** } - - private void assertAttributesMatch(String displayMessage, Tag expectedTag, Tag actualTag) { assertAllExpectedTagAttributesFoundInActualTag( --- 312,315 ---- *************** *** 422,425 **** --- 419,531 ---- } fail(failMsg.toString()); + } + } + + /** + * Mainline for individual test cases. + * @param args Command line arguments. The following options + * are understood: + * <pre> + * -text -- use junit.textui.TestRunner + * -awt -- use junit.awtui.TestRunner + * -swing -- use junit.swingui.TestRunner (default) + * </pre> + * All other options are passed on to the junit framework. + * Decides the test class by examiing the system properties looking + * for a property that starts with "org.htmlparser.tests.", this is + * used as the name of the class (the value is ignored). + * Each class that subclasses ParserTestCase can inherit this mainline + * by adding a static block in their class similar to: + * <pre> + * static + * { + * System.setProperty ("org.htmlparser.tests.ParserTest", "ParserTest"); + * } + * </pre> + */ + public static void main(String[] args) + { + String runner; + int i; + String arguments[]; + Properties properties; + Enumeration enumeration; + String name; + Class cls; + + runner = null; + for (i = 0; (i < args.length) && (null == runner); i++) + { + if (args[i].equalsIgnoreCase ("-text")) + runner = "junit.textui.TestRunner"; + else if (args[i].equalsIgnoreCase ("-awt")) + runner = "junit.awtui.TestRunner"; + else if (args[i].equalsIgnoreCase ("-swing")) + runner = "junit.swingui.TestRunner"; + } + if (null != runner) + { + // remove it from the arguments + arguments = new String[args.length - 1]; + System.arraycopy (args, 0, arguments, 0, i - 1); + System.arraycopy (args, i, arguments, i - 1, args.length - i); + args = arguments; + } + else + runner = "junit.swingui.TestRunner"; + + // find the test class that has registered in the system properties + arguments = args; // default of no class name, works in GUI mode + properties = System.getProperties (); + enumeration = properties.propertyNames (); + while (enumeration.hasMoreElements ()) + { + name = (String)enumeration.nextElement (); + if (name.startsWith ("org.htmlparser.tests.")) + { + // from http://www.mail-archive.com/commons-user%40jakarta.apache.org/msg02958.html + // + // The problem is within the UI test runners of JUnit. They bring + // with them a custom classloader, which causes the + // LogConfigurationException. Unfortunately Log4j doesn't work + // either. + // + // Solution: Disable "Reload classes every run" or start JUnit with + // command line option -noloading before the name of the Testsuite. + if (true) + { + // append the test class + arguments = new String[args.length + 2]; + System.arraycopy (args, 0, arguments, 0, args.length); + arguments[arguments.length - 2] = "-noloading"; + arguments[arguments.length - 1] = name; + } + else + { + // append the test class + arguments = new String[args.length + 1]; + System.arraycopy (args, 0, arguments, 0, args.length); + arguments[args.length] = name; + } + break; // JUnit only handles one class on the command line + } + } + + // invoke main() of the test runner + try + { + cls = Class.forName (runner); + java.lang.reflect.Method method = cls.getDeclaredMethod ( + "main", new Class[] { String[].class }); + method.invoke ( + null, + new Object[] { arguments }); + } + catch (Throwable t) + { + System.err.println ( + "cannot run unit test (" + + t.getMessage () + + ")"); } } |