KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > engine > TestPageService


1 // Copyright 2004, 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.engine;
16
17 import java.util.HashMap JavaDoc;
18 import java.util.Map JavaDoc;
19
20 import org.apache.tapestry.IRequestCycle;
21 import org.apache.tapestry.Tapestry;
22 import org.apache.tapestry.services.LinkFactory;
23 import org.apache.tapestry.services.ResponseRenderer;
24 import org.apache.tapestry.services.ServiceConstants;
25 import org.easymock.MockControl;
26
27 /**
28  * @author Howard M. Lewis Ship
29  * @since 4.0
30  */

31 public class TestPageService extends ServiceTestCase
32 {
33     public void testGetLink()
34     {
35         Map JavaDoc parameters = new HashMap JavaDoc();
36         parameters.put(ServiceConstants.SERVICE, Tapestry.PAGE_SERVICE);
37         parameters.put(ServiceConstants.PAGE, "TargetPage");
38
39         ILink link = newLink();
40
41         MockControl lfc = newControl(LinkFactory.class);
42         LinkFactory lf = (LinkFactory) lfc.getMock();
43
44         IRequestCycle cycle = newRequestCycle();
45
46         lf.constructLink(cycle, parameters, true);
47         lfc.setReturnValue(link);
48
49         replayControls();
50
51         PageService ps = new PageService();
52         ps.setLinkFactory(lf);
53
54         assertSame(link, ps.getLink(cycle, "TargetPage"));
55
56         verifyControls();
57     }
58
59     public void testService() throws Exception JavaDoc
60     {
61         MockControl cyclec = newControl(IRequestCycle.class);
62         IRequestCycle cycle = (IRequestCycle) cyclec.getMock();
63
64         cycle.getParameter(ServiceConstants.PAGE);
65         cyclec.setReturnValue("TargetPage");
66
67         cycle.activate("TargetPage");
68
69         ResponseRenderer rr = newResponseRenderer();
70
71         rr.renderResponse(cycle);
72
73         replayControls();
74
75         PageService ps = new PageService();
76         ps.setResponseRenderer(rr);
77
78         ps.service(cycle);
79
80         verifyControls();
81     }
82 }
Popular Tags