KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > junit > TestComponent


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.junit;
16
17 import org.apache.tapestry.BaseComponent;
18 import org.apache.tapestry.IMarkupWriter;
19 import org.apache.tapestry.IRender;
20 import org.apache.tapestry.IRequestCycle;
21 import org.apache.tapestry.engine.NullWriter;
22 import org.apache.tapestry.test.Creator;
23
24 /**
25  * Test a few random things in {@link org.apache.tapestry.AbstractComponent}and
26  * {@link org.apache.tapestry.BaseComponent}.
27  *
28  * @author Howard Lewis Ship
29  * @since 3.0
30  */

31
32 public class TestComponent extends TapestryTestCase
33 {
34     private static class TestRender implements IRender
35     {
36         private boolean rendered = false;
37
38         public void render(IMarkupWriter writer, IRequestCycle cycle)
39         {
40             rendered = true;
41         }
42
43     }
44
45     public abstract static class FakeComponent extends BaseComponent
46     {
47         void addOuterTest(IRender render)
48         {
49             addOuter(render);
50         }
51
52         void testRenderComponent(IMarkupWriter write, IRequestCycle cycle)
53         {
54             renderComponent(write, cycle);
55         }
56     }
57
58     /**
59      * Test the ability of {@link org.apache.tapestry.BaseComponent#addOuter(IRender)}to add a
60      * large number of objects.
61      */

62
63     public void testOuter() throws Exception JavaDoc
64     {
65         Creator creator = new Creator();
66
67         FakeComponent c = (FakeComponent) creator.newInstance(FakeComponent.class);
68
69         TestRender[] list = new TestRender[50];
70
71         for (int i = 0; i < list.length; i++)
72         {
73             list[i] = new TestRender();
74             c.addOuterTest(list[i]);
75         }
76
77         IMarkupWriter writer = new NullWriter();
78
79         c.testRenderComponent(writer, null);
80
81         for (int i = 0; i < list.length; i++)
82             assertTrue("Outer object #" + i + " did render.", list[i].rendered);
83     }
84 }
Popular Tags