1 9 10 package test.dom4j; 11 12 import junit.framework.Test; 13 import junit.framework.TestSuite; 14 import junit.textui.TestRunner; 15 import org.dom4j.DocumentType; 16 import org.dom4j.dtd.ElementDecl; 17 import org.dom4j.io.SAXReader; 18 import org.ozoneDB.xml.dom4j.io.O3SAXReader; 19 20 import java.io.FileInputStream ; 21 import java.util.List ; 22 23 28 public class TestDocType extends AbstractTestCase { 29 30 31 protected static String INPUT_XML_FILE = "xml/dtd/internal.xml"; 32 33 public static void main( String [] args ) { 34 TestRunner.run( suite() ); 35 } 36 37 public static Test suite() { 38 return new TestSuite( TestDocType.class ); 39 } 40 41 public TestDocType(String name) { 42 super(name); 43 } 44 45 public void testDocType() throws Exception { 48 DocumentType docType = document.getDocType(); 49 assertTrue( "Has DOCTYPE", docType!= null ); 50 51 List declarations = docType.getInternalDeclarations(); 52 assertTrue( "DOCTYPE has declarations", declarations != null && declarations.size() == 1 ); 53 54 ElementDecl decl = (ElementDecl) declarations.get(0); 55 56 assertEquals( "name is correct", "greeting", decl.getName() ); 57 assertEquals( "model is correct", "(#PCDATA)", decl.getModel() ); 58 59 assertEquals( "getText() is correct", "<!ELEMENT greeting (#PCDATA)>", docType.getText() ); 60 } 61 62 protected void setUp() throws Exception { 65 SAXReader reader = new O3SAXReader(db()); 66 reader.setIncludeInternalDTDDeclarations(true); 67 document = reader.read( new FileInputStream (INPUT_XML_FILE) ); 68 } 69 } 70 71 72 73 74 118 | Popular Tags |