KickJava   Java API By Example, From Geeks To Geeks.

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


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.services.impl;
16
17 import javax.servlet.http.HttpServletRequest JavaDoc;
18
19 import org.apache.tapestry.junit.TapestryTestCase;
20 import org.apache.tapestry.services.AbsoluteURLBuilder;
21 import org.apache.tapestry.web.WebRequest;
22 import org.easymock.MockControl;
23
24 /**
25  * Tests for {@link org.apache.tapestry.services.impl.AbsoluteURLBuilderImpl}.
26  *
27  * @author Howard M. Lewis Ship
28  * @since 4.0
29  */

30 public class TestAbsoluteURLBuilder extends TapestryTestCase
31 {
32     private void attempt(String JavaDoc expected, String JavaDoc URI, String JavaDoc scheme, String JavaDoc server, int port)
33     {
34         AbsoluteURLBuilder b = new AbsoluteURLBuilderImpl();
35
36         String JavaDoc actual = b.constructURL(URI, scheme, server, port);
37
38         assertEquals(expected, actual);
39     }
40
41     private void attemptDefault(String JavaDoc expected, String JavaDoc URI, String JavaDoc scheme, String JavaDoc server, int port)
42     {
43         MockControl control = newControl(WebRequest.class);
44         WebRequest request = (WebRequest) control.getMock();
45
46         request.getScheme();
47         control.setReturnValue(scheme);
48
49         request.getServerName();
50         control.setReturnValue(server);
51
52         request.getServerPort();
53         control.setReturnValue(port);
54
55         replayControls();
56
57         AbsoluteURLBuilderImpl b = new AbsoluteURLBuilderImpl();
58         b.setRequest(request);
59
60         String JavaDoc actual = b.constructURL(URI);
61
62         assertEquals(expected, actual);
63
64         verifyControls();
65     }
66
67     public void testURIIncludesServer()
68     {
69         attempt("https://foo/bar/baz", "//foo/bar/baz", "https", "SERVER", 100);
70     }
71
72     public void testPortZero()
73     {
74         attempt("http://foo/bar/baz", "/bar/baz", "http", "foo", 0);
75     }
76
77     public void testNoLeadingSlash()
78     {
79         attempt("http://foo/bar/baz", "bar/baz", "http", "foo", 0);
80     }
81
82     public void testPortNonZero()
83     {
84         attempt("http://foo.com:1024/bar/baz", "/bar/baz", "http", "foo.com", 1024);
85     }
86
87     public void testDefaultsForPort80()
88     {
89         attemptDefault("http://foo/bar/baz", "/bar/baz", "http", "foo", 80);
90     }
91
92     public void testDefault()
93     {
94         attemptDefault("http://foo:8080/bar/baz", "/bar/baz", "http", "foo", 8080);
95     }
96 }
Popular Tags