1 15 package org.apache.tapestry.services.impl; 16 17 import javax.servlet.http.HttpServletRequest ; 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 30 public class TestAbsoluteURLBuilder extends TapestryTestCase 31 { 32 private void attempt(String expected, String URI, String scheme, String server, int port) 33 { 34 AbsoluteURLBuilder b = new AbsoluteURLBuilderImpl(); 35 36 String actual = b.constructURL(URI, scheme, server, port); 37 38 assertEquals(expected, actual); 39 } 40 41 private void attemptDefault(String expected, String URI, String scheme, String 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 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 |