KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > FormComponentContributorTestCase


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.form;
16
17 import org.apache.hivemind.util.ClasspathResource;
18 import org.apache.tapestry.IEngine;
19 import org.apache.tapestry.IForm;
20 import org.apache.tapestry.IPage;
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.PageRenderSupport;
23 import org.apache.tapestry.junit.TapestryTestCase;
24 import org.easymock.MockControl;
25
26 /**
27  * Abstract test case for {@link FormComponentContributor}.
28  *
29  * @author Paul Ferraro
30  * @since 4.0
31  */

32 public abstract class FormComponentContributorTestCase extends TapestryTestCase
33 {
34     // Paul,
35
//
36
// Think you missed the newControl() and newMock() methods inherited from HiveMindTestCase.
37
// Those exist to eliminate the need for all this stuff. Instead, you create newFoo() methods that
38
// create and initialize a Foo instance.
39
// -- Howard
40

41     protected MockControl _componentControl = MockControl.createControl(IFormComponent.class);
42     protected IFormComponent _component = (IFormComponent) _componentControl.getMock();
43
44     protected MockControl _pageControl = MockControl.createControl(IPage.class);
45     protected IPage _page = (IPage) _pageControl.getMock();
46
47     protected MockControl _cycleControl = MockControl.createControl(IRequestCycle.class);
48     protected IRequestCycle _cycle = (IRequestCycle) _cycleControl.getMock();
49     
50     protected MockControl _formControl = MockControl.createControl(IForm.class);
51     protected IForm _form = (IForm) _formControl.getMock();
52
53     protected MockControl _engineControl = MockControl.createControl(IEngine.class);
54     protected IEngine _engine = (IEngine) _engineControl.getMock();
55     
56     protected MockControl _pageRenderSupportControl = MockControl.createControl(PageRenderSupport.class);
57     protected PageRenderSupport _pageRenderSupport = (PageRenderSupport) _pageRenderSupportControl.getMock();
58     
59     /**
60      * @see org.apache.hivemind.test.HiveMindTestCase#tearDown()
61      */

62     protected void tearDown() throws Exception JavaDoc
63     {
64         _componentControl.reset();
65         _pageControl.reset();
66         _cycleControl.reset();
67         _formControl.reset();
68         _engineControl.reset();
69         _pageRenderSupportControl.reset();
70         
71         super.tearDown();
72     }
73
74     protected void replay()
75     {
76         _componentControl.replay();
77         _pageControl.replay();
78         _cycleControl.replay();
79         _formControl.replay();
80         _engineControl.replay();
81         _pageRenderSupportControl.replay();
82     }
83     
84     protected void verify()
85     {
86         _componentControl.verify();
87         _pageControl.verify();
88         _cycleControl.verify();
89         _formControl.verify();
90         _engineControl.verify();
91         _pageRenderSupportControl.verify();
92     }
93     
94     protected void addScript(String JavaDoc script)
95     {
96         _cycle.getEngine();
97         _cycleControl.setReturnValue(_engine);
98         
99         _engine.getClassResolver();
100         _engineControl.setReturnValue(null);
101         
102         _cycle.getAttribute("org.apache.tapestry.PageRenderSupport");
103         _cycleControl.setReturnValue(_pageRenderSupport);
104         
105         _pageRenderSupport.addExternalScript(new ClasspathResource(null, script));
106         _pageRenderSupportControl.setVoidCallable();
107     }
108 }
109
Popular Tags