KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > iv > flash > context > XMLContextTest


1 package org.openlaszlo.iv.flash.context;
2
3 import org.openlaszlo.iv.flash.util.*;
4 import org.openlaszlo.iv.flash.url.*;
5 import org.openlaszlo.iv.flash.xml.*;
6
7 import org.w3c.dom.Node JavaDoc;
8 import java.util.*;
9 import junit.framework.*;
10
11 public class XMLContextTest extends TestCase
12 {
13     String JavaDoc xml;
14     Node JavaDoc node;
15
16     public void testGetValue() throws IVException, java.io.IOException JavaDoc
17     {
18         XMLContext ctx = XMLContext.newXMLContext( null, node );
19
20         assertEquals( "foo contents", ctx.getValue( "root/foo" ) );
21         assertEquals( "bar contents", ctx.getValue( "root/bar" ) );
22
23         assertEquals( "foo attribute", ctx.getValue( "root/foo/@attr" ) );
24         assertEquals( "bar attribute", ctx.getValue( "root/bar/@attr" ) );
25
26         // An expression which selects a nodeset should return the first item
27
// when a value is expected.
28

29         assertEquals( "item 1 contents", ctx.getValue( "root/list/item" ) );
30     }
31
32     public void testGetValueList() throws IVException, java.io.IOException JavaDoc
33     {
34         XMLContext context = XMLContext.newXMLContext( null, node );
35
36         List l = context.getValueList( "root/list/item" );
37
38         assertEquals( 4, l.size() );
39
40         ListIterator iter = l.listIterator();
41         XMLContext childContext;
42         int itemIndex = 1;
43
44         while( iter.hasNext() )
45         {
46             childContext = ( XMLContext ) iter.next();
47
48             assertEquals( "item " + itemIndex + " contents",
49                           childContext.getValue( "." ) );
50
51             itemIndex++;
52         }
53     }
54
55     public void testApply() throws IVException, java.io.IOException JavaDoc
56     {
57         XMLContext ctx = XMLContext.newXMLContext( null, node );
58
59         String JavaDoc initial = "foo: '{root/foo}', bar: '{root/bar}', item: '{root/list/item}'";
60         String JavaDoc expected = "foo: 'foo contents', bar: 'bar contents', item: 'item 1 contents'";
61
62         String JavaDoc actual = ctx.apply( initial );
63
64         assertEquals( expected, actual );
65     }
66
67     public XMLContextTest(java.lang.String JavaDoc testName) throws Exception JavaDoc
68     {
69         super(testName);
70
71         // Need to init JGen
72

73         Util.init();
74
75         // And load the test document into a node.
76

77         node = XMLHelper.getNode( IVUrl.newUrl(
78             Util.getInstallDir() + "/test_data/XMLContextTest.xml", null ) );
79     }
80
81     public static void main(java.lang.String JavaDoc[] args)
82     {
83         junit.textui.TestRunner.run( suite() );
84     }
85
86     public static Test suite()
87     {
88         TestSuite suite = new TestSuite( XMLContextTest.class );
89
90         return suite;
91     }
92 }
93
Popular Tags