1 15 package org.apache.tapestry.components; 16 17 import org.apache.tapestry.IActionListener; 18 import org.apache.tapestry.IMarkupWriter; 19 import org.apache.tapestry.IRequestCycle; 20 import org.apache.tapestry.listener.ListenerInvoker; 21 import org.easymock.MockControl; 22 23 29 public class TestInvokeListener extends BaseComponentTestCase 30 { 31 private IActionListener newListener() 32 { 33 return (IActionListener) newMock(IActionListener.class); 34 } 35 36 private ListenerInvoker newInvoker() 37 { 38 return (ListenerInvoker) newMock(ListenerInvoker.class); 39 } 40 41 public void testSuccess() 42 { 43 IMarkupWriter writer = newWriter(); 44 IRequestCycle cycle = newCycle(); 45 46 IActionListener listener = newListener(); 47 ListenerInvoker invoker = newInvoker(); 48 49 Object [] parameters = new Object [0]; 50 51 InvokeListener component = (InvokeListener) newInstance(InvokeListener.class, new Object [] 52 { "listener", listener, "parameters", parameters, "listenerInvoker", invoker, }); 53 54 cycle.setListenerParameters(parameters); 55 invoker.invokeListener(listener, component, cycle); 56 cycle.setListenerParameters(null); 57 58 replayControls(); 59 60 component.render(writer, cycle); 61 62 verifyControls(); 63 } 64 65 public void testEnsureParametersClearedAfterException() 66 { 67 IMarkupWriter writer = newWriter(); 68 IRequestCycle cycle = newCycle(); 69 70 IActionListener listener = newListener(); 71 72 MockControl invokerc = newControl(ListenerInvoker.class); 73 ListenerInvoker invoker = (ListenerInvoker) invokerc.getMock(); 74 75 Throwable t = new RuntimeException (); 76 77 Object [] parameters = new Object [0]; 78 79 InvokeListener component = (InvokeListener) newInstance(InvokeListener.class, new Object [] 80 { "listener", listener, "parameters", parameters, "listenerInvoker", invoker, }); 81 82 cycle.setListenerParameters(parameters); 83 84 invoker.invokeListener(listener, component, cycle); 85 invokerc.setThrowable(t); 86 87 cycle.setListenerParameters(null); 88 89 replayControls(); 90 91 try 92 { 93 component.render(writer, cycle); 94 unreachable(); 95 } 96 catch (RuntimeException ex) 97 { 98 assertSame(t, ex); 99 } 100 101 verifyControls(); 102 } 103 } 104 | Popular Tags |