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.Script; 27 import org.apache.commons.jelly.XMLOutput; 28 29 35 public class TestDefaultNamespaceFilter extends TestCase { 36 37 Jelly jelly = null; 38 JellyContext context = null; 39 XMLOutput xmlOutput = null; 40 41 public TestDefaultNamespaceFilter(String name) { 42 super(name); 43 } 44 45 public static TestSuite suite() throws Exception { 46 return new TestSuite(TestDefaultNamespaceFilter.class); 47 } 48 49 public void setUp() throws Exception { 50 context = new JellyContext(); 51 xmlOutput = XMLOutput.createXMLOutput(new StringWriter ()); 52 53 jelly = new Jelly(); 54 55 String script = "nsFilterTest.jelly"; 56 URL url = this.getClass().getResource(script); 57 if ( url == null ) { 58 throw new Exception ( 59 "Could not find Jelly script: " + script 60 + " in package of class: " + this.getClass().getName() 61 ); 62 } 63 jelly.setUrl(url); 64 } 65 66 public void testNamespaceDefined() throws Exception { 67 jelly.setDefaultNamespaceURI("jelly:core"); 68 Script script = jelly.compileScript(); 69 script.run(context,xmlOutput); 70 assertTrue("should have set 'usedDefaultNamespace' variable", 71 context.getVariable("usedDefaultNamespace") != null); 72 } 73 74 public void testNamespaceNotDefined() throws Exception { 75 Script script = jelly.compileScript(); 76 script.run(context,xmlOutput); 77 assertTrue("should not have set 'usedDefaultNamespace' variable", 78 context.getVariable("usedDefaultNamespace") == null); 79 } 80 } 81 | Popular Tags |