Search in sources :

Example 61 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class DefaultHttpDownloaderTest method followRedirect.

@Test
public void followRedirect() throws URISyntaxException {
    String content = new DefaultHttpDownloader(new MapSettings()).readString(new URI(baseUrl + "/redirect/"), StandardCharsets.UTF_8);
    assertThat(content).contains("agent");
}
Also used : MapSettings(org.sonar.api.config.MapSettings) URI(java.net.URI) Test(org.junit.Test)

Example 62 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class DefaultHttpDownloaderTest method userAgent_includes_only_version_when_there_is_no_SERVER_ID_and_server_is_provided.

@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");
    InputStream stream = new DefaultHttpDownloader(server, new MapSettings()).openStream(new URI(baseUrl));
    Properties props = new Properties();
    props.load(stream);
    stream.close();
    assertThat(props.getProperty("agent")).isEqualTo("SonarQube 2.2 #");
}
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 63 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class DefaultHttpDownloaderTest method readStringWithTimeout.

@Test
public void readStringWithTimeout() throws URISyntaxException {
    thrown.expect(new BaseMatcher<Exception>() {

        @Override
        public boolean matches(Object ex) {
            return ex instanceof SonarException && ((SonarException) ex).getCause() instanceof SocketTimeoutException;
        }

        @Override
        public void describeTo(Description arg0) {
        }
    });
    new DefaultHttpDownloader(new MapSettings(), 50).readString(new URI(baseUrl + "/timeout/"), StandardCharsets.UTF_8);
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) Description(org.hamcrest.Description) MapSettings(org.sonar.api.config.MapSettings) SonarException(org.sonar.api.utils.SonarException) URI(java.net.URI) SonarException(org.sonar.api.utils.SonarException) URISyntaxException(java.net.URISyntaxException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) NoRouteToHostException(java.net.NoRouteToHostException) Test(org.junit.Test)

Example 64 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class DefaultHttpDownloaderTest method shouldNotCreateFileIfFailToDownload.

@Test
public void shouldNotCreateFileIfFailToDownload() throws Exception {
    File toDir = temporaryFolder.newFolder();
    File toFile = new File(toDir, "downloadToFile.txt");
    try {
        int port = new InetSocketAddress("localhost", 0).getPort();
        new DefaultHttpDownloader(new MapSettings()).download(new URI("http://localhost:" + port), toFile);
    } catch (SonarException e) {
        assertThat(toFile).doesNotExist();
    }
}
Also used : MapSettings(org.sonar.api.config.MapSettings) InetSocketAddress(java.net.InetSocketAddress) SonarException(org.sonar.api.utils.SonarException) File(java.io.File) URI(java.net.URI) Test(org.junit.Test)

Example 65 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class ProjectBuilderTest method shouldChangeProject.

@Test
public void shouldChangeProject() {
    // this reactor is created and provided by Sonar
    final ProjectReactor projectReactor = new ProjectReactor(ProjectDefinition.create());
    ProjectBuilder builder = new ProjectBuilderSample(new MapSettings());
    builder.build(new ProjectBuilderContext(projectReactor));
    assertThat(projectReactor.getProjects().size(), is(2));
    ProjectDefinition root = projectReactor.getRoot();
    assertThat(root.getName(), is("Name changed by plugin"));
    assertThat(root.getSubProjects().size(), is(1));
    assertThat(root.getSubProjects().get(0).sources()).contains("src");
}
Also used : ProjectBuilderContext(org.sonar.api.batch.bootstrap.internal.ProjectBuilderContext) MapSettings(org.sonar.api.config.MapSettings) 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