Search in sources :

Example 1 with ScannerWsClient

use of org.sonar.scanner.bootstrap.ScannerWsClient in project sonarqube by SonarSource.

the class DefaultServerTest method publicRootUrl.

@Test
public void publicRootUrl() {
    Settings settings = new MapSettings();
    ScannerWsClient client = mock(ScannerWsClient.class);
    when(client.baseUrl()).thenReturn("http://foo.com/");
    DefaultServer metadata = new DefaultServer(settings, client, null);
    settings.setProperty(CoreProperties.SERVER_BASE_URL, "http://server.com/");
    assertThat(metadata.getPublicRootUrl()).isEqualTo("http://server.com");
    settings.removeProperty(CoreProperties.SERVER_BASE_URL);
    assertThat(metadata.getPublicRootUrl()).isEqualTo("http://foo.com");
}
Also used : ScannerWsClient(org.sonar.scanner.bootstrap.ScannerWsClient) MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 2 with ScannerWsClient

use of org.sonar.scanner.bootstrap.ScannerWsClient in project sonarqube by SonarSource.

the class DefaultRulesLoaderTest method testParseServerResponse.

@Test
public void testParseServerResponse() throws IOException {
    ScannerWsClient wsClient = mock(ScannerWsClient.class);
    InputStream is = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoaderTest/response.protobuf")).openBufferedStream();
    WsTestUtil.mockStream(wsClient, is);
    DefaultRulesLoader loader = new DefaultRulesLoader(wsClient);
    List<Rule> ruleList = loader.load();
    assertThat(ruleList).hasSize(318);
}
Also used : ScannerWsClient(org.sonar.scanner.bootstrap.ScannerWsClient) InputStream(java.io.InputStream) Rule(org.sonarqube.ws.Rules.ListResponse.Rule) Test(org.junit.Test)

Example 3 with ScannerWsClient

use of org.sonar.scanner.bootstrap.ScannerWsClient in project sonarqube by SonarSource.

the class DefaultRulesLoaderTest method testError.

@Test
public void testError() throws IOException {
    ScannerWsClient wsClient = mock(ScannerWsClient.class);
    InputStream is = ByteSource.wrap(new String("trash").getBytes()).openBufferedStream();
    WsTestUtil.mockStream(wsClient, is);
    DefaultRulesLoader loader = new DefaultRulesLoader(wsClient);
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Unable to get rules");
    loader.load();
}
Also used : ScannerWsClient(org.sonar.scanner.bootstrap.ScannerWsClient) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 4 with ScannerWsClient

use of org.sonar.scanner.bootstrap.ScannerWsClient in project sonarqube by SonarSource.

the class DefaultServerTest method invalid_startup_date_throws_exception.

@Test(expected = RuntimeException.class)
public void invalid_startup_date_throws_exception() {
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.SERVER_STARTTIME, "invalid");
    ScannerWsClient client = mock(ScannerWsClient.class);
    DefaultServer metadata = new DefaultServer(settings, client, null);
    metadata.getStartedAt();
}
Also used : ScannerWsClient(org.sonar.scanner.bootstrap.ScannerWsClient) MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 5 with ScannerWsClient

use of org.sonar.scanner.bootstrap.ScannerWsClient in project sonarqube by SonarSource.

the class DefaultServerTest method shouldLoadServerProperties.

@Test
public void shouldLoadServerProperties() {
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.SERVER_ID, "123");
    settings.setProperty(CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000");
    settings.setProperty(CoreProperties.PERMANENT_SERVER_ID, "abcde");
    ScannerWsClient client = mock(ScannerWsClient.class);
    when(client.baseUrl()).thenReturn("http://foo.com");
    DefaultServer metadata = new DefaultServer(settings, client, SonarRuntimeImpl.forSonarQube(Version.parse("2.2"), SonarQubeSide.SCANNER));
    assertThat(metadata.getId()).isEqualTo("123");
    assertThat(metadata.getVersion()).isEqualTo("2.2");
    assertThat(metadata.getStartedAt()).isNotNull();
    assertThat(metadata.getURL()).isEqualTo("http://foo.com");
    assertThat(metadata.getPermanentServerId()).isEqualTo("abcde");
    assertThat(metadata.getRootDir()).isNull();
    assertThat(metadata.getDeployDir()).isNull();
    assertThat(metadata.getContextPath()).isNull();
    assertThat(metadata.isDev()).isFalse();
    assertThat(metadata.isSecured()).isFalse();
}
Also used : ScannerWsClient(org.sonar.scanner.bootstrap.ScannerWsClient) MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 ScannerWsClient (org.sonar.scanner.bootstrap.ScannerWsClient)5 MapSettings (org.sonar.api.config.MapSettings)3 Settings (org.sonar.api.config.Settings)3 InputStream (java.io.InputStream)2 Rule (org.sonarqube.ws.Rules.ListResponse.Rule)1