Search in sources :

Example 1 with ConnectionTestTask

use of org.sonarlint.intellij.tasks.ConnectionTestTask in project sonarlint-intellij by SonarSource.

the class AuthStep method checkConnection.

private void checkConnection() throws CommitStepException {
    SonarQubeServer tmpServer = model.createServerWithoutOrganization();
    ConnectionTestTask test = new ConnectionTestTask(tmpServer);
    ProgressManager.getInstance().run(test);
    ValidationResult r = test.result();
    String msg = "Failed to connect to the server. Please check the configuration.";
    if (test.getException() != null) {
        if (test.getException().getMessage() != null) {
            msg = msg + " Error: " + test.getException().getMessage();
        }
        throw new CommitStepException(msg);
    } else if (!r.success()) {
        throw new CommitStepException(msg + " Cause: " + r.message());
    }
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) ConnectionTestTask(org.sonarlint.intellij.tasks.ConnectionTestTask) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult)

Example 2 with ConnectionTestTask

use of org.sonarlint.intellij.tasks.ConnectionTestTask in project sonarlint-intellij by SonarSource.

the class ConnectionTestTaskTest method fail_if_no_connection.

@Test
public void fail_if_no_connection() {
    SonarQubeServer server = SonarQubeServer.newBuilder().setHostUrl("invalid_url").build();
    ConnectionTestTask task = new ConnectionTestTask(server);
    ProgressIndicator progress = mock(ProgressIndicator.class);
    task.run(progress);
    verify(progress).setIndeterminate(true);
    assertThat(task.getException()).isNotNull();
    assertThat(task.result()).isNull();
    verify(globalLogOutput).logError(eq("Connection test failed"), any(Throwable.class));
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ConnectionTestTask(org.sonarlint.intellij.tasks.ConnectionTestTask) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) SonarTest(org.sonarlint.intellij.SonarTest) Test(org.junit.Test)

Aggregations

SonarQubeServer (org.sonarlint.intellij.config.global.SonarQubeServer)2 ConnectionTestTask (org.sonarlint.intellij.tasks.ConnectionTestTask)2 CommitStepException (com.intellij.ide.wizard.CommitStepException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Test (org.junit.Test)1 SonarTest (org.sonarlint.intellij.SonarTest)1 ValidationResult (org.sonarsource.sonarlint.core.client.api.connected.ValidationResult)1