use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.
the class DefaultHttpDownloaderTest method userAgent_includes_version_and_SERVER_ID_when_server_is_provided.
@Test
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");
}
use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.
the class DefaultHttpDownloaderTest method openStream_network_errors.
@Test(timeout = 10000)
public void openStream_network_errors() throws IOException, URISyntaxException {
// non routable address
String url = "http://10.255.255.1";
thrown.expect(SonarException.class);
thrown.expect(hasCause(new BaseMatcher<Exception>() {
@Override
public boolean matches(Object ex) {
return // Java 8
ex instanceof NoRouteToHostException || ex instanceof SocketException || // Java 7 or before
ex instanceof SocketTimeoutException;
}
@Override
public void describeTo(Description arg0) {
}
}));
DefaultHttpDownloader downloader = new DefaultHttpDownloader(new MapSettings(), 10, 50000);
downloader.openStream(new URI(url));
}
use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.
the class DefaultCpdTokensTest method handle_exclusions_by_pattern.
@Test
public void handle_exclusions_by_pattern() {
SensorStorage sensorStorage = mock(SensorStorage.class);
Settings settings = new MapSettings();
settings.setProperty("sonar.cpd.exclusions", "src/Foo.java,another");
DefaultCpdTokens tokens = new DefaultCpdTokens(settings, sensorStorage).onFile(INPUT_FILE).addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
tokens.save();
verifyZeroInteractions(sensorStorage);
assertThat(tokens.getTokenLines()).isEmpty();
}
use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.
the class DefaultCpdTokensTest method save_many_tokens.
@Test
public void save_many_tokens() {
SensorStorage sensorStorage = mock(SensorStorage.class);
DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage).onFile(INPUT_FILE).addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo").addToken(INPUT_FILE.newRange(1, 6, 1, 10), "bar").addToken(INPUT_FILE.newRange(1, 20, 1, 25), "biz").addToken(INPUT_FILE.newRange(2, 1, 2, 10), "next");
tokens.save();
verify(sensorStorage).store(tokens);
assertThat(tokens.getTokenLines()).extracting("value", "startLine", "hashCode", "startUnit", "endUnit").containsExactly(tuple("foobarbiz", 1, "foobarbiz".hashCode(), 1, 3), tuple("next", 2, "next".hashCode(), 4, 4));
}
use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.
the class DefaultCpdTokensTest method save_no_tokens.
@Test
public void save_no_tokens() {
SensorStorage sensorStorage = mock(SensorStorage.class);
DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage).onFile(INPUT_FILE);
tokens.save();
verify(sensorStorage).store(tokens);
assertThat(tokens.inputFile()).isEqualTo(INPUT_FILE);
}
Aggregations