Search in sources :

Example 11 with ValidationResult

use of org.sonarsource.sonarlint.core.client.api.connected.ValidationResult in project sonarlint-core by SonarSource.

the class ServerVersionAndStatusCheckerTest method serverNotReady.

@Test
public void serverNotReady() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/system/status", "{\"id\": \"20160308094653\",\"version\": \"5.5-SNAPSHOT\",\"status\": \"DOWN\"}");
    ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
    ValidationResult validateStatusAndVersion = checker.validateStatusAndVersion();
    assertThat(validateStatusAndVersion.success()).isFalse();
    assertThat(validateStatusAndVersion.message()).isEqualTo("Server not ready (DOWN)");
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 12 with ValidationResult

use of org.sonarsource.sonarlint.core.client.api.connected.ValidationResult in project sonarlint-core by SonarSource.

the class WsHelperImpl method validateConnection.

static ValidationResult validateConnection(SonarLintWsClient client, @Nullable String organizationKey) {
    ServerVersionAndStatusChecker serverChecker = new ServerVersionAndStatusChecker(client);
    AuthenticationChecker authChecker = new AuthenticationChecker(client);
    try {
        ServerInfos serverStatus = serverChecker.checkVersionAndStatus();
        ValidationResult validateCredentials = authChecker.validateCredentials();
        if (validateCredentials.success() && organizationKey != null) {
            Version serverVersion = Version.create(serverStatus.getVersion());
            if (serverVersion.compareToIgnoreQualifier(Version.create(MIN_VERSION_FOR_ORGANIZATIONS)) < 0) {
                return new DefaultValidationResult(false, "No organization support for this server version: " + serverStatus.getVersion());
            }
            if (fetchOrganizations(client, organizationKey, new ProgressWrapper(null)).isEmpty()) {
                return new DefaultValidationResult(false, "No organizations found for key: " + organizationKey);
            }
        }
        return validateCredentials;
    } catch (UnsupportedServerException e) {
        return new DefaultValidationResult(false, e.getMessage());
    } catch (RuntimeException e) {
        throw SonarLintWrappedException.wrap(e);
    }
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker) Version(org.sonarsource.sonarlint.core.plugin.Version) AuthenticationChecker(org.sonarsource.sonarlint.core.container.connected.validate.AuthenticationChecker) DefaultValidationResult(org.sonarsource.sonarlint.core.container.connected.validate.DefaultValidationResult) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos) ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) DefaultValidationResult(org.sonarsource.sonarlint.core.container.connected.validate.DefaultValidationResult) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)

Example 13 with ValidationResult

use of org.sonarsource.sonarlint.core.client.api.connected.ValidationResult 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)

Aggregations

ValidationResult (org.sonarsource.sonarlint.core.client.api.connected.ValidationResult)13 Test (org.junit.Test)11 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)5 CommitStepException (com.intellij.ide.wizard.CommitStepException)1 SonarQubeServer (org.sonarlint.intellij.config.global.SonarQubeServer)1 ConnectionTestTask (org.sonarlint.intellij.tasks.ConnectionTestTask)1 WsHelperImpl (org.sonarsource.sonarlint.core.WsHelperImpl)1 UnsupportedServerException (org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)1 AuthenticationChecker (org.sonarsource.sonarlint.core.container.connected.validate.AuthenticationChecker)1 DefaultValidationResult (org.sonarsource.sonarlint.core.container.connected.validate.DefaultValidationResult)1 ServerVersionAndStatusChecker (org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker)1 Version (org.sonarsource.sonarlint.core.plugin.Version)1 ServerInfos (org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)1 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)1