KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > services > impl > TestBaseTagWriter


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.services.impl;
16
17 import org.apache.hivemind.test.HiveMindTestCase;
18 import org.apache.tapestry.IMarkupWriter;
19 import org.apache.tapestry.INamespace;
20 import org.apache.tapestry.IPage;
21 import org.apache.tapestry.IRequestCycle;
22 import org.easymock.MockControl;
23
24 /**
25  * Tests for {@link org.apache.tapestry.services.impl.BaseTagWriter}.
26  *
27  * @author Howard M. Lewis Ship
28  * @since 4.0
29  */

30 public class TestBaseTagWriter extends HiveMindTestCase
31 {
32     private IMarkupWriter newWriter(String JavaDoc url)
33     {
34         IMarkupWriter writer = (IMarkupWriter) newMock(IMarkupWriter.class);
35
36         writer.beginEmpty("base");
37         writer.attribute("href", url);
38         writer.println();
39
40         return writer;
41     }
42
43     private INamespace newNamespace(String JavaDoc id)
44     {
45         MockControl control = newControl(INamespace.class);
46         INamespace ns = (INamespace) control.getMock();
47
48         ns.getId();
49         control.setReturnValue(id);
50
51         return ns;
52     }
53
54     private IPage newPage(String JavaDoc pageName)
55     {
56         return newPage(newNamespace(null), pageName);
57     }
58
59     private IPage newPage(INamespace ns, String JavaDoc pageName)
60     {
61         MockControl control = newControl(IPage.class);
62         IPage page = (IPage) control.getMock();
63
64         page.getNamespace();
65         control.setReturnValue(ns);
66
67         if (pageName != null)
68         {
69             page.getPageName();
70             control.setReturnValue(pageName);
71         }
72
73         return page;
74     }
75
76     private IRequestCycle newRequestCycle(IPage page, String JavaDoc url)
77     {
78         MockControl control = newControl(IRequestCycle.class);
79         IRequestCycle cycle = (IRequestCycle) control.getMock();
80
81         cycle.getPage();
82         control.setReturnValue(page);
83
84         cycle.getAbsoluteURL(url);
85         control.setReturnValue("http://foo.com/context" + url);
86
87         return cycle;
88     }
89
90     private void run(IMarkupWriter writer, IRequestCycle cycle)
91     {
92         replayControls();
93
94         new BaseTagWriter().render(writer, cycle);
95
96         verifyControls();
97     }
98
99     public void testNotApplicationNamespace()
100     {
101         INamespace ns = newNamespace("library");
102         IPage page = newPage(ns, null);
103         IRequestCycle cycle = newRequestCycle(page, "/");
104         IMarkupWriter writer = newWriter("http://foo.com/context/");
105
106         run(writer, cycle);
107     }
108     
109     public void testInRoot()
110     {
111         IPage page = newPage("Home");
112         IRequestCycle cycle = newRequestCycle(page, "/");
113         IMarkupWriter writer = newWriter("http://foo.com/context/");
114
115         run(writer, cycle);
116     }
117     
118     public void testInSubFolder()
119     {
120         IPage page = newPage("admin/AdminMenu");
121         IRequestCycle cycle = newRequestCycle(page, "/admin/");
122         IMarkupWriter writer = newWriter("http://foo.com/context/admin/");
123
124         run(writer, cycle);
125     }
126 }
Popular Tags