You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/04/04 20:26:41 UTC

svn commit: r1088697 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/impl/builder/ axiom-testsuite/src/main/java/org/apache/axiom/ts/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/

Author: veithen
Date: Mon Apr  4 18:26:40 2011
New Revision: 1088697

URL: http://svn.apache.org/viewvc?rev=1088697&view=rev
Log:
Added some unit tests for the SAXOMBuilder stuff and fixed some issues.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMXMLParserWrapper.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMXMLParserWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMXMLParserWrapper.java?rev=1088697&r1=1088696&r2=1088697&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMXMLParserWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMXMLParserWrapper.java Mon Apr  4 18:26:40 2011
@@ -56,12 +56,18 @@ public class SAXOMXMLParserWrapper imple
             XMLReader reader = source.getXMLReader();
             reader.setContentHandler(builder);
             try {
+                reader.setProperty("http://xml.org/sax/properties/lexical-handler", builder);
+            } catch (SAXException ex) {
+                // Ignore
+            }
+            try {
                 reader.parse(source.getInputSource());
             } catch (IOException ex) {
                 throw new OMException(ex);
             } catch (SAXException ex) {
                 throw new OMException(ex);
             }
+            document = builder.getDocument();
         }
         return document;
     }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1088697&r1=1088696&r2=1088697&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java Mon Apr  4 18:26:40 2011
@@ -50,6 +50,9 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.builder.TestInvalidXML(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestIOExceptionInGetText(metaFactory));
         for (int i=0; i<conformanceFiles.length; i++) {
+            addTest(new org.apache.axiom.ts.om.builder.TestSAXOMBuilder(metaFactory, conformanceFiles[i]));
+        }
+        for (int i=0; i<conformanceFiles.length; i++) {
             for (int j=0; j<containerFactories.length; j++) {
                 addTest(new org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory, conformanceFiles[i], containerFactories[j], true));
                 addTest(new org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory, conformanceFiles[i], containerFactories[j], false));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java?rev=1088697&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java Mon Apr  4 18:26:40 2011
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axiom.ts.om.builder;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.sax.SAXSource;
+
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.ts.ConformanceTestCase;
+import org.xml.sax.InputSource;
+
+public class TestSAXOMBuilder extends ConformanceTestCase {
+    public TestSAXOMBuilder(OMMetaFactory metaFactory, String file) {
+        super(metaFactory, file);
+    }
+
+    protected void runTest() throws Throwable {
+        SAXParserFactory factory = SAXParserFactory.newInstance();
+        factory.setNamespaceAware(true);
+        factory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
+        SAXParser parser = factory.newSAXParser();
+        InputStream in = getFileAsStream();
+        try {
+            SAXSource source = new SAXSource(parser.getXMLReader(), new InputSource(in));
+            OMXMLParserWrapper builder = OMXMLBuilderFactory.createSAXOMBuilder(metaFactory.getOMFactory(), source);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            builder.getDocument().serialize(baos);
+            assertXMLIdentical(compareXML(
+                    AbstractTestCase.toDocumentWithoutDTD(getFileAsStream()),
+                    AbstractTestCase.toDocumentWithoutDTD(new ByteArrayInputStream(baos.toByteArray()))), true);
+        } finally {
+            in.close();
+        }
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native