commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Janner" <jan...@anecon.com>
Subject [jxpath] problem with Container interface
Date Mon, 08 Mar 2004 18:24:59 GMT
it seems that i misunderstand the usage of the "Container"-interface: why
does the following unit test fail?
thank you very much for any help!

public class XpathUtilTest extends TestCase {
    public void testEval2(){
        Foo foo = new Foo();
        foo.setBar( new Bar() );
        JXPathContext ctx = JXPathContext.newContext(foo);
        // this test succeeds:
        assertEquals(foo.getBar().getValue(),
            ctx.getValue("/bar"));
        // fails because "/bar[1]" returns whole arraylist:
        assertEquals("1", ctx.getValue("/bar[1]"));
        // fails because of JXPathException:
        //  "No value for xpath: /bar[2]"
        assertEquals("2", ctx.getValue("/bar[2]"));
    }
    public class Foo{
        private Bar bar;
        public Bar getBar() {
            return bar;
        }
        public void setBar(Bar bar){
            this.bar = bar;
        }
    }
    public class Bar implements Container{
        private List list;
        public Bar(){
            l = new ArrayList();
            l.add("1");l.add("2");l.add("3");
        }
        public Object getValue() {
            return l;
        }
        public void setValue(Object arg0) { /* not needed */ }
    }
}


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


Mime
View raw message