1 16 package org.apache.commons.jelly.core; 17 18 import junit.framework.TestSuite; 19 20 import org.apache.commons.jelly.JellyException; 21 import org.apache.commons.jelly.Script; 22 import org.apache.commons.jelly.test.BaseJellyTest; 23 24 28 public class TestInvokeStaticTag extends BaseJellyTest { 29 30 public TestInvokeStaticTag(String name) { 31 super(name); 32 } 33 34 public static TestSuite suite() throws Exception { 35 return new TestSuite(TestInvokeStaticTag.class); 36 } 37 38 public void setUp() throws Exception { 39 super.setUp(); 40 } 41 42 public void tearDown() throws Exception { 43 super.tearDown(); 44 } 45 46 50 public void testSimpleSystemInvoke() throws Exception { 51 setUpScript( "testInvokeStaticTag.jelly" ); 52 Script script = getJelly().compileScript(); 53 54 getJellyContext().setVariable( "test.simpleSystemInvoke",Boolean.TRUE ); 55 56 getJellyContext().setVariable( "propertyName", "java.runtime.version" ); 57 script.run( getJellyContext(),getXMLOutput() ); 58 59 assertTrue( System.getProperty( "java.runtime.version" ).equals( getJellyContext().getVariable("propertyName" ) ) ); 60 } 61 62 66 public void testSystemInvoke() throws Exception { 67 setUpScript( "testInvokeStaticTag.jelly" ); 68 Script script = getJelly().compileScript(); 69 70 getJellyContext().setVariable( "test.systemInvoke",Boolean.TRUE ); 71 72 getJellyContext().setVariable( "propertyName", "TEST PROPERTY" ); 73 getJellyContext().setVariable( "propertyValue", "Jelly is cool" ); 74 script.run( getJellyContext(),getXMLOutput() ); 75 76 assertTrue( System.getProperty( "TEST PROPERTY" ).equals( "Jelly is cool" ) ); 77 78 } 79 80 84 public void testMessageFormatInvoke() throws Exception { 85 System.out.println( System.getProperties() ); 86 setUpScript( "testInvokeStaticTag.jelly" ); 87 Script script = getJelly().compileScript(); 88 89 getJellyContext().setVariable( "test.messageFormatInvoke", Boolean.TRUE ); 90 91 Object [] args = new Object [3]; 92 args[0] = "Jelly"; 93 args[1] = "coolest"; 94 args[2] = "used"; 95 96 getJellyContext().setVariable( "args", args ); 97 getJellyContext().setVariable( "message", "Is not {0} the {1} thing you have ever {2}?" ); 98 script.run( getJellyContext(),getXMLOutput() ); 99 100 assertNotNull( getJellyContext().getVariable("message") ); 101 assertTrue( getJellyContext().getVariable("message").equals("Is not Jelly the coolest thing you have ever used?") ); 102 103 } 104 105 public void testInvokeThatThrowsException() throws Exception { 106 setUpScript( "testInvokeStaticTag.jelly" ); 107 Script script = getJelly().compileScript(); 108 getJellyContext().setVariable("test.invokeThatThrowsException",Boolean.TRUE); 109 script.run(getJellyContext(),getXMLOutput()); 110 String exceptionMessage = (String ) getJellyContext().getVariable("exceptionMessage"); 111 assertNotNull( exceptionMessage ); 112 Exception jellyException = (Exception ) getJellyContext().getVariable("jellyException"); 113 assertNull( jellyException ); 114 Exception exception = (Exception ) getJellyContext().getVariable("exceptionThrown"); 115 assertNotNull( exception ); 116 assertEquals( exceptionMessage, exception.getMessage() ); 117 } 118 119 public void testInvokeThatDoesNotHandleException() throws Exception { 120 setUpScript( "testInvokeStaticTag.jelly" ); 121 Script script = getJelly().compileScript(); 122 getJellyContext().setVariable("test.invokeThatDoesNotHandleException",Boolean.TRUE); 123 script.run(getJellyContext(),getXMLOutput()); 124 String exceptionMessage = (String ) getJellyContext().getVariable("exceptionMessage"); 125 assertNotNull( exceptionMessage ); 126 JellyException jellyException = (JellyException) getJellyContext().getVariable("jellyException"); 127 assertNotNull( jellyException ); 128 assertTrue( "messages are the same", ! exceptionMessage.equals(jellyException.getMessage()) ); 129 assertTrue( "exception '" + jellyException.getMessage() + "' does not ends with '" + 130 exceptionMessage+"'", jellyException.getMessage().endsWith(exceptionMessage) ); 131 assertNotNull( jellyException.getCause() ); 132 assertEquals( exceptionMessage, jellyException.getCause().getMessage() ); 133 } 134 135 } 136 | Popular Tags |