/*
 * @(#)$Id: $
 *
 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * This software is the proprietary information of Sun Microsystems, Inc.  
 * Use is subject to license terms.
 * 
 */
import java.net.UnknownHostException;

import junit.framework.TestCase;
import junit.textui.TestRunner;

import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * 
 * 
 * @author
 *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
 */
public class ExtDTD extends TestCase {
    
    public ExtDTD(String name) {
        super(name);
    }

    public static void main(String[] args) {
        TestRunner.run(ExtDTD.class);
    }
    
    public void test1() throws Exception {
        // make sure the parsing fails unless the feature is on.
        DOMParser parser = new DOMParser();
        try {
            go(parser);
            fail("expected to fail to parse");
        } catch( UnknownHostException e ) {
            ; // as expected
        }
    }
    
    public void test2() throws Exception {
        // then check if the property makes it work.
        DOMParser parser = new DOMParser();
        parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        go(parser);
    }
    
    private void go( DOMParser parser ) throws Exception { 
        parser.setFeature("http://xml.org/sax/features/namespaces",true);
        parser.parse(ExtDTD.class.getResource("test.xml").toExternalForm());
        Document doc = parser.getDocument(); 
        Element root = doc.getDocumentElement();
        assertEquals("root",root.getLocalName());
        assertEquals("test",root.getFirstChild().getFirstChild().getNodeValue());
    }
}
