Search in sources :

Example 1 with ServerApiHelper

use of org.sonarsource.sonarlint.core.serverapi.ServerApiHelper in project sonarlint-core by SonarSource.

the class ConnectionValidatorTests method testConnection_ok_with_org.

@Test
void testConnection_ok_with_org() throws Exception {
    var underTest = new ConnectionValidator(new ServerApiHelper(mockServer.endpointParams("henryju-github"), MockWebServerExtension.httpClient()));
    mockServer.addStringResponse("/api/system/status", "{\"id\": \"20160308094653\",\"version\": \"7.9\",\"status\": \"UP\"}");
    mockServer.addStringResponse("/api/authentication/validate?format=json", "{\"valid\": true}");
    mockServer.addResponseFromResource("/api/organizations/search.protobuf?organizations=henryju-github&ps=500&p=1", "/orgs/single.pb");
    mockServer.addResponseFromResource("/api/organizations/search.protobuf?organizations=henryju-github&ps=500&p=2", "/orgs/empty.pb");
    var futureValidation = underTest.validateConnection();
    var validation = futureValidation.get();
    assertThat(validation.success()).isTrue();
}
Also used : ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) Test(org.junit.jupiter.api.Test)

Example 2 with ServerApiHelper

use of org.sonarsource.sonarlint.core.serverapi.ServerApiHelper in project sonarlint-core by SonarSource.

the class ConnectionValidatorTests method testUnsupportedServer.

@Test
void testUnsupportedServer() throws ExecutionException, InterruptedException {
    var underTest = new ConnectionValidator(new ServerApiHelper(mockServer.endpointParams(), MockWebServerExtension.httpClient()));
    mockServer.addStringResponse("/api/system/status", "{\"id\": \"20160308094653\",\"version\": \"6.7\",\"status\": \"UP\"}");
    when(serverChecker.checkVersionAndStatus()).thenThrow(UnsupportedServerException.class);
    var futureValidation = underTest.validateConnection();
    var validation = futureValidation.get();
    assertThat(validation.success()).isFalse();
    assertThat(validation.message()).isEqualTo("SonarQube server has version 6.7. Version should be greater or equal to 7.9");
}
Also used : ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) Test(org.junit.jupiter.api.Test)

Example 3 with ServerApiHelper

use of org.sonarsource.sonarlint.core.serverapi.ServerApiHelper in project sonarlint-core by SonarSource.

the class ConnectionValidatorTests method testResponseError.

@Test
void testResponseError() throws ExecutionException, InterruptedException {
    var underTest = new ConnectionValidator(new ServerApiHelper(mockServer.endpointParams(), MockWebServerExtension.httpClient()));
    mockServer.addStringResponse("/api/system/status", "{\"id\": }");
    var futureValidation = underTest.validateConnection();
    var validation = futureValidation.get();
    assertThat(validation.success()).isFalse();
    assertThat(validation.message()).isEqualTo("Unable to parse server infos from: {\"id\": }");
}
Also used : ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) Test(org.junit.jupiter.api.Test)

Example 4 with ServerApiHelper

use of org.sonarsource.sonarlint.core.serverapi.ServerApiHelper in project sonarlint-core by SonarSource.

the class ConnectedSonarLintEngineImpl method downloadServerIssues.

private List<ServerIssue> downloadServerIssues(EndpointParams endpoint, HttpClient client, ProjectBinding projectBinding, String ideFilePath, boolean fetchTaintVulnerabilities, @Nullable String branchName, ProgressMonitor progress) {
    var updater = partialUpdaterFactory.create();
    var configuration = storageReader.readProjectConfig(projectBinding.projectKey());
    updater.updateFileIssues(new ServerApiHelper(endpoint, client), projectBinding, configuration, ideFilePath, fetchTaintVulnerabilities, branchName, progress);
    return getServerIssues(projectBinding, ideFilePath);
}
Also used : ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)

Example 5 with ServerApiHelper

use of org.sonarsource.sonarlint.core.serverapi.ServerApiHelper in project sonarlint-core by SonarSource.

the class ConnectedSonarLintEngineImpl method updateProject.

@Override
public void updateProject(EndpointParams endpoint, HttpClient client, String projectKey, boolean fetchTaintVulnerabilities, @Nullable String branchName, @Nullable ClientProgressMonitor monitor) {
    requireNonNull(endpoint);
    requireNonNull(projectKey);
    setLogging(null);
    var globalStorageStatus = globalStatusReader.read();
    if (globalStorageStatus == null || globalStorageStatus.isStale()) {
        throw new StorageException("Missing or outdated storage for connection '" + globalConfig.getConnectionId() + "'");
    }
    projectStorageUpdateExecutor.update(new ServerApiHelper(endpoint, client), projectKey, fetchTaintVulnerabilities, branchName, new ProgressMonitor(monitor));
}
Also used : ClientProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException)

Aggregations

ServerApiHelper (org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)18 Test (org.junit.jupiter.api.Test)10 ClientProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor)4 ProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor)4 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 PluginDetails (org.sonarsource.sonarlint.core.client.api.common.PluginDetails)2 ConnectedGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration)2 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)2 ConnectionValidator (org.sonarsource.sonarlint.core.client.api.connected.ConnectionValidator)2 UpdateResult (org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)2 StorageException (org.sonarsource.sonarlint.core.client.api.exceptions.StorageException)2 Orchestrator (com.sonar.orchestrator.Orchestrator)1 MavenLocation (com.sonar.orchestrator.locator.MavenLocation)1 SONAR_VERSION (its.tools.ItUtils.SONAR_VERSION)1 Paths (java.nio.file.Paths)1 Collection (java.util.Collection)1 Collections.emptySet (java.util.Collections.emptySet)1