01: package org.openlaszlo.iv.flash.context;
02:
03: import org.openlaszlo.iv.flash.util.*;
04: import org.openlaszlo.iv.flash.url.*;
05: import org.openlaszlo.iv.flash.xml.*;
06:
07: import org.w3c.dom.Node;
08: import java.util.*;
09: import junit.framework.*;
10:
11: public class XMLContextTest extends TestCase {
12: String xml;
13: Node node;
14:
15: public void testGetValue() throws IVException, java.io.IOException {
16: XMLContext ctx = XMLContext.newXMLContext(null, node);
17:
18: assertEquals("foo contents", ctx.getValue("root/foo"));
19: assertEquals("bar contents", ctx.getValue("root/bar"));
20:
21: assertEquals("foo attribute", ctx.getValue("root/foo/@attr"));
22: assertEquals("bar attribute", ctx.getValue("root/bar/@attr"));
23:
24: // An expression which selects a nodeset should return the first item
25: // when a value is expected.
26:
27: assertEquals("item 1 contents", ctx.getValue("root/list/item"));
28: }
29:
30: public void testGetValueList() throws IVException,
31: java.io.IOException {
32: XMLContext context = XMLContext.newXMLContext(null, node);
33:
34: List l = context.getValueList("root/list/item");
35:
36: assertEquals(4, l.size());
37:
38: ListIterator iter = l.listIterator();
39: XMLContext childContext;
40: int itemIndex = 1;
41:
42: while (iter.hasNext()) {
43: childContext = (XMLContext) iter.next();
44:
45: assertEquals("item " + itemIndex + " contents",
46: childContext.getValue("."));
47:
48: itemIndex++;
49: }
50: }
51:
52: public void testApply() throws IVException, java.io.IOException {
53: XMLContext ctx = XMLContext.newXMLContext(null, node);
54:
55: String initial = "foo: '{root/foo}', bar: '{root/bar}', item: '{root/list/item}'";
56: String expected = "foo: 'foo contents', bar: 'bar contents', item: 'item 1 contents'";
57:
58: String actual = ctx.apply(initial);
59:
60: assertEquals(expected, actual);
61: }
62:
63: public XMLContextTest(java.lang.String testName) throws Exception {
64: super (testName);
65:
66: // Need to init JGen
67:
68: Util.init();
69:
70: // And load the test document into a node.
71:
72: node = XMLHelper.getNode(IVUrl.newUrl(Util.getInstallDir()
73: + "/test_data/XMLContextTest.xml", null));
74: }
75:
76: public static void main(java.lang.String[] args) {
77: junit.textui.TestRunner.run(suite());
78: }
79:
80: public static Test suite() {
81: TestSuite suite = new TestSuite(XMLContextTest.class);
82:
83: return suite;
84: }
85: }
|