Search in sources :

Example 1 with DefaultScannerWsClient

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

the class DefaultServerTest method publicRootUrl.

@Test
public void publicRootUrl() {
    MapSettings settings = new MapSettings();
    DefaultScannerWsClient client = mock(DefaultScannerWsClient.class);
    when(client.baseUrl()).thenReturn("http://foo.com/");
    DefaultServer metadata = new DefaultServer(settings.asConfig(), 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 : MapSettings(org.sonar.api.config.internal.MapSettings) DefaultScannerWsClient(org.sonar.scanner.bootstrap.DefaultScannerWsClient) Test(org.junit.Test)

Example 2 with DefaultScannerWsClient

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

the class DefaultServerTest method shouldLoadServerProperties.

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

Example 3 with DefaultScannerWsClient

use of org.sonar.scanner.bootstrap.DefaultScannerWsClient 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() {
    MapSettings settings = new MapSettings();
    settings.setProperty(CoreProperties.SERVER_STARTTIME, "invalid");
    DefaultScannerWsClient client = mock(DefaultScannerWsClient.class);
    DefaultServer metadata = new DefaultServer(settings.asConfig(), client, null);
    metadata.getStartedAt();
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) DefaultScannerWsClient(org.sonar.scanner.bootstrap.DefaultScannerWsClient) Test(org.junit.Test)

Example 4 with DefaultScannerWsClient

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

the class DefaultRulesLoaderTest method testParseServerResponse.

@Test
public void testParseServerResponse() throws IOException {
    DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.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 : InputStream(java.io.InputStream) DefaultScannerWsClient(org.sonar.scanner.bootstrap.DefaultScannerWsClient) Rule(org.sonarqube.ws.Rules.ListResponse.Rule) Test(org.junit.Test)

Example 5 with DefaultScannerWsClient

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

the class DefaultRulesLoaderTest method testError.

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

Aggregations

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