Author: veithen
Date: Thu Mar 26 10:15:54 2009
New Revision: 758580
URL: http://svn.apache.org/viewvc?rev=758580&view=rev
Log:
Improved the test suite for OMStAXWrapper and corrected the behavior of
OMStAXWrapper#getTextStart().
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/XMLStreamReaderComparator.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java?rev=758580&r1=758579&r2=758580&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java
Thu Mar 26 10:15:54 2009
@@ -376,9 +376,13 @@
if (parser != null) {
return parser.getTextStart();
} else {
- // getTextCharacters always returns a new char array and the start
- // index is therefore always 0
- return 0;
+ if (hasText()) {
+ // getTextCharacters always returns a new char array and the
start
+ // index is therefore always 0
+ return 0;
+ } else {
+ throw new IllegalStateException();
+ }
}
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/XMLStreamReaderComparator.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/XMLStreamReaderComparator.java?rev=758580&r1=758579&r2=758580&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/XMLStreamReaderComparator.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/XMLStreamReaderComparator.java
Thu Mar 26 10:15:54 2009
@@ -21,7 +21,10 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import javax.xml.stream.XMLStreamReader;
@@ -41,23 +44,8 @@
this.actual = actual;
}
- private Object[] invoke(String methodName, Object[] args) throws Exception
{
- if (args == null) {
- args = new Object[0];
- }
- Method[] methods = XMLStreamReader.class.getMethods();
- Method method = null;
- for (int i=0; i<methods.length; i++) {
- Method candidate = methods[i];
- if (candidate.getName().equals(methodName) &&
- candidate.getParameterTypes().length == args.length) {
- method = candidate;
- break;
- }
- }
- if (method == null) {
- fail("Method " + methodName + " not found");
- }
+ private Object[] invoke(String methodName, Class[] paramTypes, Object[]
args) throws Exception {
+ Method method = XMLStreamReader.class.getMethod(methodName,
paramTypes);
Object expectedResult;
Throwable expectedException;
@@ -100,8 +88,12 @@
return null;
}
- private Object assertSameResult(String methodName, Object[] args) throws
Exception {
- Object[] results = invoke(methodName, args);
+ private Object[] invoke(String methodName) throws Exception {
+ return invoke(methodName, new Class[0], new Object[0]);
+ }
+
+ private Object assertSameResult(String methodName, Class[] paramTypes,
Object[] args) throws Exception {
+ Object[] results = invoke(methodName, paramTypes, args);
if (results != null) {
assertEquals("Return value of " + methodName + " (event type " +
StAXUtils.getEventTypeString(expected.getEventType())
+ ")",
@@ -112,47 +104,73 @@
}
}
+ private Object assertSameResult(String methodName) throws Exception {
+ return assertSameResult(methodName, new Class[0], new Object[0]);
+ }
+
public void compare() throws Exception {
+ // Collect all prefixes seen in the document to be able to test
getNamespaceURI(String)
+ Set prefixes = new HashSet();
while (expected.next() != XMLStreamReader.END_DOCUMENT) {
actual.next();
- Integer attributeCount =
(Integer)assertSameResult("getAttributeCount", null);
+ Integer attributeCount =
(Integer)assertSameResult("getAttributeCount");
if (attributeCount != null) {
for (int i=0; i<attributeCount.intValue(); i++) {
+ Class[] paramTypes = { Integer.TYPE };
Object[] args = { Integer.valueOf(i) };
- assertSameResult("getAttributeLocalName", args);
- assertSameResult("getAttributeName", args);
- assertSameResult("getAttributeNamespace", args);
- assertSameResult("getAttributePrefix", args);
- assertSameResult("getAttributeType", args);
- assertSameResult("getAttributeValue", args);
+ assertSameResult("getAttributeLocalName", paramTypes,
args);
+ assertSameResult("getAttributeName", paramTypes, args);
+ assertSameResult("getAttributeNamespace", paramTypes,
args);
+ prefixes.add(assertSameResult("getAttributePrefix",
paramTypes, args));
+ assertSameResult("getAttributeType", paramTypes, args);
+ assertSameResult("getAttributeValue", paramTypes, args);
}
}
- assertSameResult("getLocalName", null);
- assertSameResult("getName", null);
- Integer namespaceCount =
(Integer)assertSameResult("getNamespaceCount", null);
+ assertSameResult("getLocalName");
+ assertSameResult("getName");
+ Integer namespaceCount =
(Integer)assertSameResult("getNamespaceCount");
if (namespaceCount != null) {
Map expectedNamespaces = new HashMap();
Map actualNamespaces = new HashMap();
for (int i=0; i<namespaceCount.intValue(); i++) {
- expectedNamespaces.put(expected.getNamespacePrefix(i),
+ String prefix = expected.getNamespacePrefix(i);
+ expectedNamespaces.put(prefix,
expected.getNamespaceURI(i));
actualNamespaces.put(actual.getNamespacePrefix(i),
actual.getNamespaceURI(i));
+ prefixes.add(prefix);
}
assertEquals(expectedNamespaces, actualNamespaces);
}
- assertSameResult("getNamespaceURI", null);
- assertSameResult("getPIData", null);
- assertSameResult("getPITarget", null);
- assertSameResult("getPrefix", null);
- assertSameResult("getText", null);
- assertSameResult("getTextLength", null);
- assertSameResult("hasName", null);
- assertSameResult("hasText", null);
- assertSameResult("isCharacters", null);
- assertSameResult("isEndElement", null);
- assertSameResult("isStartElement", null);
- assertSameResult("isWhiteSpace", null);
+ assertSameResult("getNamespaceURI");
+ assertSameResult("getPIData");
+ assertSameResult("getPITarget");
+ prefixes.add(assertSameResult("getPrefix"));
+ assertSameResult("getText");
+ Integer textLength = (Integer)assertSameResult("getTextLength");
+ Object[] textStart = invoke("getTextStart");
+ Object[] textCharacters = invoke("getTextCharacters");
+ if (textLength != null) {
+ assertEquals(new String((char[])textCharacters[0],
+ ((Integer)textStart[0]).intValue(),
+ textLength.intValue()),
+ new String((char[])textCharacters[1],
+ ((Integer)textStart[1]).intValue(),
+ textLength.intValue()));
+ }
+ assertSameResult("hasName");
+ assertSameResult("hasText");
+ assertSameResult("isCharacters");
+ assertSameResult("isEndElement");
+ assertSameResult("isStartElement");
+ assertSameResult("isWhiteSpace");
+ for (Iterator it = prefixes.iterator(); it.hasNext(); ) {
+ String prefix = (String)it.next();
+ if (prefix != null) {
+ assertSameResult("getNamespaceURI",
+ new Class[] { String.class }, new Object[] {
prefix });
+ }
+ }
}
}
}