KickJava   Java API By Example, From Geeks To Geeks.

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


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.IPage;
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.Tapestry;
23 import org.apache.tapestry.services.LinkFactory;
24 import org.apache.tapestry.services.ServiceConstants;
25 import org.easymock.MockControl;
26
27 /**
28  * Tests for {@link org.apache.tapestry.engine.ResetService}.
29  *
30  * @author Howard M. Lewis Ship
31  * @since 4.0
32  */

33 public class TestResetService extends ServiceTestCase
34 {
35     private IRequestCycle newRequestCycle(IPage page)
36     {
37         MockControl control = newControl(IRequestCycle.class);
38         IRequestCycle cycle = (IRequestCycle) control.getMock();
39
40         cycle.getPage();
41         control.setReturnValue(page);
42
43         return cycle;
44     }
45
46     public void testGetLink()
47     {
48         IPage page = newPage("TargetPage");
49         IRequestCycle cycle = newRequestCycle(page);
50
51         Map JavaDoc parameters = new HashMap JavaDoc();
52         parameters.put(ServiceConstants.SERVICE, Tapestry.RESET_SERVICE);
53         parameters.put(ServiceConstants.PAGE, "TargetPage");
54
55         ILink link = newLink();
56         LinkFactory lf = newLinkFactory(cycle, parameters, true, link);
57
58         replayControls();
59
60         ResetService s = new ResetService();
61         s.setLinkFactory(lf);
62
63         assertSame(link, s.getLink(cycle, null));
64
65         verifyControls();
66     }
67
68     public void testGetLinkNonNullParameter()
69     {
70         ResetService s = new ResetService();
71
72         try
73         {
74             s.getLink(null, "NonNullValue");
75             unreachable();
76         }
77         catch (IllegalArgumentException JavaDoc ex)
78         {
79             assertEquals(EngineMessages.serviceNoParameter(s), ex.getMessage());
80         }
81     }
82
83 }
Popular Tags