001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 021 package org.apache.geronimo.testsupport; 022 023 import java.util.List; 024 025 import javax.xml.namespace.QName; 026 027 import org.apache.xmlbeans.XmlObject; 028 import org.apache.xmlbeans.XmlCursor; 029 030 /** 031 * @version $Rev: 514087 $ $Date: 2007-03-03 01:13:40 -0500 (Sat, 03 Mar 2007) $ 032 */ 033 public class XmlBeansTestSupport extends TestSupport { 034 035 /** 036 * Constructor for tests that specify a specific test name. 037 * 038 * @see #TestSupport() This is the prefered constructor for sub-classes to use. 039 */ 040 protected XmlBeansTestSupport(final String name) { 041 super(name); 042 } 043 044 /** 045 * Default constructor. 046 */ 047 protected XmlBeansTestSupport() { 048 super(); 049 } 050 051 public boolean compareXmlObjects(XmlObject xmlObject, XmlObject expectedObject, List problems) { 052 XmlCursor test = xmlObject.newCursor(); 053 XmlCursor expected = expectedObject.newCursor(); 054 boolean similar = true; 055 int elementCount = 0; 056 while (toNextStartToken(test)) { 057 elementCount++; 058 if (!toNextStartToken(expected)) { 059 problems.add("test longer than expected at element: " + elementCount); 060 return false; 061 } 062 QName actualQName = test.getName(); 063 QName expectedQName = expected.getName(); 064 if (!actualQName.equals(expectedQName)) { 065 problems.add("Different elements at elementCount: " + elementCount + ", test: " + actualQName + ", expected: " + expectedQName); 066 similar = false; 067 } 068 test.toNextToken(); 069 expected.toNextToken(); 070 } 071 if (toNextStartToken(expected)) { 072 problems.add("test shorter that expected at element: " + elementCount); 073 similar = false; 074 } 075 return similar; 076 } 077 078 public boolean toNextStartToken(XmlCursor cursor) { 079 while (!cursor.isStart()) { 080 if (!cursor.hasNextToken()) { 081 return false; 082 } 083 cursor.toNextToken(); 084 } 085 return true; 086 } 087 088 089 090 }