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/ri/model MixedModelTest.java BeanModelTestCase.java
Date Fri, 10 Jan 2003 02:11:29 GMT
dmitri      2003/01/09 18:11:29

  Modified:    jxpath/src/test/org/apache/commons/jxpath
                        TestMixedModelBean.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model/beans
                        PropertyOwnerPointer.java NullElementPointer.java
                        CollectionPointer.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model
                        MixedModelTest.java BeanModelTestCase.java
  Log:
  More testing, fixes of error messages
  
  Revision  Changes    Path
  1.2       +14 -5     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/TestMixedModelBean.java
  
  Index: TestMixedModelBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/TestMixedModelBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestMixedModelBean.java	20 Oct 2002 03:48:21 -0000	1.1
  +++ TestMixedModelBean.java	10 Jan 2003 02:11:28 -0000	1.2
  @@ -84,6 +84,7 @@
       private Map map;
   
       private List list;
  +    private int[][] matrix;
   
       public TestMixedModelBean(){
           string = "string";
  @@ -106,10 +107,14 @@
           list.add(string);
           list.add(bean);
           list.add(map);
  -        list.add(Collections.singletonList("string2"));
  +        list.add(new ArrayList(Collections.singletonList("string2")));
           list.add(document);
           list.add(element);
           list.add(container);
  +        
  +        matrix = new int[1][];
  +        matrix[0] = new int[1];
  +        matrix[0][0] = 3;
       }
   
       public String getString(){
  @@ -138,5 +143,9 @@
       
       public Container getContainer(){
           return container;
  +    }
  +    
  +    public int[][] getMatrix(){
  +        return matrix;
       }
   }
  
  
  
  1.12      +10 -3     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java
  
  Index: PropertyOwnerPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PropertyOwnerPointer.java	28 Nov 2002 01:02:04 -0000	1.11
  +++ PropertyOwnerPointer.java	10 Jan 2003 02:11:28 -0000	1.12
  @@ -64,6 +64,7 @@
   import java.util.Locale;
   
   import org.apache.commons.jxpath.JXPathContext;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.ri.Compiler;
   import org.apache.commons.jxpath.ri.QName;
   import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
  @@ -162,9 +163,15 @@
               parent.setValue(value);
           }
           else if (parent != null){
  -            throw new UnsupportedOperationException(
  -                "Cannot setValue of an object that is not " +
  -                "some other object's property");
  +            if (index == WHOLE_COLLECTION){
  +                throw new UnsupportedOperationException(
  +                    "Cannot setValue of an object that is not " +
  +                    "some other object's property");
  +            }
  +            else {
  +                throw new JXPathException(
  +                    "The specified collection element does not exist: " + this);
  +            }
           }
           else {
               throw new UnsupportedOperationException(
  
  
  
  1.12      +72 -31    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java
  
  Index: NullElementPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- NullElementPointer.java	28 Nov 2002 01:02:04 -0000	1.11
  +++ NullElementPointer.java	10 Jan 2003 02:11:28 -0000	1.12
  @@ -79,10 +79,10 @@
    * @author Dmitri Plotnikov
    * @version $Revision$ $Date$
    */
  -public class NullElementPointer extends PropertyOwnerPointer {
  +public class NullElementPointer extends CollectionPointer {
   
       public NullElementPointer(NodePointer parent, int index){
  -        super(parent);
  +        super(parent, (Object)null);
           this.index = index;
       }
   
  @@ -115,13 +115,8 @@
       }
   
       public void setValue(Object value){
  -        super.setValue(value);
  -        if (parent instanceof PropertyPointer){
  -            parent.setValue(value);
  -        }
  -        else {
  -            throw new UnsupportedOperationException("Cannot setValue of an object that
is not some other object's property");
  -        }
  +        throw new UnsupportedOperationException(
  +            "Collection element does not exist: " + this);
       }
   
       public boolean isActual(){
  @@ -133,8 +128,12 @@
       }
   
       public NodePointer createPath(JXPathContext context, Object value){
  -        if (parent instanceof PropertyPointer){
  -            return parent.getParent().createChild(context, parent.getName(), index, value);
  +        if (parent instanceof PropertyPointer) {
  +            return parent.getParent().createChild(
  +                context,
  +                parent.getName(),
  +                index,
  +                value);
           }
           else {
               return parent.createChild(context, null, index, value);
  @@ -142,34 +141,57 @@
       }
   
       public NodePointer createPath(JXPathContext context){
  -        if (parent instanceof PropertyPointer){
  -            return parent.getParent().createChild(context, parent.getName(), index);
  +        if (parent instanceof PropertyPointer) {
  +            return parent.getParent().createChild(
  +                context,
  +                parent.getName(),
  +                index);
           }
           else {
               return parent.createChild(context, null, index);
           }
       }
   
  -    public NodePointer createChild(JXPathContext context, QName name, int index, Object
value){
  -        if (index != 0 && index != WHOLE_COLLECTION){
  -            throw new JXPathException("Internal error. " +
  -                "Indexed passed to NullElementPointer.createChild() is not 0: " + index);
  -        }
  -        if (parent instanceof PropertyPointer){
  -            return parent.getParent().createChild(context, parent.getName(), getIndex(),
value);
  +    public NodePointer createChild(
  +        JXPathContext context,
  +        QName name,
  +        int index,
  +        Object value) 
  +    {
  +        if (index != 0 && index != WHOLE_COLLECTION) {
  +            throw new JXPathException(
  +                "Internal error. Indexed passed to "
  +                    + "NullElementPointer.createChild() is not 0: "
  +                    + index);
  +        }
  +        if (parent instanceof PropertyPointer) {
  +            return parent.getParent().createChild(
  +                context,
  +                parent.getName(),
  +                getIndex(),
  +                value);
           }
           else {
               return parent.createChild(context, name, getIndex(), value);
           }
       }
   
  -    public NodePointer createChild(JXPathContext context, QName name, int index){
  -        if (index != 0 && index != WHOLE_COLLECTION){
  -            throw new JXPathException("Internal error. " +
  -                "Indexed passed to NullElementPointer.createChild() is not 0: " + index);
  -        }
  -        if (parent instanceof PropertyPointer){
  -            return parent.getParent().createChild(context, parent.getName(), getIndex());
  +    public NodePointer createChild(
  +        JXPathContext context,
  +        QName name,
  +        int index) 
  +    {
  +        if (index != 0 && index != WHOLE_COLLECTION) {
  +            throw new JXPathException(
  +                "Internal error. Indexed passed to "
  +                    + "NullElementPointer.createChild() is not 0: "
  +                    + index);
  +        }
  +        if (parent instanceof PropertyPointer) {
  +            return parent.getParent().createChild(
  +                context,
  +                parent.getName(),
  +                getIndex());
           }
           else {
               return parent.createChild(context, name, getIndex());
  @@ -194,11 +216,30 @@
               index == other.index;
       }
   
  -    public String asPath(){
  -        return parent.asPath() + "[" + (index + 1) + "]";
  -    }
  -
       public int getLength(){
           return 0;
       }
  +    
  +    public String asPath() {
  +        StringBuffer buffer = new StringBuffer();
  +        NodePointer parent = getParent();
  +        if (parent != null) {
  +            buffer.append(parent.asPath());
  +        }
  +        if (index != WHOLE_COLLECTION) {
  +            // Address the list[1][2] case
  +            if (parent != null && parent.getIndex() != WHOLE_COLLECTION) {
  +                buffer.append("/.");
  +            }
  +            else if (
  +                parent != null
  +                    && parent.getParent() != null
  +                    && parent.getParent().getIndex() != WHOLE_COLLECTION) {
  +                buffer.append("/.");
  +            }
  +            buffer.append("[").append(index + 1).append(']');
  +        }
  +
  +        return buffer.toString();
  +    }    
   }
  
  
  
  1.11      +1 -2      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java
  
  Index: CollectionPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CollectionPointer.java	28 Nov 2002 01:02:04 -0000	1.10
  +++ CollectionPointer.java	10 Jan 2003 02:11:28 -0000	1.11
  @@ -269,8 +269,7 @@
           }
           if (index != WHOLE_COLLECTION) {
               // Address the list[1][2] case
  -            if (parent != null && parent.isContainer() &&
  -                    parent.getIndex() != WHOLE_COLLECTION){
  +            if (parent != null && parent.getIndex() != WHOLE_COLLECTION){
                   buffer.append("/.");
               }
               buffer.append("[").append(index + 1).append(']');
  
  
  
  1.3       +50 -1     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/MixedModelTest.java
  
  Index: MixedModelTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/MixedModelTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MixedModelTest.java	28 Nov 2002 01:02:05 -0000	1.2
  +++ MixedModelTest.java	10 Jan 2003 02:11:29 -0000	1.3
  @@ -122,8 +122,12 @@
           vars.declareVariable("document", bean.getDocument());
           vars.declareVariable("element", bean.getElement());
           vars.declareVariable("container", bean.getContainer());
  -        
           vars.declareVariable("testnull", new TestNull());
  +        
  +        int[][] matrix = new int[1][];
  +        matrix[0] = new int[1];
  +        matrix[0][0] = 3;
  +        vars.declareVariable("matrix", matrix);
       }
   
       public void testVarPrimitive(){
  @@ -500,5 +504,50 @@
           assertXPathPointerIterator(context,
               "$e//error",
               Collections.EMPTY_LIST);
  +    }
  +    
  +    public void testMatrix(){
  +        assertXPathValueAndPointer(context,
  +               "$matrix[1]/.[1]",
  +               new Integer(3),
  +               "$matrix[1]/.[1]");
  +                
  +        context.setValue("$matrix[1]/.[1]", new Integer(2));
  +
  +        assertXPathValueAndPointer(context,
  +              "matrix[1]/.[1]",
  +              new Integer(3),
  +              "/matrix[1]/.[1]");
  +                
  +        context.setValue("matrix[1]/.[1]", "2");
  +      
  +        assertXPathValue(context, "matrix[1]/.[1]", new Integer(2));
  +      
  +        context.getVariables().declareVariable(
  +            "wholebean",
  +            context.getContextBean());
  +            
  +        assertXPathValueAndPointer(context,
  +            "$wholebean/matrix[1]/.[1]",
  +            new Integer(2),
  +            "$wholebean/matrix[1]/.[1]");
  +
  +        boolean ex = false;
  +        try {
  +            context.setValue("$wholebean/matrix[1]/.[2]", "4");
  +        }
  +        catch (Exception e){
  +            ex = true;
  +        }        
  +        assertTrue("Exception setting value of non-existent element", ex);
  +        
  +        ex = false;
  +        try {
  +            context.setValue("$wholebean/matrix[2]/.[1]", "4");
  +        }
  +        catch (Exception e){
  +            ex = true;
  +        }        
  +        assertTrue("Exception setting value of non-existent element", ex);
       }
   }
  
  
  
  1.5       +24 -4     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/BeanModelTestCase.java
  
  Index: BeanModelTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/BeanModelTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BeanModelTestCase.java	29 Nov 2002 07:22:01 -0000	1.4
  +++ BeanModelTestCase.java	10 Jan 2003 02:11:29 -0000	1.5
  @@ -677,9 +677,29 @@
   
       public void testBooleanPredicate(){
           // use child axis
  +        
  +        // bean[1]/int = 1
  +        // bean[2]/int = 3
  +        
           assertXPathValue(context,
                   "beans[int > 2]/name",
                   "Name 2");
  +
  +        assertXPathValueIterator(context,
  +                "beans[int > 2]/name",
  +                list("Name 2"));
  +
  +        assertXPathValueIterator(context,
  +                "beans[int >= 1]/name",
  +                list("Name 1", "Name 2"));
  +                
  +        assertXPathValueIterator(context,
  +                "beans[int < 2]/name",
  +                list("Name 1"));
  +                
  +        assertXPathValueIterator(context,
  +                "beans[int <= 3]/name",
  +                list("Name 1", "Name 2"));
   
           assertXPathValueIterator(
               context,
  
  
  

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


Mime
View raw message