1 15 package org.apache.tapestry.form.translator; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.Location; 19 import org.apache.hivemind.lib.BeanFactory; 20 import org.apache.tapestry.IBinding; 21 import org.apache.tapestry.IComponent; 22 import org.apache.tapestry.binding.BindingTestCase; 23 import org.apache.tapestry.coerce.ValueConverter; 24 import org.easymock.MockControl; 25 26 33 public class TestTranslatorBinding extends BindingTestCase 34 { 35 public void testCreate() 36 { 37 Location l = newLocation(); 38 ValueConverter vc = newValueConverter(); 39 IComponent component = newComponent(); 40 41 MockControl bfc = newControl(BeanFactory.class); 42 BeanFactory bf = (BeanFactory) bfc.getMock(); 43 44 Translator translator = (Translator) newMock(Translator.class); 45 46 bf.get("string"); 47 bfc.setReturnValue(translator); 48 49 replayControls(); 50 51 TranslatorBindingFactory f = new TranslatorBindingFactory(); 52 f.setValueConverter(vc); 53 f.setTranslatorBeanFactory(bf); 54 55 IBinding binding = f.createBinding(component, "description", "string", l); 56 57 assertSame(translator, binding.getObject()); 58 assertSame(l, binding.getLocation()); 59 assertTrue(binding.isInvariant()); 60 assertEquals("description", binding.getDescription()); 61 62 verifyControls(); 63 } 64 65 public void testFailure() 66 { 67 Location l = newLocation(); 68 IComponent component = newComponent(); 69 70 MockControl bfc = newControl(BeanFactory.class); 71 BeanFactory bf = (BeanFactory) bfc.getMock(); 72 73 Throwable t = new RuntimeException ("Boom!"); 74 75 bf.get("string"); 76 bfc.setThrowable(t); 77 78 replayControls(); 79 80 TranslatorBindingFactory f = new TranslatorBindingFactory(); 81 f.setTranslatorBeanFactory(bf); 82 83 try 84 { 85 f.createBinding(component, "description", "string", l); 86 unreachable(); 87 } 88 catch (ApplicationRuntimeException ex) 89 { 90 assertEquals("Boom!", ex.getMessage()); 91 assertSame(t, ex.getRootCause()); 92 assertSame(l, ex.getLocation()); 93 } 94 95 verifyControls(); 96 97 } 98 } 99 | Popular Tags |