KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > web > TestWebContextResource


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.web;
16
17 import java.net.URL JavaDoc;
18 import java.util.Locale JavaDoc;
19
20 import org.apache.hivemind.Resource;
21 import org.apache.hivemind.test.HiveMindTestCase;
22 import org.apache.tapestry.web.WebContextResource;
23 import org.apache.tapestry.web.WebContext;
24 import org.easymock.MockControl;
25
26 /**
27  * Tests for {@link org.apache.tapestry.web.WebContextResource}.
28  *
29  * @author Howard M. Lewis Ship
30  * @since 4.0
31  */

32 public class TestWebContextResource extends HiveMindTestCase
33 {
34     private WebContext newContext()
35     {
36         return (WebContext) newMock(WebContext.class);
37     }
38
39     public void testConstructor()
40     {
41         WebContext context = newContext();
42
43         replayControls();
44
45         Resource r = new WebContextResource(context, "/foo/bar/baz_en.html", Locale.ENGLISH);
46
47         assertEquals("context:/foo/bar/baz_en.html", r.toString());
48
49         assertEquals("/foo/bar/baz_en.html", r.getPath());
50
51         assertEquals("baz_en.html", r.getName());
52
53         assertEquals(Locale.ENGLISH, r.getLocale());
54
55         verifyControls();
56     }
57
58     public void testLocalizationExists() throws Exception JavaDoc
59     {
60         MockControl control = newControl(WebContext.class);
61         WebContext context = (WebContext) control.getMock();
62
63         context.getResource("/foo/bar/baz_en.html");
64         control.setReturnValue(new URL JavaDoc("http://foo.com"));
65
66         replayControls();
67
68         Resource r1 = new WebContextResource(context, "/foo/bar/baz.html");
69
70         Resource r2 = r1.getLocalization(Locale.ENGLISH);
71
72         assertEquals("/foo/bar/baz_en.html", r2.getPath());
73         assertEquals(Locale.ENGLISH, r2.getLocale());
74
75         verifyControls();
76     }
77
78     public void testLocalizationSame() throws Exception JavaDoc
79     {
80         MockControl control = newControl(WebContext.class);
81         WebContext context = (WebContext) control.getMock();
82
83         context.getResource("/foo/bar/baz_en.html");
84         control.setReturnValue(null);
85
86         context.getResource("/foo/bar/baz.html");
87         control.setReturnValue(new URL JavaDoc("http://foo.com"));
88
89         replayControls();
90
91         Resource r1 = new WebContextResource(context, "/foo/bar/baz.html");
92
93         Resource r2 = r1.getLocalization(Locale.ENGLISH);
94
95         assertSame(r2, r1);
96
97         verifyControls();
98     }
99
100     public void testLocalizationMissing() throws Exception JavaDoc
101     {
102         MockControl control = newControl(WebContext.class);
103         WebContext context = (WebContext) control.getMock();
104
105         context.getResource("/foo/bar/baz_en.html");
106         control.setReturnValue(null);
107
108         context.getResource("/foo/bar/baz.html");
109         control.setReturnValue(null);
110
111         replayControls();
112
113         Resource r1 = new WebContextResource(context, "/foo/bar/baz.html");
114
115         assertNull(r1.getLocalization(Locale.ENGLISH));
116
117         verifyControls();
118     }
119
120     public void testGetRelativeResource()
121     {
122         WebContext context = newContext();
123
124         replayControls();
125
126         Resource r1 = new WebContextResource(context, "/foo/bar/baz.html");
127         Resource r2 = r1.getRelativeResource("baz.gif");
128
129         assertEquals("/foo/bar/baz.gif", r2.getPath());
130
131         verifyControls();
132     }
133 }
Popular Tags