KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > services > impl > TestEngineServiceInnerProxy


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.services.impl;
16
17 import org.apache.hivemind.test.HiveMindTestCase;
18 import org.apache.tapestry.IRequestCycle;
19 import org.apache.tapestry.engine.IEngineService;
20 import org.apache.tapestry.engine.ILink;
21 import org.easymock.MockControl;
22
23 /**
24  * Tests for {@link org.apache.tapestry.services.impl.EngineServiceInnerProxy}.
25  *
26  * @author Howard M. Lewis Ship
27  * @since 4.0
28  */

29 public class TestEngineServiceInnerProxy extends HiveMindTestCase
30 {
31     private ILink newLink()
32     {
33         return (ILink) newMock(ILink.class);
34     }
35
36     private IRequestCycle newCycle()
37     {
38         return (IRequestCycle) newMock(IRequestCycle.class);
39     }
40
41     private EngineServiceSource newSource(String JavaDoc name, IEngineService service)
42     {
43         MockControl control = newControl(EngineServiceSource.class);
44         EngineServiceSource source = (EngineServiceSource) control.getMock();
45
46         source.resolveEngineService(name);
47         control.setReturnValue(service);
48
49         return source;
50     }
51
52     public void testGetName()
53     {
54         EngineServiceOuterProxy outer = new EngineServiceOuterProxy("Outer");
55         EngineServiceSource source = (EngineServiceSource) newMock(EngineServiceSource.class);
56
57         replayControls();
58
59         EngineServiceInnerProxy proxy = new EngineServiceInnerProxy("Inner", outer, source);
60
61         assertEquals("Inner", proxy.getName());
62         assertEquals("<InnerProxy for engine service 'Inner'>", proxy.toString());
63
64         verifyControls();
65     }
66
67     public void testGetLink()
68     {
69         ILink link = newLink();
70         IRequestCycle cycle = newCycle();
71
72         MockControl control = newControl(IEngineService.class);
73         IEngineService service = (IEngineService) control.getMock();
74
75         Object JavaDoc parameter = new Object JavaDoc();
76
77         service.getLink(cycle, parameter);
78         control.setReturnValue(link);
79
80         EngineServiceSource source = newSource("fred", service);
81
82         replayControls();
83
84         EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred");
85         EngineServiceInnerProxy inner = new EngineServiceInnerProxy("fred", outer, source);
86
87         outer.installDelegate(inner);
88
89         assertSame(link, outer.getLink(cycle, parameter));
90
91         assertSame(service, outer.getDelegate());
92
93         verifyControls();
94     }
95
96     public void testService() throws Exception JavaDoc
97     {
98         IRequestCycle cycle = newCycle();
99         IEngineService service = (IEngineService) newMock(IEngineService.class);
100
101         service.service(cycle);
102
103         EngineServiceSource source = newSource("fred", service);
104
105         replayControls();
106
107         EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred");
108         EngineServiceInnerProxy inner = new EngineServiceInnerProxy("fred", outer, source);
109
110         outer.installDelegate(inner);
111
112         outer.service(cycle);
113
114         assertSame(service, outer.getDelegate());
115
116         verifyControls();
117     }
118 }
Popular Tags