ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Ws Wiki] Update of "FrontPage/Axis2/w3cXMLSuiteConformance" by JayachandraSunkara
Date Mon, 11 Apr 2005 10:19:59 GMT
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 JayachandraSunkara:
http://wiki.apache.org/ws/FrontPage/Axis2/w3cXMLSuiteConformance

------------------------------------------------------------------------------
  package junittesting;
  
  import java.io.File;
+ 
- import org.custommonkey.xmlunit.XMLTestCase; [[br]]
+ import org.custommonkey.xmlunit.XMLTestCase;
+ 
- import org.custommonkey.xmlunit.Diff; [[br]]
+ import org.custommonkey.xmlunit.Diff;
+ 
- import org.apache.axis.om.OMElement; [[br]]
+ import org.apache.axis.om.OMElement;
+ 
- import org.apache.axis.om.impl.llom.factory.OMXMLBuilderFactory; [[br]]
+ 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;
+ 
  
  
  /**
@@ -37, +50 @@

  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 setUp() {
  	}
- 	
+ 
  	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]));	           
+ 	           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)));
+  			StAXOMBuilder staxOMBuilder=OMXMLBuilderFactory.createStAXOMBuilder( OMFactory.newInstance(),
XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(absolutePath)));
  
- 		rootElement = staxOMBuilder.getDocumentElement();
+ 			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. SAVE
step
+ 
  		String tempFile = "TempOutputFile.txt";
+ 
  		XMLStreamWriter writer;
+ 
  		try {
- 		   writer = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(tempFile));
	
+ 		   writer = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(tempFile));
                  rootElement.serialize(writer, true);
  		}catch(XMLStreamException e) {
  			System.err.println("Error in creating XMLStreamWriter to write parsed xml into");
@@ -106, +140 @@

  			System.err.println("in file: "+ absolutePath +"\n");
  			return;
  		}
+ 
-         writer.flush();
+         	writer.flush();
+ 
-         writer.close();        
+         	writer.close();
+ 
-         parsedCount++;
+         	parsedCount++;
+ 
+ 
-         //Comparing the equality of the TempOutputFile.txt and the input xml is due COMPARE
step
+         //Comparing the equality of the TempOutputFile.txt and the input xml is due. COMPARE
step
-         /* */
+ 
          Diff diff;
+ 
          try {
-         diff = compareXML(new FileReader(absolutePath), new FileReader("TempOutputFile.txt"));
+         	diff = compareXML(new FileReader(absolutePath), new FileReader("TempOutputFile.txt"));
          } catch (Exception e) {
          	System.out.println("Error comparing original and generated files for: "+absolutePath);
          	return;
@@ -122, +162 @@

          	assertXMLEqual(diff,true);
          	successCount++;
          } catch (Error e) {
-         	System.out.println("XMLEquality failed for file: "+absolutePath);        	
+         	System.out.println("XMLEquality failed for file: "+absolutePath);
          	return;
          }
-         
+ 
  	}
+ 
- 	public void tearDown() {		
+ 	public void tearDown() {
  	}
  
  }

Mime
View raw message