You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2005/08/26 06:53:54 UTC
svn commit: r240161 - in
/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset:
XMLConformanceTest.java XMLConformanceUnit.java
Author: dims
Date: Thu Aug 25 21:53:51 2005
New Revision: 240161
URL: http://svn.apache.org/viewcvs?rev=240161&view=rev
Log:
Cleanup test case
Added:
webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceUnit.java (with props)
Modified:
webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java
Modified: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java?rev=240161&r1=240160&r2=240161&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java (original)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java Thu Aug 25 21:53:51 2005
@@ -15,130 +15,38 @@
*/
package org.apache.axis2.om.infoset;
-import org.apache.axis2.om.OMAbstractFactory;
-import org.apache.axis2.om.OMElement;
-import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
-import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLTestCase;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-public class XMLConformanceTest extends XMLTestCase {
- private static int successCount = 0;
- private static int parsedCount = 0;
- private static int fileCount = 0;
- private Log log = LogFactory.getLog(getClass());
+public class XMLConformanceTest extends TestCase {
- public XMLConformanceTest(String name) {
- super(name);
- }
-
- public void setUp() {
- }
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite();
- 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("test-resources/XMLSuite/xmlconf");
- if(testSuiteDirectory.exists()) {
- ProcessDir(testSuiteDirectory);
- log.info("File count is " + fileCount);
- log.info("Parsed count is " + parsedCount +
- ". This is just partial success");
- log.info("Complete success count is " + successCount);
- } else {
- log.info("Skipping W3C XMLSuite test");
+ if (testSuiteDirectory.exists()) {
+ ProcessDir(testSuiteDirectory, suite);
}
+ return suite;
}
- public void ProcessDir(File dir) throws Exception {
+ private static void ProcessDir(File dir, TestSuite suite) 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);
+ ProcessDir(child, suite);
}
- } else { //meaning you got a file
+ } else {
//check if it's xml file
String absPath = dir.getAbsolutePath();
if (absPath.endsWith(".xml")) {
- //process it
- testSingleFileConformance(absPath);
- fileCount++;
- } else {
- //ignore non .xml files
+ suite.addTest(new XMLConformanceUnit(absPath, "testSingleFileConformance"));
}
}
- }
-
- public void testSingleFileConformance(String absolutePath)
- throws Exception {
- OMElement rootElement;
- //fileCount++;
- //get a stax om builder
- try {
- StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.
- createStAXOMBuilder(OMAbstractFactory.getOMFactory(),
- XMLInputFactory.newInstance().createXMLStreamReader(
- new FileInputStream(absolutePath), "UTF-8"));
- rootElement = staxOMBuilder.getDocumentElement();
- } catch (Exception e) {
- log.info("Exception trying to get hold of rootElement: "
- + e.getMessage());
- log.info("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));
- rootElement.serializeWithCache(writer);
- } catch (XMLStreamException e) {
- log.info("Error in creating XMLStreamWriter to write parsed xml into");
- return;
- } catch (Exception e) {
- log.info("Exception while serializing: " +
- e.getMessage());
- log.info("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) {
- log.info("" +
- "Error comparing original and generated files for: " +
- absolutePath);
- log.info("Error message is: " + e.getMessage());
- return;
- }
- try {
- assertXMLEqual(diff, true);
- successCount++;
- } catch (Error e) {
- log.info("XMLEquality failed for file: " + absolutePath);
- }
- }
-
- public void tearDown() {
}
}
Added: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceUnit.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceUnit.java?rev=240161&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceUnit.java (added)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceUnit.java Thu Aug 25 21:53:51 2005
@@ -0,0 +1,108 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.axis2.om.infoset;
+
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLTestCase;
+import org.w3c.dom.Document;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+public class XMLConformanceUnit extends XMLTestCase implements EntityResolver {
+
+ private String filePath;
+ private File directory;
+
+ public XMLConformanceUnit(String filePath, String testName) {
+ super(testName);
+ this.filePath = filePath;
+ this.directory = new File(filePath).getParentFile();
+ }
+
+ public void testSingleFileConformance()
+ throws Exception {
+ OMElement rootElement;
+
+ System.out.println("XML File:" + filePath);
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.
+ createStAXOMBuilder(OMAbstractFactory.getOMFactory(),
+ factory.createXMLStreamReader(
+ new FileInputStream(filePath)));
+ rootElement = staxOMBuilder.getDocumentElement();
+
+ XMLStreamWriter writer;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ writer = XMLOutputFactory.newInstance().
+ createXMLStreamWriter(baos);
+ rootElement.serializeWithCache(writer);
+
+ writer.flush();
+ writer.close();
+
+ InputSource resultXML = new InputSource(new InputStreamReader(
+ new ByteArrayInputStream(baos.toByteArray())));
+
+ Document dom1 = newDocument(new InputSource(new FileReader(filePath)));
+ Document dom2 = newDocument(resultXML);
+
+ Diff diff = compareXML(dom1, dom2);
+ assertXMLEqual(diff, true);
+ }
+
+ /**
+ * Method newDocument
+ *
+ * @param in
+ * @return
+ * @throws javax.xml.parsers.ParserConfigurationException
+ *
+ * @throws org.xml.sax.SAXException
+ * @throws java.io.IOException
+ */
+ public Document newDocument(InputSource in)
+ throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ db.setEntityResolver(this);
+ return db.parse(in);
+ }
+
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+ File f = new File(directory, systemId.substring(systemId.lastIndexOf('/')));
+ return new InputSource(new FileInputStream(f));
+ }
+}
Propchange: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceUnit.java
------------------------------------------------------------------------------
svn:eol-style = native