1 15 package org.apache.tapestry.binding; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.Location; 19 import org.apache.hivemind.test.HiveMindTestCase; 20 import org.apache.tapestry.IBinding; 21 import org.apache.tapestry.coerce.ValueConverter; 22 import org.apache.tapestry.engine.state.ApplicationStateManager; 23 import org.easymock.MockControl; 24 25 32 public class TestStateBinding extends HiveMindTestCase 33 { 34 35 private ValueConverter newValueConverter() 36 { 37 return (ValueConverter) newMock(ValueConverter.class); 38 } 39 40 private IBinding newBinding(String objectName, ValueConverter vc, ApplicationStateManager asm, 41 Location location) 42 { 43 StateBindingFactory f = new StateBindingFactory(); 44 f.setValueConverter(vc); 45 f.setApplicationStateManager(asm); 46 47 return f.createBinding(null, "binding description", objectName, location); 48 } 49 50 public void testSuccess() 51 { 52 MockControl asmc = newControl(ApplicationStateManager.class); 53 ApplicationStateManager asm = (ApplicationStateManager) asmc.getMock(); 54 55 asm.exists("fred"); 56 asmc.setReturnValue(true); 57 58 ValueConverter vc = newValueConverter(); 59 60 replayControls(); 61 62 IBinding b = newBinding("fred", vc, asm, null); 63 64 assertEquals(Boolean.TRUE, b.getObject()); 65 66 verifyControls(); 67 } 68 69 public void testFailure() 70 { 71 Location l = fabricateLocation(22); 72 73 Throwable t = new RuntimeException ("Nested exception."); 74 75 MockControl asmc = newControl(ApplicationStateManager.class); 76 ApplicationStateManager asm = (ApplicationStateManager) asmc.getMock(); 77 78 asm.exists("fred"); 79 asmc.setThrowable(t); 80 81 ValueConverter vc = newValueConverter(); 82 83 replayControls(); 84 85 IBinding b = newBinding("fred", vc, asm, l); 86 87 88 try 89 { 90 b.getObject(); 91 unreachable(); 92 } 93 catch (ApplicationRuntimeException ex) 94 { 95 assertEquals("Nested exception.", ex.getMessage()); 96 assertSame(l, ex.getLocation()); 97 assertSame(t, ex.getRootCause()); 98 } 99 100 verifyControls(); 101 } 102 103 } | Popular Tags |