KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > callback > TestExternalCallback


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.callback;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.tapestry.IExternalPage;
19 import org.apache.tapestry.IPage;
20 import org.apache.tapestry.IRequestCycle;
21 import org.apache.tapestry.components.BaseComponentTestCase;
22 import org.easymock.MockControl;
23
24 /**
25  * Tests for {@link org.apache.tapestry.callback.ExternalCallback}.
26  *
27  * @author Howard M. Lewis Ship
28  * @since 4.0
29  */

30 public class TestExternalCallback extends BaseComponentTestCase
31 {
32     private IExternalPage newExternalPage()
33     {
34         return (IExternalPage) newMock(IExternalPage.class);
35     }
36
37     private IExternalPage newExternalPage(String JavaDoc pageName)
38     {
39         MockControl control = newControl(IExternalPage.class);
40         IExternalPage page = (IExternalPage) control.getMock();
41
42         page.getPageName();
43         control.setReturnValue(pageName);
44
45         return page;
46     }
47
48     public void testByName()
49     {
50         Object JavaDoc[] parameters =
51         { "param1", "param2" };
52
53         IExternalPage page = newExternalPage();
54         IRequestCycle cycle = newCycle("Fred", page);
55
56         cycle.activate(page);
57
58         page.activateExternalPage(parameters, cycle);
59
60         replayControls();
61
62         ExternalCallback callback = new ExternalCallback("Fred", parameters);
63
64         assertEquals("ExternalCallback[Fred/param1, param2]", callback.toString());
65
66         callback.performCallback(cycle);
67
68         verifyControls();
69     }
70
71     public void testByNameNoParameters()
72     {
73         IExternalPage page = newExternalPage();
74         IRequestCycle cycle = newCycle("Fred", page);
75
76         cycle.activate(page);
77
78         page.activateExternalPage(null, cycle);
79
80         replayControls();
81
82         ExternalCallback callback = new ExternalCallback("Fred", null);
83
84         assertEquals("ExternalCallback[Fred]", callback.toString());
85
86         callback.performCallback(cycle);
87
88         verifyControls();
89     }
90
91     public void testByPage()
92     {
93         Object JavaDoc[] parameters =
94         { "param1", "param2" };
95
96         IExternalPage page = newExternalPage("Barney");
97         IRequestCycle cycle = newCycle("Barney", page);
98
99         cycle.activate(page);
100
101         page.activateExternalPage(parameters, cycle);
102
103         replayControls();
104
105         ExternalCallback callback = new ExternalCallback(page, parameters);
106
107         assertEquals("ExternalCallback[Barney/param1, param2]", callback.toString());
108
109         callback.performCallback(cycle);
110
111         verifyControls();
112     }
113
114     public void testNotExternalPage()
115     {
116         IPage page = newPage();
117         IRequestCycle cycle = newCycle("Barney", page);
118
119         replayControls();
120
121         ExternalCallback callback = new ExternalCallback("Barney", null);
122
123         try
124         {
125             callback.performCallback(cycle);
126         }
127         catch (ApplicationRuntimeException ex)
128         {
129             assertEquals(
130                     "Page Barney does not implement the IExternalPage interface, and may not be used with the external service.",
131                     ex.getMessage());
132         }
133
134         verifyControls();
135     }
136 }
137
Popular Tags