axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ven...@apache.org
Subject svn commit: r179795 [4/4] - in /webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject: ./ bin/ src/org/apache/axis/encoding/ src/org/apache/axis/om/ src/org/apache/axis/om/impl/llom/ src/org/apache/axis/om/impl/llom/builder/ src/org/apache/axis/om/impl/llom/factory/ src/org/apache/axis/om/impl/llom/mtom/ src/org/apache/axis/om/impl/llom/serialize/ src/org/apache/axis/om/impl/llom/traverse/ src/org/apache/axis/om/impl/llom/util/ src/org/apache/axis/om/impl/mtom/ src/org/apache/axis/soap/ src/org/apache/axis/soap/impl/ src/org/apache/axis/soap/impl/llom/ src/org/apache/axis/soap/impl/llom/builder/ src/org/apache/axis/soap/impl/llom/factory/ src/org/apache/axis/soap/impl/llom/soap11/ src/org/apache/axis/soap/impl/llom/soap12/ test/org/ test/org/apache/ test/org/apache/axis/ test/org/apache/axis/om/ test/org/apache/axis/om/infoset/
Date Fri, 03 Jun 2005 14:23:50 GMT
Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/test/org/apache/axis/om/infoset/XMLConformanceTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/test/org/apache/axis/om/infoset/XMLConformanceTest.java?rev=179795&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/test/org/apache/axis/om/infoset/XMLConformanceTest.java
(added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/test/org/apache/axis/om/infoset/XMLConformanceTest.java
Fri Jun  3 07:23:47 2005
@@ -0,0 +1,146 @@
+/*
+ * Created on Jun 3, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.axis.om.infoset;
+
+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 org.apache.axis.om.impl.llom.OMDocument;
+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.OMAbstractFactory;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileInputStream;
+
+/**
+ * @author sunja07
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class XMLConformanceTest extends XMLTestCase {
+
+	private static int successCount=0;
+	private static int parsedCount=0;
+	private static int fileCount=0;
+	/**
+	 * @param name
+	 */
+	public XMLConformanceTest(String name) {
+		super(name);
+	}
+	
+	public void setUp() {		
+	}
+	
+	public void testXMLConformance() throws Exception{
+		//The 'testSuiteDirectory' value can also be a specific file location
+		//value, needn't necessarily be a directory
+		File testSuiteDirectory = new File("C:\\work\\XMLConformanceWork\\XMLSuite\\xmlconf\\");
+		ProcessDir(testSuiteDirectory);
+		System.out.println("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()) {
+			//process all children
+			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);
+           		fileCount++;
+           	} else {
+           		//ignore non .xml files
+           	}
+        }		
+	}
+	
+	public void testSingleFileConformance(String absolutePath) 
+		throws Exception {
+		OMElement rootElement;
+		OMDocument document;
+		//fileCount++;
+		//get a stax om builder
+		try {
+		StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.
+			createStAXOMBuilder(OMAbstractFactory.getOMFactory(), 
+				XMLInputFactory.newInstance().createXMLStreamReader(
+							new FileInputStream(absolutePath) , "UTF-8"));
+
+		document = (OMDocument)staxOMBuilder.getDocument();
+		rootElement = staxOMBuilder.getDocumentElement();
+		} catch (Exception e) {
+			System.err.println("Exception trying to get hold of rootElement: "
+					+ e.getMessage());
+			System.err.println("in file: "+ absolutePath +"\n");
+			return;
+		}		
+
+		//we will write output into the file named TempOutputFile.txt in 
+		//current directory
+		String tempFile = "TempOutputFile.txt";
+		XMLStreamWriter writer;
+		try {
+		writer = XMLOutputFactory.newInstance().
+                createXMLStreamWriter(new FileOutputStream(tempFile));		
+		document.serializeWithCache(writer); 
+//        rootElement.serialize(writer, true);
+		}catch(XMLStreamException e) {
+			System.err.println(
+				"Error in creating XMLStreamWriter to write parsed xml into");
+			return;
+		} catch (Exception e) {
+			System.err.println("Exception while serializing: " + 
+					e.getMessage());
+			System.err.println("in file: "+ absolutePath +"\n");
+			return;
+		}
+        writer.flush();
+        writer.close();        
+        parsedCount++;
+        //Comparing the equality of the TempOutputFile.txt and the input xml is due
+        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);
+        	System.out.println("Error message is: "+e.getMessage());
+        	return;
+        }
+        try {
+        	assertXMLEqual(diff,true);
+        	successCount++;
+        } catch (Error e) {
+        	System.out.println("XMLEquality failed for file: "+absolutePath);        	
+        	return;
+        }
+        
+	}
+	public void tearDown() {
+	}
+
+}



Mime
View raw message