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");
}
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();
}
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();
}
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);
}
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");
}
Aggregations