1 15 package org.apache.tapestry.enhance; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.Location; 19 import org.apache.hivemind.Resource; 20 import org.apache.hivemind.test.HiveMindTestCase; 21 import org.apache.tapestry.IScript; 22 import org.apache.tapestry.engine.IScriptSource; 23 import org.easymock.MockControl; 24 25 31 public class TestDeferredScript extends HiveMindTestCase 32 { 33 public void testSuccess() 34 { 35 MockControl control = newControl(IScriptSource.class); 36 IScriptSource source = (IScriptSource) control.getMock(); 37 38 Resource r = (Resource) newMock(Resource.class); 39 IScript script = (IScript) newMock(IScript.class); 40 41 source.getScript(r); 42 control.setReturnValue(script); 43 44 replayControls(); 45 46 DeferredScript ds = new DeferredScriptImpl(r, source, null); 47 48 assertSame(script, ds.getScript()); 49 50 53 assertTrue(ds.toString().indexOf(r.toString()) > 0); 54 55 verifyControls(); 56 } 57 58 public void testFailure() 59 { 60 MockControl control = newControl(IScriptSource.class); 61 IScriptSource source = (IScriptSource) control.getMock(); 62 63 Resource newResource = (Resource) newMock(Resource.class); 64 Resource r = newResource; 65 66 Location l = newLocation(); 67 Throwable t = new RuntimeException ("Woops!"); 68 69 source.getScript(r); 70 control.setThrowable(t); 71 72 replayControls(); 73 74 DeferredScript ds = new DeferredScriptImpl(r, source, l); 75 76 try 77 { 78 ds.getScript(); 79 unreachable(); 80 } 81 catch (ApplicationRuntimeException ex) 82 { 83 assertEquals("Woops!", ex.getMessage()); 84 assertSame(l, ex.getLocation()); 85 assertSame(t, ex.getRootCause()); 86 } 87 88 verifyControls(); 89 90 } 91 } 92 | Popular Tags |