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 ; 8 import java.util.*; 9 import junit.framework.*; 10 11 public class XMLContextTest extends TestCase 12 { 13 String xml; 14 Node node; 15 16 public void testGetValue() throws IVException, java.io.IOException 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 29 assertEquals( "item 1 contents", ctx.getValue( "root/list/item" ) ); 30 } 31 32 public void testGetValueList() throws IVException, java.io.IOException 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 56 { 57 XMLContext ctx = XMLContext.newXMLContext( null, node ); 58 59 String initial = "foo: '{root/foo}', bar: '{root/bar}', item: '{root/list/item}'"; 60 String expected = "foo: 'foo contents', bar: 'bar contents', item: 'item 1 contents'"; 61 62 String actual = ctx.apply( initial ); 63 64 assertEquals( expected, actual ); 65 } 66 67 public XMLContextTest(java.lang.String testName) throws Exception 68 { 69 super(testName); 70 71 73 Util.init(); 74 75 77 node = XMLHelper.getNode( IVUrl.newUrl( 78 Util.getInstallDir() + "/test_data/XMLContextTest.xml", null ) ); 79 } 80 81 public static void main(java.lang.String [] 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 |