1 5 package com.opensymphony.workflow; 6 7 import com.opensymphony.workflow.loader.DTDEntityResolver; 8 import com.opensymphony.workflow.loader.WorkflowDescriptor; 9 10 import org.custommonkey.xmlunit.Diff; 11 import org.custommonkey.xmlunit.ElementNameAndTextQualifier; 12 import org.custommonkey.xmlunit.XMLTestCase; 13 14 import org.w3c.dom.Document ; 15 16 import org.xml.sax.InputSource ; 17 import org.xml.sax.SAXException ; 18 19 import java.io.*; 20 21 import java.net.URL ; 22 23 import javax.xml.parsers.DocumentBuilder ; 24 import javax.xml.parsers.DocumentBuilderFactory ; 25 import javax.xml.parsers.ParserConfigurationException ; 26 27 28 37 public class SaveDescriptorTestCase extends XMLTestCase { 38 40 private DocumentBuilder documentBuilder; 41 42 44 public SaveDescriptorTestCase(String s) throws ParserConfigurationException { 45 super(s); 46 documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 47 documentBuilder.setEntityResolver(new DTDEntityResolver()); 48 } 49 50 52 55 public void testSave() throws Exception { 56 URL url = getClass().getResource("/samples/saved.xml"); 57 Document inputDocument = documentBuilder.parse(url.toString()); 58 WorkflowDescriptor descriptor = DescriptorLoader.getDescriptor(url.toString()); 59 StringWriter out = new StringWriter(); 60 PrintWriter writer = new PrintWriter(out); 61 writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 62 writer.println("<!DOCTYPE workflow PUBLIC \"-//OpenSymphony Group//DTD OSWorkflow 2.7//EN\" \"http://www.opensymphony.com/osworkflow/workflow_2_7.dtd\">"); 63 descriptor.writeXML(new PrintWriter(out), 0); 64 65 PrintWriter blah = new PrintWriter(new FileWriter("foo.xml")); 66 descriptor.writeXML(blah, 0); 67 blah.flush(); 68 69 Document outputDocument = getDocument(out.toString()); 70 71 Diff diff = new Diff(inputDocument, outputDocument); 72 diff.overrideElementQualifier(new ElementNameAndTextQualifier()); 73 assertTrue(diff.toString(), diff.similar()); 74 assertXMLEqual("But they are equal when an ElementQualifier controls which test element is compared with each control element", diff, true); 75 assertTrue(diff.toString(), diff.similar()); 76 } 77 78 private Document getDocument(String xml) throws IOException, SAXException { 79 InputSource source = new InputSource (new StringReader(xml)); 80 81 return documentBuilder.parse(source); 82 } 83 } 84 | Popular Tags |