Search in sources :

Example 21 with MapSettings

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");
}
Also used : Server(org.sonar.api.platform.Server) MapSettings(org.sonar.api.config.MapSettings) InputStream(java.io.InputStream) Properties(java.util.Properties) CoreProperties(org.sonar.api.CoreProperties) URI(java.net.URI) Test(org.junit.Test)

Example 22 with MapSettings

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));
}
Also used : SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) MapSettings(org.sonar.api.config.MapSettings) NoRouteToHostException(java.net.NoRouteToHostException) URI(java.net.URI) Test(org.junit.Test)

Example 23 with MapSettings

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();
}
Also used : MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 24 with MapSettings

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));
}
Also used : MapSettings(org.sonar.api.config.MapSettings) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 25 with MapSettings

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);
}
Also used : MapSettings(org.sonar.api.config.MapSettings) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Aggregations

MapSettings (org.sonar.api.config.MapSettings)98 Test (org.junit.Test)75 Settings (org.sonar.api.config.Settings)36 Before (org.junit.Before)20 URI (java.net.URI)13 Languages (org.sonar.api.resources.Languages)9 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)9 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)8 File (java.io.File)7 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)7 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)6 Properties (java.util.Properties)5 IndexedFile (org.sonar.api.batch.fs.IndexedFile)5 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)5 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)5 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)5 InputFile (org.sonar.api.batch.fs.InputFile)4 InputStream (java.io.InputStream)3 Description (org.hamcrest.Description)3 CoreProperties (org.sonar.api.CoreProperties)3