Search in sources :

Example 1 with SonarApplication

use of org.sonarlint.intellij.SonarApplication in project sonarlint-intellij by SonarSource.

the class ConnectionTestTaskTest method prepare.

@Before
public void prepare() {
    super.register(app, SonarApplication.class, new SonarApplication());
    super.register(app, GlobalLogOutput.class, globalLogOutput);
}
Also used : SonarApplication(org.sonarlint.intellij.SonarApplication) Before(org.junit.Before)

Example 2 with SonarApplication

use of org.sonarlint.intellij.SonarApplication in project sonarlint-intellij by SonarSource.

the class SonarLintUtils method getServerConfiguration.

public static ServerConfiguration getServerConfiguration(SonarQubeServer server, int connectTimeout, int readTimeout) {
    CertificateManager certificateManager = get(CertificateManager.class);
    SonarApplication sonarlint = get(SonarApplication.class);
    ServerConfiguration.Builder serverConfigBuilder = ServerConfiguration.builder().userAgent("SonarLint IntelliJ " + sonarlint.getVersion()).connectTimeoutMilliseconds(connectTimeout).readTimeoutMilliseconds(readTimeout).sslSocketFactory(certificateManager.getSslContext().getSocketFactory()).trustManager(certificateManager.getCustomTrustManager()).url(server.getHostUrl());
    if (!isBlank(server.getOrganizationKey())) {
        serverConfigBuilder.organizationKey(server.getOrganizationKey());
    }
    if (!isBlank(server.getToken())) {
        serverConfigBuilder.token(server.getToken());
    } else {
        serverConfigBuilder.credentials(server.getLogin(), server.getPassword());
    }
    if (server.enableProxy()) {
        configureProxy(server.getHostUrl(), serverConfigBuilder);
    }
    return serverConfigBuilder.build();
}
Also used : SonarApplication(org.sonarlint.intellij.SonarApplication) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) CertificateManager(com.intellij.util.net.ssl.CertificateManager)

Example 3 with SonarApplication

use of org.sonarlint.intellij.SonarApplication in project sonarlint-intellij by SonarSource.

the class SonarLintUtilsTest method testServerConfigurationToken.

@Test
public void testServerConfigurationToken() {
    SonarApplication app = mock(SonarApplication.class);
    when(app.getVersion()).thenReturn("1.0");
    super.register(ApplicationManager.getApplication(), SonarApplication.class, app);
    SonarQubeServer server = SonarQubeServer.newBuilder().setHostUrl("http://myhost").setEnableProxy(false).setToken("token").build();
    ServerConfiguration config = SonarLintUtils.getServerConfiguration(server);
    assertThat(config.getLogin()).isEqualTo(server.getToken());
    assertThat(config.getPassword()).isNull();
    assertThat(config.getConnectTimeoutMs()).isEqualTo(SonarLintUtils.CONNECTION_TIMEOUT_MS);
    assertThat(config.getReadTimeoutMs()).isEqualTo(SonarLintUtils.READ_TIMEOUT_MS);
    assertThat(config.getUserAgent()).contains("SonarLint");
    assertThat(config.getUrl()).isEqualTo(server.getHostUrl());
    assertThat(config.getOrganizationKey()).isNull();
}
Also used : SonarApplication(org.sonarlint.intellij.SonarApplication) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) SonarTest(org.sonarlint.intellij.SonarTest) Test(org.junit.Test)

Example 4 with SonarApplication

use of org.sonarlint.intellij.SonarApplication in project sonarlint-intellij by SonarSource.

the class SonarLintUtilsTest method testServerConfigurationPassword.

@Test
public void testServerConfigurationPassword() {
    SonarApplication app = mock(SonarApplication.class);
    when(app.getVersion()).thenReturn("1.0");
    super.register(ApplicationManager.getApplication(), SonarApplication.class, app);
    SonarQubeServer server = SonarQubeServer.newBuilder().setHostUrl("http://myhost").setLogin("token").setPassword("pass").build();
    ServerConfiguration config = SonarLintUtils.getServerConfiguration(server);
    assertThat(config.getLogin()).isEqualTo(server.getLogin());
    assertThat(config.getPassword()).isEqualTo(server.getPassword());
}
Also used : SonarApplication(org.sonarlint.intellij.SonarApplication) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) SonarTest(org.sonarlint.intellij.SonarTest) Test(org.junit.Test)

Aggregations

SonarApplication (org.sonarlint.intellij.SonarApplication)4 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)3 Test (org.junit.Test)2 SonarTest (org.sonarlint.intellij.SonarTest)2 SonarQubeServer (org.sonarlint.intellij.config.global.SonarQubeServer)2 CertificateManager (com.intellij.util.net.ssl.CertificateManager)1 Before (org.junit.Before)1