KickJava   Java API By Example, From Geeks To Geeks.

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


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.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.Location;
19 import org.apache.tapestry.IBinding;
20 import org.apache.tapestry.IMarkupWriter;
21 import org.apache.tapestry.IRender;
22 import org.apache.tapestry.IRequestCycle;
23 import org.apache.tapestry.spec.ComponentSpecification;
24
25 /**
26  * Tests for the {@link org.apache.tapestry.components.Any} component.
27  *
28  * @author Howard M. Lewis Ship
29  * @since 4.0
30  */

31 public class TestAny extends BaseComponentTestCase
32 {
33     public void testElementNull()
34     {
35         IMarkupWriter writer = newWriter();
36         IRequestCycle cycle = newCycle();
37         Location l = newLocation();
38
39         replayControls();
40
41         Any any = (Any) newInstance(Any.class, new Object JavaDoc[]
42         { "location", l });
43
44         try
45         {
46             any.render(writer, cycle);
47             unreachable();
48         }
49         catch (ApplicationRuntimeException ex)
50         {
51             assertEquals(ComponentMessages.anyElementNotDefined(), ex.getMessage());
52             assertSame(l, ex.getLocation());
53         }
54
55         verifyControls();
56     }
57
58     public void testRender()
59     {
60         IMarkupWriter writer = newWriter();
61         IRequestCycle cycle = newCycle(false);
62         IRender body = newRender();
63
64         writer.begin("span");
65
66         body.render(writer, cycle);
67
68         writer.end("span");
69
70         replayControls();
71
72         Any any = (Any) newInstance(Any.class, new Object JavaDoc[]
73         { "element", "span" });
74
75         any.addBody(body);
76
77         any.render(writer, cycle);
78
79         verifyControls();
80     }
81
82     public void testRenderWithInformalParameters()
83     {
84         IMarkupWriter writer = newWriter();
85         IRequestCycle cycle = newCycle(false);
86         IRender body = newRender();
87         IBinding binding = newBinding("fred");
88
89         writer.begin("span");
90         writer.attribute("class", "fred");
91
92         body.render(writer, cycle);
93
94         writer.end("span");
95
96         replayControls();
97
98         Any any = (Any) newInstance(Any.class, new Object JavaDoc[]
99         { "element", "span", "specification", new ComponentSpecification() });
100
101         any.addBody(body);
102         any.setBinding("class", binding);
103
104         any.render(writer, cycle);
105
106         verifyControls();
107     }
108
109     public void testRewind()
110     {
111         IMarkupWriter writer = newWriter();
112         IRequestCycle cycle = newCycle(true);
113         IRender body = newRender();
114
115         body.render(writer, cycle);
116
117         replayControls();
118
119         Any any = (Any) newInstance(Any.class, new Object JavaDoc[]
120         { "element", "span" });
121
122         any.addBody(body);
123
124         any.render(writer, cycle);
125
126         verifyControls();
127     }
128 }
129
Popular Tags