Dear Wiki user, You have subscribed to a wiki page or wiki category on "Ws Wiki" for change notification.
The following page has been changed by AjithRanabahu: http://wiki.apache.org/ws/FrontPage/Axis2/w3cXMLSuiteConformance The comment on the change is: Just making things look nicer ------------------------------------------------------------------------------ Make sure to have in the directory of test case a folder named "XMLSuite" which contains in it all the unzipped files of the W3C XML test suite. Here is the listing of the test case code. + {{{ /* * Created on Apr 8, 2005 @@ -14, +15 @@ package junittesting; import java.io.File; - import org.custommonkey.xmlunit.XMLTestCase; - import org.custommonkey.xmlunit.Diff; - import org.apache.axis.om.OMElement; - import org.apache.axis.om.impl.llom.factory.OMXMLBuilderFactory; - import org.apache.axis.om.impl.llom.builder.StAXOMBuilder; - import javax.xml.stream.XMLInputFactory; - import javax.xml.stream.XMLOutputFactory; - import javax.xml.stream.XMLStreamWriter; - import javax.xml.stream.XMLStreamException; - import org.apache.axis.om.OMFactory; - import java.io.FileOutputStream; - import java.io.FileReader; - /** @@ -50, +38 @@ public class XMLConformanceTest extends XMLTestCase { private static int successCount=0; - private static int parsedCount=0; - private static int fileCount=0; /** @@ -67, +53 @@ public void testXMLConformance() throws Exception{ File testSuiteDirectory = new File("XMLSuite"); - ProcessDir(testSuiteDirectory); - System.out.println("Total file count is " + fileCount); - System.out.println("Parsed count is " + parsedCount +". This is just partial success"); - System.out.println("Complete success count is " + successCount); - } public void ProcessDir(File dir) throws Exception { if (dir.isDirectory()) { //System.out.println("Processing Directory: "+dir.getAbsolutePath() ); - String[] children = dir.list(); - for (int i=0; i<children.length; i++) { File child = (new File(dir, children[i])); ProcessDir(child); } } else { //meaning you got a file - //check if it's xml file String absPath = dir.getAbsolutePath(); - if(absPath.endsWith(".xml")) { //process it testSingleFileConformance(absPath); } else { //ignore non .xml files } - } - } public void testSingleFileConformance(String absolutePath) throws Exception{ OMElement rootElement; - fileCount++; - //get a stax om builder out of the file. LOAD step - try { StAXOMBuilder staxOMBuilder=OMXMLBuilderFactory.createStAXOMBuilder( OMFactory.newInstance(), XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(absolutePath))); @@ -126, +98 @@ //we will write output into the file named TempOutputFile.txt in current directory. SAVE step String tempFile = "TempOutputFile.txt"; - XMLStreamWriter writer; - try { writer = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(tempFile)); rootElement.serialize(writer, true); @@ -153, +123 @@ Diff diff; try { - diff = compareXML(new FileReader(absolutePath), new FileReader("TempOutputFile.txt")); - } catch (Exception e) { System.out.println("Error comparing original and generated files for: "+absolutePath); return; @@ -176, +144 @@ } } + }}}
