1 23 24 package org.enhydra.xml.xmlc.metadata; 25 26 import java.io.File ; 27 import java.io.FileWriter ; 28 import java.io.IOException ; 29 import java.io.PrintWriter ; 30 import java.lang.reflect.Method ; 31 32 import junit.framework.Test; 33 34 import org.enhydra.xml.dom.DOMInfo; 35 import org.enhydra.xml.driver.TestCaseBase; 36 import org.enhydra.xml.driver.TestException; 37 import org.enhydra.xml.io.ErrorReporter; 38 import org.enhydra.xml.xmlc.XMLCException; 39 import org.xml.sax.InputSource ; 40 import org.xml.sax.SAXException ; 41 42 45 public class BasicTests extends TestCaseBase { 46 47 private static final String XMLC_XSD 48 = "../../../../../../org/enhydra/xml/xmlc/metadata/xmlc-1.0.2.xsd"; 49 50 51 public static Test suite() { 52 return createSuite(BasicTests.class, null); 53 } 54 55 56 public BasicTests(Method method) { 57 super(method); 58 } 59 60 63 private MetaDataDocument parseDump(File xmlcFile, 64 String outExt) 65 throws IOException , 66 SAXException , 67 XMLCException { 68 File outFile = getResultFile(outExt); 69 File expectFile = getExpectedFile(outExt); 70 71 outFile.getParentFile().mkdirs(); 72 PrintWriter out = new PrintWriter (new FileWriter (outFile)); 73 MetaDataDocument metaDataDoc; 74 try { 75 metaDataDoc 76 = MetaDataDocument.parseMetaData(new InputSource (xmlcFile.getPath()), 77 new ErrorReporter(out), 78 null); 79 DOMInfo.printTree(xmlcFile.getPath(), metaDataDoc, out); 80 } finally { 81 out.close(); 82 } 83 getDiffer().diff(expectFile, outFile); 84 return metaDataDoc; 85 } 86 87 88 91 private void testParseMetaData(File xmlcFile) { 92 try { 93 MetaDataDocument doc = parseDump(xmlcFile, "1.dump"); 94 File docOut = getResultFile("xmlc"); 95 doc.serialize(docOut); 96 parseDump(docOut, "2.dump"); 97 } catch (IOException except) { 98 throw new TestException(except); 99 } catch (SAXException except) { 100 throw new TestException(except); 101 } catch (XMLCException except) { 102 throw new TestException(except); 103 } 104 } 105 106 109 public void test1() { 110 testParseMetaData(getInputFile("most-xml-1.1.xmlc")); 111 } 112 113 116 public void test2() { 117 testParseMetaData(getInputFile("empty-sections.xmlc")); 118 } 119 120 123 public void test3() throws XMLCException { 124 MetaDataDocument doc = MetaDataDocument.newInstance(); 126 MetaData metaData = doc.getMetaData(); 127 InputDocument inputDoc = metaData.getInputDocument(); 128 inputDoc.setProcessSSI(true); 129 inputDoc.setDocumentFormat(DocumentFormat.XML); 130 131 File createdFile = getResultFile("new.xmlc"); 133 doc.serialize(createdFile); 134 testParseMetaData(createdFile); 135 } 136 137 140 public void disable_test3() { 141 testParseMetaData(getInputFile("most-xml-1.0.xmlc")); 143 } 144 145 148 private void disable_test4() { 149 testParseMetaData(getInputFile("most-xml-1.0.1.xmlc")); 151 } 152 } 153 | Popular Tags |