KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > components > TestBlock


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.components;
16
17 import org.apache.tapestry.IBinding;
18 import org.apache.tapestry.IComponent;
19 import org.apache.tapestry.IMarkupWriter;
20 import org.apache.tapestry.IRender;
21 import org.apache.tapestry.IRequestCycle;
22 import org.easymock.MockControl;
23
24 /**
25  * Tests for {@link org.apache.tapestry.components.Block}.
26  *
27  * @author Howard M. Lewis Ship
28  * @since 4.0
29  */

30 public class TestBlock extends BaseComponentTestCase
31 {
32     public void testRender()
33     {
34         final IComponent invoker = newComponent();
35
36         final Block block = (Block) newInstance(Block.class);
37
38         IMarkupWriter writer = newWriter();
39         IRequestCycle cycle = newCycle();
40
41         replayControls();
42
43         IRender body = new IRender()
44         {
45             public void render(IMarkupWriter writer, IRequestCycle cycle)
46             {
47                 assertSame(block.getInvoker(), invoker);
48                 assertSame(block.getInserter(), invoker);
49             }
50         };
51
52         assertNull(block.getInvoker());
53
54         block.addBody(body);
55
56         block.renderForComponent(writer, cycle, invoker);
57
58         assertNull(block.getInvoker());
59
60         verifyControls();
61     }
62
63     public void testGetParameter()
64     {
65         Object JavaDoc parameterValue = new Object JavaDoc();
66
67         IBinding binding = newBinding(parameterValue);
68
69         MockControl control = newControl(IComponent.class);
70         IComponent component = (IComponent) control.getMock();
71
72         component.getBinding("fred");
73         control.setReturnValue(binding);
74
75         replayControls();
76
77         Block block = (Block) newInstance(Block.class);
78
79         block.setInvoker(component);
80
81         assertSame(parameterValue, block.getParameter("fred"));
82
83         verifyControls();
84     }
85
86     private IComponent newComponent()
87     {
88         return (IComponent) newMock(IComponent.class);
89     }
90
91 }
92
Popular Tags