1 package test.ozoneDB.xml.dom4j; 9 10 import junit.framework.TestCase; 11 import org.dom4j.Document; 12 import org.dom4j.Element; 13 import org.ozoneDB.ExternalDatabase; 14 import org.ozoneDB.xml.dom4j.O3DocumentHelper; 15 16 import java.util.List ; 17 18 21 public class XPathTest extends TestCase { 22 23 final String addressXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 24 "<addresses>" + 25 "<address name=\"Andreas\"><town>New York</town></address>" + 26 "<address name=\"Lars\"><town>Los Angeles</town></address>" + 27 "</addresses>"; 28 29 ExternalDatabase db; 30 31 public XPathTest(String methodName) { 32 super(methodName); 33 } 34 35 public void setUp() { 36 try { 37 db = ExternalDatabase.openDatabase("ozonedb:remote://localhost:3333"); 38 O3DocumentHelper.configure(db); 39 } catch (Exception e) { 40 e.printStackTrace(); 41 } 42 } 43 44 public void tearDown() { 45 try { 46 if ((db != null) && (db.isOpen())) { 47 db.close(); 48 } 49 } catch (Exception e) { 50 fail(e.toString()); 51 } 52 } 53 54 public void testXPathl() { 55 try { 56 Document doc; 57 System.out.println("Parsing string"); 58 doc = O3DocumentHelper.parseText(addressXML); 59 Element root = doc.getRootElement(); 60 List nodes = root.selectNodes("/addresses/address/town"); 61 assertEquals("expected 2 nodes", 2, nodes.size()); 62 root.selectObject("//address@name='Lars'"); 63 O3DocumentHelper.deleteDocument(doc); 64 } catch (Exception e) { 65 e.printStackTrace(); 66 fail(e.toString()); 67 } 68 69 } 70 } 71 | Popular Tags |