001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.xml.impl.jxpath;
017:
018: import java.util.Iterator;
019:
020: import junit.framework.TestCase;
021:
022: import org.apache.commons.jxpath.JXPathContext;
023: import org.apache.commons.jxpath.JXPathContextFactory;
024: import org.apache.commons.jxpath.JXPathIntrospector;
025: import org.geotools.xml.impl.ElementHandlerImpl;
026: import org.geotools.xml.impl.ElementImpl;
027: import org.geotools.xml.impl.NodeImpl;
028:
029: public class JXPathTest extends TestCase {
030: NodeImpl root;
031: NodeImpl child1;
032: NodeImpl child2;
033: JXPathContext context;
034:
035: protected void setUp() throws Exception {
036: ElementImpl e = new ElementImpl(null);
037: e.setName("root");
038: root = new NodeImpl(e);
039:
040: e = new ElementImpl(null);
041: e.setName("child");
042: child1 = new NodeImpl(e);
043: //root.addChild( child1 );
044:
045: e = new ElementImpl(null);
046: e.setName("child");
047: child2 = new NodeImpl(e);
048: //root.addChild( child2 );
049:
050: JXPathIntrospector.registerDynamicClass(NodeImpl.class,
051: NodePropertyHandler.class);
052:
053: context = JXPathContextFactory.newInstance().newContext(null,
054: root);
055: }
056:
057: public void testIterate() {
058: // root.getChildHandlers().add(child1);
059: // root.getChildHandlers().add(child2);
060: root.addChild(child1);
061: root.addChild(child2);
062:
063: Iterator itr = context.iterate("child");
064: assertTrue(itr.hasNext());
065: assertEquals(child1, itr.next());
066: assertTrue(itr.hasNext());
067: assertEquals(child2, itr.next());
068:
069: itr = context.iterate("child[position() = 2]");
070: assertTrue(itr.hasNext());
071: assertEquals(child2, itr.next());
072:
073: assertFalse(itr.hasNext());
074:
075: //
076: // assertTrue(itr.hasNext());
077: // assertEquals(itr.next(), child2);
078: }
079:
080: //
081: // public void testSimple() {
082: // root.getChildHandlers().add(child1);
083: // root.getChildHandlers().add(child2);
084: //
085: // Object obj = context.getValue("child1");
086: // assertNotNull(obj);
087: // assertEquals(obj, child1);
088: //
089: // obj = context.getValue("child2");
090: // assertNotNull(obj);
091: // assertEquals(obj, child2);
092: // }
093: //
094: // public void testDynamic() {
095: // root.getChildHandlers().add(child1);
096: //
097: // Object obj = context.getValue("child1");
098: // assertNotNull(obj);
099: // assertEquals(obj, child1);
100: //
101: // root.getChildHandlers().add(child2);
102: // obj = context.getValue("child2");
103: // assertNotNull(obj);
104: // assertEquals(obj, child2);
105: // }
106: }
|