KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > testsupport > XmlBeansTestSupport


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */

19
20
21 package org.apache.geronimo.testsupport;
22
23 import java.util.List JavaDoc;
24
25 import javax.xml.namespace.QName JavaDoc;
26
27 import org.apache.xmlbeans.XmlObject;
28 import org.apache.xmlbeans.XmlCursor;
29
30 /**
31  * @version $Rev: 476321 $ $Date: 2006-11-17 16:18:49 -0500 (Fri, 17 Nov 2006) $
32  */

33 public class XmlBeansTestSupport extends TestSupport {
34
35     /**
36      * Constructor for tests that specify a specific test name.
37      *
38      * @see #TestSupport() This is the prefered constructor for sub-classes to use.
39      */

40     protected XmlBeansTestSupport(final String JavaDoc name) {
41         super(name);
42     }
43
44     /**
45      * Default constructor.
46      */

47     protected XmlBeansTestSupport() {
48         super();
49     }
50
51     public boolean compareXmlObjects(XmlObject xmlObject, XmlObject expectedObject, List JavaDoc 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 JavaDoc actualQName = test.getName();
63             QName JavaDoc 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