You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2006/09/19 21:59:05 UTC

svn commit: r447942 - in /geronimo/server/trunk/testsupport/testsupport-common: pom.xml src/main/java/org/apache/geronimo/testsupport/XmlBeansTestSupport.java

Author: djencks
Date: Tue Sep 19 12:59:04 2006
New Revision: 447942

URL: http://svn.apache.org/viewvc?view=rev&rev=447942
Log:
GERONIMO-2415 add xmlbeans test support class

Added:
    geronimo/server/trunk/testsupport/testsupport-common/src/main/java/org/apache/geronimo/testsupport/XmlBeansTestSupport.java   (with props)
Modified:
    geronimo/server/trunk/testsupport/testsupport-common/pom.xml

Modified: geronimo/server/trunk/testsupport/testsupport-common/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsupport/testsupport-common/pom.xml?view=diff&rev=447942&r1=447941&r2=447942
==============================================================================
--- geronimo/server/trunk/testsupport/testsupport-common/pom.xml (original)
+++ geronimo/server/trunk/testsupport/testsupport-common/pom.xml Tue Sep 19 12:59:04 2006
@@ -52,7 +52,21 @@
             <artifactId>junit</artifactId>
             <scope>compile</scope>
         </dependency>
-        
+
+        <!--xmlbeans -->
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-qname_1.1_spec</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>xmlbeans</groupId>
+            <artifactId>xbean</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>stax</groupId>
+            <artifactId>stax-api</artifactId>
+        </dependency>
+
     </dependencies>
     
 </project>

Added: geronimo/server/trunk/testsupport/testsupport-common/src/main/java/org/apache/geronimo/testsupport/XmlBeansTestSupport.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsupport/testsupport-common/src/main/java/org/apache/geronimo/testsupport/XmlBeansTestSupport.java?view=auto&rev=447942
==============================================================================
--- geronimo/server/trunk/testsupport/testsupport-common/src/main/java/org/apache/geronimo/testsupport/XmlBeansTestSupport.java (added)
+++ geronimo/server/trunk/testsupport/testsupport-common/src/main/java/org/apache/geronimo/testsupport/XmlBeansTestSupport.java Tue Sep 19 12:59:04 2006
@@ -0,0 +1,90 @@
+/*
+ * 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.geronimo.testsupport;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlCursor;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class XmlBeansTestSupport extends TestSupport {
+
+    /**
+     * Constructor for tests that specify a specific test name.
+     *
+     * @see #TestSupport()  This is the prefered constructor for sub-classes to use.
+     */
+    protected XmlBeansTestSupport(final String name) {
+        super(name);
+    }
+
+    /**
+     * Default constructor.
+     */
+    protected XmlBeansTestSupport() {
+        super();
+    }
+
+    public boolean compareXmlObjects(XmlObject xmlObject, XmlObject expectedObject, List problems) {
+        XmlCursor test = xmlObject.newCursor();
+        XmlCursor expected = expectedObject.newCursor();
+        boolean similar = true;
+        int elementCount = 0;
+        while (toNextStartToken(test)) {
+            elementCount++;
+            if (!toNextStartToken(expected)) {
+                problems.add("test longer than expected at element: " + elementCount);
+                return false;
+            }
+            QName actualQName = test.getName();
+            QName expectedQName = expected.getName();
+            if (!actualQName.equals(expectedQName)) {
+                problems.add("Different elements at elementCount: " + elementCount + ", test: " + actualQName + ", expected: " + expectedQName);
+                similar = false;
+            }
+            test.toNextToken();
+            expected.toNextToken();
+        }
+        if (toNextStartToken(expected)) {
+            problems.add("test shorter that expected at element: " + elementCount);
+            similar = false;
+        }
+        return similar;
+    }
+
+    public boolean toNextStartToken(XmlCursor cursor) {
+        while (!cursor.isStart()) {
+            if (!cursor.hasNextToken()) {
+                return false;
+            }
+            cursor.toNextToken();
+        }
+        return true;
+    }
+
+
+
+}

Propchange: geronimo/server/trunk/testsupport/testsupport-common/src/main/java/org/apache/geronimo/testsupport/XmlBeansTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/testsupport/testsupport-common/src/main/java/org/apache/geronimo/testsupport/XmlBeansTestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/testsupport/testsupport-common/src/main/java/org/apache/geronimo/testsupport/XmlBeansTestSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain