KickJava   Java API By Example, From Geeks To Geeks.

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


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.IMarkupWriter;
19 import org.apache.tapestry.IRender;
20 import org.apache.tapestry.IRequestCycle;
21 import org.apache.tapestry.spec.IComponentSpecification;
22
23 /**
24  * Tests for {@link org.apache.tapestry.components.Conditional}  component.
25  *
26  * @author Howard M. Lewis Ship
27  * @since 4.0
28  */

29 public class TestConditional extends BaseComponentTestCase
30 {
31     private IRender newRender(IMarkupWriter writer, IRequestCycle cycle)
32     {
33         IRender render = (IRender) newMock(IRender.class);
34
35         render.render(writer, cycle);
36
37         return render;
38     }
39
40     public void testFalseAndFalse()
41     {
42         Conditional conditional = (Conditional) newInstance(Conditional.class, new Object JavaDoc[]
43         { "condition", Boolean.FALSE, "invert", Boolean.FALSE });
44
45         conditional.renderComponent(null, null);
46     }
47
48     public void testTrueAndTrue()
49     {
50         Conditional conditional = (Conditional) newInstance(Conditional.class, new Object JavaDoc[]
51         { "condition", Boolean.TRUE, "invert", Boolean.TRUE });
52
53         conditional.renderComponent(null, null);
54     }
55
56     public void testRenderSimple()
57     {
58         IRequestCycle cycle = newCycle(false);
59         IMarkupWriter writer = newWriter();
60         IRender body = newRender(writer, cycle);
61
62         replayControls();
63
64         Conditional conditional = (Conditional) newInstance(Conditional.class, new Object JavaDoc[]
65         { "condition", Boolean.TRUE });
66         conditional.addBody(body);
67
68         conditional.render(writer, cycle);
69
70         verifyControls();
71     }
72
73     public void testIgnoreElementWhenRewinding()
74     {
75         IRequestCycle cycle = newCycle(true);
76         IMarkupWriter writer = newWriter();
77         IRender body = newRender(writer, cycle);
78
79         replayControls();
80
81         Conditional conditional = (Conditional) newInstance(Conditional.class, new Object JavaDoc[]
82         { "condition", Boolean.TRUE, "element", "div" });
83         conditional.addBody(body);
84
85         conditional.render(writer, cycle);
86
87         verifyControls();
88     }
89
90     public void testElement()
91     {
92         IBinding informal = newBinding("informal-value");
93         IComponentSpecification spec = newSpec("informal", null);
94
95         IRequestCycle cycle = newCycle(false);
96         IMarkupWriter writer = newWriter();
97         IRender body = newRender(writer, cycle);
98
99         writer.begin("div");
100         writer.attribute("informal", "informal-value");
101
102         // We've trained body, but there's no way to ensure,
103
// using EasyMock, that methods are invoked in the correct
104
// order. But sometimes you have to trust the code (
105
// and trust that future developers won't break something
106
// that obvious!).
107

108         writer.end("div");
109
110         replayControls();
111
112         Conditional conditional = (Conditional) newInstance(Conditional.class, new Object JavaDoc[]
113         { "condition", Boolean.TRUE, "element", "div", "specification", spec });
114         conditional.addBody(body);
115         conditional.setBinding("informal", informal);
116
117         conditional.render(writer, cycle);
118
119         verifyControls();
120     }
121 }
Popular Tags