Failing to handle unrecognized character entities in XML files w/o DOCTYPEs (e.g. fragments included from master
docs), but at least printing parse errors in log file for diagnostic purposes.
1.1 --- a/xmlnavigation/test/unit/src/org/netbeans/modules/xmlnavigation/XMLNavigatorPanelTest.java Mon Aug 08 16:39:26 2005 -0400
1.2 +++ b/xmlnavigation/test/unit/src/org/netbeans/modules/xmlnavigation/XMLNavigatorPanelTest.java Mon Aug 08 16:39:26 2005 -0400
1.3 @@ -13,10 +13,18 @@
1.4
1.5 package org.netbeans.modules.xmlnavigation;
1.6
1.7 +import java.io.IOException;
1.8 import java.io.StringReader;
1.9 +import junit.framework.Assert;
1.10 +import org.netbeans.api.xml.services.UserCatalog;
1.11 import org.netbeans.junit.NbTestCase;
1.12 import org.netbeans.modules.xmlnavigation.XMLNavigatorPanel.Item;
1.13 +import org.openide.util.Lookup;
1.14 +import org.openide.util.lookup.Lookups;
1.15 +import org.openide.util.lookup.ProxyLookup;
1.16 +import org.xml.sax.EntityResolver;
1.17 import org.xml.sax.InputSource;
1.18 +import org.xml.sax.SAXException;
1.19
1.20 /**
1.21 * Test functionality of {@link XMLNavigatorPanel}.
1.22 @@ -24,10 +32,38 @@
1.23 */
1.24 public class XMLNavigatorPanelTest extends NbTestCase {
1.25
1.26 + static {
1.27 + System.setProperty("org.openide.util.Lookup", Lkp.class.getName());
1.28 + Assert.assertEquals(Lkp.class, Lookup.getDefault().getClass());
1.29 + }
1.30 + public static final class Lkp extends ProxyLookup {
1.31 + private static Lkp DEFAULT;
1.32 + public Lkp() {
1.33 + Assert.assertNull(DEFAULT);
1.34 + DEFAULT = this;
1.35 + setLookup(new Object[0]);
1.36 + }
1.37 + public static void setLookup(Object[] instances) {
1.38 + ClassLoader l = Lkp.class.getClassLoader();
1.39 + DEFAULT.setLookups(new Lookup[] {
1.40 + Lookups.fixed(instances),
1.41 + Lookups.metaInfServices(l),
1.42 + Lookups.singleton(l),
1.43 + });
1.44 + }
1.45 + }
1.46 +
1.47 public XMLNavigatorPanelTest(String name) {
1.48 super(name);
1.49 }
1.50
1.51 + protected void setUp() throws Exception {
1.52 + super.setUp();
1.53 + Lkp.setLookup(new Object[] {
1.54 + new TestCatalog(),
1.55 + });
1.56 + }
1.57 +
1.58 public void testParse() throws Exception {
1.59 assertEquals("correct parse of some XHTML sections",
1.60 "1[h1/h1]Intro\n" +
1.61 @@ -84,6 +120,37 @@
1.62 // as well as <section id="section"><title>Title here...</title>...</section>
1.63 }
1.64
1.65 + public void testParseWithUnresolvedEntityRefs() throws Exception {
1.66 + assertEquals("handles unref'd entities when we have a DOCTYPE",
1.67 + "1[section/title]First\n" +
1.68 + "4[section/title]Second\n",
1.69 + itemsSummary(parse(
1.70 + "<!DOCTYPE article PUBLIC 'whatever' 'http://wherever/'> <article>\n" + // 0
1.71 + " <section><title>First</title>\n" + // 1
1.72 + " <para>&whatever;</para>\n" + // 2
1.73 + " </section>\n" + // 3
1.74 + " <section><title>Second</title>\n" + // 4
1.75 + " <para>Stuff...</para>\n" + // 5
1.76 + " </section>\n" + // 6
1.77 + "</article>\n" // 17
1.78 + )));
1.79 + /*XXX cannot figure out how to make this pass; even http://apache.org/xml/features/continue-after-fatal-error does not work!
1.80 + assertEquals("handles unref'd entities when we have no DOCTYPE",
1.81 + "1[section/title]First\n" +
1.82 + "4[section/title]Second\n",
1.83 + itemsSummary(parse(
1.84 + "<article>\n" + // 0
1.85 + " <section><title>First</title>\n" + // 1
1.86 + " <para>&whatever;</para>\n" + // 2
1.87 + " </section>\n" + // 3
1.88 + " <section><title>Second</title>\n" + // 4
1.89 + " <para>Stuff...</para>\n" + // 5
1.90 + " </section>\n" + // 6
1.91 + "</article>\n" // 17
1.92 + )));
1.93 + */
1.94 + }
1.95 +
1.96 private static Item[] parse(String xml) throws Exception {
1.97 return XMLNavigatorPanel.parse(new InputSource(new StringReader(xml)), null);
1.98 }
1.99 @@ -103,4 +170,14 @@
1.100 return b.toString();
1.101 }
1.102
1.103 + private static final class TestCatalog extends UserCatalog implements EntityResolver {
1.104 + public TestCatalog() {}
1.105 + public EntityResolver getEntityResolver() {
1.106 + return this;
1.107 + }
1.108 + public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
1.109 + return null;
1.110 + }
1.111 + }
1.112 +
1.113 }