KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > ozoneDB > xml > dom4j > XPathTest


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: XPathTest.java,v 1.2 2003/07/07 10:30:30 per_nyfelt Exp $
8
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 JavaDoc;
17
18 /**
19  * $Id: XPathTest.java,v 1.2 2003/07/07 10:30:30 per_nyfelt Exp $
20  */

21 public class XPathTest extends TestCase {
22
23     final String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc e) {
65             e.printStackTrace();
66             fail(e.toString());
67         }
68
69     }
70 }
71
Popular Tags