KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > components > TestInvokeListener


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

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 /**
24  * Tests for {@link org.apache.tapestry.components.InvokeListener}.
25  *
26  * @author Howard M. Lewis Ship
27  * @since 4.0
28  */

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 JavaDoc[] parameters = new Object JavaDoc[0];
50
51         InvokeListener component = (InvokeListener) newInstance(InvokeListener.class, new Object JavaDoc[]
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 JavaDoc t = new RuntimeException JavaDoc();
76
77         Object JavaDoc[] parameters = new Object JavaDoc[0];
78
79         InvokeListener component = (InvokeListener) newInstance(InvokeListener.class, new Object JavaDoc[]
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 JavaDoc ex)
97         {
98             assertSame(t, ex);
99         }
100
101         verifyControls();
102     }
103 }
104
Popular Tags