You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ra...@apache.org on 2008/04/04 03:48:11 UTC

svn commit: r644577 - in /xmlbeans/trunk/test/src/xmlcursor/xpath: common/ complex/detailed/

Author: radup
Date: Thu Apr  3 18:48:10 2008
New Revision: 644577

URL: http://svn.apache.org/viewvc?rev=644577&view=rev
Log:
Contributed by Wing Yew Poon. Clean up of xpath tests.

Modified:
    xmlbeans/trunk/test/src/xmlcursor/xpath/common/BaseXPathTest.java
    xmlbeans/trunk/test/src/xmlcursor/xpath/common/XPathExpressionTest.java
    xmlbeans/trunk/test/src/xmlcursor/xpath/common/XPathFunctionTest.java
    xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/DeclareNamespaceTest.java
    xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/NodeCopyTest.java
    xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/TypesTest.java
    xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathExpressionTestImpl.java
    xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathFunctionTestImpl.java
    xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathNodeTest.java

Modified: xmlbeans/trunk/test/src/xmlcursor/xpath/common/BaseXPathTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlcursor/xpath/common/BaseXPathTest.java?rev=644577&r1=644576&r2=644577&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/xmlcursor/xpath/common/BaseXPathTest.java (original)
+++ xmlbeans/trunk/test/src/xmlcursor/xpath/common/BaseXPathTest.java Thu Apr  3 18:48:10 2008
@@ -71,39 +71,38 @@
         testMap.put("testAnd", and);
 
         testMap.put("testFunctionId", new String[]{
-                 "id(\"bobdylan\")",
-        "id(\"foobar\")",
-        "id(\"*\")/child::cd[position()=3]"}
-                );
+            "id(\"bobdylan\")",
+            "id(\"foobar\")",
+            "id(\"*\")/child::cd[position()=3]"});
+
         testMap.put("testFunctionLast", new String[]{
-        "/catalog/cd[last()]"   });
+            "/catalog/cd[last()]"});
 
         testMap.put("testFunctionNamespaceURI", new String[]{
-        "//*[namespace-uri(.)=\"uri.org\"]"
-        });
+            "//*[namespace-uri(.)=\"uri.org\"]"});
+
+        testMap.put("testFunctionNumber", new String[]{
+            "/foo/bar[number(price)+1=4]"});
+
+        testMap.put("testFunctionRound", new String[]{
+            "//bar//*[round(text())=3]"});
+
+        testMap.put("testFunctionSum", new String[]{
+            "//bar[position()=sum(price)-4]"});
+
+        testMap.put("testFunctionBoolean", new String[]{
+            "/foo[boolean(.//@at)]"});
 
-          testMap.put("testFunctionNumber",new String[]{
-                  "/foo/bar[number(price)+1=4]"});
+        testMap.put("testFunctionFalse", new String[]{
+            "//foo[boolean(price)=false()]"});
 
-          testMap.put("testFunctionRound",new String[]{
-        "//bar//*[round(text())=3]"      });
+        testMap.put("testFunctionLang", new String[]{
+            "//price[xf:lang(\"en\")=true()]",
+            "//foo[xf:lang(\"en\")=true()]"});
 
-         testMap.put("testFunctionSum",new String[]{
-        "//bar[position()=sum(price)-4]"  });
-
-        testMap.put("testFunctionBoolean",new String[]{
-        "/foo[boolean(.//@at)]" });
-
-        testMap.put("testFunctionFalse",new String[]{
-        "//foo[boolean(price)=false()]"    });
-
-          testMap.put("testFunctionLang",new String[]{
-        "//price[xf:lang(\"en\")=true()]",
-        "//foo[xf:lang(\"en\")=true()]"}
-        );
-          testMap.put("testFunctionTrue",new String[]{
-        "//*[xf:boolean(@at)=true()]"  });
+        testMap.put("testFunctionTrue", new String[]{
+            "//*[xf:boolean(@at)=true()]"});
     }
 
     public abstract String getQuery(String testName, int testCase);
-}
\ No newline at end of file
+}

Modified: xmlbeans/trunk/test/src/xmlcursor/xpath/common/XPathExpressionTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlcursor/xpath/common/XPathExpressionTest.java?rev=644577&r1=644576&r2=644577&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/xmlcursor/xpath/common/XPathExpressionTest.java (original)
+++ xmlbeans/trunk/test/src/xmlcursor/xpath/common/XPathExpressionTest.java Thu Apr  3 18:48:10 2008
@@ -14,12 +14,8 @@
  */
 package xmlcursor.xpath.common;
 
-
 import org.apache.xmlbeans.XmlObject;
 
-import junit.framework.*;
-import junit.framework.Test;
-import junit.framework.TestSuite;
 /**
  * Verifies XPath with Expressions
  * http://www.w3schools.com/xpath/xpath_expressions.asp
@@ -35,118 +31,114 @@
         super(sName);
     }
 
-
     //("/catalog/cd[price>10.80]/price
     //Numerical Expressions
     /**
      * + Addition 6 + 4 10
      */
     public void testAddition() throws Exception {
-	String sXpath=getQuery("testAddition",0);
-	m_xc.selectPath(sXpath);
-	assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
-	assertEquals("<price at=\"val0\">3.00</price>",m_xc.xmlText());
+        String sXpath=getQuery("testAddition",0);
+        m_xc.selectPath(sXpath);
+        assertEquals(1,m_xc.getSelectionCount());
+        m_xc.toNextSelection();
+        assertEquals("<price at=\"val0\">3.00</price>",m_xc.xmlText());
     }
     /**
      * - Subtraction 6 - 4 2
      */
     public void testSubtraction() throws Exception {
 
-	String sXpath=getQuery("testSubtraction",0);
-	String sExpected="<price at=\"val1\">2</price>";
-	m_xc.selectPath(sXpath);
-	assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
+        String sXpath=getQuery("testSubtraction",0);
+        String sExpected="<price at=\"val1\">2</price>";
+        m_xc.selectPath(sXpath);
+        assertEquals(1,m_xc.getSelectionCount());
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
     }
     /**
-     * \* Multiplication 6 * 4 24
+     * * Multiplication 6 * 4 24
      */
     public void testMultiplication() throws Exception {
-	String sXpath=getQuery("testMultiplication",0);
-	String sExpected="<price at=\"val1\">2</price>";
-	m_xc.selectPath(sXpath);
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
-
+        String sXpath=getQuery("testMultiplication",0);
+        String sExpected="<price at=\"val1\">2</price>";
+        m_xc.selectPath(sXpath);
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
     }
     /**
      * div Division 8 div 4 2
-     * $NOTE: do a case where res is infinite (eg 10 div 3 or 22/7)
+     * NOTE: do a case where res is infinite (eg 10 div 3 or 22/7)
      */
     public void testDiv() throws Exception {
+        String sXpath=getQuery("testDiv",0); //get the second(last) price child
+        String sExpected="<price at=\"val0\">3.00</price>";
+        m_xc.selectPath(sXpath);
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
 
-	String sXpath=getQuery("testDiv",0); //get the second(last) price child
-	String sExpected="<price at=\"val0\">3.00</price>";
-	m_xc.selectPath(sXpath);
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
-
-	m_xc.clearSelections();
-         m_xc.toStartDoc();
-
-
-	 sXpath=getQuery("testDiv",1); //get the second(last) price child
-	 sExpected="<price at=\"val1\">2</price>";
-	m_xc.selectPath(sXpath);
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
-
-	m_xc.clearSelections();
+        m_xc.clearSelections();
         m_xc.toStartDoc();
 
+        sXpath=getQuery("testDiv",1); //get the second(last) price child
+        sExpected="<price at=\"val1\">2</price>";
+        m_xc.selectPath(sXpath);
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
+
+        m_xc.clearSelections();
+        m_xc.toStartDoc();
 
-	String sXpathZero=getQuery("testDiv",2);
+        String sXpathZero=getQuery("testDiv",2);
+        int i = 0;
         try{
             m_xc.selectPath(sXpathZero);
+            i = m_xc.getSelectionCount();
             fail("Division by 0");
         }catch (Exception e){}
-	assertEquals(0,m_xc.getSelectionCount());
+        assertEquals(0,i);
 
-	m_xc.clearSelections();
+        m_xc.clearSelections();
         m_xc.toStartDoc();
 
-
-	String sXpathInf=getQuery("testDiv",3);
-	m_xc.selectPath(sXpathInf);
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
-
+        String sXpathInf=getQuery("testDiv",3);
+        m_xc.selectPath(sXpathInf);
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
     }
     /**
      * mod Modulus (division remainder) 5 mod 2 1
      */
     public void testMod() throws Exception {
 
-	String sXpath=getQuery("testMod",0); //get the second(last) price child
-	String sExpected="<price at=\"val1\">2</price>";
+        String sXpath=getQuery("testMod",0); //get the second(last) price child
+        String sExpected="<price at=\"val1\">2</price>";
 
-	m_xc.selectPath(sXpath);
-	assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
+        m_xc.selectPath(sXpath);
+        assertEquals(1,m_xc.getSelectionCount());
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
 
-	m_xc.clearSelections();
+        m_xc.clearSelections();
         m_xc.toStartDoc();
 
 
-	sXpath=getQuery("testMod",1); //get the second(last) price child
+        sXpath=getQuery("testMod",1); //get the second(last) price child
 
-	m_xc.selectPath(sXpath);
-	assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
+        m_xc.selectPath(sXpath);
+        assertEquals(1,m_xc.getSelectionCount());
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
 
-	String sXpathZero="10 mod 0";
-	m_xc.clearSelections();
+        String sXpathZero="10 mod 0";
+        m_xc.clearSelections();
         m_xc.toStartDoc();
-	try{
-	    m_xc.selectPath(sXpathZero);
+        int i = 0;
+        try{
+            m_xc.selectPath(sXpathZero);
+            i = m_xc.getSelectionCount();
             fail("Mod by 0");
-	}catch (Exception e){}
-	assertEquals(0,m_xc.getSelectionCount());
-
+        }catch (Exception e){}
+        assertEquals(0,i);
     }
 
     //Equality Expressions
@@ -154,44 +146,41 @@
      * = Like (equal) price=9.80 true (if price is 9.80)
      */
     public void testEqual() throws Exception {
-	String sXml="<foo><bar>" +
+        String sXml="<foo><bar>" +
                 "<price at=\"val0\">3.00</price>" +
                 "<price at=\"val1\">2</price></bar><bar>" +
                 "<price>5.00</price></bar></foo>";
-	m_xc=XmlObject.Factory.parse(sXml).newCursor();
-	String sXpath=getQuery("testEqual",0);
-	String sExpected="<bar><price>5.00</price></bar>";
-	m_xc.selectPath(sXpath);
-	assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
+        m_xc=XmlObject.Factory.parse(sXml).newCursor();
+        String sXpath=getQuery("testEqual",0);
+        String sExpected="<bar><price>5.00</price></bar>";
+        m_xc.selectPath(sXpath);
+        assertEquals(1,m_xc.getSelectionCount());
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
     }
 
     //Existential semantics of equality in a node set
     //check this--not sure how to create this test
     public void testEqualityNodeset() throws Exception {
-	String sXpath=getQuery("testEqualityNodeset",0);
-	String sExpected="<bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar>";
-	m_xc.selectPath(sXpath);
-	assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
-
+        String sXpath=getQuery("testEqualityNodeset",0);
+        String sExpected="<bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar>";
+        m_xc.selectPath(sXpath);
+        assertEquals(1,m_xc.getSelectionCount());
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
     }
     /**
      * != Not like (not equal) price!=9.80 false
      */
     public void testNotEqual() throws Exception {
-
         assertEquals(0,m_xc.getSelectionCount());
-	String sXpath=getQuery("testNotEqual",0); //has to be double-comparison
-	String sExpected="<bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar>";
-	m_xc.selectPath(sXpath);
+        String sXpath=getQuery("testNotEqual",0); //has to be double-comparison
+        String sExpected="<bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar>";
+        m_xc.selectPath(sXpath);
         assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
+        m_xc.toNextSelection();
         System.out.println(m_xc.xmlText());
-	assertEquals(sExpected,m_xc.xmlText());
-
+        assertEquals(sExpected,m_xc.xmlText());
     }
 
     //Relational Expressions
@@ -199,77 +188,69 @@
      * < Less than price<9.80 false (if price is 9.80)
      */
     public void testLessThan() throws Exception {
-	String sXpath=getQuery("testLessThan",0);
-	m_xc.selectPath(sXpath);
-	assertEquals(0,m_xc.getSelectionCount());
+        String sXpath=getQuery("testLessThan",0);
+        m_xc.selectPath(sXpath);
+        assertEquals(0,m_xc.getSelectionCount());
     }
     /**
      * <= Less or equal price<=9.80 true
      */
     public void testLessOrEqual() throws Exception {
-	String sXpath=getQuery("testLessOrEqual",0);
-	String sExpected="<bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar>";
-	m_xc.selectPath(sXpath);
-	assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
+        String sXpath=getQuery("testLessOrEqual",0);
+        String sExpected="<bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar>";
+        m_xc.selectPath(sXpath);
+        assertEquals(1,m_xc.getSelectionCount());
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
     }
     /**
      * > Greater than price>9.80 false
      */
     public void testGreaterThan() throws Exception {
-	String sXpath=getQuery("testGreaterThan",0);
-	String sExpected="<bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar>";
-	m_xc.selectPath(sXpath);
-	assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
+        String sXpath=getQuery("testGreaterThan",0);
+        String sExpected="<bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar>";
+        m_xc.selectPath(sXpath);
+        assertEquals(1,m_xc.getSelectionCount());
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
     }
     /**
      * >= Greater or equal price>=9.80 true
      */
     public void testGreaterOrEqual() throws Exception {
-	String sXpath=getQuery("testGreaterOrEqual",0);
-	String sExpected="<bar>" +
+        String sXpath=getQuery("testGreaterOrEqual",0);
+        String sExpected="<bar>" +
                 "<price at=\"val0\">3.00</price><price at=\"val1\">2</price>" +
                 "</bar>";
-	m_xc.selectPath(sXpath);
-	assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
+        m_xc.selectPath(sXpath);
+        assertEquals(1,m_xc.getSelectionCount());
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
     }
 
-
     //Boolean Expressions
     /**
      * or or price=9.80 or price=9.70 true (if price is 9.80)
      */
     public void testOr() throws Exception {
-	String sXpath=getQuery("testOr",0);
-	String sExpected="<price at=\"val1\">2</price>";
-	m_xc.selectPath(sXpath);
+        String sXpath=getQuery("testOr",0);
+        String sExpected="<price at=\"val1\">2</price>";
+        m_xc.selectPath(sXpath);
         assertEquals(1,m_xc.getSelectionCount());
-	m_xc.toNextSelection();
-	assertEquals(sExpected,m_xc.xmlText());
-
+        m_xc.toNextSelection();
+        assertEquals(sExpected,m_xc.xmlText());
     }
     /**
      * and and  price<=9.80 and price=9.70 false
      */
     public void testAnd() throws Exception {
-	String sXpath=getQuery("testAnd",0);
-
-	String sExpected="";
-	assertEquals(0,m_xc.getSelectionCount());
-	m_xc.selectPath(sXpath);
-	assertEquals(0,m_xc.getSelectionCount());
-
+        String sXpath=getQuery("testAnd",0);
+        m_xc.selectPath(sXpath);
+        assertEquals(0,m_xc.getSelectionCount());
     }
 
-
     public void setUp()throws Exception{
-	m_xc=XmlObject.Factory.parse(sXml).newCursor();
+        m_xc=XmlObject.Factory.parse(sXml).newCursor();
     }
-
 
 }

Modified: xmlbeans/trunk/test/src/xmlcursor/xpath/common/XPathFunctionTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlcursor/xpath/common/XPathFunctionTest.java?rev=644577&r1=644576&r2=644577&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/xmlcursor/xpath/common/XPathFunctionTest.java (original)
+++ xmlbeans/trunk/test/src/xmlcursor/xpath/common/XPathFunctionTest.java Thu Apr  3 18:48:10 2008
@@ -15,22 +15,9 @@
 
 package xmlcursor.xpath.common;
 
-import xmlcursor.common.BasicCursorTestCase;
-import xmlcursor.common.Common;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.framework.Assert;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlCursor;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.XmlException;
 import tools.util.JarUtil;
-import tools.xml.XmlComparator;
-
-import java.io.IOException;
-
-
 
 /**
  * Verifies XPath using functions
@@ -41,26 +28,16 @@
         super(sName);
     }
 
-
-    //
-    //    ***********************
     //    Node Set Functions
     //    http://www.w3.org/TR/xpath#section-Node-Set-Functions
-    //    Name Description Syntax
+
     /**
-     *     count()
+     * count()
      *      Returns the number of nodes in a node-set
      *      number=count(node-set)
      *
      */
-
     public void testFunctionCount() throws Exception {
-        System.out.println("====== Example-1 ==========");
-        XmlObject xDoc = XmlObject.Factory.parse(
-                JarUtil.getResourceFromJar
-                ("xbean/xmlcursor/xpath/cdcatalog.xml"));
-
-
         String ex0Simple =getQuery("testFunctionCount",0) ;
         String ex0Simple1 =getQuery("testFunctionCount",1) ;
         System.out.println("Test 0: " + ex0Simple);
@@ -92,22 +69,16 @@
 
     }
 
-
     /**
      * id()
      *      Selects elements by their unique ID
      *      node-set=id(value)
      */
-    /**
-     * email Dana-present in spec but not suported
-     *
-     * @status inactive
-     */
     public void testFunctionId() throws Exception {
         XmlObject xDoc = XmlObject.Factory.parse(
                 JarUtil.getResourceFromJar("xbean/xmlcursor/xpath/cdcatalog.xml"));
-
-        String ex1Simple =getQuery("testFunctionId",0) ;
+        //System.out.println(xDoc.xmlText());
+        String ex1Simple =getQuery("testFunctionId",0); //"id(\"bobdylan\")"
 
         String ex1R1 = "<cd id=\"bobdylan\">" +
                 "<title>Empire Burlesque</title>" +
@@ -116,17 +87,20 @@
                 "<year>1985</year></cd>";
         XmlObject[] exXml1 = new XmlObject[]{XmlObject.Factory.parse(ex1R1)};
 
-        String ex2Simple = getQuery("testFunctionId",1);
+        String ex2Simple = getQuery("testFunctionId",1); //"id(\"foobar\")"
         String ex2R1 = "<cd/>";
         XmlObject[] exXml2 = new XmlObject[]{XmlObject.Factory.parse(ex2R1)};
 
-        String ex3Simple = getQuery("testFunctionId",2);
+        String ex3Simple = getQuery("testFunctionId",2); //"id(\"*\")/child::cd[position()=3]"
         String ex3R1 = "<cd id=\"id3\"><title>Greatest Hits</title><artist>Dolly Parton</artist><country>USA</country><company>RCA</company><price>9.90</price><year>1982</year></cd>";
         XmlObject[] exXml3 = new XmlObject[]{XmlObject.Factory.parse(ex3R1)};
 
 
         System.out.println("Test 1: " + ex1Simple);
         XmlCursor x1 = xDoc.newCursor();
+        x1.toChild("catalog");
+        System.out.println(x1.currentTokenType());
+        System.out.println(x1.getName());
         x1.selectPath(ex1Simple);
         //XPathCommon.display(x1);
         //assertEquals(1,x1.getSelectionCount());
@@ -147,7 +121,6 @@
         XPathCommon.display(x3);
         XPathCommon.compare(x3, exXml3);
         x3.dispose();
-
     }
 
     /**
@@ -155,13 +128,11 @@
      *      Returns the position number of the last node in the processed node list
      *      number=last()
      */
-
     public void testFunctionLast() throws Exception {
         XmlObject xDoc = XmlObject.Factory.parse(
                 JarUtil.getResourceFromJar("xbean/xmlcursor/xpath/cdcatalog.xml"));
 
         String ex1Simple = getQuery("testFunctionLast",0);
-        String ex1Expanded = "";
         String ex1R1 = "<cd>" +
                 "<title>Unchain my heart</title>" +
                 "<artist>Joe Cocker</artist><country>USA</country>" +
@@ -175,7 +146,6 @@
         XPathCommon.display(x1);
         XPathCommon.compare(x1, exXml1);
         x1.dispose();
-
     }
 
     /**
@@ -183,7 +153,6 @@
      *      Returns the local part of a node. A node usually consists of a prefix, a colon, followed by the local name
      *      string=local-name(node)
      */
-
     public void testFunctionLocalName() throws Exception {
         String sXPath = getQuery("testFunctionLocalName",0);
         String sXml = "<foo xmlns:pre=\"uri.org\">" +
@@ -198,22 +167,21 @@
         m_xc.toNextSelection();
         assertEquals(sExpected, m_xc.xmlText());
     }
-    //
+
     //    /**
     //     * name()
     //     *      Returns the name of a node
     //     *      string=name(node)
     //     */
     //    public void testFunctionName() throws Exception {
-    // Zvon8
-    //    }
     //
-    //    /**
-    //     * namespace-uri()
-    //     *      Returns the namespace URI of a specified node
-    //     *      uri=namespace-uri(node)
-    //     */
+    //    }
 
+    /**
+     * namespace-uri()
+     *      Returns the namespace URI of a specified node
+     *      uri=namespace-uri(node)
+     */
     public void testFunctionNamespaceURI() throws Exception {
         String sXPath = getQuery("testFunctionNamespaceURI",0);
 
@@ -237,18 +205,16 @@
     //    public void testFunctionPosition() throws Exception {
     //
     //    }
-    //
-    //
-    //    ///   String Functions
-    //    //    http://www.w3.org/TR/xpath#section-String-Functions
-    //  /**
-    //     * concat()
-    //     *      Returns the concatenation of all its arguments string=concat(val1, val2, ..)
-    //     *      Example: concat('The',' ','XML') Result: 'The XML'
-    //     */
 
-    public void testFunctionConcat() throws Exception {
+    //    String Functions
+    //    http://www.w3.org/TR/xpath#section-String-Functions
 
+    /**
+     * concat()
+     *      Returns the concatenation of all its arguments string=concat(val1, val2, ..)
+     *      Example: concat('The',' ','XML') Result: 'The XML'
+     */
+    public void testFunctionConcat() throws Exception {
         String sXPath=getQuery("testFunctionConcat",0);
         String sXml = "<foo><bar><price at=\"val0\">3.00</price>" +
                 "<price at=\"val1\">2</price></bar><bar1>3.00</bar1></foo>";
@@ -258,25 +224,20 @@
         assertEquals(2, m_xc.getSelectionCount());
     }
 
-
     /**
      * string()
      *      Converts the value argument to a string
      *      string(value)
      *      Example:  string(314)    Result: '314'
      */
-
     public void testFunctionString() throws Exception {
-
-
         String sXml = "<foo><bar><price at=\"val0\">3.00</price>" +
                 "<price at=\"val1\">1</price></bar><bar1>3.00</bar1></foo>";
         m_xc = XmlObject.Factory.parse(sXml).newCursor();
 
-
         String sXPath =getQuery("testFunctionString",0);
         m_xc.selectPath(sXPath);
-       assertEquals(1,m_xc.getSelectionCount());
+        assertEquals(1,m_xc.getSelectionCount());
 
         System.out.println(" Test 0 Pass==================");
 
@@ -288,17 +249,14 @@
                 assertEquals(sExpected,m_xc.xmlText());
         */
     }
-    //
-    //    /**
-    //     * string-length()
-    //     *      Returns the number of characters in a string
-    //     *      number=string-length(string)
-    //     *    Example: string-length('Beatles') Result: 7
-    //     */
 
+    /**
+     * string-length()
+     *      Returns the number of characters in a string
+     *      number=string-length(string)
+     *    Example: string-length('Beatles') Result: 7
+     */
     public void testFunctionStringLength() throws Exception {
-
-
         String sXml = "<foo><bar>" +
                 "<price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar>" +
                 "<bar1>3.00</bar1></foo>";
@@ -312,18 +270,13 @@
         m_xc.clearSelections();
     }
 
-
-    //
-    //    /**
-    //     * substring()
-    //     *      Returns a part of the string in the string argument
-    //     *      string=substring(string,start,length)
-    //     *    Example: substring('Beatles',1,4) Result: 'Beat'
-    //     */
-
+    /**
+     * substring()
+     *      Returns a part of the string in the string argument
+     *      string=substring(string,start,length)
+     *    Example: substring('Beatles',1,4) Result: 'Beat'
+     */
     public void testFunctionSubString() throws Exception {
-
-
         String sXml = "<foo><bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar><bar1>3.00</bar1></foo>";
         m_xc = XmlObject.Factory.parse(sXml).newCursor();
 
@@ -335,37 +288,28 @@
         System.out.println(" Test 0 Pass==================");
     }
 
-    //
-    //    /**
-    //     * substring-after()
-    //     *      Returns the part of the string in the string argument that occurs after the substring in the substr argument
-    //     *      string=substring-after(string,substr)
-    //     *      Example: substring-after('12/10','/') Result: '10'
-    //     */
-
+    /**
+     * substring-after()
+     *      Returns the part of the string in the string argument that occurs after the substring in the substr argument
+     *      string=substring-after(string,substr)
+     *      Example: substring-after('12/10','/') Result: '10'
+     */
     public void testFunctionSubStringAfter() throws Exception {
-
-
         String sXml = "<foo><bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar><bar1>3.00</bar1></foo>";
         m_xc = XmlObject.Factory.parse(sXml).newCursor();
 
         String sXPath = getQuery("testFunctionSubStringAfter",0);
                 m_xc.selectPath(sXPath);
         assertEquals(2, m_xc.getSelectionCount());
-
     }
 
-    //
-    //    /**
-    //     * substring-before()
-    //     *      Returns the part of the string in the string argument that occurs before the substring in the substr argument
-    //     *      string=substring-before(string,substr)
-    //     *      Example: substring-before('12/10','/') Result: '12'
-    //     */
-
+    /**
+     * substring-before()
+     *      Returns the part of the string in the string argument that occurs before the substring in the substr argument
+     *      string=substring-before(string,substr)
+     *      Example: substring-before('12/10','/') Result: '12'
+     */
     public void testFunctionSubStringBefore() throws Exception {
-
-
         String sXml = "<foo><bar><price at=\"val0\">3.00</price>" +
                 "<price at=\"val1\">2</price></bar><bar1>3.00</bar1></foo>";
         m_xc = XmlObject.Factory.parse(sXml).newCursor();
@@ -375,39 +319,32 @@
         assertEquals(2, m_xc.getSelectionCount());
     }
 
-    //
-    //    /**
-    //     * translate()
-    //     *      Performs a character by character replacement. It looks in the value argument for characters
-    //     *      contained in string1, and replaces each character for the one in the same position in the string2
-    //     *      string=translate(value,string1,string2)
-    //     *      Examples: translate('12:30','30','45') Result: '12:45'
-    //     *                translate('12:30','03','54') Result: '12:45'
-    //     *                translate('12:30','0123','abcd') Result: 'bc:da'
-    //     */
-
+    /**
+     * translate()
+     *      Performs a character by character replacement. It looks in the value argument for characters
+     *      contained in string1, and replaces each character for the one in the same position in the string2
+     *      string=translate(value,string1,string2)
+     *      Examples: translate('12:30','30','45') Result: '12:45'
+     *                translate('12:30','03','54') Result: '12:45'
+     *                translate('12:30','0123','abcd') Result: 'bc:da'
+     */
     public void testFunctionTranslate() throws Exception {
-
-
         String sXml = "<foo><bar><price at=\"val0\">3.00</price><price at=\"val1\">2</price></bar><bar1>3.00</bar1></foo>";
         m_xc = XmlObject.Factory.parse(sXml).newCursor();
 
-        //TODO: is this a bug in XQRL
-        //I though result should be prepre
+        //TODO: is this a bug in XQRL?
         String sXPath =getQuery("testFunctionTranslate",0);
         m_xc.selectPath(sXPath);
         assertEquals(2, m_xc.getSelectionCount());
-
-        System.out.println(" Test 0 Pass==================");
+        m_xc.toNextSelection();
+        assertEquals("<price at=\"val0\">3.00</price>", m_xc.xmlText());
+        m_xc.toNextSelection();
+        assertEquals("<price at=\"val1\">2</price>", m_xc.xmlText());
     }
 
-    //
-    //
-    //
-    //
-    //
-    ////    Number Functions
-    ////    http://www.w3.org/TR/xpath#section-Number-Functions
+    //    Number Functions
+    //    http://www.w3.org/TR/xpath#section-Number-Functions
+
     //    /**
     //     * ceiling()
     //     *      Returns the smallest integer that is not less than the number argument
@@ -417,7 +354,7 @@
     //    public void testFunctionCeiling() throws Exception {
     //
     //    }
-    //
+
     //    /**
     //     * floor()
     //     *      Returns the largest integer that is not greater than the number argument
@@ -427,14 +364,13 @@
     //    public void testFunctionFloor() throws Exception {
     //
     //    }
-    //
-    //    /**
-    //     * number()
-    //     *      Converts the value argument to a number
-    //     *      number=number(value)
-    //     *      Example: number('100') Result: 100
-    //     */
 
+    /**
+     * number()
+     *      Converts the value argument to a number
+     *      number=number(value)
+     *      Example: number('100') Result: 100
+     */
     public void testFunctionNumber() throws Exception {
         String sXml = "<foo><bar><price at=\"val0\">3.00</price></bar><bar1>3.00</bar1></foo>";
         m_xc = XmlObject.Factory.parse(sXml).newCursor();
@@ -448,41 +384,34 @@
         m_xc.clearSelections();
     }
 
-    //
-    //
-    //    /**
-    //     * round()
-    //     *      Rounds the number argument to the nearest integer
-    //     *      integer=round(number)
-    //     *      Example: round(3.14) Result: 3
-    //     */
-
+    /**
+     * round()
+     *      Rounds the number argument to the nearest integer
+     *      integer=round(number)
+     *      Example: round(3.14) Result: 3
+     */
     public void testFunctionRound() throws Exception {
-
-
         String sXml = "<foo><bar><price at=\"val0\">3.15</price>" +
                 "<price at=\"val1\">2.87</price></bar><bar1>3.00</bar1></foo>";
         m_xc = XmlObject.Factory.parse(sXml).newCursor();
 
         String sXPath = getQuery("testFunctionRound",0);
-        m_xc.selectPath(sXPath);
-        assertEquals(1, m_xc.getSelectionCount());
-
-        System.out.println(" Test 0 Pass==================");
+        m_xc.selectPath(sXPath); //"//bar//*[round(text())=3]"
+        assertEquals(2, m_xc.getSelectionCount());
+        m_xc.toNextSelection();
+        assertEquals("<price at=\"val0\">3.15</price>", m_xc.xmlText());
+        m_xc.toNextSelection();
+        assertEquals("<price at=\"val1\">2.87</price>", m_xc.xmlText());
         m_xc.clearSelections();
     }
 
-    //
-    //    /**
-    //     * sum()
-    //     *      Returns the total value of a set of numeric values in a node-set
-    //     *      number=sum(nodeset)
-    //     *      Example: sum(/cd/price)
-    //     */
-
+    /**
+     * sum()
+     *      Returns the total value of a set of numeric values in a node-set
+     *      number=sum(nodeset)
+     *      Example: sum(/cd/price)
+     */
     public void testFunctionSum() throws Exception {
-
-
         String sXml = "<foo><bar><price at=\"val0\">" +
                 "3.00</price><price at=\"val1\">2</price>" +
                 "</bar><bar1>3.00</bar1></foo>";
@@ -491,13 +420,17 @@
         String sXPath = getQuery("testFunctionSum",0);
         m_xc.selectPath(sXPath);
         assertEquals(1, m_xc.getSelectionCount());
-
-        System.out.println(" Test 0 Pass==================");
+        m_xc.toNextSelection();
+        String exp = "<bar><price at=\"val0\">" +
+                "3.00</price><price at=\"val1\">2</price>" +
+                "</bar>";
+        assertEquals(exp, m_xc.xmlText());
         m_xc.clearSelections();
     }
 
-    //    ///**    Boolean Functions
-    //    // *    http://www.w3.org/TR/xpath#section-Boolean-Functions
+    //    Boolean Functions
+    //    http://www.w3.org/TR/xpath#section-Boolean-Functions
+
     /**
      * boolean()
      *      Converts the value argument to Boolean and returns true or false
@@ -507,7 +440,6 @@
      * a string is true if and only if its length is non-zero
      * an object of a type other than the four basic types is converted to a boolean in a way that is dependent on that type
      */
-
     public void testFunctionBoolean() throws Exception {
         m_xc =
                 XmlObject.Factory.parse(
@@ -519,13 +451,11 @@
         assertEquals(1, m_xc.getSelectionCount());
     }
 
-    //
     /**
      * false()
      *      Returns false false()
      *    Example: number(false()) Result: 0
      */
-
     public void testFunctionFalse() throws Exception {
         m_xc =
                 XmlObject.Factory.parse(
@@ -534,21 +464,14 @@
           String sXPath= getQuery("testFunctionFalse",0);
         m_xc.selectPath(sXPath);
         assertEquals(0, m_xc.getSelectionCount());
-
     }
 
-
     /**
      * lang()
      *      Returns true if the language argument matches the language of the the
      *      xsl:lang element, otherwise it returns false
      *      bool=lang(language)
      */
-    /**
-     * email Dana-present in spec but not suported
-     *
-     *
-     */
     public void testFunctionLang() throws Exception {
         m_xc =
                 XmlObject.Factory.parse(
@@ -565,7 +488,7 @@
         m_xc.selectPath(sXPath);
         assertEquals(0, m_xc.getSelectionCount());
     }
-    //
+
     //    /**
     //     * not()
     //     *      Returns true if the condition argument is false,
@@ -576,14 +499,13 @@
     //    public void testFunctionNot() throws Exception {
     //
     //    }
-    //
-    //    /**
-    //     * true()
-    //     *      Returns true
-    //     *      true()
-    //     *    Example: number(true()) Result: 1
-    //     */
 
+    /**
+     * true()
+     *      Returns true
+     *      true()
+     *    Example: number(true()) Result: 1
+     */
     public void testFunctionTrue() throws Exception {
         m_xc =
                 XmlObject.Factory.parse(
@@ -595,8 +517,6 @@
         String sExpected = "<price at=\"val0\">3.00</price>";
         m_xc.toNextSelection();
         assertEquals(sExpected, m_xc.xmlText());
-
     }
-
 
 }

Modified: xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/DeclareNamespaceTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/DeclareNamespaceTest.java?rev=644577&r1=644576&r2=644577&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/DeclareNamespaceTest.java (original)
+++ xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/DeclareNamespaceTest.java Thu Apr  3 18:48:10 2008
@@ -31,11 +31,12 @@
         XmlObject s = XmlObject.Factory.parse(
             "<a xmlns:ack='abc' ack:attr='val1'>foo<b>bar</b></a>");
         XmlObject[] res;
-        /*res=s.selectPath("./a");
+        /*
+        res=s.selectPath("./a");
         assertTrue(s.selectChildren("","a")[0] == res[0] );
         assertEquals( res[0].xmlText(),"<xml-fragment ack:attr=\"val1\" xmlns:ack=\"abc\">foo<b>bar</b></xml-fragment>");
         //"for $e in ./a return <doc>{ $e } </doc>"
-       */
+        */
         String query = "declare namespace ack='abc'; .//@ack:attr";
         XmlCursor s1 = s.newCursor();
         s1.selectPath(query);
@@ -62,23 +63,22 @@
         XmlObject[] res;
 
         String query = "declare default element namespace 'abc'; .//b[position()=last()]";
-        /*   XmlCursor s1=s.newCursor();
-           s1.selectPath(query);
-           assertEquals(1,s1.getSelectionCount());
-           s1.toNextSelection();
-           assertEquals( s1.xmlText(),"<b xmlns=\"abc\">bar</b>");
-         */
+        /*
+        XmlCursor s1=s.newCursor();
+        s1.selectPath(query);
+        assertEquals(1,s1.getSelectionCount());
+        s1.toNextSelection();
+        assertEquals( s1.xmlText(),"<b xmlns=\"abc\">bar</b>");
+        */
         res = s.execQuery(query);
         XmlCursor c1 = s.newCursor();
         c1.toFirstContentToken();
 
         XmlObject o = c1.getObject();
         assertTrue(o != res[0]);
-        assertEquals(res[0].xmlText(), "<b xmlns=\"abc\">bar</b>");
+        assertEquals(res[0].xmlText(), "<abc:b xmlns:abc=\"abc\">bar</abc:b>");
     }
 
-   
-
     public void testSequence()
         throws Exception
     {
@@ -127,11 +127,10 @@
         throws Exception
     {
         XmlCursor o = XmlObject.Factory.parse("<a><b>1</b>1</a>").newCursor();
-        o.selectPath("//a/b intersect //b");
+        o.selectPath("//b intersect //b");
         assertEquals(1, o.getSelectionCount());
         o.toNextSelection();
-        assertEquals(Common.wrapInXmlFrag("1"), o.xmlText());
-
+        assertEquals("<b>1</b>", o.xmlText());
     }
 
     public void testSequenceExcept()
@@ -164,4 +163,3 @@
     }
 
 }
-

Modified: xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/NodeCopyTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/NodeCopyTest.java?rev=644577&r1=644576&r2=644577&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/NodeCopyTest.java (original)
+++ xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/NodeCopyTest.java Thu Apr  3 18:48:10 2008
@@ -12,7 +12,7 @@
  *   See the License for the specific language governing permissions and
  *  limitations under the License.
  */
- package xmlcursor.xpath.complex.detailed;
+package xmlcursor.xpath.complex.detailed;
 
 import junit.framework.TestCase;
 import org.apache.xmlbeans.*;
@@ -22,75 +22,74 @@
  *
  */
 public class NodeCopyTest extends TestCase {
-     public static void testNS() throws Exception{
-         XmlObject s=XmlObject.Factory.parse("<a xmlns:ack='abc' ack:attr='val1'>foo<b>bar</b></a>");
-         XmlObject[] res;
-         /*res=s.selectPath("./a");
-         assertTrue(s.selectChildren("","a")[0] == res[0] );
-         assertEquals( res[0].xmlText(),"<xml-fragment ack:attr=\"val1\" xmlns:ack=\"abc\">foo<b>bar</b></xml-fragment>");
-         //"for $e in ./a return <doc>{ $e } </doc>"
+
+    public static void testNS() throws Exception{
+        XmlObject s=XmlObject.Factory.parse("<a xmlns:ack='abc' ack:attr='val1'>foo<b>bar</b></a>");
+        XmlObject[] res;
+        /*
+        res=s.selectPath("./a");
+        assertTrue(s.selectChildren("","a")[0] == res[0] );
+        assertEquals( res[0].xmlText(),"<xml-fragment ack:attr=\"val1\" xmlns:ack=\"abc\">foo<b>bar</b></xml-fragment>");
+        //"for $e in ./a return <doc>{ $e } </doc>"
         */
         XmlCursor s1=s.newCursor().execQuery("./a");
-         assertEquals( s1.xmlText(),"<a ack:attr=\"val1\" xmlns:ack=\"abc\">foo<b>bar</b></a>");
+        assertEquals("<a ack:attr=\"val1\" xmlns:ack=\"abc\">foo<b>bar</b></a>",s1.xmlText());
 
-         res=s.execQuery("./a");
-         XmlCursor c1=s.newCursor();
-         c1.toFirstContentToken();
-
-         XmlObject o = c1.getObject();
-         assertTrue(o != res[0] );
-         assertEquals( res[0].xmlText(),"<a ack:attr=\"val1\" xmlns:ack=\"abc\">foo<b>bar</b></a>");
+        res=s.execQuery("./a");
+        XmlCursor c1=s.newCursor();
+        c1.toFirstContentToken();
+
+        XmlObject o = c1.getObject();
+        assertTrue(o != res[0]);
+        assertEquals("<a ack:attr=\"val1\" xmlns:ack=\"abc\">foo<b>bar</b></a>",res[0].xmlText());
     }
 
-
     public static void testText() throws Exception{
         XmlObject s=XmlObject.Factory.parse("<a><b>bar</b>foo</a>");
         XmlObject[] res;
         res=s.selectPath(".//text()");
+        assertEquals(2, res.length);
         assertEquals("<xml-fragment>bar</xml-fragment>",res[0].xmlText());
-        assertEquals("<xml-fragment>foo</xml-fragment>",res[1]);
-
+        assertEquals("<xml-fragment>foo</xml-fragment>",res[1].xmlText());
     }
-     public static void testCount() throws Exception{
-         XmlObject s=XmlObject.Factory.parse("<a><b>bar</b>foo</a>");
-         XmlObject[] res;
-         res=s.selectPath("count(.//b)");
-         System.out.println(res[0].xmlText());
-         XmlLong i=(XmlLong)res[0];
-
 
-         // res= s.selectPath("//b");
-
-}
+    public static void testCount() throws Exception{
+        XmlObject s=XmlObject.Factory.parse("<a><b>bar</b>foo</a>");
+        XmlObject[] res;
+        res=s.selectPath("count(.//b)");
+        System.out.println(res[0].xmlText());
+        XmlLong i=(XmlLong)res[0];
+        assertEquals((long)1, i.getLongValue());
+        // res= s.selectPath("//b");
+    }
 
-  /*  public void testInt()throws Exception{
-       GlobalEltDefaultIntDocument d=
+    /*
+    public void testInt()throws Exception{
+        GlobalEltDefaultIntDocument d=
            GlobalEltDefaultIntDocument.Factory
                .parse("<GlobalEltDefaultInt xmlns='http://xbean/scomp/element/GlobalEltDefault'>" +
                  "3"+
                "</GlobalEltDefaultInt>");
         d.getGlobalEltDefaultInt();
     }
-   */
+    */
 
     public void testXmlObjectSelectPath(){
 
     }
 
-     public void testDeleteMe() throws Exception
+    public void testDeleteMe() throws Exception
     {
-        float balance = 0;
         XmlObject t= XmlObject.Factory.parse("<a><b/><b/></a>");
         XmlCursor cursor =
             t.newCursor();
-        cursor.toFirstContentToken();
         System.out.println(cursor.getObject());
         // use xpath to select elements
-        cursor.selectPath( "*/*" );
+        cursor.selectPath("*/*");
 
         System.out.println("cnt "+cursor.getSelectionCount());
         // iterate over the selection
-        while ( cursor.toNextSelection() )
+        while (cursor.toNextSelection())
         {
             // two views of the same data:
             // move back and forth between XmlObject <-> XmlCursor

Modified: xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/TypesTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/TypesTest.java?rev=644577&r1=644576&r2=644577&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/TypesTest.java (original)
+++ xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/TypesTest.java Thu Apr  3 18:48:10 2008
@@ -14,15 +14,18 @@
  */
 package xmlcursor.xpath.complex.detailed;
 
+import org.apache.xmlbeans.GDurationSpecification;
+import org.apache.xmlbeans.GDurationBuilder;
 import org.apache.xmlbeans.XmlDate;
 import org.apache.xmlbeans.XmlDecimal;
 import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlDuration;
-import org.apache.xmlbeans.XmlInt;
+//import org.apache.xmlbeans.XmlInt;
+import org.apache.xmlbeans.XmlLong;
 import org.apache.xmlbeans.XmlTime;
-import org.apache.xmlbeans.XmlByte;
+//import org.apache.xmlbeans.XmlByte;
 import org.apache.xmlbeans.XmlAnyURI;
-import org.apache.xmlbeans.XmlDateTime;
+//import org.apache.xmlbeans.XmlDateTime;
+
 import junit.framework.TestCase;
 
 /**
@@ -31,6 +34,15 @@
 public class TypesTest
     extends TestCase
 {
+    XmlObject o;
+    XmlObject[] res;
+
+    public void setUp()
+        throws Exception
+    {
+        o = XmlObject.Factory.parse("<a/>");
+    }
+
     public void testDate()
     {
         res = o.selectPath("xs:date(\"2000-01-01\")");
@@ -55,66 +67,73 @@
     //representation
     public void testDuration() throws Exception
     {
-        res = o.selectPath("xdt:dayTimeDuration(\"PT12H\")*4");
+        res = o.selectPath("xs:dayTimeDuration(\"PT12H\")*4");
         assertEquals(1, res.length);
-        XmlDuration test=XmlDuration.Factory.parse(res[0].xmlText());
-        System.out.println(test.getGDurationValue().getDay());
-        XmlDuration dec = ((XmlDuration) res[0]);
-        assertEquals("", dec.xmlText());
+        System.out.println(res[0].schemaType());
+        String s = res[0].xmlText();
+        System.out.println(s);
+        int i = s.indexOf("(\"");
+        int j = s.indexOf("\")");
+        assertTrue(0 < i);
+        assertTrue(i < j);
+        String duration = s.substring(i+2, j);
+        System.out.println(duration);
+        GDurationSpecification gDur = new GDurationBuilder(duration);
+        System.out.println(gDur.getDay());
+        assertEquals(2, gDur.getDay());
     }
 
-
-     public static void testTypes()
+    public static void testTypes()
         throws Exception
     {
         XmlObject o = XmlObject.Factory.parse(
-            "<a xmlns='abc'>foo<b>bar</b></a>");
+            "<a xml:base='abc'>foo<b>bar</b></a>");
         XmlObject[] res = null;
 
         //Long
         res = o.selectPath("hours-from-dateTime(" +
             "current-dateTime()) cast as xs:integer");
         assertEquals(1, res.length);
-        XmlInt xi = ((XmlInt) res[0]);
-        System.out.println(xi.xmlText());
+        System.out.println(res[0].schemaType());
+        XmlLong xl = ((XmlLong) res[0]);
+        System.out.println(xl.xmlText());
 
         //Java type is string...
         res = o.selectPath("current-time()");
         assertEquals(1, res.length);
-        XmlTime time = ((XmlTime) res[0]);
+        System.out.println(res[0].schemaType());
+        System.out.println(res[0].xmlText());
+        XmlTime time = XmlTime.Factory.parse(res[0].xmlText());
         System.out.println(time.xmlText());
 
-
+        /*
         res = o.selectPath("subtract-dateTimes-yielding-dayTimeDuration(" +
             "current-dateTime()," +
             "current-dateTime())");
         assertEquals(1, res.length);
         XmlDuration dur = ((XmlDuration) res[0]);
         System.out.println(dur.xmlText());
-
-        //Java type is long--is query rigth?
+        */
+        //Java type is long--is query right?
         res = o.selectPath("xs:byte(3)");
         assertEquals(1, res.length);
-        XmlByte b = ((XmlByte) res[0]);
-        System.out.println(b.xmlText());
+        System.out.println(res[0].schemaType()); //xs:long
+        //XmlByte b = ((XmlByte) res[0]);
+        //System.out.println(b.xmlText());
 
         //Java type is string
-        res = o.selectPath("base-uri()");
+        res = o.selectPath("base-uri(/a)");
         assertEquals(1, res.length);
-        XmlAnyURI u = ((XmlAnyURI) res[0]);
+        System.out.println(res[0].schemaType()); //xs:string
+        XmlAnyURI u = XmlAnyURI.Factory.parse(res[0].xmlText());
         System.out.println(u.xmlText());
+
         //java type is Date
         res = o.selectPath("current-dateTime()");
         assertEquals(1, res.length);
-        XmlDateTime dt = ((XmlDateTime) res[0]);
+        System.out.println(res[0].schemaType());
+        XmlDate dt = ((XmlDate) res[0]);
         System.out.println(dt.xmlText());
     }
-    public void setUp()
-        throws Exception
-    {
-        o = XmlObject.Factory.parse("<a/>");
-    }
 
-    XmlObject o;
-    XmlObject[] res;
 }

Modified: xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathExpressionTestImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathExpressionTestImpl.java?rev=644577&r1=644576&r2=644577&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathExpressionTestImpl.java (original)
+++ xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathExpressionTestImpl.java Thu Apr  3 18:48:10 2008
@@ -15,10 +15,9 @@
 
 package xmlcursor.xpath.complex.detailed;
 
+import xmlcursor.common.Common;
 import xmlcursor.xpath.common.XPathExpressionTest;
 
-import java.util.HashMap;
-
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlCursor;
 
@@ -26,7 +25,6 @@
  * Verifies XPath with Expressions
  * http://www.w3schools.com/xpath/xpath_expressions.asp
  */
-
 public class XPathExpressionTestImpl
     extends XPathExpressionTest
 {
@@ -51,6 +49,17 @@
 
     }
 
+    private void verifySelection(XmlCursor c, String[] expected)
+    {
+        int count = c.getSelectionCount();
+        assertEquals(expected.length, count);
+        for (int i = 0; i < count; i++)
+        {
+            c.toNextSelection();
+            assertEquals(expected[i], c.xmlText());
+        }
+    }
+
     public void testForExpression()
         throws Exception
     {
@@ -61,7 +70,7 @@
             "    <publisher>Addison-Wesley</publisher>\n" +
             "  </book>\n" +
             "  <book>\n" +
-            "    <title>Advanced Unix Programming</title>\n" +
+            "    <title>Advanced Programming in the Unix environment</title>\n" +
             "    <author>Stevens</author>\n" +
             "    <publisher>Addison-Wesley</publisher>\n" +
             "  </book>\n" +
@@ -73,24 +82,24 @@
             "  </book>\n" +
             "</bib>";
 
-        String query = "for $a in distinct-values(//author)" +
+        String query = "for $a in distinct-values(//author) " +
             "return ($a," +
             "        for $b in //book[author = $a]" +
             "        return $b/title)";
-        String expXml = "<author>Stevens</author> \n" +
-            "<title>TCP/IP Illustrated</title>\n" +
-            "<title>Advanced Programming in the Unix environment</title>\n" +
-            "<author>Abiteboul</author>\n" +
-            "<title>Data on the Web</title>\n" +
-            "<author>Buneman</author>\n" +
-            "<title>Data on the Web</title>\n" +
-            "<author>Suciu</author>\n" +
-            "<title>Data on the Web</title>";
+        String[] exp = new String[] {
+            "<xml-fragment>Stevens</xml-fragment>",
+            "<title>TCP/IP Illustrated</title>",
+            "<title>Advanced Programming in the Unix environment</title>",
+            "<xml-fragment>Abiteboul</xml-fragment>",
+            "<title>Data on the Web</title>",
+            "<xml-fragment>Buneman</xml-fragment>",
+            "<title>Data on the Web</title>",
+            "<xml-fragment>Suciu</xml-fragment>",
+            "<title>Data on the Web</title>"
+            };
         XmlCursor c = XmlObject.Factory.parse(sXml).newCursor();
         c.selectPath(query);
-        assertEquals(1, c.getSelectionCount());
-        c.toNextSelection();
-        assertEquals(expXml, c.xmlText());
+        verifySelection(c, exp);
     }
 
     public void testFor_1()
@@ -101,30 +110,35 @@
             "    $j in (1, 2)\n" +
             "return ($i + $j)";
         c.selectPath(query);
-        assertEquals(2, c.getSelectionCount());
-        c.toNextSelection();
-        assertEquals("", c.xmlText());
-        c.toNextSelection();
-        assertEquals("", c.xmlText());
+        String[] expected = new String[] {
+            Common.wrapInXmlFrag("11"),
+            Common.wrapInXmlFrag("12"),
+            Common.wrapInXmlFrag("21"),
+            Common.wrapInXmlFrag("22")
+        };
+        verifySelection(c, expected);
     }
+
     public void testFor_2()
-           throws Exception
-       {
-           XmlCursor c = XmlObject.Factory.parse("<a/>").newCursor();
-           String query = "sum (for $i in (10, 20)" +
-               "return $i)";
-           c.selectPath(query);
-           assertEquals(1, c.getSelectionCount());
-           c.toNextSelection();
-           assertEquals("300", c.xmlText());
-}
+        throws Exception
+    {
+        XmlCursor c = XmlObject.Factory.parse("<a/>").newCursor();
+        String query = "sum (for $i in (10, 20)" +
+            "return $i)";
+        c.selectPath(query);
+        assertEquals(1, c.getSelectionCount());
+        c.toNextSelection();
+        assertEquals(Common.wrapInXmlFrag("30"), c.xmlText());
+    }
 
     public void testIf()
         throws Exception
     {
         XmlCursor c = XmlObject.Factory.parse("<root>" +
             "<book price='20'>Pooh</book>" +
+            "<cd price='25'>Pooh</cd>" +
             "<book price='50'>Maid</book>" +
+            "<cd price='25'>Maid</cd>" +
             "</root>").newCursor();
         String query = "if (//book[1]/@price) " +
             "  then //book[1] " +
@@ -134,34 +148,34 @@
         c.toNextSelection();
         assertEquals("<book price=\"20\">Pooh</book>", c.xmlText());
 
-        query = "for $b1 in //book, $b2 in //book " +
+        query = "for $b1 in //book, $b2 in //cd " +
             "return " +
             "if ( $b1/@price < $b2/@price )" +
             " then $b1" +
             " else $b2";
         c.selectPath(query);
-        assertEquals(2, c.getSelectionCount());
+        assertEquals(4, c.getSelectionCount());
         c.toNextSelection();
-        assertEquals("<book price='20'>Pooh</book>", c.xmlText());
+        assertEquals("<book price=\"20\">Pooh</book>", c.xmlText());
         c.toNextSelection();
-        assertEquals("<book price='20'>Pooh</book>", c.xmlText());
- }
-
+        assertEquals("<book price=\"20\">Pooh</book>", c.xmlText());
+        c.toNextSelection();
+        assertEquals("<cd price=\"25\">Pooh</cd>", c.xmlText());
+        c.toNextSelection();
+        assertEquals("<cd price=\"25\">Maid</cd>", c.xmlText());
+    }
 
-     public void testQuantifiedExpression()
+    public void testQuantifiedExpression()
         throws Exception
     {
         XmlCursor c = XmlObject.Factory.parse("<root></root>").newCursor();
-        String query = "if  " +
-            " ( some $x in (1, 2, 3), $y in (2, 3, 4) \n" +
-            "     satisfies $x + $y = 4)" +
-            "then true " +
-            "else false";
+        String query =
+            "some $x in (1, 2, 3), $y in (2, 3, 4) " +
+            "satisfies $x + $y = 4";
         c.selectPath(query);
         assertEquals(1, c.getSelectionCount());
         c.toNextSelection();
-        assertEquals("", c.xmlText());
-
- }
+        assertEquals("<xml-fragment>true</xml-fragment>", c.xmlText());
+    }
 
 }

Modified: xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathFunctionTestImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathFunctionTestImpl.java?rev=644577&r1=644576&r2=644577&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathFunctionTestImpl.java (original)
+++ xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathFunctionTestImpl.java Thu Apr  3 18:48:10 2008
@@ -17,7 +17,6 @@
 
 import xmlcursor.xpath.common.XPathFunctionTest;
 
-
 import org.apache.xmlbeans.XmlObject;
 
 /**
@@ -31,34 +30,31 @@
     public XPathFunctionTestImpl(String name)
     {
         super(name);
+
         testMap.put("testFunctionCount", new String[]{
             "count(//cd)",
-            "//cd[position()=2]"
-        });
+            "//cd[position()=2]"});
+
         testMap.put("testFunctionLocalName", new String[]{
-            "//*[local-name(.)='bar']"
-        });
+            "//*[local-name(.)='bar']"});
+
         testMap.put("testFunctionConcat", new String[]{
-            "//bar/*[name(.)=concat(\"pr\",\"ice\")]"
-        });
+            "//bar/*[name(.)=concat(\"pr\",\"ice\")]"});
 
         testMap.put("testFunctionString", new String[]{
             "/foo/*[name(.)=" +
-            "concat(\"bar\",string(./foo/bar/price[last()]))]"
-        });
+            "concat(\"bar\",string(./foo/bar/price[last()]))]"});
 
         testMap.put("testFunctionStringLength", new String[]{
-            "//bar/*[string-length(name(.))=5]"
-        });
+            "//bar/*[string-length(name(.))=5]"});
+
         testMap.put("testFunctionSubString", new String[]{
-            "//bar/*[substring(name(.),3,3)=\"ice\"]"
-        });
+            "//bar/*[substring(name(.),3,3)=\"ice\"]"});
 
         testMap.put("testFunctionSubStringAfter", new String[]{
             "//bar/*[substring-after(" +
             "name(.),'pr'" +
-            ")=\"ice\"]"
-        });
+            ")=\"ice\"]"});
 
         testMap.put("testFunctionSubStringBefore", new String[]{
             "//bar/*[substring-before(" +
@@ -77,7 +73,6 @@
             "//*[boolean(@at)=true()]"});
     }
 
-
     public String getQuery(String testName, int testCase)
         throws IllegalArgumentException
     {
@@ -91,10 +86,8 @@
                 " for test" + testName);
         else
             return ((String[]) queries)[testCase];
-
     }
 
-
     public void testErrorMessages()
         throws Exception
     {
@@ -112,7 +105,6 @@
         catch (Throwable t)
         {
         }
-
     }
 
     public void testExternalVariable()
@@ -181,6 +173,5 @@
         assertEquals(1, res.length);
         assertEquals("", res[0].xmlText());
     }
-
 
 }

Modified: xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathNodeTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathNodeTest.java?rev=644577&r1=644576&r2=644577&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathNodeTest.java (original)
+++ xmlbeans/trunk/test/src/xmlcursor/xpath/complex/detailed/XPathNodeTest.java Thu Apr  3 18:48:10 2008
@@ -14,11 +14,11 @@
  */
 package xmlcursor.xpath.complex.detailed;
 
-import xmlcursor.xpath.common.XPathFunctionTest;
-import xmlcursor.common.Common;
+import javax.xml.namespace.QName;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 import junit.framework.TestCase;
+import xmlcursor.common.Common;
 
 /**
  *
@@ -32,7 +32,7 @@
         XmlCursor c = XmlObject.Factory.parse("<root>" +
             "<book isbn='012345' id='09876'/></root>")
             .newCursor();
-        c.selectPath("//book[isbn='012345'] is //book[id='09876']");
+        c.selectPath("//book[@isbn='012345'] is //book[@id='09876']");
         assertEquals(1, c.getSelectionCount());
         c.toNextSelection();
         assertEquals(Common.wrapInXmlFrag("true"), c.xmlText());
@@ -44,12 +44,12 @@
         XmlCursor c = XmlObject.Factory.parse("<root>" +
             "<book isbn='012345'/><book id='09876'/></root>")
             .newCursor();
-        c.selectPath("//book[isbn='012345'] << //book[id='09876']");
+        c.selectPath("//book[@isbn='012345'] << //book[@id='09876']");
         assertEquals(1, c.getSelectionCount());
         c.toNextSelection();
         assertEquals(Common.wrapInXmlFrag("true"), c.xmlText());
 
-        c.selectPath("//book[isbn='012345'] >> //book[id='09876']");
+        c.selectPath("//book[@isbn='012345'] >> //book[@id='09876']");
         assertEquals(1, c.getSelectionCount());
         c.toNextSelection();
         assertEquals(Common.wrapInXmlFrag("false"), c.xmlText());
@@ -69,19 +69,20 @@
         XmlObject[] res = o.selectPath("..");
         assertEquals(1, res.length);
         assertEquals("<B><C/></B>", res[0].newCursor().xmlText());
-
     }
-      public void testParent1()
+
+    public void testParent1()
         throws Exception
     {
-        String input = "<AttributeCertificate \n" +
-            "xmlns=\"http://www.eurecom.fr/security/xac#\" \n" +
-            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
+        String input = 
+            "<AttributeCertificate " +
+            "xmlns=\"http://www.eurecom.fr/security/xac#\" " +
+            "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
             "<Content>" +
-            " <Validity>"+
-        "<ValidityFrom>2005-02-10T11:02:57.590+01:00</ValidityFrom>"+
-         "<ValidityTo>2006-02-10T11:02:57.590+01:00</ValidityTo>"+
-        "</Validity></Content></AttributeCertificate>";
+            "<Validity>" +
+            "<ValidityFrom>2005-02-10T11:02:57.590+01:00</ValidityFrom>" +
+            "<ValidityTo>2006-02-10T11:02:57.590+01:00</ValidityTo>" +
+            "</Validity></Content></AttributeCertificate>";
 
         XmlObject o;
         XmlCursor c = XmlObject.Factory.parse(input).newCursor();
@@ -89,10 +90,14 @@
         c.toFirstChild();
         c.toFirstChild();
         o = c.getObject();
-        assertEquals("<C/>", o.newCursor().xmlText());
+        QName qn = o.newCursor().getName();
+        assertEquals("http://www.eurecom.fr/security/xac#", qn.getNamespaceURI());
+        assertEquals("Validity", qn.getLocalPart());
         XmlObject[] res = o.selectPath("..");
         assertEquals(1, res.length);
-        assertEquals("<B><C/></B>", res[0].newCursor().xmlText());
+        qn = res[0].newCursor().getName();
+        assertEquals("http://www.eurecom.fr/security/xac#", qn.getNamespaceURI());
+        assertEquals("Content", qn.getLocalPart());
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org