Search in sources :

Example 6 with ValidationResult

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

the class WsHelperImplTest method testConnectionOrganizationNotFound.

@Test
public void testConnectionOrganizationNotFound() throws Exception {
    WsClientTestUtils.addResponse(client, "api/system/status", "{\"id\": \"20160308094653\",\"version\": \"6.3\",\"status\": \"UP\"}");
    String content = Resources.toString(this.getClass().getResource(RESPONSE_FILE_LTS), StandardCharsets.UTF_8);
    WsClientTestUtils.addResponse(client, PluginListDownloader.WS_PATH_LTS, content);
    WsClientTestUtils.addResponse(client, "api/authentication/validate?format=json", "{\"valid\": true}");
    WsClientTestUtils.addStreamResponse(client, "api/organizations/search.protobuf?organizations=myOrg&ps=500&p=1", "/orgs/empty.pb");
    ValidationResult validation = WsHelperImpl.validateConnection(client, "myOrg");
    assertThat(validation.success()).isFalse();
    assertThat(validation.message()).isEqualTo("No organizations found for key: myOrg");
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) Test(org.junit.Test)

Example 7 with ValidationResult

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

the class WsHelperImplTest method testConnection_ok_with_org.

@Test
public void testConnection_ok_with_org() throws Exception {
    WsClientTestUtils.addResponse(client, "api/system/status", "{\"id\": \"20160308094653\",\"version\": \"6.3\",\"status\": \"UP\"}");
    String content = Resources.toString(this.getClass().getResource(RESPONSE_FILE_LTS), StandardCharsets.UTF_8);
    WsClientTestUtils.addResponse(client, PluginListDownloader.WS_PATH_LTS, content);
    WsClientTestUtils.addResponse(client, "api/authentication/validate?format=json", "{\"valid\": true}");
    WsClientTestUtils.addStreamResponse(client, "api/organizations/search.protobuf?organizations=henryju-github&ps=500&p=1", "/orgs/single.pb");
    WsClientTestUtils.addStreamResponse(client, "api/organizations/search.protobuf?organizations=henryju-github&ps=500&p=2", "/orgs/empty.pb");
    ValidationResult validation = WsHelperImpl.validateConnection(client, "henryju-github");
    assertThat(validation.success()).isTrue();
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) Test(org.junit.Test)

Example 8 with ValidationResult

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

the class AuthenticationCheckerTest method test_connection_issue.

@Test
public void test_connection_issue() {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    WsClientTestUtils.addFailedResponse(wsClient, "api/authentication/validate?format=json", 500, "Foo");
    AuthenticationChecker checker = new AuthenticationChecker(wsClient);
    ValidationResult validationResult = checker.validateCredentials();
    assertThat(validationResult.success()).isFalse();
    assertThat(validationResult.message()).isEqualTo("HTTP Connection failed (500): Foo");
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 9 with ValidationResult

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

the class AuthenticationCheckerTest method test_authentication_ko.

@Test
public void test_authentication_ko() {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/authentication/validate?format=json", "{\"valid\": false}");
    AuthenticationChecker checker = new AuthenticationChecker(wsClient);
    ValidationResult validationResult = checker.validateCredentials();
    assertThat(validationResult.success()).isFalse();
    assertThat(validationResult.message()).isEqualTo("Authentication failed");
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 10 with ValidationResult

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

the class ServerVersionAndStatusCheckerTest method incompatibleVersion.

@Test
public void incompatibleVersion() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/system/status", "{\"id\": \"20160308094653\",\"version\": \"4.5\",\"status\": \"UP\"}");
    ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
    ValidationResult validateStatusAndVersion = checker.validateStatusAndVersion();
    assertThat(validateStatusAndVersion.success()).isFalse();
    assertThat(validateStatusAndVersion.message()).isEqualTo("SonarQube server has version 4.5. Version should be greater or equal to 5.6");
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

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