BaseURLSourceImpl implements BaseURLSource { public String getBaseURL(boolean secure) { return String.format("%s: secure ? "https" : "http", hostname(), portExtension(secure)); } BaseURLSourceImpl(Request request, @Inject @Symbol(SymbolConstants.HOSTNAME) String hostname,
                             @Symbol(SymbolConstants.HOSTPORT) int hostPort, @Symbol(SymbolConstants.HOSTPORT_SECURE) int secureHostPort); String getBaseURL(boolean secure);  }
@Test public void server_name_from_request_object() { expect(request.getServerName()).andReturn("localhost").once(); expect(request.getServerPort()).andReturn(80).once(); expect(request.isSecure()).andReturn(false); replay(); BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "", 0, 0); assertEquals(baseURLSource.getBaseURL(false), "http: verify(); }
@Test public void contributed_hostname() { expect(request.getServerPort()).andReturn(80).once(); expect(request.isSecure()).andReturn(false); replay(); BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "my.server.com", 0, 0); assertEquals(baseURLSource.getBaseURL(false), "http: verify(); }
@Test public void hostname_from_environment_variable() { expect(request.getServerPort()).andReturn(80).once(); expect(request.isSecure()).andReturn(false); replay(); BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "$HOSTNAME", 0, 0); assertEquals(baseURLSource.getBaseURL(false), "http: verify(); }
@Test public void insecure_url_using_default_port() { replay(); BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "localhost", 80, 443); assertEquals(baseURLSource.getBaseURL(false), "http: verify(); }
@Test public void secure_url_using_default_port() { replay(); BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "localhost", 80, 443); assertEquals(baseURLSource.getBaseURL(true), "https: verify(); }
@Test public void getBaseURLWithContributedNonStandardSecurePort() { replay(); BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "localhost", 80, 8443); assertEquals(baseURLSource.getBaseURL(true), "https: verify(); }
@Test public void secure_url_without_configured_hostports() { expect(request.isSecure()).andReturn(false).once(); replay(); BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "localhost", 0, 0); assertEquals(baseURLSource.getBaseURL(true), "https: verify(); }