1 19 20 21 package org.apache.geronimo.testsupport; 22 23 import java.util.List ; 24 25 import javax.xml.namespace.QName ; 26 27 import org.apache.xmlbeans.XmlObject; 28 import org.apache.xmlbeans.XmlCursor; 29 30 33 public class XmlBeansTestSupport extends TestSupport { 34 35 40 protected XmlBeansTestSupport(final String name) { 41 super(name); 42 } 43 44 47 protected XmlBeansTestSupport() { 48 super(); 49 } 50 51 public boolean compareXmlObjects(XmlObject xmlObject, XmlObject expectedObject, List problems) { 52 XmlCursor test = xmlObject.newCursor(); 53 XmlCursor expected = expectedObject.newCursor(); 54 boolean similar = true; 55 int elementCount = 0; 56 while (toNextStartToken(test)) { 57 elementCount++; 58 if (!toNextStartToken(expected)) { 59 problems.add("test longer than expected at element: " + elementCount); 60 return false; 61 } 62 QName actualQName = test.getName(); 63 QName expectedQName = expected.getName(); 64 if (!actualQName.equals(expectedQName)) { 65 problems.add("Different elements at elementCount: " + elementCount + ", test: " + actualQName + ", expected: " + expectedQName); 66 similar = false; 67 } 68 test.toNextToken(); 69 expected.toNextToken(); 70 } 71 if (toNextStartToken(expected)) { 72 problems.add("test shorter that expected at element: " + elementCount); 73 similar = false; 74 } 75 return similar; 76 } 77 78 public boolean toNextStartToken(XmlCursor cursor) { 79 while (!cursor.isStart()) { 80 if (!cursor.hasNextToken()) { 81 return false; 82 } 83 cursor.toNextToken(); 84 } 85 return true; 86 } 87 88 89 90 } 91 | Popular Tags |