1 16 package org.apache.commons.jelly.test.xml; 17 18 import java.io.StringWriter ; 19 import java.net.URL ; 20 21 import junit.framework.TestCase; 22 import junit.framework.TestSuite; 23 24 import org.apache.commons.jelly.Jelly; 25 import org.apache.commons.jelly.JellyContext; 26 import org.apache.commons.jelly.JellyException; 27 import org.apache.commons.jelly.Script; 28 import org.apache.commons.jelly.XMLOutput; 29 30 37 public class TestXMLParserCache extends TestCase { 38 39 Jelly jelly = null; 40 JellyContext context = null; 41 XMLOutput xmlOutput = null; 42 43 public TestXMLParserCache(String name) { 44 super(name); 45 } 46 47 public static TestSuite suite() throws Exception { 48 return new TestSuite(TestXMLParserCache.class); 49 } 50 51 public void setUp(String scriptName) throws Exception { 52 context = new JellyContext(); 53 xmlOutput = XMLOutput.createXMLOutput(new StringWriter ()); 54 55 jelly = new Jelly(); 56 57 String script = scriptName; 58 URL url = this.getClass().getResource(script); 59 if ( url == null ) { 60 throw new Exception ( 61 "Could not find Jelly script: " + script 62 + " in package of class: " + this.getClass().getName() 63 ); 64 } 65 jelly.setUrl(url); 66 } 67 68 public void testParserCache1() throws Exception { 69 setUp("invalidScript1.jelly"); 72 jelly.setValidateXML(false); 73 Script script = jelly.compileScript(); 74 script.run(context,xmlOutput); 75 assertTrue("should have set 'foo' variable to 'bar'", 76 context.getVariable("foo").equals("bar")); 77 78 jelly.setValidateXML(true); 81 try { 82 script = jelly.compileScript(); 83 fail("Invalid scripts should throw JellyException on parse, despite the cache"); 84 } catch (JellyException e) { 85 } 86 } 87 88 public void testParserCache2() throws Exception { 89 setUp("nsFilterTest.jelly"); 91 Script script = jelly.compileScript(); 92 script.run(context,xmlOutput); 93 assertTrue("should have no var when default namspace is not set", 94 context.getVariable("usedDefaultNamespace") == null); 95 96 jelly.setDefaultNamespaceURI("jelly:core"); 99 script = jelly.compileScript(); 100 script.run(context,xmlOutput); 101 assertTrue("should have var when default namspace is set", 102 context.getVariable("usedDefaultNamespace").equals("true")); 103 } 104 } 105 | Popular Tags |