You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ni...@apache.org on 2010/10/06 02:00:42 UTC
svn commit: r1004857 - in
/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input:
XmlStreamReaderUtilitiesTest.java compatibility/XmlStreamReaderException.java
compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java
Author: niallp
Date: Wed Oct 6 00:00:41 2010
New Revision: 1004857
URL: http://svn.apache.org/viewvc?rev=1004857&view=rev
Log:
Create a version of the XmlStreamReaderUtilitiesTest to run against the original XmlStreamReader implementation (Sanity check to make sure all the refactoring hasn't screwed things up)
Added:
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java (with props)
Modified:
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderUtilitiesTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderException.java
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderUtilitiesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderUtilitiesTest.java?rev=1004857&r1=1004856&r2=1004857&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderUtilitiesTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderUtilitiesTest.java Wed Oct 6 00:00:41 2010
@@ -166,10 +166,15 @@ public class XmlStreamReaderUtilitiesTes
builder.append("xmlGuessEnc=[").append(xmlGuessEnc).append("], ");
builder.append("xmlEnc=[").append(xmlEnc).append("], ");
builder.append("defaultEncoding=[").append(defaultEncoding).append("],");
- MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding);
- String encoding = mock.calculateRawEncoding(bomEnc,xmlGuessEnc,xmlEnc);
+ String encoding = calculateRawEncoding(bomEnc,xmlGuessEnc,xmlEnc, defaultEncoding);
assertEquals(builder.toString(), expected, encoding);
}
+ protected String calculateRawEncoding(String bomEnc, String xmlGuessEnc, String xmlEnc,
+ String defaultEncoding) throws IOException {
+ MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding);
+ String encoding = mock.calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc);
+ return encoding;
+ }
private void checkRawError(String msgSuffix,
String bomEnc, String xmlGuessEnc, String xmlEnc, String defaultEncoding) {
try {
@@ -212,20 +217,25 @@ public class XmlStreamReaderUtilitiesTes
checkHttpEncoding("UTF-8", false, APPXML_UTF8, null, null, null, null);
checkHttpEncoding("UTF-8", false, APPXML_UTF8, "UTF-16BE", "UTF-16BE", "UTF-16BE", "UTF-16BE");
}
- private void checkHttpEncoding(String expected, boolean lenienet, String httpContentType,
+ private void checkHttpEncoding(String expected, boolean lenient, String httpContentType,
String bomEnc, String xmlGuessEnc, String xmlEnc, String defaultEncoding) throws IOException {
StringBuilder builder = new StringBuilder();
builder.append("HttpEncoding: ").append(bomEnc).append("], ");
- builder.append("lenienet=[").append(lenienet).append("], ");
+ builder.append("lenient=[").append(lenient).append("], ");
builder.append("httpContentType=[").append(httpContentType).append("], ");
builder.append("bomEnc=[").append(bomEnc).append("], ");
builder.append("xmlGuessEnc=[").append(xmlGuessEnc).append("], ");
builder.append("xmlEnc=[").append(xmlEnc).append("], ");
builder.append("defaultEncoding=[").append(defaultEncoding).append("],");
- MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding);
- String encoding = mock.calculateHttpEncoding(httpContentType, bomEnc, xmlGuessEnc, xmlEnc, lenienet);
+ String encoding = calculateHttpEncoding(httpContentType, bomEnc, xmlGuessEnc, xmlEnc, lenient, defaultEncoding);
assertEquals(builder.toString(), expected, encoding);
}
+ protected String calculateHttpEncoding(String httpContentType, String bomEnc, String xmlGuessEnc,
+ String xmlEnc, boolean lenient, String defaultEncoding) throws IOException {
+ MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding);
+ String encoding = mock.calculateHttpEncoding(httpContentType, bomEnc, xmlGuessEnc, xmlEnc, lenient);
+ return encoding;
+ }
private void checkHttpError(String msgSuffix, boolean lenienet, String httpContentType,
String bomEnc, String xmlGuessEnc, String xmlEnc, String defaultEncoding) {
try {
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderException.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderException.java?rev=1004857&r1=1004856&r2=1004857&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderException.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderException.java Wed Oct 6 00:00:41 2010
@@ -17,7 +17,6 @@
package org.apache.commons.io.input.compatibility;
import java.io.InputStream;
-import java.io.IOException;
/**
* The XmlStreamReaderException is thrown by the XmlStreamReader constructors if
@@ -32,16 +31,9 @@ import java.io.IOException;
* @author Alejandro Abdelnur
* @version $Id$
*/
-public class XmlStreamReaderException extends IOException {
- private final String bomEncoding;
+public class XmlStreamReaderException extends org.apache.commons.io.input.XmlStreamReaderException {
- private final String xmlGuessEncoding;
-
- private final String xmlEncoding;
-
- private final String contentTypeMime;
-
- private final String contentTypeEncoding;
+ private static final long serialVersionUID = 1L;
private final InputStream is;
@@ -78,66 +70,11 @@ public class XmlStreamReaderException ex
*/
public XmlStreamReaderException(String msg, String ctMime, String ctEnc,
String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is) {
- super(msg);
- contentTypeMime = ctMime;
- contentTypeEncoding = ctEnc;
- bomEncoding = bomEnc;
- xmlGuessEncoding = xmlGuessEnc;
- xmlEncoding = xmlEnc;
+ super(msg, ctMime, ctEnc, bomEnc, xmlGuessEnc, xmlEnc);
this.is = is;
}
/**
- * Returns the BOM encoding found in the InputStream.
- *
- * @return the BOM encoding, null if none.
- */
- public String getBomEncoding() {
- return bomEncoding;
- }
-
- /**
- * Returns the encoding guess based on the first bytes of the InputStream.
- *
- * @return the encoding guess, null if it couldn't be guessed.
- */
- public String getXmlGuessEncoding() {
- return xmlGuessEncoding;
- }
-
- /**
- * Returns the encoding found in the XML prolog of the InputStream.
- *
- * @return the encoding of the XML prolog, null if none.
- */
- public String getXmlEncoding() {
- return xmlEncoding;
- }
-
- /**
- * Returns the MIME type in the content-type used to attempt determining the
- * encoding.
- *
- * @return the MIME type in the content-type, null if there was not
- * content-type or the encoding detection did not involve HTTP.
- */
- public String getContentTypeMime() {
- return contentTypeMime;
- }
-
- /**
- * Returns the encoding in the content-type used to attempt determining the
- * encoding.
- *
- * @return the encoding in the content-type, null if there was not
- * content-type, no encoding in it or the encoding detection did not
- * involve HTTP.
- */
- public String getContentTypeEncoding() {
- return contentTypeEncoding;
- }
-
- /**
* Returns the unconsumed InputStream to allow the application to do an
* alternate encoding detection on the InputStream.
*
Added: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java?rev=1004857&view=auto
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java (added)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java Wed Oct 6 00:00:41 2010
@@ -0,0 +1,51 @@
+/*
+ * 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.commons.io.input.compatibility;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.apache.commons.io.input.XmlStreamReaderUtilitiesTest;
+
+/**
+ * Test compatibility of the original XmlStreamReader (before all the refactoring).
+ */
+public class XmlStreamReaderUtilitiesCompatibilityTest extends XmlStreamReaderUtilitiesTest {
+
+ protected String calculateRawEncoding(String bomEnc, String xmlGuessEnc, String xmlEnc,
+ String defaultEncoding) throws IOException {
+ MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding);
+ String encoding = mock.calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, null);
+ return encoding;
+ }
+ protected String calculateHttpEncoding(String httpContentType, String bomEnc, String xmlGuessEnc,
+ String xmlEnc, boolean lenient, String defaultEncoding) throws IOException {
+ MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding);
+ String encoding = mock.calculateHttpEncoding(
+ XmlStreamReader.getContentTypeMime(httpContentType),
+ XmlStreamReader.getContentTypeEncoding(httpContentType),
+ bomEnc, xmlGuessEnc, xmlEnc, null, lenient);
+ return encoding;
+ }
+
+ /** Mock {@link XmlStreamReader} implementation */
+ private static class MockXmlStreamReader extends XmlStreamReader {
+ MockXmlStreamReader(String defaultEncoding) throws IOException {
+ super(new ByteArrayInputStream("".getBytes()), null, true, defaultEncoding);
+ }
+ }
+}
Propchange: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL