@Override
public String getURL() {
+ String serverBaseUrl = settings.getString(SERVER_BASE_URL);
+ if (isEmpty(serverBaseUrl)) {
+ return computeUrl();
+ }
+ return serverBaseUrl;
+ }
+
+ private String computeUrl() {
String host = settings.getString("sonar.web.host");
int port = settings.getInt("sonar.web.port");
String context = settings.getString("sonar.web.context");
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
+import static org.sonar.api.CoreProperties.SERVER_BASE_URL;
public class ServerImplTest {
assertThat(underTest.getURL()).isEqualTo("http://localhost:9000");
}
+ @Test
+ public void getUrl_returns_http_localhost_9000_when_serverBaseUrl_is_null() {
+ settings.setProperty(SERVER_BASE_URL, (String) null);
+ assertThat(underTest.getURL()).isEqualTo("http://localhost:9000");
+ }
+
+
+ @Test
+ public void getUrl_returns_serverBaseUrl_it_is_non_empty() {
+ String serverBaseUrl = "whatever";
+ settings.setProperty(SERVER_BASE_URL, serverBaseUrl);
+ assertThat(underTest.getURL()).isEqualTo(serverBaseUrl);
+ }
+
+ @Test
+ public void getUrl_returns_http_localhost_9000_when_serverBaseUrl_is_empty() {
+ settings.setProperty(SERVER_BASE_URL, "");
+ assertThat(underTest.getURL()).isEqualTo("http://localhost:9000");
+ }
+
@Test
public void getUrl_returns_http_localhost_9000_when_host_set_to_0_0_0_0() {
settings.setProperty(HOST_PROPERTY, "0.0.0.0");
/**
* @return the server URL
- * @since since 2.4 on batch side only, since 5.6 on both batch side and server side
+ * @since since 2.4 on batch side only, since 5.6 on both batch side and server side (WebServer and Compute Engine)
*/
public abstract String getURL();