commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmi...@apache.org
Subject cvs commit: jakarta-commons/jxpath/src/test/org/apache/commons/jxpath JXPathTestCase.java
Date Sat, 24 Jan 2004 02:42:22 GMT
dmitri      2004/01/23 18:42:22

  Modified:    jxpath/src/test/org/apache/commons/jxpath/ri/compiler
                        ExtensionFunctionTest.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model
                        XMLModelTestCase.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model/dom
                        DOMModelTest.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model/jdom
                        JDOMModelTest.java
               jxpath/src/test/org/apache/commons/jxpath
                        JXPathTestCase.java
  Log:
  Added some testing for pointer.getNode()
  
  Revision  Changes    Path
  1.13      +12 -8     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java
  
  Index: ExtensionFunctionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ExtensionFunctionTest.java	24 Jan 2004 02:16:51 -0000	1.12
  +++ ExtensionFunctionTest.java	24 Jan 2004 02:42:21 -0000	1.13
  @@ -63,6 +63,7 @@
   package org.apache.commons.jxpath.ri.compiler;
   
   import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.List;
   import java.util.Locale;
   
  @@ -358,10 +359,13 @@
           List list = new ArrayList();
           list.add("foo");
           list.add("bar");
  -        context.getVariables().declareVariable("myList", list); 
  -        Object
  -        values = context.getValue("test:items($myList)");
  -        System.err.println("Values: " + values);
  +        context.getVariables().declareVariable("list", list);
  +        Object values = context.getValue("test:items($list)");
  +        assertTrue("Return type: ", values instanceof Collection);
  +        assertEquals(
  +            "Return values: ",
  +            list,
  +            new ArrayList((Collection) values));
       }
   
       public void testNodeSetReturn() {
  
  
  
  1.18      +5 -5      jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
  
  Index: XMLModelTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XMLModelTestCase.java	24 Jan 2004 01:12:01 -0000	1.17
  +++ XMLModelTestCase.java	24 Jan 2004 02:42:22 -0000	1.18
  @@ -80,7 +80,7 @@
    */
   
   public abstract class XMLModelTestCase extends JXPathTestCase {
  -    private JXPathContext context;
  +    protected JXPathContext context;
   
       /**
        * Construct a new instance of this test case.
  
  
  
  1.11      +13 -4     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/dom/DOMModelTest.java
  
  Index: DOMModelTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/dom/DOMModelTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DOMModelTest.java	19 Jan 2004 20:44:52 -0000	1.10
  +++ DOMModelTest.java	24 Jan 2004 02:42:22 -0000	1.11
  @@ -66,8 +66,11 @@
   import junit.framework.TestSuite;
   
   import org.apache.commons.jxpath.AbstractFactory;
  +import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.ri.model.XMLModelTestCase;
   import org.apache.commons.jxpath.xml.DocumentContainer;
  +import org.w3c.dom.Attr;
  +import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
  @@ -103,6 +106,12 @@
   
       protected AbstractFactory getAbstractFactory() {
           return new TestDOMFactory();
  +    }
  +    
  +    public void testGetNode() {
  +        assertXPathNodeType(context, "/", Document.class);
  +        assertXPathNodeType(context, "/vendor/location", Element.class);
  +        assertXPathNodeType(context, "//location/@name", Attr.class);
       }
       
       protected String getXMLSignature(
  
  
  
  1.11      +12 -5     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/jdom/JDOMModelTest.java
  
  Index: JDOMModelTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/jdom/JDOMModelTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JDOMModelTest.java	19 Jan 2004 20:44:52 -0000	1.10
  +++ JDOMModelTest.java	24 Jan 2004 02:42:22 -0000	1.11
  @@ -70,6 +70,7 @@
   import org.apache.commons.jxpath.AbstractFactory;
   import org.apache.commons.jxpath.ri.model.XMLModelTestCase;
   import org.apache.commons.jxpath.xml.DocumentContainer;
  +import org.jdom.Attribute;
   import org.jdom.CDATA;
   import org.jdom.Document;
   import org.jdom.Element;
  @@ -102,7 +103,13 @@
       protected String getModel() {
           return DocumentContainer.MODEL_JDOM;
       }
  -        
  +    
  +    public void testGetNode() {
  +        assertXPathNodeType(context, "/", Document.class);
  +        assertXPathNodeType(context, "/vendor/location", Element.class);
  +        assertXPathNodeType(context, "//location/@name", Attribute.class);
  +    }    
  +    
       public void testID() {
           // id() is not supported by JDOM
       }
  
  
  
  1.34      +27 -5     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java
  
  Index: JXPathTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- JXPathTestCase.java	9 Oct 2003 21:31:42 -0000	1.33
  +++ JXPathTestCase.java	24 Jan 2004 02:42:22 -0000	1.34
  @@ -246,7 +246,29 @@
               expected,
               res);
       }
  -
  +    
  +    protected void assertXPathValueType(
  +            JXPathContext ctx,
  +            String xpath,
  +            Class clazz) 
  +    {
  +        ctx.setLenient(false);
  +        Object actual = ctx.getValue(xpath);
  +        assertTrue("Evaluating <" + xpath + "> = " + actual.getClass(), 
  +                clazz.isAssignableFrom(actual.getClass()));
  +    }
  +    
  +    protected void assertXPathNodeType(
  +            JXPathContext ctx,
  +            String xpath,
  +            Class clazz) 
  +    {
  +        ctx.setLenient(false);
  +        Pointer actual = ctx.getPointer(xpath);
  +        assertTrue("Evaluating <" + xpath + "> = " + actual.getNode().getClass(),

  +                clazz.isAssignableFrom(actual.getNode().getClass()));
  +    }
  +    
       protected static List list() {
           return Collections.EMPTY_LIST;
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message