diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-09-12 10:54:28 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-09-12 17:12:12 +0200 |
commit | 24a49907b94212826a2f1d270371a9e156774f60 (patch) | |
tree | cd6443496ffff75ec2e3c79b35631b4ab807fe61 /sonar-core/src/test | |
parent | 541d1867dd5683455843c2fc8b7c7dc342a9750a (diff) | |
download | sonarqube-24a49907b94212826a2f1d270371a9e156774f60.tar.gz sonarqube-24a49907b94212826a2f1d270371a9e156774f60.zip |
SONAR-6662 add ServerId to HTTP user agent of UPC client
Diffstat (limited to 'sonar-core/src/test')
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java b/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java index 60884967562..3dbd4c88800 100644 --- a/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java @@ -51,6 +51,7 @@ import org.simpleframework.http.Request; import org.simpleframework.http.Response; import org.simpleframework.http.core.Container; import org.simpleframework.transport.connect.SocketConnection; +import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; import org.sonar.api.config.MapSettings; import org.sonar.api.platform.Server; @@ -214,7 +215,22 @@ public class DefaultHttpDownloaderTest { } @Test - public void userAgentIsSonarVersion() throws URISyntaxException, IOException { + public void userAgent_includes_version_and_SERVER_ID_when_server_is_provided() throws URISyntaxException, IOException { + Server server = mock(Server.class); + when(server.getVersion()).thenReturn("2.2"); + MapSettings settings = new MapSettings(); + settings.setProperty(CoreProperties.SERVER_ID, "blablabla"); + + InputStream stream = new DefaultHttpDownloader(server, settings).openStream(new URI(baseUrl)); + Properties props = new Properties(); + props.load(stream); + stream.close(); + + assertThat(props.getProperty("agent")).isEqualTo("SonarQube 2.2 # blablabla"); + } + + @Test + public void userAgent_includes_only_version_when_there_is_no_SERVER_ID_and_server_is_provided() throws URISyntaxException, IOException { Server server = mock(Server.class); when(server.getVersion()).thenReturn("2.2"); @@ -223,7 +239,17 @@ public class DefaultHttpDownloaderTest { props.load(stream); stream.close(); - assertThat(props.getProperty("agent")).isEqualTo("SonarQube 2.2"); + assertThat(props.getProperty("agent")).isEqualTo("SonarQube 2.2 #"); + } + + @Test + public void userAgent_is_static_value_when_server_is_not_provided() throws URISyntaxException, IOException { + InputStream stream = new DefaultHttpDownloader(new MapSettings()).openStream(new URI(baseUrl)); + Properties props = new Properties(); + props.load(stream); + stream.close(); + + assertThat(props.getProperty("agent")).isEqualTo("SonarQube"); } @Test |