1 16 package org.apache.commons.jelly.core; 17 18 import junit.framework.TestSuite; 19 20 import org.apache.commons.jelly.Script; 21 import org.apache.commons.jelly.test.BaseJellyTest; 22 23 26 public class TestUseBeanTag extends BaseJellyTest { 27 28 public TestUseBeanTag(String name) { 29 super(name); 30 } 31 32 public static TestSuite suite() throws Exception { 33 return new TestSuite(TestUseBeanTag.class); 34 } 35 36 40 public void testSimple() throws Exception { 41 setUpScript("testUseBeanTag.jelly"); 42 Script script = getJelly().compileScript(); 43 getJellyContext().setVariable("test.simple",Boolean.TRUE); 44 script.run(getJellyContext(),getXMLOutput()); 45 assertNotNull(getJellyContext().getVariable("foo")); 46 assertTrue(getJellyContext().getVariable("foo") instanceof Customer); 47 Customer customer = (Customer)(getJellyContext().getVariable("foo")); 48 assertEquals("name not set", "testing", customer.getName()); 49 assertEquals("city not set", "sydney", customer.getCity()); 50 } 51 52 55 public void testExtension() throws Exception { 56 setUpScript("testUseBeanTag.jelly"); 57 Script script = getJelly().compileScript(); 58 getJellyContext().setVariable("test.extension",Boolean.TRUE); 59 script.run(getJellyContext(),getXMLOutput()); 60 assertNotNull(getJellyContext().getVariable("foo")); 61 assertTrue(getJellyContext().getVariable("foo") instanceof Customer); 62 Customer customer = (Customer)(getJellyContext().getVariable("foo")); 63 assertNull("name set wrongly", customer.getName()); 64 assertEquals("city not set", "sydney", customer.getCity()); 65 } 66 67 70 public void testBadProperty() throws Exception { 71 setUpScript("testUseBeanTag.jelly"); 72 Script script = getJelly().compileScript(); 73 getJellyContext().setVariable("test.badProperty",Boolean.TRUE); 74 script.run(getJellyContext(),getXMLOutput()); 75 Exception e = (Exception )getJellyContext().getVariable("ex"); 76 assertNotNull("Should have failed to set invalid bean property", e); 77 } 78 79 82 public void testIgnoredBadProperty() throws Exception { 83 setUpScript("testUseBeanTag.jelly"); 84 Script script = getJelly().compileScript(); 85 getJellyContext().setVariable("test.badPropertyIgnored",Boolean.TRUE); 86 script.run(getJellyContext(),getXMLOutput()); 87 Customer customer = (Customer)(getJellyContext().getVariable("foo")); 88 assertNotNull("Should have ignored invalid bean property", customer); 89 } 90 } 91 | Popular Tags |