Author: veithen
Date: Sun Sep  5 13:51:42 2010
New Revision: 992784

URL: http://svn.apache.org/viewvc?rev=992784&view=rev
Log:
Increased test coverage for StAX dialects.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingExternalTestCase.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingWithCharacterStreamTestCase.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/NextAfterEndDocumentTestCase.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java?rev=992784&r1=992783&r2=992784&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
 Sun Sep  5 13:51:42 2010
@@ -91,7 +91,6 @@ class BEAStreamReaderWrapper extends XML
 
     public String getEncoding() {
         if (getEventType() == START_DOCUMENT) {
-            // TODO: this needs some more unit testing!
             String encoding = super.getEncoding();
             if (encoding != null) {
                 return encoding;

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java?rev=992784&r1=992783&r2=992784&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
 Sun Sep  5 13:51:42 2010
@@ -43,16 +43,19 @@ public class DialectTest extends TestSui
         addDialectTest(new DisallowDoctypeDeclWithExternalSubsetTestCase());
         addDialectTest(new DisallowDoctypeDeclWithInternalSubsetTestCase());
         addDialectTest(new GetCharacterEncodingSchemeTestCase());
+        addDialectTest(new GetEncodingExternalTestCase());
         addDialectTest(new GetEncodingFromDetectionTestCase("UTF-8", "UTF-8"));
         addDialectTest(new GetEncodingFromDetectionTestCase("UnicodeBig", 
"UTF-16BE"));
         addDialectTest(new GetEncodingFromDetectionTestCase("UnicodeLittle", 
"UTF-16LE"));
         addDialectTest(new 
GetEncodingFromDetectionTestCase("UnicodeBigUnmarked", "UTF-16BE"));
         addDialectTest(new 
GetEncodingFromDetectionTestCase("UnicodeLittleUnmarked", "UTF-16LE"));
         addDialectTest(new GetEncodingTestCase());
+        addDialectTest(new GetEncodingWithCharacterStreamTestCase());
         addDialectTest(new GetVersionTestCase());
         addDialectTest(new IsCharactersOnCDATASectionTestCase());
         addDialectTest(new IsStandaloneTestCase());
         addDialectTest(new MaskedNamespaceTestCase());
+        addDialectTest(new NextAfterEndDocumentTestCase());
         addDialectTest(new StandaloneSetTestCase());
         addDialectTest(new WriteStartDocumentWithNullEncodingTestCase());
     }

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingExternalTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingExternalTestCase.java?rev=992784&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingExternalTestCase.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingExternalTestCase.java
 Sun Sep  5 13:51:42 2010
@@ -0,0 +1,37 @@
+/*
+ * 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.util.stax.dialect;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Checks that {...@link XMLStreamReader#getEncoding()} returns the charset 
passed to
+ * {...@link XMLInputFactory#createXMLStreamReader(java.io.InputStream, 
String)}.
+ */
+public class GetEncodingExternalTestCase extends DialectTestCase {
+    protected void runTest() throws Throwable {
+        XMLInputFactory factory = newNormalizedXMLInputFactory();
+        XMLStreamReader reader = factory.createXMLStreamReader(new 
ByteArrayInputStream(
+                "<root/>".getBytes("ISO-8859-1")), "ISO-8859-1");
+        assertEquals("ISO-8859-1", reader.getEncoding());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingExternalTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingWithCharacterStreamTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingWithCharacterStreamTestCase.java?rev=992784&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingWithCharacterStreamTestCase.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingWithCharacterStreamTestCase.java
 Sun Sep  5 13:51:42 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.util.stax.dialect;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Checks that {...@link XMLStreamReader#getEncoding()} returns 
<code>null</code> if the reader was
+ * created from a character stream.
+ */
+public class GetEncodingWithCharacterStreamTestCase extends DialectTestCase {
+    protected void runTest() throws Throwable {
+        XMLInputFactory factory = newNormalizedXMLInputFactory();
+        XMLStreamReader reader = factory.createXMLStreamReader(new 
StringReader("<root/>"));
+        assertNull(reader.getEncoding());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingWithCharacterStreamTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/NextAfterEndDocumentTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/NextAfterEndDocumentTestCase.java?rev=992784&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/NextAfterEndDocumentTestCase.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/NextAfterEndDocumentTestCase.java
 Sun Sep  5 13:51:42 2010
@@ -0,0 +1,50 @@
+/*
+ * 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.util.stax.dialect;
+
+import java.io.StringReader;
+import java.util.NoSuchElementException;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Checks the type of exception thrown by {...@link XMLStreamReader#next()} if 
the end of the document
+ * has already been reached.
+ */
+public class NextAfterEndDocumentTestCase extends DialectTestCase {
+    protected void runTest() throws Throwable {
+        XMLInputFactory factory = newNormalizedXMLInputFactory();
+        XMLStreamReader reader = factory.createXMLStreamReader(new 
StringReader("<root/>"));
+        while (reader.next() != XMLStreamReader.END_DOCUMENT) {
+            // Just loop
+        }
+        try {
+            reader.next();
+            fail("Expected exception");
+        } catch (IllegalStateException ex) {
+            // Expected
+        } catch (NoSuchElementException ex) {
+            // This is also OK
+        } catch (XMLStreamException ex) {
+            fail("Expected IllegalStateException or NoSuchElementException");
+        }
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/NextAfterEndDocumentTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to